From 9dfd488ddac540e2a2387e4deab245a03927d318 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 13 Mar 2008 17:57:38 +0100 Subject: [PATCH] Change colors handling --- awesome-menu.c | 42 ++++++++++++---------------- awesome-message.c | 11 ++------ awesomerc.5.txt | 68 +++++++++++++++++---------------------------- common/configopts.c | 41 +++++++++++---------------- common/draw.c | 22 +++++++++++++++ common/draw.h | 4 +++ config.c | 41 ++++++++------------------- widgets/tasklist.c | 27 +++++++----------- widgets/textbox.c | 16 ++++------- 9 files changed, 116 insertions(+), 156 deletions(-) diff --git a/awesome-menu.c b/awesome-menu.c index d79490ca..a457b00d 100644 --- a/awesome-menu.c +++ b/awesome-menu.c @@ -123,6 +123,7 @@ config_parse(const char *confpatharg, const char *menu_title, Area *geometry) char *confpath, *opt; cfg_t *cfg, *cfg_menu = NULL, *cfg_screen, *cfg_general, *cfg_colors, *cfg_menu_colors = NULL; + colors_ctx_t colors_normal, colors_focus; if(!confpatharg) confpath = config_file(); @@ -157,41 +158,34 @@ config_parse(const char *confpatharg, const char *menu_title, Area *geometry) cfg_general = cfg_getsec(cfg_screen, "general"); cfg_colors = cfg_getsec(cfg_screen, "colors"); - /* colors */ - if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "normal_fg"))) - opt = cfg_getstr(cfg_colors, "normal_fg"); + /* Colors */ - draw_color_new(globalconf.display, DefaultScreen(globalconf.display), - opt, &globalconf.colors.normal.fg); + /* Grab default colors */ + draw_colors_ctx_init(globalconf.display, DefaultScreen(globalconf.display), + cfg_getsec(cfg_colors, "normal"), + &colors_normal, NULL); - if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "normal_bg"))) - opt = cfg_getstr(cfg_colors, "normal_bg"); + draw_colors_ctx_init(globalconf.display, DefaultScreen(globalconf.display), + cfg_getsec(cfg_colors, "normal"), + &colors_normal, NULL); - draw_color_new(globalconf.display, DefaultScreen(globalconf.display), - opt, &globalconf.colors.normal.bg); + /* Now grab menu colors if any */ + draw_colors_ctx_init(globalconf.display, DefaultScreen(globalconf.display), + cfg_getsec(cfg_colors, "normal"), + &globalconf.colors.normal, &colors_normal); - if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "focus_fg"))) - opt = cfg_getstr(cfg_colors, "focus_fg"); - - draw_color_new(globalconf.display, DefaultScreen(globalconf.display), - opt, &globalconf.colors.focus.fg); - - if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "focus_bg"))) - opt = cfg_getstr(cfg_colors, "focus_bg"); - - draw_color_new(globalconf.display, DefaultScreen(globalconf.display), - opt, &globalconf.colors.focus.bg); + draw_colors_ctx_init(globalconf.display, DefaultScreen(globalconf.display), + cfg_getsec(cfg_colors, "focus"), + &globalconf.colors.focus, &colors_focus); /* font */ if(!cfg_menu || !(opt = cfg_getstr(cfg_menu, "font"))) opt = cfg_getstr(cfg_general, "font"); - globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display), + globalconf.font = XftFontOpenName(globalconf.display, + DefaultScreen(globalconf.display), opt); - globalconf.colors.normal.shadow_offset = - globalconf.colors.focus.shadow_offset = cfg_getint(cfg_general, "text_shadow_offset"); - if(cfg_menu) { if((i = cfg_getint(cfg_menu, "x")) != (int) 0xffffffff) diff --git a/awesome-message.c b/awesome-message.c index 9c261c24..dc82c2da 100644 --- a/awesome-message.c +++ b/awesome-message.c @@ -102,14 +102,9 @@ config_parse(const char *confpatharg) cfg_colors = cfg_getsec(cfg_screen, "colors"); /* colors */ - draw_color_new(globalconf.display, DefaultScreen(globalconf.display), - cfg_getstr(cfg_colors, "normal_fg"), - &globalconf.colors.fg); - draw_color_new(globalconf.display, DefaultScreen(globalconf.display), - cfg_getstr(cfg_colors, "normal_bg"), - &globalconf.colors.bg); - - globalconf.colors.shadow_offset = cfg_getint(cfg_general, "text_shadow_offset"); + draw_colors_ctx_init(globalconf.display, DefaultScreen(globalconf.display), + cfg_getsec(cfg_colors, "normal"), + &globalconf.colors, NULL); /* font */ globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display), diff --git a/awesomerc.5.txt b/awesomerc.5.txt index 980ae88f..701629d3 100644 --- a/awesomerc.5.txt +++ b/awesomerc.5.txt @@ -100,26 +100,19 @@ image:: colors ^^^^^^ -Colors is a section containing the color parameters. +Colors is a section containing the colors parameters which is composed of a normal, focus and urgent +subsection each ones containing: -normal_fg:: - Set the normal foreground color. -normal_bg:: - Set the normal background color. -normal_border:: - Set the unfocused window's border color. -focus_fg:: - Set the focused foreground color. -focus_bg:: - Set the focused background color. -focus_border:: - Set the focused window's border color. -urgent_fg:: - Set the foreground color to use for urgent flag. This is mostly useful - with the taglist widget which will use this color whenever a window sets its - XUrgencyHint on a non-visible tag. -urgent_bg:: - Set the background color to use for urgent flag. +fg:: + Set the foreground color. +bg:: + Set the background color. +border:: + Set the window's border color. +shadow:: + Set the shadow color. +shadow_offset:: + Set the shadow offset in pixel. padding ^^^^^^^ @@ -393,12 +386,8 @@ This widget shows a list of running windows. Font to use. *bg*:: Background color. -*fg*:: - Foreground color. -*focus_bg*:: - Background color for focused window. -*focus_fg*:: - Foreground color for focused window. +*colors*:: + Colors section with a focus and normal subsection. *text_align*:: Text alignement. *show_icons*:: @@ -418,12 +407,10 @@ This widget shows a text. Set mouse bindings. *font*:: Font to use. -*bg*:: - Background color. -*fg*:: - Foreground color. *width*:: Set width. +*colors*:: + Colors section with a focus and normal subsection. *text*:: Text to change. *text_align*:: @@ -551,11 +538,11 @@ Note: when there is no whitespace, quotes are optional. -> prog, 3... (argument to a uicb function, where required) -> spawn, exec, client_tag... (see UICB FUNCTIONS above) <{.., ...}> -> list of available options + -> a section with fg, bg, border, shadow and shadow_offset options. [MULTI] means, you can use an item multiple times. - screen [MULTI] { general @@ -570,7 +557,6 @@ screen [MULTI] sloppy_focus_raise = snap = floating_placement = <{smart,under_mouse}> - text_shadow_offset = mwfact_lower_limit = mwfact_upper_limit = } @@ -593,14 +579,9 @@ screen [MULTI] } colors { - normal_fg = - normal_bg = - normal_border = - focus_fg = - focus_bg = - focus_border = - urgent_fg = - urgent_bg = + normal { } + focus { } + urgent { } } padding { @@ -647,10 +628,11 @@ screen [MULTI] } tasklist { - fg = - bg = - focus_fg = - focus_bg = + colors + { + normal { } + focus { } + } font = show_icons = show = <{all,tags,focus}> diff --git a/common/configopts.c b/common/configopts.c index 510a52bf..9030e0f8 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -77,7 +77,6 @@ cfg_opt_t general_opts[] = CFG_BOOL((char *) "new_become_master", cfg_true, CFGF_NONE), CFG_BOOL((char *) "new_get_focus", cfg_true, CFGF_NONE), CFG_STR((char *) "font", (char *) "vera-10", CFGF_NONE), - CFG_INT((char *) "text_shadow_offset", 1, CFGF_NONE), CFG_INT((char *) "opacity_unfocused", -1, CFGF_NONE), CFG_STR((char *) "floating_placement", (char *) "smart", CFGF_NONE), CFG_FLOAT((char *) "mwfact_lower_limit", 0.1, CFGF_NONE), @@ -86,14 +85,18 @@ cfg_opt_t general_opts[] = }; cfg_opt_t colors_opts[] = { - CFG_STR((char *) "normal_border", (char *) "#111111", CFGF_NONE), - CFG_STR((char *) "normal_bg", (char *) "#111111", CFGF_NONE), - CFG_STR((char *) "normal_fg", (char *) "#eeeeee", CFGF_NONE), - CFG_STR((char *) "focus_border", (char *) "#6666ff", CFGF_NONE), - CFG_STR((char *) "focus_bg", (char *) "#6666ff", CFGF_NONE), - CFG_STR((char *) "focus_fg", (char *) "#ffffff", CFGF_NONE), - CFG_STR((char *) "urgent_bg", (char *) "#ff0000", CFGF_NONE), - CFG_STR((char *) "urgent_fg", (char *) "#ffffff", CFGF_NONE), + CFG_STR((char *) "border", (char *) NULL, CFGF_NONE), + CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE), + CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE), + CFG_STR((char *) "shadow", (char *) NULL, CFGF_NONE), + CFG_INT((char *) "shadow_offset", 0, CFGF_NONE), + CFG_AWESOME_END() +}; +cfg_opt_t screen_colors_opts[] = +{ + CFG_SEC((char *) "normal", colors_opts, CFGF_NONE), + CFG_SEC((char *) "focus", colors_opts, CFGF_NONE), + CFG_SEC((char *) "urgent", colors_opts, CFGF_NONE), CFG_AWESOME_END() }; cfg_opt_t mouse_taglist_opts[] = @@ -145,10 +148,9 @@ cfg_opt_t widget_textbox_opts[] = CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI), CFG_INT((char *) "width", 0, CFGF_NONE), CFG_STR((char *) "text", (char *) NULL, CFGF_NONE), - CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE), - CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "font", (char *) NULL, CFGF_NONE), CFG_STR((char *) "text_align", (char *) "center", CFGF_NONE), + CFG_SEC((char *) "colors", colors_opts, CFGF_NONE), CFG_AWESOME_END() }; cfg_opt_t widget_tasklist_opts[] = @@ -156,10 +158,7 @@ cfg_opt_t widget_tasklist_opts[] = CFG_INT((char *) "x", 0xffffffff, CFGF_NONE), CFG_INT((char *) "y", 0xffffffff, CFGF_NONE), CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI), - CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE), - CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE), - CFG_STR((char *) "focus_fg", (char *) NULL, CFGF_NONE), - CFG_STR((char *) "focus_bg", (char *) NULL, CFGF_NONE), + CFG_SEC((char *) "colors", screen_colors_opts, CFGF_NONE), CFG_STR((char *) "font", (char *) NULL, CFGF_NONE), CFG_STR((char *) "text_align", (char *) "left", CFGF_NONE), CFG_STR((char *) "show", (char *) "tags", CFGF_NONE), @@ -266,7 +265,7 @@ cfg_opt_t screen_opts[] = CFG_SEC((char *) "general", general_opts, CFGF_NONE), CFG_SEC((char *) "statusbar", statusbar_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES), CFG_SEC((char *) "tags", tags_opts, CFGF_NONE), - CFG_SEC((char *) "colors", colors_opts, CFGF_NONE), + CFG_SEC((char *) "colors", screen_colors_opts, CFGF_NONE), CFG_SEC((char *) "layouts", layouts_opts, CFGF_NONE), CFG_SEC((char *) "padding", padding_opts, CFGF_NONE), CFG_AWESOME_END() @@ -317,14 +316,6 @@ cfg_opt_t mouse_opts[] = CFG_SEC((char *) "client", mouse_generic_opts, CFGF_MULTI), CFG_AWESOME_END() }; -cfg_opt_t menu_colors_opts[] = -{ - CFG_STR((char *) "normal_bg", NULL, CFGF_NONE), - CFG_STR((char *) "normal_fg", NULL, CFGF_NONE), - CFG_STR((char *) "focus_bg", NULL, CFGF_NONE), - CFG_STR((char *) "focus_fg", NULL, CFGF_NONE), - CFG_AWESOME_END() -}; cfg_opt_t menu_opts[] = { CFG_INT((char *) "width", 0, CFGF_NONE), @@ -332,7 +323,7 @@ cfg_opt_t menu_opts[] = CFG_INT((char *) "y", 0xffffffff, CFGF_NONE), CFG_INT((char *) "x", 0xffffffff, CFGF_NONE), CFG_STR((char *) "font", NULL, CFGF_NONE), - CFG_SEC((char *) "colors", menu_colors_opts, CFGF_NONE), + CFG_SEC((char *) "colors", screen_colors_opts, CFGF_NONE), CFG_AWESOME_END() }; cfg_opt_t awesome_opts[] = diff --git a/common/draw.c b/common/draw.c index d9610766..080dcae3 100644 --- a/common/draw.c +++ b/common/draw.c @@ -657,6 +657,9 @@ draw_color_new(Display *disp, int phys_screen, const char *colstr, XColor *color Bool ret; XColor exactColor; + if(!a_strlen(colstr)) + return False; + if(!(ret = XAllocNamedColor(disp, DefaultColormap(disp, phys_screen), colstr, @@ -667,6 +670,25 @@ draw_color_new(Display *disp, int phys_screen, const char *colstr, XColor *color return ret; } +void +draw_colors_ctx_init(Display *disp, int phys_screen, cfg_t *cfg_colors, + colors_ctx_t *c, colors_ctx_t *m) +{ + if(m) + *c = *m; + + draw_color_new(disp, phys_screen, + cfg_getstr(cfg_colors, "fg"), &c->fg); + draw_color_new(disp, phys_screen, + cfg_getstr(cfg_colors, "bg"), &c->bg); + draw_color_new(disp, phys_screen, + cfg_getstr(cfg_colors, "border"), &c->border); + draw_color_new(disp, phys_screen, + cfg_getstr(cfg_colors, "shadow"), &c->shadow); + + c->shadow_offset = cfg_getint(cfg_colors, "shadow_offset"); +} + /** Remove a area from a list of them, * spliting the space between several area that can overlaps * \param head list head diff --git a/common/draw.h b/common/draw.h index cd7c59fd..c5a3320c 100644 --- a/common/draw.h +++ b/common/draw.h @@ -23,6 +23,9 @@ #define AWESOME_COMMON_DRAW_H #include + +#include + #include #include @@ -123,6 +126,7 @@ Drawable draw_rotate(DrawCtx *, int, double, int, int); unsigned short draw_textwidth(Display *, XftFont *, char *); Alignment draw_get_align(const char *); Bool draw_color_new(Display *, int, const char *, XColor *); +void draw_colors_ctx_init(Display *, int, cfg_t *, colors_ctx_t *, colors_ctx_t *); void area_list_remove(Area **, Area *); diff --git a/config.c b/config.c index 22fbfc0b..9d3ca30b 100644 --- a/config.c +++ b/config.c @@ -282,7 +282,8 @@ config_parse_screen(cfg_t *cfg, int screen) Tag *tag = NULL; Statusbar *statusbar = NULL; cfg_t *cfg_general, *cfg_colors, *cfg_screen, *cfg_tags, - *cfg_layouts, *cfg_padding, *cfgsectmp; + *cfg_layouts, *cfg_padding, *cfgsectmp, + *cfg_colors_normal, *cfg_colors_focus, *cfg_colors_urgent; VirtScreen *virtscreen = &globalconf.screens[screen]; int i, phys_screen = get_phys_screen(screen); @@ -318,10 +319,6 @@ config_parse_screen(cfg_t *cfg, int screen) virtscreen->font = XftFontOpenName(globalconf.display, phys_screen, cfg_getstr(cfg_general, "font")); - virtscreen->colors.normal.shadow_offset = - virtscreen->colors.focus.shadow_offset = - virtscreen->colors.urgent.shadow_offset = - cfg_getint(cfg_general, "text_shadow_offset"); virtscreen->floating_placement = name_func_lookup(cfg_getstr(cfg_general, "floating_placement"), FloatingPlacementList); @@ -360,30 +357,16 @@ config_parse_screen(cfg_t *cfg, int screen) eprint("awesome: cannot init font\n"); /* Colors */ - draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "normal_border"), - &virtscreen->colors.normal.border); - draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "normal_bg"), - &virtscreen->colors.normal.bg); - draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "normal_fg"), - &virtscreen->colors.normal.fg); - draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "focus_border"), - &virtscreen->colors.focus.border); - draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "focus_bg"), - &virtscreen->colors.focus.bg); - draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "focus_fg"), - &virtscreen->colors.focus.fg); - draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "urgent_bg"), - &virtscreen->colors.urgent.bg); - draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "urgent_fg"), - &virtscreen->colors.urgent.fg); + cfg_colors_normal = cfg_getsec(cfg_colors, "normal"); + cfg_colors_focus = cfg_getsec(cfg_colors, "focus"); + cfg_colors_urgent = cfg_getsec(cfg_colors, "urgent"); + + draw_colors_ctx_init(globalconf.display, phys_screen, + cfg_colors_normal, &virtscreen->colors.normal, NULL); + draw_colors_ctx_init(globalconf.display, phys_screen, + cfg_colors_focus, &virtscreen->colors.focus, NULL); + draw_colors_ctx_init(globalconf.display, phys_screen, + cfg_colors_urgent, &virtscreen->colors.urgent, NULL); /* Statusbar */ diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 087706c8..d72dcdad 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -268,6 +268,7 @@ tasklist_new(Statusbar *statusbar, cfg_t *config) Widget *w; Data *d; char *buf; + cfg_t *cfg_colors; int phys_screen = get_phys_screen(statusbar->screen); w = p_new(Widget, 1); @@ -277,25 +278,17 @@ tasklist_new(Statusbar *statusbar, cfg_t *config) w->alignment = AlignFlex; w->data = d = p_new(Data, 1); - if((buf = cfg_getstr(config, "fg"))) - draw_color_new(globalconf.display, phys_screen, buf, &d->colors.normal.fg); - else - d->colors.normal.fg = globalconf.screens[statusbar->screen].colors.normal.fg; + cfg_colors = cfg_getsec(config, "colors"); - if((buf = cfg_getstr(config, "bg"))) - draw_color_new(globalconf.display, phys_screen, buf, &d->colors.normal.bg); - else - d->colors.normal.bg = globalconf.screens[statusbar->screen].colors.normal.bg; + draw_colors_ctx_init(globalconf.display, phys_screen, + cfg_getsec(cfg_colors, "normal"), + &d->colors.normal, + &globalconf.screens[statusbar->screen].colors.normal); - if((buf = cfg_getstr(config, "focus_bg"))) - draw_color_new(globalconf.display, phys_screen, buf, &d->colors.focus.bg); - else - d->colors.focus.bg = globalconf.screens[statusbar->screen].colors.focus.bg; - - if((buf = cfg_getstr(config, "focus_fg"))) - draw_color_new(globalconf.display, phys_screen, buf, &d->colors.focus.fg); - else - d->colors.focus.fg = globalconf.screens[statusbar->screen].colors.focus.fg; + draw_colors_ctx_init(globalconf.display, phys_screen, + cfg_getsec(cfg_colors, "focus"), + &d->colors.focus, + &globalconf.screens[statusbar->screen].colors.focus); d->align = draw_get_align(cfg_getstr(config, "text_align")); d->show_icons = cfg_getbool(config, "show_icons"); diff --git a/widgets/textbox.c b/widgets/textbox.c index a8473ec5..da2fa872 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -114,6 +114,7 @@ textbox_new(Statusbar *statusbar, cfg_t *config) Widget *w; Data *d; char *buf; + int phys_screen = get_phys_screen(statusbar->screen); w = p_new(Widget, 1); widget_common_new(w, statusbar, config); @@ -123,21 +124,16 @@ textbox_new(Statusbar *statusbar, cfg_t *config) w->data = d = p_new(Data, 1); - if((buf = cfg_getstr(config, "fg"))) - draw_color_new(globalconf.display, get_phys_screen(statusbar->screen), buf, &d->colors.fg); - else - d->colors.fg = globalconf.screens[statusbar->screen].colors.normal.fg; - - if((buf = cfg_getstr(config, "bg"))) - draw_color_new(globalconf.display, get_phys_screen(statusbar->screen), buf, &d->colors.bg); - else - d->colors.bg = globalconf.screens[statusbar->screen].colors.normal.bg; + draw_colors_ctx_init(globalconf.display, phys_screen, + cfg_getsec(config, "colors"), + &d->colors, + &globalconf.screens[statusbar->screen].colors.normal); d->width = cfg_getint(config, "width"); d->align = draw_get_align(cfg_getstr(config, "text_align")); if((buf = cfg_getstr(config, "font"))) - w->font = XftFontOpenName(globalconf.display, get_phys_screen(statusbar->screen), buf); + w->font = XftFontOpenName(globalconf.display, phys_screen, buf); if(!w->font) w->font = globalconf.screens[statusbar->screen].font;