Rework colors stuff, add a common colors_ctx_t containing colors and shadow options

This commit is contained in:
Julien Danjou 2008-03-13 14:03:03 +01:00
parent cbc5ec8060
commit 0a980095b3
13 changed files with 112 additions and 109 deletions

View File

@ -82,14 +82,12 @@ typedef struct
DrawCtx *ctx; DrawCtx *ctx;
/** Font to use */ /** Font to use */
XftFont *font; XftFont *font;
/** Draw shadow_offset under text */ /** Colors */
Bool shadow_offset; struct
/** Foreground color */ {
XColor fg; colors_ctx_t normal;
/** Background color */ colors_ctx_t focus;
XColor bg; } colors;
/** List background */
XColor fg_focus, bg_focus;
/** Numlock mask */ /** Numlock mask */
unsigned int numlockmask; unsigned int numlockmask;
/** The text */ /** The text */
@ -161,25 +159,25 @@ config_parse(const char *confpatharg, const char *menu_title, Area *geometry)
opt = cfg_getstr(cfg_colors, "normal_fg"); opt = cfg_getstr(cfg_colors, "normal_fg");
draw_color_new(globalconf.display, DefaultScreen(globalconf.display), draw_color_new(globalconf.display, DefaultScreen(globalconf.display),
opt, &globalconf.fg); opt, &globalconf.colors.normal.fg);
if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "normal_bg"))) if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "normal_bg")))
opt = cfg_getstr(cfg_colors, "normal_bg"); opt = cfg_getstr(cfg_colors, "normal_bg");
draw_color_new(globalconf.display, DefaultScreen(globalconf.display), draw_color_new(globalconf.display, DefaultScreen(globalconf.display),
opt, &globalconf.bg); opt, &globalconf.colors.normal.bg);
if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "focus_fg"))) if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "focus_fg")))
opt = cfg_getstr(cfg_colors, "focus_fg"); opt = cfg_getstr(cfg_colors, "focus_fg");
draw_color_new(globalconf.display, DefaultScreen(globalconf.display), draw_color_new(globalconf.display, DefaultScreen(globalconf.display),
opt, &globalconf.fg_focus); opt, &globalconf.colors.focus.fg);
if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "focus_bg"))) if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "focus_bg")))
opt = cfg_getstr(cfg_colors, "focus_bg"); opt = cfg_getstr(cfg_colors, "focus_bg");
draw_color_new(globalconf.display, DefaultScreen(globalconf.display), draw_color_new(globalconf.display, DefaultScreen(globalconf.display),
opt, &globalconf.bg_focus); opt, &globalconf.colors.focus.bg);
/* font */ /* font */
if(!cfg_menu || !(opt = cfg_getstr(cfg_menu, "font"))) if(!cfg_menu || !(opt = cfg_getstr(cfg_menu, "font")))
@ -188,7 +186,8 @@ config_parse(const char *confpatharg, const char *menu_title, Area *geometry)
globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display), globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display),
opt); opt);
globalconf.shadow_offset = cfg_getint(cfg_general, "text_shadow_offset"); globalconf.colors.normal.shadow_offset =
globalconf.colors.focus.shadow_offset = cfg_getint(cfg_general, "text_shadow_offset");
if(cfg_menu) if(cfg_menu)
{ {
@ -376,13 +375,11 @@ draw_item(item_t *item, Area geometry)
if(item == globalconf.item_selected) if(item == globalconf.item_selected)
draw_text(globalconf.ctx, geometry, AlignLeft, draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN / 2, globalconf.font, item->data, MARGIN / 2, globalconf.font, item->data,
globalconf.shadow_offset, globalconf.colors.focus);
globalconf.fg_focus, globalconf.bg_focus);
else else
draw_text(globalconf.ctx, geometry, AlignLeft, draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN / 2, globalconf.font, item->data, MARGIN / 2, globalconf.font, item->data,
globalconf.shadow_offset, globalconf.colors.normal);
globalconf.fg, globalconf.bg);
} }
static void static void
@ -400,8 +397,7 @@ redraw(void)
{ {
draw_text(globalconf.ctx, geometry, AlignLeft, draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN, globalconf.font, globalconf.prompt, MARGIN, globalconf.font, globalconf.prompt,
globalconf.shadow_offset, globalconf.colors.focus);
globalconf.fg_focus, globalconf.bg_focus);
len = MARGIN * 2 + draw_textwidth(globalconf.display, globalconf.font, globalconf.prompt); len = MARGIN * 2 + draw_textwidth(globalconf.display, globalconf.font, globalconf.prompt);
geometry.x += len; geometry.x += len;
@ -410,8 +406,7 @@ redraw(void)
draw_text(globalconf.ctx, geometry, AlignLeft, draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN, globalconf.font, globalconf.text, MARGIN, globalconf.font, globalconf.text,
globalconf.shadow_offset, globalconf.colors.normal);
globalconf.fg, globalconf.bg);
len = MARGIN * 2 + MAX(draw_textwidth(globalconf.display, globalconf.font, globalconf.text), len = MARGIN * 2 + MAX(draw_textwidth(globalconf.display, globalconf.font, globalconf.text),
geometry.width / 20); geometry.width / 20);
@ -457,11 +452,11 @@ redraw(void)
{ {
geometry.x = prompt_len; geometry.x = prompt_len;
geometry.width = x_of_previous_item - prompt_len; geometry.width = x_of_previous_item - prompt_len;
draw_rectangle(globalconf.ctx, geometry, True, globalconf.bg); draw_rectangle(globalconf.ctx, geometry, True, globalconf.colors.normal.bg);
} }
} }
else if(geometry.width) else if(geometry.width)
draw_rectangle(globalconf.ctx, geometry, True, globalconf.bg); draw_rectangle(globalconf.ctx, geometry, True, globalconf.colors.normal.bg);
simplewindow_refresh_drawable(globalconf.sw, DefaultScreen(globalconf.display)); simplewindow_refresh_drawable(globalconf.sw, DefaultScreen(globalconf.display));
XSync(globalconf.display, False); XSync(globalconf.display, False);

