Make textbox foreground and background configurable.

This commit is contained in:
Aldo Cortesi 2007-12-19 13:20:21 +11:00 committed by Julien Danjou
parent eb57f68ed3
commit 9bb28772ed
4 changed files with 49 additions and 29 deletions

View File

@ -31,6 +31,7 @@
#include "rules.h"
#include "screen.h"
#include "widget.h"
#include "xutil.h"
#include "defconfig.h"
#define AWESOME_CONFIG_FILE ".awesomerc"
@ -55,19 +56,7 @@ extern const NameFuncLink UicbList[];
extern const NameFuncLink WidgetList[];
extern const NameFuncLink LayoutsList[];
/** Initialize color from X side
* \param disp Display ref
* \param scr Screen number
* \param colorstr Color code
*/
static XColor
initxcolor(Display *disp, int scr, const char *colstr)
{
XColor color;
if(!XAllocNamedColor(disp, DefaultColormap(disp, scr), colstr, &color, &color))
die("awesome: error, cannot allocate color '%s'\n", colstr);
return color;
}
static unsigned int
get_numlockmask(Display *disp)
{
@ -346,6 +335,8 @@ config_parse(const char *confpatharg)
static cfg_opt_t widget_textbox_opts[] =
{
CFG_STR((char *) "default", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
CFG_END()
};
static cfg_opt_t statusbar_opts[] =
@ -542,23 +533,17 @@ config_parse(const char *confpatharg)
if(!virtscreen->font)
eprint("awesome: cannot init font\n");
/* Colors */
virtscreen->colors_normal[ColBorder] = initxcolor(globalconf.display,
get_phys_screen(screen),
virtscreen->colors_normal[ColBorder] = initxcolor(screen,
cfg_getstr(cfg_colors, "normal_border"));
virtscreen->colors_normal[ColBG] = initxcolor(globalconf.display,
get_phys_screen(screen),
virtscreen->colors_normal[ColBG] = initxcolor(screen,
cfg_getstr(cfg_colors, "normal_bg"));
virtscreen->colors_normal[ColFG] = initxcolor(globalconf.display,
get_phys_screen(screen),
virtscreen->colors_normal[ColFG] = initxcolor(screen,
cfg_getstr(cfg_colors, "normal_fg"));
virtscreen->colors_selected[ColBorder] = initxcolor(globalconf.display,
get_phys_screen(screen),
virtscreen->colors_selected[ColBorder] = initxcolor(screen,
cfg_getstr(cfg_colors, "focus_border"));
virtscreen->colors_selected[ColBG] = initxcolor(globalconf.display,
get_phys_screen(screen),
virtscreen->colors_selected[ColBG] = initxcolor(screen,
cfg_getstr(cfg_colors, "focus_bg"));
virtscreen->colors_selected[ColFG] = initxcolor(globalconf.display,
get_phys_screen(screen),
virtscreen->colors_selected[ColFG] = initxcolor(screen,
cfg_getstr(cfg_colors, "focus_fg"));
/* Statusbar */

View File

@ -1,6 +1,7 @@
#include <confuse.h>
#include "util.h"
#include "widget.h"
#include "xutil.h"
extern awesome_config globalconf;
@ -9,6 +10,8 @@ typedef struct Data Data;
struct Data
{
char *text;
XColor fg;
XColor bg;
};
@ -36,9 +39,7 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
offset,
widget->alignment);
drawtext(ctx, location, 0, width, vscreen.statusbar->height,
vscreen.font, d->text,
vscreen.colors_normal[ColFG],
vscreen.colors_normal[ColBG]);
vscreen.font, d->text, d->fg, d->bg);
return width;
}
@ -55,15 +56,27 @@ textbox_new(Statusbar *statusbar, cfg_t *config)
{
Widget *w;
Data *d;
char *color;
w = p_new(Widget, 1);
common_new(w, statusbar, config);
w->draw = textbox_draw;
w->tell = textbox_tell;
d = p_new(Data, 1);
w->data = (void*) d;
if ((color = cfg_getstr(config, "fg")))
d->fg = initxcolor(statusbar->screen, color);
else
d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG];
if ((color = cfg_getstr(config, "bg")))
d->bg = initxcolor(statusbar->screen, color);
else
d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG];
update(w, cfg_getstr(config, "default"));
return w;
}

22
xutil.c
View File

@ -18,7 +18,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/extensions/Xinerama.h>
@ -113,4 +112,25 @@ xgettextprop(Display *disp, Window w, Atom atom, char *text, ssize_t textlen)
return True;
}
/** Initialize an X color
* \param screen Screen number
* \param colorstr Color specification
*/
XColor
initxcolor(int screen, const char *colstr)
{
XColor screenColor, exactColor;
int ret, physcreen = get_phys_screen(screen);
ret = XAllocNamedColor(globalconf.display,
DefaultColormap(globalconf.display, physcreen),
colstr,
&screenColor,
&exactColor);
if(!ret)
die("awesome: error, cannot allocate color '%s'\n", colstr);
return screenColor;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -23,8 +23,10 @@
#define AWESOME_XUTIL_H
#include "common.h"
#include "screen.h"
Bool xgettextprop(Display *, Window, Atom, char *, ssize_t);
XColor initxcolor(int, const char *);
UICB_PROTO(uicb_spawn);
UICB_PROTO(uicb_exec);