rename initxcolor to draw_color_new() and move it to draw.c

This commit is contained in:
Julien Danjou 2008-01-27 18:56:37 +01:00
parent 16607e39e6
commit b6642e45c8
11 changed files with 54 additions and 58 deletions

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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 */

View File

@ -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];

View File

@ -23,7 +23,6 @@
#include <cairo.h>
#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;

View File

@ -21,7 +21,6 @@
#include <string.h>
#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];

View File

@ -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];

View File

@ -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];

19
xutil.c
View File

@ -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)
{

View File

@ -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;