diff --git a/config.c b/config.c index 39c8b767e..49d07ddcf 100644 --- a/config.c +++ b/config.c @@ -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 */ diff --git a/widgets/textbox.c b/widgets/textbox.c index d0b7a8b04..5714b6adf 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -1,6 +1,7 @@ #include #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; } diff --git a/xutil.c b/xutil.c index f8edc68bb..358a44a7a 100644 --- a/xutil.c +++ b/xutil.c @@ -18,7 +18,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ - #include #include #include @@ -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 diff --git a/xutil.h b/xutil.h index f0608e1b8..db5d3fca7 100644 --- a/xutil.h +++ b/xutil.h @@ -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);