View File

@ -49,12 +49,8 @@ typedef struct
Display *display; Display *display;
/** Font to use */ /** Font to use */
XftFont *font; XftFont *font;
/** Foreground color */ /** Colors */
XColor fg; colors_ctx_t colors;
/** Background color */
XColor bg;
/** Draw shadow_offset under text */
Bool shadow_offset;
} AwesomeMsgConf; } AwesomeMsgConf;
static AwesomeMsgConf globalconf; static AwesomeMsgConf globalconf;
@ -108,12 +104,12 @@ config_parse(const char *confpatharg)
/* colors */ /* colors */
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.fg); &globalconf.colors.fg);
draw_color_new(globalconf.display, DefaultScreen(globalconf.display), draw_color_new(globalconf.display, DefaultScreen(globalconf.display),
cfg_getstr(cfg_colors, "normal_bg"), cfg_getstr(cfg_colors, "normal_bg"),
&globalconf.bg); &globalconf.colors.bg);
globalconf.shadow_offset = cfg_getint(cfg_general, "text_shadow_offset"); globalconf.colors.shadow_offset = cfg_getint(cfg_general, "text_shadow_offset");
/* font */ /* font */
globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display), globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display),
@ -208,7 +204,7 @@ main(int argc, char **argv)
geometry.x = geometry.y = 0; geometry.x = geometry.y = 0;
draw_text(ctx, geometry, AlignRight, draw_text(ctx, geometry, AlignRight,
0, globalconf.font, argv[optind], 0, globalconf.font, argv[optind],
globalconf.shadow_offset, globalconf.fg, globalconf.bg); globalconf.colors);
if(icon_geometry.width > 0 && icon_geometry.height > 0) if(icon_geometry.width > 0 && icon_geometry.height > 0)
draw_image(ctx, 0, (geometry.height / 2) - (globalconf.font->height / 2), draw_image(ctx, 0, (geometry.height / 2) - (globalconf.font->height / 2),

View File

@ -152,7 +152,7 @@ client_unfocus(Client *c)
if(globalconf.screens[c->screen].opacity_unfocused != -1) if(globalconf.screens[c->screen].opacity_unfocused != -1)
window_settrans(c->win, globalconf.screens[c->screen].opacity_unfocused); window_settrans(c->win, globalconf.screens[c->screen].opacity_unfocused);
XSetWindowBorder(globalconf.display, c->win, XSetWindowBorder(globalconf.display, c->win,
globalconf.screens[c->screen].colors_normal[ColBorder].pixel); globalconf.screens[c->screen].colors.normal.border.pixel);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
focus_add_client(NULL); focus_add_client(NULL);
} }
@ -200,7 +200,7 @@ client_focus(Client *c, int screen, Bool raise)
if(globalconf.screens[c->screen].opacity_unfocused != -1) if(globalconf.screens[c->screen].opacity_unfocused != -1)
window_settrans(c->win, -1); window_settrans(c->win, -1);
XSetWindowBorder(globalconf.display, c->win, XSetWindowBorder(globalconf.display, c->win,
globalconf.screens[screen].colors_selected[ColBorder].pixel); globalconf.screens[screen].colors.focus.border.pixel);
XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime); XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime);
if(raise) if(raise)
{ {
@ -281,7 +281,7 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
/* Set windows borders */ /* Set windows borders */
wc.border_width = c->border; wc.border_width = c->border;
XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc); XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel); XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors.normal.border.pixel);
/* propagates border_width, if size doesn't change */ /* propagates border_width, if size doesn't change */
window_configure(c->win, c->geometry, c->border); window_configure(c->win, c->geometry, c->border);

