From b6642e45c8192a91a4d421e97f3ae1fc0ef5b749 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 27 Jan 2008 18:56:37 +0100 Subject: [PATCH] rename initxcolor to draw_color_new() and move it to draw.c --- client.c | 1 - common/draw.c | 21 +++++++++++++++++++++ common/draw.h | 1 + config.c | 32 ++++++++++++++++---------------- widgets/focustitle.c | 5 ++--- widgets/graph.c | 7 +++---- widgets/progressbar.c | 7 +++---- widgets/tasklist.c | 9 ++++----- widgets/textbox.c | 9 ++++----- xutil.c | 19 ------------------- xutil.h | 1 - 11 files changed, 54 insertions(+), 58 deletions(-) diff --git a/client.c b/client.c index 9be75341..ebc5957a 100644 --- a/client.c +++ b/client.c @@ -26,7 +26,6 @@ #include "client.h" #include "tag.h" #include "rules.h" -#include "xutil.h" #include "window.h" #include "focus.h" #include "ewmh.h" diff --git a/common/draw.c b/common/draw.c index fdce07f0..3fd13e24 100644 --- a/common/draw.c +++ b/common/draw.c @@ -407,4 +407,25 @@ draw_get_align(const char *align) return AlignLeft; } +/** Initialize an X color + * \param disp display ref + * \param screen Physical screen number + * \param colstr Color specification + * \return XColor struct + */ +XColor +draw_color_new(Display *disp, int phys_screen, const char *colstr) +{ + XColor screenColor, exactColor; + + if(!XAllocNamedColor(disp, + DefaultColormap(disp, phys_screen), + colstr, + &screenColor, + &exactColor)) + eprint("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/common/draw.h b/common/draw.h index ace4120b..dec3df7b 100644 --- a/common/draw.h +++ b/common/draw.h @@ -70,6 +70,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 *); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/config.c b/config.c index 67605c19..223815d7 100644 --- a/config.c +++ b/config.c @@ -323,22 +323,22 @@ config_parse_screen(cfg_t *cfg, int screen) eprint("awesome: cannot init font\n"); /* Colors */ - virtscreen->colors_normal[ColBorder] = initxcolor(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "normal_border")); - virtscreen->colors_normal[ColBG] = initxcolor(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "normal_bg")); - virtscreen->colors_normal[ColFG] = initxcolor(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "normal_fg")); - virtscreen->colors_selected[ColBorder] = initxcolor(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "focus_border")); - virtscreen->colors_selected[ColBG] = initxcolor(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "focus_bg")); - virtscreen->colors_selected[ColFG] = initxcolor(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "focus_fg")); - virtscreen->colors_urgent[ColBG] = initxcolor(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "urgent_bg")); - virtscreen->colors_urgent[ColFG] = initxcolor(globalconf.display, phys_screen, - cfg_getstr(cfg_colors, "urgent_fg")); + 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")); /* Statusbar */ diff --git a/widgets/focustitle.c b/widgets/focustitle.c index 5efcec1b..c072bde8 100644 --- a/widgets/focustitle.c +++ b/widgets/focustitle.c @@ -25,7 +25,6 @@ #include "layout.h" #include "tag.h" #include "focus.h" -#include "xutil.h" #include "screen.h" #include "common/util.h" @@ -88,12 +87,12 @@ focustitle_new(Statusbar *statusbar, cfg_t *config) w->data = d = p_new(Data, 1); if((buf = cfg_getstr(config, "fg"))) - d->fg = initxcolor(globalconf.display, phys_screen, buf); + d->fg = draw_color_new(globalconf.display, phys_screen, buf); else d->fg = globalconf.screens[statusbar->screen].colors_selected[ColFG]; if((buf = cfg_getstr(config, "bg"))) - d->bg = initxcolor(globalconf.display, phys_screen, buf); + d->bg = draw_color_new(globalconf.display, phys_screen, buf); else d->bg = globalconf.screens[statusbar->screen].colors_selected[ColBG]; diff --git a/widgets/graph.c b/widgets/graph.c index e843d6d8..5cb6d98e 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -23,7 +23,6 @@ #include #include "common/draw.h" #include "widget.h" -#include "xutil.h" #include "screen.h" #include "common/util.h" @@ -291,7 +290,7 @@ graph_new(Statusbar *statusbar, cfg_t *config) cfg = cfg_getnsec(config, "data", i); if((color = cfg_getstr(cfg, "fg"))) - tmp_color = initxcolor(globalconf.display, phys_screen, color); + tmp_color = draw_color_new(globalconf.display, phys_screen, color); else tmp_color = globalconf.screens[statusbar->screen].colors_normal[ColFG]; @@ -335,12 +334,12 @@ graph_new(Statusbar *statusbar, cfg_t *config) } if((color = cfg_getstr(config, "bg"))) - d->bg = initxcolor(globalconf.display, phys_screen, color); + d->bg = draw_color_new(globalconf.display, phys_screen, color); else d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG]; if((color = cfg_getstr(config, "bordercolor"))) - d->bordercolor = initxcolor(globalconf.display, phys_screen, color); + d->bordercolor = draw_color_new(globalconf.display, phys_screen, color); else d->bordercolor = tmp_color; diff --git a/widgets/progressbar.c b/widgets/progressbar.c index 00bdd5b6..f35b0d0f 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -21,7 +21,6 @@ #include #include "widget.h" -#include "xutil.h" #include "screen.h" #include "common/util.h" @@ -163,17 +162,17 @@ progressbar_new(Statusbar *statusbar, cfg_t *config) cfg = cfg_getnsec(config, "bar", i); if((color = cfg_getstr(cfg, "fg"))) - d->fg[i] = initxcolor(globalconf.display, phys_screen, color); + d->fg[i] = draw_color_new(globalconf.display, phys_screen, color); else d->fg[i] = globalconf.screens[statusbar->screen].colors_normal[ColFG]; if((color = cfg_getstr(cfg, "bg"))) - d->bg[i] = initxcolor(globalconf.display, phys_screen, color); + d->bg[i] = draw_color_new(globalconf.display, phys_screen, color); else d->bg[i] = globalconf.screens[statusbar->screen].colors_normal[ColBG]; if((color = cfg_getstr(cfg, "bordercolor"))) - d->bordercolor[i] = initxcolor(globalconf.display, phys_screen, color); + d->bordercolor[i] = draw_color_new(globalconf.display, phys_screen, color); else d->bordercolor[i] = d->fg[i]; diff --git a/widgets/tasklist.c b/widgets/tasklist.c index d19ca148..280965f0 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -22,7 +22,6 @@ #include "widget.h" #include "client.h" #include "focus.h" -#include "xutil.h" #include "screen.h" #include "event.h" #include "ewmh.h" @@ -241,22 +240,22 @@ tasklist_new(Statusbar *statusbar, cfg_t *config) w->data = d = p_new(Data, 1); if((buf = cfg_getstr(config, "fg"))) - d->fg = initxcolor(globalconf.display, phys_screen, buf); + d->fg = draw_color_new(globalconf.display, phys_screen, buf); else d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG]; if((buf = cfg_getstr(config, "bg"))) - d->bg = initxcolor(globalconf.display, phys_screen, buf); + d->bg = draw_color_new(globalconf.display, phys_screen, buf); else d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG]; if((buf = cfg_getstr(config, "focus_bg"))) - d->bg_sel = initxcolor(globalconf.display, phys_screen, buf); + d->bg_sel = draw_color_new(globalconf.display, phys_screen, buf); else d->bg_sel = globalconf.screens[statusbar->screen].colors_selected[ColBG]; if((buf = cfg_getstr(config, "focus_fg"))) - d->fg_sel = initxcolor(globalconf.display, phys_screen, buf); + d->fg_sel = draw_color_new(globalconf.display, phys_screen, buf); else d->fg_sel = globalconf.screens[statusbar->screen].colors_selected[ColFG]; diff --git a/widgets/textbox.c b/widgets/textbox.c index 73687d85..c0982eee 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -20,7 +20,6 @@ */ #include "widget.h" -#include "xutil.h" #include "screen.h" #include "common/util.h" @@ -81,9 +80,9 @@ textbox_tell(Widget *widget, char *command) if (ntok) *ntok = 0; if (!i) - d->fg = initxcolor(globalconf.display, phys_screen, tok); + d->fg = draw_color_new(globalconf.display, phys_screen, tok); else - d->bg = initxcolor(globalconf.display, phys_screen, tok); + d->bg = draw_color_new(globalconf.display, phys_screen, tok); if (ntok) *ntok = ' '; tok = ntok + (ntok != NULL); @@ -109,12 +108,12 @@ textbox_new(Statusbar *statusbar, cfg_t *config) w->data = d = p_new(Data, 1); if((buf = cfg_getstr(config, "fg"))) - d->fg = initxcolor(globalconf.display, statusbar->screen, buf); + d->fg = draw_color_new(globalconf.display, statusbar->screen, buf); else d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG]; if((buf = cfg_getstr(config, "bg"))) - d->bg = initxcolor(globalconf.display, get_phys_screen(statusbar->screen), buf); + d->bg = draw_color_new(globalconf.display, get_phys_screen(statusbar->screen), buf); else d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG]; diff --git a/xutil.c b/xutil.c index ea0da3de..ca2ac1cf 100644 --- a/xutil.c +++ b/xutil.c @@ -123,25 +123,6 @@ xgettextprop(Window w, Atom atom, char *text, ssize_t textlen) return True; } -/** Initialize an X color - * \param screen Physical screen number - * \param colstr Color specification - */ -XColor -initxcolor(Display *disp, int phys_screen, const char *colstr) -{ - XColor screenColor, exactColor; - - if(!XAllocNamedColor(disp, - DefaultColormap(disp, phys_screen), - colstr, - &screenColor, - &exactColor)) - eprint("awesome: error, cannot allocate color '%s'\n", colstr); - - return screenColor; -} - unsigned int get_numlockmask(Display *disp) { diff --git a/xutil.h b/xutil.h index dfc87e54..5eab7838 100644 --- a/xutil.h +++ b/xutil.h @@ -26,7 +26,6 @@ #include "uicb.h" Bool xgettextprop(Window, Atom, char *, ssize_t); -XColor initxcolor(Display *, int, const char *); unsigned int get_numlockmask(Display *); Uicb uicb_spawn; Uicb uicb_exec;