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

View File

@ -49,12 +49,8 @@ typedef struct
Display *display;
/** Font to use */
XftFont *font;
/** Foreground color */
XColor fg;
/** Background color */
XColor bg;
/** Draw shadow_offset under text */
Bool shadow_offset;
/** Colors */
colors_ctx_t colors;
} AwesomeMsgConf;
static AwesomeMsgConf globalconf;
@ -108,12 +104,12 @@ config_parse(const char *confpatharg)
/* colors */
draw_color_new(globalconf.display, DefaultScreen(globalconf.display),
cfg_getstr(cfg_colors, "normal_fg"),
&globalconf.fg);
&globalconf.colors.fg);
draw_color_new(globalconf.display, DefaultScreen(globalconf.display),
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 */
globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display),
@ -208,7 +204,7 @@ main(int argc, char **argv)
geometry.x = geometry.y = 0;
draw_text(ctx, geometry, AlignRight,
0, globalconf.font, argv[optind],
globalconf.shadow_offset, globalconf.fg, globalconf.bg);
globalconf.colors);
if(icon_geometry.width > 0 && icon_geometry.height > 0)
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)
window_settrans(c->win, globalconf.screens[c->screen].opacity_unfocused);
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);
focus_add_client(NULL);
}
@ -200,7 +200,7 @@ client_focus(Client *c, int screen, Bool raise)
if(globalconf.screens[c->screen].opacity_unfocused != -1)
window_settrans(c->win, -1);
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);
if(raise)
{
@ -281,7 +281,7 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
/* Set windows borders */
wc.border_width = c->border;
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 */
window_configure(c->win, c->geometry, c->border);

View File

@ -131,15 +131,14 @@ draw_text(DrawCtx *ctx,
Alignment align,
int padding,
XftFont *font, char *text,
int shadow_offset,
XColor fg, XColor bg)
colors_ctx_t colors_ctx)
{
int nw = 0, x, y;
ssize_t len, olen;
char *buf = NULL, *utf8 = NULL;
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)))
return;
@ -195,14 +194,20 @@ draw_text(DrawCtx *ctx,
break;
}
if(shadow_offset > 0)
if(colors_ctx.shadow_offset > 0)
{
cairo_set_source_rgb(ctx->cr, 0.0, 0.0, 0.0);
cairo_move_to(ctx->cr, x + shadow_offset, y + shadow_offset);
cairo_set_source_rgb(ctx->cr,
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_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_show_text(ctx->cr, buf);

View File

@ -78,6 +78,20 @@ area_get_intersect_area(Area a, Area b)
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
{
Display *display;
@ -94,7 +108,7 @@ typedef struct
DrawCtx *draw_context_new(Display *, int, int, int, Drawable);
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_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,
phys_screen,
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 =
name_func_lookup(cfg_getstr(cfg_general, "floating_placement"),
FloatingPlacementList);
@ -359,28 +362,28 @@ config_parse_screen(cfg_t *cfg, int screen)
/* Colors */
draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "normal_border"),
&virtscreen->colors_normal[ColBorder]);
&virtscreen->colors.normal.border);
draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "normal_bg"),
&virtscreen->colors_normal[ColBG]);
&virtscreen->colors.normal.bg);
draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "normal_fg"),
&virtscreen->colors_normal[ColFG]);
&virtscreen->colors.normal.fg);
draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "focus_border"),
&virtscreen->colors_selected[ColBorder]);
&virtscreen->colors.focus.border);
draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "focus_bg"),
&virtscreen->colors_selected[ColBG]);
&virtscreen->colors.focus.bg);
draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "focus_fg"),
&virtscreen->colors_selected[ColFG]);
&virtscreen->colors.focus.fg);
draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "urgent_bg"),
&virtscreen->colors_urgent[ColBG]);
&virtscreen->colors.urgent.bg);
draw_color_new(globalconf.display, phys_screen,
cfg_getstr(cfg_colors, "urgent_fg"),
&virtscreen->colors_urgent[ColFG]);
&virtscreen->colors.urgent.fg);
/* Statusbar */

View File

@ -106,7 +106,7 @@ statusbar_draw(Statusbar *statusbar)
rectangle.width = statusbar->width;
rectangle.height = statusbar->height;
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)
if (widget->alignment == AlignLeft)

View File

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

View File

@ -346,7 +346,7 @@ graph_new(Statusbar *statusbar, cfg_t *config)
if((color = cfg_getstr(cfg, "fg")))
draw_color_new(globalconf.display, phys_screen, color, &tmp_color);
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")))
{
@ -411,7 +411,7 @@ graph_new(Statusbar *statusbar, cfg_t *config)
if((color = cfg_getstr(config, "bg")))
draw_color_new(globalconf.display, phys_screen, color, &d->bg);
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")))
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")))
draw_color_new(globalconf.display, phys_screen, color, &d->fg[i]);
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")))
{
@ -476,7 +476,7 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
if((color = cfg_getstr(cfg, "bg")))
draw_color_new(globalconf.display, phys_screen, color, &d->bg[i]);
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")))
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;
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
int w = 0, flagsize;
XColor *colors;
colors_ctx_t colors;
Area area;
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;
if(tag->selected)
colors = vscreen.colors_selected;
colors = vscreen.colors.focus;
else if(isurgent(tag))
colors = vscreen.colors_urgent;
colors = vscreen.colors.urgent;
else
colors = vscreen.colors_normal;
colors = vscreen.colors.normal;
area.x = widget->area.x + widget->area.width;
area.y = widget->area.y;
area.width = w;
@ -107,9 +107,8 @@ taglist_draw(Widget *widget,
vscreen.font->height / 2,
vscreen.font,
tag->name,
vscreen.shadow_offset,
colors[ColFG],
colors[ColBG]);
colors);
if(isoccupied(tag))
{
Area rectangle = { widget->area.x + widget->area.width,
@ -117,7 +116,7 @@ taglist_draw(Widget *widget,
flagsize,
flagsize,
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;
}

View File

@ -43,10 +43,11 @@ typedef struct
ShowClient show;
Bool show_icons;
Alignment align;
XColor fg_sel;
XColor bg_sel;
XColor fg;
XColor bg;
struct
{
colors_ctx_t normal;
colors_ctx_t focus;
} colors;
} Data;
static inline Bool
@ -121,9 +122,9 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
area.height = widget->statusbar->height;
area.width = box_width;
if(sel == c)
draw_rectangle(ctx, area, True, d->bg_sel);
draw_rectangle(ctx, area, True, d->colors.focus.bg);
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)
{
@ -165,13 +166,11 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
if(sel == c)
draw_text(ctx, area, d->align,
widget->font->height / 2, widget->font, c->name,
globalconf.screens[widget->statusbar->screen].shadow_offset,
d->fg_sel, d->bg_sel);
d->colors.focus);
else
draw_text(ctx, area, d->align,
widget->font->height / 2, widget->font, c->name,
globalconf.screens[widget->statusbar->screen].shadow_offset,
d->fg, d->bg);
d->colors.normal);
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.width = (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)
draw_circle(ctx, widget->area.x + icon_width + box_width * i,
widget->area.y,
(widget->font->height + 2) / 4,
c->ismax, d->fg);
c->ismax, d->colors.normal.fg);
i++;
}
@ -279,24 +278,24 @@ tasklist_new(Statusbar *statusbar, cfg_t *config)
w->data = d = p_new(Data, 1);
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
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")))
draw_color_new(globalconf.display, phys_screen, buf, &d->bg);
draw_color_new(globalconf.display, phys_screen, buf, &d->colors.normal.bg);
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")))
draw_color_new(globalconf.display, phys_screen, buf, &d->bg_sel);
draw_color_new(globalconf.display, phys_screen, buf, &d->colors.focus.bg);
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")))
draw_color_new(globalconf.display, phys_screen, buf, &d->fg_sel);
draw_color_new(globalconf.display, phys_screen, buf, &d->colors.focus.fg);
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->show_icons = cfg_getbool(config, "show_icons");

View File

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