View File

@ -131,15 +131,14 @@ draw_text(DrawCtx *ctx,
Alignment align, Alignment align,
int padding, int padding,
XftFont *font, char *text, XftFont *font, char *text,
int shadow_offset, colors_ctx_t colors_ctx)
XColor fg, XColor bg)
{ {
int nw = 0, x, y; int nw = 0, x, y;
ssize_t len, olen; ssize_t len, olen;
char *buf = NULL, *utf8 = NULL; char *buf = NULL, *utf8 = NULL;
cairo_font_face_t *font_face; cairo_font_face_t *font_face;
draw_rectangle(ctx, area, True, bg); draw_rectangle(ctx, area, True, colors_ctx.bg);
if(!(len = olen = a_strlen(text))) if(!(len = olen = a_strlen(text)))
return; return;
@ -195,14 +194,20 @@ draw_text(DrawCtx *ctx,
break; break;
} }
if(shadow_offset > 0) if(colors_ctx.shadow_offset > 0)
{ {
cairo_set_source_rgb(ctx->cr, 0.0, 0.0, 0.0); cairo_set_source_rgb(ctx->cr,
cairo_move_to(ctx->cr, x + shadow_offset, y + shadow_offset); colors_ctx.shadow.red / 65535.0,
colors_ctx.shadow.green / 65535.0,
colors_ctx.shadow.blue / 65535.0);
cairo_move_to(ctx->cr, x + colors_ctx.shadow_offset, y + colors_ctx.shadow_offset);
cairo_show_text(ctx->cr, buf); cairo_show_text(ctx->cr, buf);
} }
cairo_set_source_rgb(ctx->cr, fg.red / 65535.0, fg.green / 65535.0, fg.blue / 65535.0); cairo_set_source_rgb(ctx->cr,
colors_ctx.fg.red / 65535.0,
colors_ctx.fg.green / 65535.0,
colors_ctx.fg.blue / 65535.0);
cairo_move_to(ctx->cr, x, y); cairo_move_to(ctx->cr, x, y);
cairo_show_text(ctx->cr, buf); cairo_show_text(ctx->cr, buf);

View File

@ -78,6 +78,20 @@ area_get_intersect_area(Area a, Area b)
return g; return g;
} }
typedef struct
{
/** Foreground color */
XColor fg;
/** Background color */
XColor bg;
/** Shadow color */
XColor shadow;
/** Border color */
XColor border;
/** Shadow offset */
int shadow_offset;
} colors_ctx_t;
typedef struct typedef struct
{ {
Display *display; Display *display;
@ -94,7 +108,7 @@ typedef struct
DrawCtx *draw_context_new(Display *, int, int, int, Drawable); DrawCtx *draw_context_new(Display *, int, int, int, Drawable);
void draw_context_delete(DrawCtx *); void draw_context_delete(DrawCtx *);
void draw_text(DrawCtx *, Area, Alignment, int, XftFont *, char *, int, XColor fg, XColor bg); void draw_text(DrawCtx *, Area, Alignment, int, XftFont *, char *, colors_ctx_t);
void draw_rectangle(DrawCtx *, Area, Bool, XColor); void draw_rectangle(DrawCtx *, Area, Bool, XColor);
void draw_rectangle_gradient(DrawCtx *, Area, Bool, Area, XColor *, XColor *, XColor *); void draw_rectangle_gradient(DrawCtx *, Area, Bool, Area, XColor *, XColor *, XColor *);

View File

@ -318,7 +318,10 @@ config_parse_screen(cfg_t *cfg, int screen)
virtscreen->font = XftFontOpenName(globalconf.display, virtscreen->font = XftFontOpenName(globalconf.display,
phys_screen, phys_screen,
cfg_getstr(cfg_general, "font")); cfg_getstr(cfg_general, "font"));
virtscreen->shadow_offset = cfg_getint(cfg_general, "text_shadow_offset"); 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 = virtscreen->floating_placement =
name_func_lookup(cfg_getstr(cfg_general, "floating_placement"), name_func_lookup(cfg_getstr(cfg_general, "floating_placement"),
FloatingPlacementList); FloatingPlacementList);
@ -359,28 +362,28 @@ config_parse_screen(cfg_t *cfg, int screen)
/* Colors */ /* Colors */
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[ColBorder]); &virtscreen->colors.normal.border);
draw_color_new(globalconf.display, phys_screen, draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "normal_bg"), cfg_getstr(cfg_colors, "normal_bg"),
&virtscreen->colors_normal[ColBG]); &virtscreen->colors.normal.bg);
draw_color_new(globalconf.display, phys_screen, draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "normal_fg"), cfg_getstr(cfg_colors, "normal_fg"),
&virtscreen->colors_normal[ColFG]); &virtscreen->colors.normal.fg);
draw_color_new(globalconf.display, phys_screen, draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "focus_border"), cfg_getstr(cfg_colors, "focus_border"),
&virtscreen->colors_selected[ColBorder]); &virtscreen->colors.focus.border);
draw_color_new(globalconf.display, phys_screen, draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "focus_bg"), cfg_getstr(cfg_colors, "focus_bg"),
&virtscreen->colors_selected[ColBG]); &virtscreen->colors.focus.bg);
draw_color_new(globalconf.display, phys_screen, draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "focus_fg"), cfg_getstr(cfg_colors, "focus_fg"),
&virtscreen->colors_selected[ColFG]); &virtscreen->colors.focus.fg);
draw_color_new(globalconf.display, phys_screen, draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "urgent_bg"), cfg_getstr(cfg_colors, "urgent_bg"),
&virtscreen->colors_urgent[ColBG]); &virtscreen->colors.urgent.bg);
draw_color_new(globalconf.display, phys_screen, draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "urgent_fg"), cfg_getstr(cfg_colors, "urgent_fg"),
&virtscreen->colors_urgent[ColFG]); &virtscreen->colors.urgent.fg);
/* Statusbar */ /* Statusbar */

View File

@ -106,7 +106,7 @@ statusbar_draw(Statusbar *statusbar)
rectangle.width = statusbar->width; rectangle.width = statusbar->width;
rectangle.height = statusbar->height; rectangle.height = statusbar->height;
draw_rectangle(ctx, rectangle, True, draw_rectangle(ctx, rectangle, True,
globalconf.screens[statusbar->screen].colors_normal[ColBG]); globalconf.screens[statusbar->screen].colors.normal.bg);
for(widget = statusbar->widgets; widget; widget = widget->next) for(widget = statusbar->widgets; widget; widget = widget->next)
if (widget->alignment == AlignLeft) if (widget->alignment == AlignLeft)

View File

@ -46,10 +46,6 @@ typedef enum
Auto Auto
} Fuzzy; } Fuzzy;
/** Common colors */
enum
{ ColBorder, ColFG, ColBG, ColLast };
/** Cursors */ /** Cursors */
enum enum
{ CurNormal, CurResize, CurMove, CurLast }; { CurNormal, CurResize, CurMove, CurLast };
@ -286,12 +282,13 @@ typedef struct
Bool new_become_master; Bool new_become_master;
/** True if we need to arrange() */ /** True if we need to arrange() */
Bool need_arrange; Bool need_arrange;
/** Normal colors */ /** Colors */
XColor colors_normal[ColLast]; struct
/** Selected colors */ {
XColor colors_selected[ColLast]; colors_ctx_t normal;
/** Urgency colors */ colors_ctx_t focus;
XColor colors_urgent[ColLast]; colors_ctx_t urgent;
} colors;
/** Transparency of unfocused clients */ /** Transparency of unfocused clients */
int opacity_unfocused; int opacity_unfocused;
/** Tag list */ /** Tag list */
@ -304,8 +301,6 @@ typedef struct
Padding padding; Padding padding;
/** Font */ /** Font */
XftFont *font; XftFont *font;
/** Draw shadow under text */
int shadow_offset;
} VirtScreen; } VirtScreen;
/** Main configuration structure */ /** Main configuration structure */

View File

@ -346,7 +346,7 @@ graph_new(Statusbar *statusbar, cfg_t *config)
if((color = cfg_getstr(cfg, "fg"))) if((color = cfg_getstr(cfg, "fg")))
draw_color_new(globalconf.display, phys_screen, color, &tmp_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.fg;
if((color = cfg_getstr(cfg, "fg_center"))) if((color = cfg_getstr(cfg, "fg_center")))
{ {
@ -411,7 +411,7 @@ graph_new(Statusbar *statusbar, cfg_t *config)
if((color = cfg_getstr(config, "bg"))) if((color = cfg_getstr(config, "bg")))
draw_color_new(globalconf.display, phys_screen, color, &d->bg); 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.bg;
if((color = cfg_getstr(config, "bordercolor"))) if((color = cfg_getstr(config, "bordercolor")))
draw_color_new(globalconf.display, phys_screen, color, &d->bordercolor); draw_color_new(globalconf.display, phys_screen, color, &d->bordercolor);

View File

@ -459,7 +459,7 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
if((color = cfg_getstr(cfg, "fg"))) if((color = cfg_getstr(cfg, "fg")))
draw_color_new(globalconf.display, phys_screen, color, &d->fg[i]); 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.fg;
if((color = cfg_getstr(cfg, "fg_center"))) if((color = cfg_getstr(cfg, "fg_center")))
{ {
@ -476,7 +476,7 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
if((color = cfg_getstr(cfg, "bg"))) if((color = cfg_getstr(cfg, "bg")))
draw_color_new(globalconf.display, phys_screen, color, &d->bg[i]); 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.fg;
if((color = cfg_getstr(cfg, "bordercolor"))) if((color = cfg_getstr(cfg, "bordercolor")))
draw_color_new(globalconf.display, phys_screen, color, &d->bordercolor[i]); draw_color_new(globalconf.display, phys_screen, color, &d->bordercolor[i]);

View File

@ -68,7 +68,7 @@ taglist_draw(Widget *widget,
Client *sel = globalconf.focus->client; Client *sel = globalconf.focus->client;
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
int w = 0, flagsize; int w = 0, flagsize;
XColor *colors; colors_ctx_t colors;
Area area; Area area;
flagsize = (vscreen.font->height + 2) / 3; flagsize = (vscreen.font->height + 2) / 3;
@ -93,11 +93,11 @@ taglist_draw(Widget *widget,
{ {
w = draw_textwidth(ctx->display, vscreen.font, tag->name) + vscreen.font->height; w = draw_textwidth(ctx->display, vscreen.font, tag->name) + vscreen.font->height;
if(tag->selected) if(tag->selected)
colors = vscreen.colors_selected; colors = vscreen.colors.focus;
else if(isurgent(tag)) else if(isurgent(tag))
colors = vscreen.colors_urgent; colors = vscreen.colors.urgent;
else else
colors = vscreen.colors_normal; colors = vscreen.colors.normal;
area.x = widget->area.x + widget->area.width; area.x = widget->area.x + widget->area.width;
area.y = widget->area.y; area.y = widget->area.y;
area.width = w; area.width = w;
@ -107,9 +107,8 @@ taglist_draw(Widget *widget,
vscreen.font->height / 2, vscreen.font->height / 2,
vscreen.font, vscreen.font,
tag->name, tag->name,
vscreen.shadow_offset, colors);
colors[ColFG],
colors[ColBG]);
if(isoccupied(tag)) if(isoccupied(tag))
{ {
Area rectangle = { widget->area.x + widget->area.width, Area rectangle = { widget->area.x + widget->area.width,
@ -117,7 +116,7 @@ taglist_draw(Widget *widget,
flagsize, flagsize,
flagsize, flagsize,
NULL, NULL }; NULL, NULL };
draw_rectangle(ctx, rectangle, sel && is_client_tagged(sel, tag), colors[ColFG]); draw_rectangle(ctx, rectangle, sel && is_client_tagged(sel, tag), colors.fg);
} }
widget->area.width += w; widget->area.width += w;
} }

View File

@ -43,10 +43,11 @@ typedef struct
ShowClient show; ShowClient show;
Bool show_icons; Bool show_icons;
Alignment align; Alignment align;
XColor fg_sel; struct
XColor bg_sel; {
XColor fg; colors_ctx_t normal;
XColor bg; colors_ctx_t focus;
} colors;
} Data; } Data;
static inline Bool static inline Bool
@ -121,9 +122,9 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
area.height = widget->statusbar->height; area.height = widget->statusbar->height;
area.width = box_width; area.width = box_width;
if(sel == c) if(sel == c)
draw_rectangle(ctx, area, True, d->bg_sel); draw_rectangle(ctx, area, True, d->colors.focus.bg);
else else
draw_rectangle(ctx, area, True, d->bg); draw_rectangle(ctx, area, True, d->colors.normal.bg);
if((r = rule_matching_client(c)) && r->icon) if((r = rule_matching_client(c)) && r->icon)
{ {
@ -165,13 +166,11 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
if(sel == c) if(sel == c)
draw_text(ctx, area, d->align, draw_text(ctx, area, d->align,
widget->font->height / 2, widget->font, c->name, widget->font->height / 2, widget->font, c->name,
globalconf.screens[widget->statusbar->screen].shadow_offset, d->colors.focus);
d->fg_sel, d->bg_sel);
else else
draw_text(ctx, area, d->align, draw_text(ctx, area, d->align,
widget->font->height / 2, widget->font, c->name, widget->font->height / 2, widget->font, c->name,
globalconf.screens[widget->statusbar->screen].shadow_offset, d->colors.normal);
d->fg, d->bg);
if(c == globalconf.scratch.client) if(c == globalconf.scratch.client)
{ {
@ -179,13 +178,13 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
area.y = widget->area.y; area.y = widget->area.y;
area.width = (widget->font->height + 2) / 3; area.width = (widget->font->height + 2) / 3;
area.height = (widget->font->height + 2) / 3; area.height = (widget->font->height + 2) / 3;
draw_rectangle(ctx, area, c->isfloating, d->fg); draw_rectangle(ctx, area, c->isfloating, d->colors.normal.fg);
} }
else if(c->isfloating || c->ismax) else if(c->isfloating || c->ismax)
draw_circle(ctx, widget->area.x + icon_width + box_width * i, draw_circle(ctx, widget->area.x + icon_width + box_width * i,
widget->area.y, widget->area.y,
(widget->font->height + 2) / 4, (widget->font->height + 2) / 4,
c->ismax, d->fg); c->ismax, d->colors.normal.fg);
i++; i++;
} }
@ -279,24 +278,24 @@ 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")))
draw_color_new(globalconf.display, phys_screen, buf, &d->fg); draw_color_new(globalconf.display, phys_screen, buf, &d->colors.normal.fg);
else else
d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG]; d->colors.normal.fg = globalconf.screens[statusbar->screen].colors.normal.fg;
if((buf = cfg_getstr(config, "bg"))) if((buf = cfg_getstr(config, "bg")))
draw_color_new(globalconf.display, phys_screen, buf, &d->bg); draw_color_new(globalconf.display, phys_screen, buf, &d->colors.normal.bg);
else else
d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG]; d->colors.normal.bg = globalconf.screens[statusbar->screen].colors.normal.bg;
if((buf = cfg_getstr(config, "focus_bg"))) if((buf = cfg_getstr(config, "focus_bg")))
draw_color_new(globalconf.display, phys_screen, buf, &d->bg_sel); draw_color_new(globalconf.display, phys_screen, buf, &d->colors.focus.bg);
else else
d->bg_sel = globalconf.screens[statusbar->screen].colors_selected[ColBG]; d->colors.focus.bg = globalconf.screens[statusbar->screen].colors.focus.bg;
if((buf = cfg_getstr(config, "focus_fg"))) if((buf = cfg_getstr(config, "focus_fg")))
draw_color_new(globalconf.display, phys_screen, buf, &d->fg_sel); draw_color_new(globalconf.display, phys_screen, buf, &d->colors.focus.fg);
else else
d->fg_sel = globalconf.screens[statusbar->screen].colors_selected[ColFG]; d->colors.focus.fg = globalconf.screens[statusbar->screen].colors.focus.fg;
d->align = draw_get_align(cfg_getstr(config, "text_align")); d->align = draw_get_align(cfg_getstr(config, "text_align"));
d->show_icons = cfg_getbool(config, "show_icons"); d->show_icons = cfg_getbool(config, "show_icons");

View File

@ -30,8 +30,7 @@ typedef struct
char *text; char *text;
int width; int width;
Alignment align; Alignment align;
XColor fg; colors_ctx_t colors;
XColor bg;
} Data; } Data;
static int static int
@ -57,9 +56,7 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
if(!widget->user_supplied_y) if(!widget->user_supplied_y)
widget->area.y = 0; widget->area.y = 0;
draw_text(ctx, widget->area, d->align, 0, widget->font, d->text, draw_text(ctx, widget->area, d->align, 0, widget->font, d->text, d->colors);
globalconf.screens[widget->statusbar->screen].shadow_offset,
d->fg, d->bg);
return widget->area.width; return widget->area.width;
} }
@ -80,12 +77,12 @@ textbox_tell(Widget *widget, char *property, char *command)
d->text = a_strdup(command); d->text = a_strdup(command);
} }
else if(!a_strcmp(property, "fg")) else if(!a_strcmp(property, "fg"))
if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->fg)) if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->colors.fg))
return WIDGET_NOERROR; return WIDGET_NOERROR;
else else
return WIDGET_ERROR_FORMAT_COLOR; return WIDGET_ERROR_FORMAT_COLOR;
else if(!a_strcmp(property, "bg")) else if(!a_strcmp(property, "bg"))
if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->bg)) if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->colors.bg))
return WIDGET_NOERROR; return WIDGET_NOERROR;
else else
return WIDGET_ERROR_FORMAT_COLOR; return WIDGET_ERROR_FORMAT_COLOR;
@ -128,14 +125,14 @@ 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")))
draw_color_new(globalconf.display, get_phys_screen(statusbar->screen), buf, &d->fg); draw_color_new(globalconf.display, get_phys_screen(statusbar->screen), buf, &d->colors.fg);
else else
d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG]; d->colors.fg = globalconf.screens[statusbar->screen].colors.normal.fg;
if((buf = cfg_getstr(config, "bg"))) if((buf = cfg_getstr(config, "bg")))
draw_color_new(globalconf.display, get_phys_screen(statusbar->screen), buf, &d->bg); draw_color_new(globalconf.display, get_phys_screen(statusbar->screen), buf, &d->colors.bg);
else else
d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG]; d->colors.bg = globalconf.screens[statusbar->screen].colors.normal.bg;
d->width = cfg_getint(config, "width"); d->width = cfg_getint(config, "width");
d->align = draw_get_align(cfg_getstr(config, "text_align")); d->align = draw_get_align(cfg_getstr(config, "text_align"));