From ae75f55acd564ebbec4f165f07b55cdf7f0ec764 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 13 Feb 2008 08:58:21 +0100 Subject: [PATCH] change draw_color_new() proto to fill the struct and return status --- awesome-message.c | 10 ++++++---- common/draw.c | 21 +++++++++++---------- common/draw.h | 2 +- config.c | 40 ++++++++++++++++++++++++---------------- widgets/graph.c | 10 +++++----- widgets/progressbar.c | 10 +++++----- widgets/tasklist.c | 8 ++++---- widgets/textbox.c | 12 ++++++------ 8 files changed, 62 insertions(+), 51 deletions(-) diff --git a/awesome-message.c b/awesome-message.c index e995f306..77fe0866 100644 --- a/awesome-message.c +++ b/awesome-message.c @@ -104,10 +104,12 @@ config_parse(const char *confpatharg) cfg_colors = cfg_getsec(cfg_screen, "colors"); /* colors */ - globalconf.fg = draw_color_new(globalconf.display, DefaultScreen(globalconf.display), - cfg_getstr(cfg_colors, "normal_fg")); - globalconf.bg = draw_color_new(globalconf.display, DefaultScreen(globalconf.display), - cfg_getstr(cfg_colors, "normal_bg")); + draw_color_new(globalconf.display, DefaultScreen(globalconf.display), + cfg_getstr(cfg_colors, "normal_fg"), + &globalconf.fg); + draw_color_new(globalconf.display, DefaultScreen(globalconf.display), + cfg_getstr(cfg_colors, "normal_bg"), + &globalconf.bg); /* font */ globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display), diff --git a/common/draw.c b/common/draw.c index 30ff8293..bc079da0 100644 --- a/common/draw.c +++ b/common/draw.c @@ -563,19 +563,20 @@ draw_get_align(const char *align) * \param colstr Color specification * \return XColor struct */ -XColor -draw_color_new(Display *disp, int phys_screen, const char *colstr) +Bool +draw_color_new(Display *disp, int phys_screen, const char *colstr, XColor *color) { - XColor screenColor, exactColor; + Bool ret; + XColor exactColor; - if(!XAllocNamedColor(disp, - DefaultColormap(disp, phys_screen), - colstr, - &screenColor, - &exactColor)) - eprint("awesome: error, cannot allocate color '%s'\n", colstr); + if(!(ret = XAllocNamedColor(disp, + DefaultColormap(disp, phys_screen), + colstr, + color, + &exactColor))) + warn("awesome: error, cannot allocate color '%s'\n", colstr); - return screenColor; + return ret; } /** Remove a area from a list of them, diff --git a/common/draw.h b/common/draw.h index 1437d61c..eef69c43 100644 --- a/common/draw.h +++ b/common/draw.h @@ -109,7 +109,7 @@ Area draw_get_image_size(const char *filename); Drawable draw_rotate(DrawCtx *, int, double, int, int); unsigned short draw_textwidth(Display *, XftFont *, char *); Alignment draw_get_align(const char *); -XColor draw_color_new(Display *, int, const char *); +Bool draw_color_new(Display *, int, const char *, XColor *); void area_list_remove(Area **, Area *); diff --git a/config.c b/config.c index 201f356d..a695bde0 100644 --- a/config.c +++ b/config.c @@ -321,22 +321,30 @@ config_parse_screen(cfg_t *cfg, int screen) eprint("awesome: cannot init font\n"); /* Colors */ - virtscreen->colors_normal[ColBorder] = draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "normal_border")); - virtscreen->colors_normal[ColBG] = draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "normal_bg")); - virtscreen->colors_normal[ColFG] = draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "normal_fg")); - virtscreen->colors_selected[ColBorder] = draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "focus_border")); - virtscreen->colors_selected[ColBG] = draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "focus_bg")); - virtscreen->colors_selected[ColFG] = draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "focus_fg")); - virtscreen->colors_urgent[ColBG] = draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "urgent_bg")); - virtscreen->colors_urgent[ColFG] = draw_color_new(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "urgent_fg")); + draw_color_new(globalconf.display, phys_screen, + cfg_getstr(cfg_colors, "normal_border"), + &virtscreen->colors_normal[ColBorder]); + draw_color_new(globalconf.display, phys_screen, + cfg_getstr(cfg_colors, "normal_bg"), + &virtscreen->colors_normal[ColBG]); + draw_color_new(globalconf.display, phys_screen, + cfg_getstr(cfg_colors, "normal_fg"), + &virtscreen->colors_normal[ColFG]); + draw_color_new(globalconf.display, phys_screen, + cfg_getstr(cfg_colors, "focus_border"), + &virtscreen->colors_selected[ColBorder]); + draw_color_new(globalconf.display, phys_screen, + cfg_getstr(cfg_colors, "focus_bg"), + &virtscreen->colors_selected[ColBG]); + draw_color_new(globalconf.display, phys_screen, + cfg_getstr(cfg_colors, "focus_fg"), + &virtscreen->colors_selected[ColFG]); + draw_color_new(globalconf.display, phys_screen, + cfg_getstr(cfg_colors, "urgent_bg"), + &virtscreen->colors_urgent[ColBG]); + draw_color_new(globalconf.display, phys_screen, + cfg_getstr(cfg_colors, "urgent_fg"), + &virtscreen->colors_urgent[ColFG]); /* Statusbar */ diff --git a/widgets/graph.c b/widgets/graph.c index 01780f96..8b5e34b5 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -302,20 +302,20 @@ graph_new(Statusbar *statusbar, cfg_t *config) cfg = cfg_getnsec(config, "data", i); if((color = cfg_getstr(cfg, "fg"))) - tmp_color = draw_color_new(globalconf.display, phys_screen, color); + draw_color_new(globalconf.display, phys_screen, color, &tmp_color); else tmp_color = globalconf.screens[statusbar->screen].colors_normal[ColFG]; if((color = cfg_getstr(cfg, "fg_center"))) { ptmp_color_center = p_new(XColor, 1); - *ptmp_color_center = draw_color_new(globalconf.display, phys_screen, color); + draw_color_new(globalconf.display, phys_screen, color, ptmp_color_center); } if((color = cfg_getstr(cfg, "fg_end"))) { ptmp_color_end = p_new(XColor, 1); - *ptmp_color_end = draw_color_new(globalconf.display, phys_screen, color); + draw_color_new(globalconf.display, phys_screen, color, ptmp_color_center); } if (cfg_getbool(cfg, "scale")) @@ -364,12 +364,12 @@ graph_new(Statusbar *statusbar, cfg_t *config) } if((color = cfg_getstr(config, "bg"))) - d->bg = draw_color_new(globalconf.display, phys_screen, color); + draw_color_new(globalconf.display, phys_screen, color, &d->bg); else d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG]; if((color = cfg_getstr(config, "bordercolor"))) - d->bordercolor = draw_color_new(globalconf.display, phys_screen, color); + draw_color_new(globalconf.display, phys_screen, color, &d->bordercolor); else d->bordercolor = tmp_color; diff --git a/widgets/progressbar.c b/widgets/progressbar.c index 7a029f79..a2fbc678 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -169,29 +169,29 @@ progressbar_new(Statusbar *statusbar, cfg_t *config) cfg = cfg_getnsec(config, "bar", i); if((color = cfg_getstr(cfg, "fg"))) - d->fg[i] = draw_color_new(globalconf.display, phys_screen, color); + draw_color_new(globalconf.display, phys_screen, color, &d->fg[i]); else d->fg[i] = globalconf.screens[statusbar->screen].colors_normal[ColFG]; if((color = cfg_getstr(cfg, "fg_center"))) { d->pfg_center[i] = p_new(XColor, 1); - *(d->pfg_center[i]) = draw_color_new(globalconf.display, phys_screen, color); + draw_color_new(globalconf.display, phys_screen, color, d->pfg_center[i]); } if((color = cfg_getstr(cfg, "fg_end"))) { d->pfg_end[i] = p_new(XColor, 1); - *(d->pfg_end[i]) = draw_color_new(globalconf.display, phys_screen, color); + draw_color_new(globalconf.display, phys_screen, color, d->pfg_end[i]); } if((color = cfg_getstr(cfg, "bg"))) - d->bg[i] = draw_color_new(globalconf.display, phys_screen, color); + draw_color_new(globalconf.display, phys_screen, color, &d->bg[i]); else d->bg[i] = globalconf.screens[statusbar->screen].colors_normal[ColBG]; if((color = cfg_getstr(cfg, "bordercolor"))) - d->bordercolor[i] = draw_color_new(globalconf.display, phys_screen, color); + draw_color_new(globalconf.display, phys_screen, color, &d->bordercolor[i]); else d->bordercolor[i] = d->fg[i]; } diff --git a/widgets/tasklist.c b/widgets/tasklist.c index a2864bd1..bf228074 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -277,22 +277,22 @@ tasklist_new(Statusbar *statusbar, cfg_t *config) w->data = d = p_new(Data, 1); if((buf = cfg_getstr(config, "fg"))) - d->fg = draw_color_new(globalconf.display, phys_screen, buf); + draw_color_new(globalconf.display, phys_screen, buf, &d->fg); else d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG]; if((buf = cfg_getstr(config, "bg"))) - d->bg = draw_color_new(globalconf.display, phys_screen, buf); + draw_color_new(globalconf.display, phys_screen, buf, &d->bg); else d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG]; if((buf = cfg_getstr(config, "focus_bg"))) - d->bg_sel = draw_color_new(globalconf.display, phys_screen, buf); + draw_color_new(globalconf.display, phys_screen, buf, &d->bg_sel); else d->bg_sel = globalconf.screens[statusbar->screen].colors_selected[ColBG]; if((buf = cfg_getstr(config, "focus_fg"))) - d->fg_sel = draw_color_new(globalconf.display, phys_screen, buf); + draw_color_new(globalconf.display, phys_screen, buf, &d->fg_sel); else d->fg_sel = globalconf.screens[statusbar->screen].colors_selected[ColFG]; diff --git a/widgets/textbox.c b/widgets/textbox.c index 48c7a1c9..45890dcb 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -77,12 +77,12 @@ textbox_tell(Widget *widget, char *command) if((!ntok && command_len - (tok - command) == 7) || ntok - tok == 7) { - if (ntok) + if(ntok) *ntok = 0; - if (!i) - d->fg = draw_color_new(globalconf.display, phys_screen, tok); + if(!i) + draw_color_new(globalconf.display, phys_screen, tok, &d->fg); else - d->bg = draw_color_new(globalconf.display, phys_screen, tok); + draw_color_new(globalconf.display, phys_screen, tok, &d->bg); if (ntok) *ntok = ' '; tok = ntok + (ntok != NULL); @@ -109,12 +109,12 @@ textbox_new(Statusbar *statusbar, cfg_t *config) w->data = d = p_new(Data, 1); if((buf = cfg_getstr(config, "fg"))) - d->fg = draw_color_new(globalconf.display, statusbar->screen, buf); + draw_color_new(globalconf.display, statusbar->screen, buf, &d->fg); else d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG]; if((buf = cfg_getstr(config, "bg"))) - d->bg = draw_color_new(globalconf.display, get_phys_screen(statusbar->screen), buf); + draw_color_new(globalconf.display, get_phys_screen(statusbar->screen), buf, &d->bg); else d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG];