change draw_color_new() proto to fill the struct and return status

This commit is contained in:
Julien Danjou 2008-02-13 08:58:21 +01:00
parent 0b6129e625
commit ae75f55acd
8 changed files with 62 additions and 51 deletions

View File

@ -104,10 +104,12 @@ config_parse(const char *confpatharg)
cfg_colors = cfg_getsec(cfg_screen, "colors"); cfg_colors = cfg_getsec(cfg_screen, "colors");
/* colors */ /* colors */
globalconf.fg = draw_color_new(globalconf.display, DefaultScreen(globalconf.display), draw_color_new(globalconf.display, DefaultScreen(globalconf.display),
cfg_getstr(cfg_colors, "normal_fg")); cfg_getstr(cfg_colors, "normal_fg"),
globalconf.bg = draw_color_new(globalconf.display, DefaultScreen(globalconf.display), &globalconf.fg);
cfg_getstr(cfg_colors, "normal_bg")); draw_color_new(globalconf.display, DefaultScreen(globalconf.display),
cfg_getstr(cfg_colors, "normal_bg"),
&globalconf.bg);
/* font */ /* font */
globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display), globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display),

View File

@ -563,19 +563,20 @@ draw_get_align(const char *align)
* \param colstr Color specification * \param colstr Color specification
* \return XColor struct * \return XColor struct
*/ */
XColor Bool
draw_color_new(Display *disp, int phys_screen, const char *colstr) draw_color_new(Display *disp, int phys_screen, const char *colstr, XColor *color)
{ {
XColor screenColor, exactColor; Bool ret;
XColor exactColor;
if(!XAllocNamedColor(disp, if(!(ret = XAllocNamedColor(disp,
DefaultColormap(disp, phys_screen), DefaultColormap(disp, phys_screen),
colstr, colstr,
&screenColor, color,
&exactColor)) &exactColor)))
eprint("awesome: error, cannot allocate color '%s'\n", colstr); warn("awesome: error, cannot allocate color '%s'\n", colstr);
return screenColor; return ret;
} }
/** Remove a area from a list of them, /** Remove a area from a list of them,

View File

@ -109,7 +109,7 @@ Area draw_get_image_size(const char *filename);
Drawable draw_rotate(DrawCtx *, int, double, int, int); Drawable draw_rotate(DrawCtx *, int, double, int, int);
unsigned short draw_textwidth(Display *, XftFont *, char *); unsigned short draw_textwidth(Display *, XftFont *, char *);
Alignment draw_get_align(const 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 *); void area_list_remove(Area **, Area *);

View File

@ -321,22 +321,30 @@ config_parse_screen(cfg_t *cfg, int screen)
eprint("awesome: cannot init font\n"); eprint("awesome: cannot init font\n");
/* Colors */ /* Colors */
virtscreen->colors_normal[ColBorder] = draw_color_new(globalconf.display, phys_screen, draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "normal_border")); cfg_getstr(cfg_colors, "normal_border"),
virtscreen->colors_normal[ColBG] = draw_color_new(globalconf.display, phys_screen, &virtscreen->colors_normal[ColBorder]);
cfg_getstr(cfg_colors, "normal_bg")); draw_color_new(globalconf.display, phys_screen,
virtscreen->colors_normal[ColFG] = draw_color_new(globalconf.display, phys_screen, cfg_getstr(cfg_colors, "normal_bg"),
cfg_getstr(cfg_colors, "normal_fg")); &virtscreen->colors_normal[ColBG]);
virtscreen->colors_selected[ColBorder] = draw_color_new(globalconf.display, phys_screen, draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "focus_border")); cfg_getstr(cfg_colors, "normal_fg"),
virtscreen->colors_selected[ColBG] = draw_color_new(globalconf.display, phys_screen, &virtscreen->colors_normal[ColFG]);
cfg_getstr(cfg_colors, "focus_bg")); draw_color_new(globalconf.display, phys_screen,
virtscreen->colors_selected[ColFG] = draw_color_new(globalconf.display, phys_screen, cfg_getstr(cfg_colors, "focus_border"),
cfg_getstr(cfg_colors, "focus_fg")); &virtscreen->colors_selected[ColBorder]);
virtscreen->colors_urgent[ColBG] = draw_color_new(globalconf.display, phys_screen, draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "urgent_bg")); cfg_getstr(cfg_colors, "focus_bg"),
virtscreen->colors_urgent[ColFG] = draw_color_new(globalconf.display, phys_screen, &virtscreen->colors_selected[ColBG]);
cfg_getstr(cfg_colors, "urgent_fg")); 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 */ /* Statusbar */

View File

@ -302,20 +302,20 @@ graph_new(Statusbar *statusbar, cfg_t *config)
cfg = cfg_getnsec(config, "data", i); cfg = cfg_getnsec(config, "data", i);
if((color = cfg_getstr(cfg, "fg"))) 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 else
tmp_color = globalconf.screens[statusbar->screen].colors_normal[ColFG]; tmp_color = globalconf.screens[statusbar->screen].colors_normal[ColFG];
if((color = cfg_getstr(cfg, "fg_center"))) if((color = cfg_getstr(cfg, "fg_center")))
{ {
ptmp_color_center = p_new(XColor, 1); 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"))) if((color = cfg_getstr(cfg, "fg_end")))
{ {
ptmp_color_end = p_new(XColor, 1); 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")) if (cfg_getbool(cfg, "scale"))
@ -364,12 +364,12 @@ graph_new(Statusbar *statusbar, cfg_t *config)
} }
if((color = cfg_getstr(config, "bg"))) 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 else
d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG]; d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG];
if((color = cfg_getstr(config, "bordercolor"))) 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 else
d->bordercolor = tmp_color; d->bordercolor = tmp_color;

View File

@ -169,29 +169,29 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
cfg = cfg_getnsec(config, "bar", i); cfg = cfg_getnsec(config, "bar", i);
if((color = cfg_getstr(cfg, "fg"))) 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 else
d->fg[i] = globalconf.screens[statusbar->screen].colors_normal[ColFG]; d->fg[i] = globalconf.screens[statusbar->screen].colors_normal[ColFG];
if((color = cfg_getstr(cfg, "fg_center"))) if((color = cfg_getstr(cfg, "fg_center")))
{ {
d->pfg_center[i] = p_new(XColor, 1); 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"))) if((color = cfg_getstr(cfg, "fg_end")))
{ {
d->pfg_end[i] = p_new(XColor, 1); 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"))) 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 else
d->bg[i] = globalconf.screens[statusbar->screen].colors_normal[ColBG]; d->bg[i] = globalconf.screens[statusbar->screen].colors_normal[ColBG];
if((color = cfg_getstr(cfg, "bordercolor"))) 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 else
d->bordercolor[i] = d->fg[i]; d->bordercolor[i] = d->fg[i];
} }

View File

@ -277,22 +277,22 @@ tasklist_new(Statusbar *statusbar, cfg_t *config)
w->data = d = p_new(Data, 1); w->data = d = p_new(Data, 1);
if((buf = cfg_getstr(config, "fg"))) 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 else
d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG]; d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG];
if((buf = cfg_getstr(config, "bg"))) 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 else
d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG]; d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG];
if((buf = cfg_getstr(config, "focus_bg"))) 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 else
d->bg_sel = globalconf.screens[statusbar->screen].colors_selected[ColBG]; d->bg_sel = globalconf.screens[statusbar->screen].colors_selected[ColBG];
if((buf = cfg_getstr(config, "focus_fg"))) 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 else
d->fg_sel = globalconf.screens[statusbar->screen].colors_selected[ColFG]; d->fg_sel = globalconf.screens[statusbar->screen].colors_selected[ColFG];

View File

@ -80,9 +80,9 @@ textbox_tell(Widget *widget, char *command)
if(ntok) if(ntok)
*ntok = 0; *ntok = 0;
if(!i) if(!i)
d->fg = draw_color_new(globalconf.display, phys_screen, tok); draw_color_new(globalconf.display, phys_screen, tok, &d->fg);
else else
d->bg = draw_color_new(globalconf.display, phys_screen, tok); draw_color_new(globalconf.display, phys_screen, tok, &d->bg);
if (ntok) if (ntok)
*ntok = ' '; *ntok = ' ';
tok = ntok + (ntok != NULL); tok = ntok + (ntok != NULL);
@ -109,12 +109,12 @@ textbox_new(Statusbar *statusbar, cfg_t *config)
w->data = d = p_new(Data, 1); w->data = d = p_new(Data, 1);
if((buf = cfg_getstr(config, "fg"))) 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 else
d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG]; d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG];
if((buf = cfg_getstr(config, "bg"))) 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 else
d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG]; d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG];