Change colors infrastructure to style: rename colors_ctx_t to style_t and add font in it

This commit is contained in:
Julien Danjou 2008-03-14 08:35:06 +01:00
parent b4ec0e2d13
commit fa47024714
16 changed files with 263 additions and 299 deletions

View File

@ -83,14 +83,12 @@ typedef struct
SimpleWindow *sw;
/** The draw contet */
DrawCtx *ctx;
/** Font to use */
XftFont *font;
/** Colors */
struct
{
colors_ctx_t normal;
colors_ctx_t focus;
} colors;
style_t normal;
style_t focus;
} styles;
/** Numlock mask */
unsigned int numlockmask;
/** The text */
@ -120,10 +118,8 @@ static int
config_parse(const char *confpatharg, const char *menu_title, Area *geometry)
{
int ret, i;
char *confpath, *opt;
cfg_t *cfg, *cfg_menu = NULL, *cfg_screen, *cfg_general,
*cfg_colors, *cfg_menu_colors = NULL;
colors_ctx_t colors_normal, colors_focus;
char *confpath;
cfg_t *cfg, *cfg_menu = NULL, *cfg_screen = NULL, *cfg_styles, *cfg_menu_styles = NULL;
if(!confpatharg)
confpath = config_file();
@ -147,47 +143,13 @@ config_parse(const char *confpatharg, const char *menu_title, Area *geometry)
if(menu_title && !(cfg_menu = cfg_gettsec(cfg, "menu", menu_title)))
warn("no definition for menu %s in configuration file: using default\n", menu_title);
/* get global screen section */
if(!(cfg_screen = cfg_getsec(cfg, "screen")))
eprint("parsing configuration file failed, no screen section found\n");
/* get colors and general section */
if(cfg_menu)
cfg_menu_colors = cfg_getsec(cfg_menu, "colors");
cfg_general = cfg_getsec(cfg_screen, "general");
cfg_colors = cfg_getsec(cfg_screen, "colors");
/* Colors */
/* Grab default colors */
draw_colors_ctx_init(globalconf.display, DefaultScreen(globalconf.display),
cfg_getsec(cfg_colors, "normal"),
&colors_normal, NULL);
draw_colors_ctx_init(globalconf.display, DefaultScreen(globalconf.display),
cfg_getsec(cfg_colors, "normal"),
&colors_normal, NULL);
/* Now grab menu colors if any */
draw_colors_ctx_init(globalconf.display, DefaultScreen(globalconf.display),
cfg_getsec(cfg_colors, "normal"),
&globalconf.colors.normal, &colors_normal);
draw_colors_ctx_init(globalconf.display, DefaultScreen(globalconf.display),
cfg_getsec(cfg_colors, "focus"),
&globalconf.colors.focus, &colors_focus);
/* font */
if(!cfg_menu || !(opt = cfg_getstr(cfg_menu, "font")))
opt = cfg_getstr(cfg_general, "font");
globalconf.font = XftFontOpenName(globalconf.display,
DefaultScreen(globalconf.display),
opt);
cfg_screen = cfg_getsec(cfg, "screen");
if(cfg_menu)
{
cfg_menu_styles = cfg_getsec(cfg_menu, "styles");
if((i = cfg_getint(cfg_menu, "x")) != (int) 0xffffffff)
geometry->x = i;
if((i = cfg_getint(cfg_menu, "y")) != (int) 0xffffffff)
@ -198,6 +160,34 @@ config_parse(const char *confpatharg, const char *menu_title, Area *geometry)
geometry->height = i;
}
if(cfg_screen
&& (cfg_styles = cfg_getsec(cfg_screen, "styles")))
{
/* Grab default styles */
draw_style_init(globalconf.display, DefaultScreen(globalconf.display),
cfg_getsec(cfg_styles, "normal"),
&globalconf.styles.normal, NULL);
draw_style_init(globalconf.display, DefaultScreen(globalconf.display),
cfg_getsec(cfg_styles, "focus"),
&globalconf.styles.focus, &globalconf.styles.normal);
}
/* Now grab menu styles if any */
if(cfg_menu_styles)
{
draw_style_init(globalconf.display, DefaultScreen(globalconf.display),
cfg_getsec(cfg_menu_styles, "normal"),
&globalconf.styles.normal, NULL);
draw_style_init(globalconf.display, DefaultScreen(globalconf.display),
cfg_getsec(cfg_menu_styles, "focus"),
&globalconf.styles.focus, &globalconf.styles.normal);
}
if(!globalconf.styles.normal.font)
eprint("no default font available\n");
p_delete(&confpath);
return ret;
@ -368,19 +358,6 @@ compute_match(const char *word)
/* Why not? */
#define MARGIN 10
static void
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.colors.focus);
else
draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN / 2, globalconf.font, item->data,
globalconf.colors.normal);
}
static void
redraw(void)
{
@ -388,6 +365,7 @@ redraw(void)
Area geometry = { 0, 0, 0, 0, NULL, NULL };
Bool selected_item_is_drawn = False;
int len, prompt_len, x_of_previous_item;
style_t style;
geometry.width = globalconf.sw->geometry.width;
geometry.height = globalconf.sw->geometry.height;
@ -395,19 +373,17 @@ redraw(void)
if(a_strlen(globalconf.prompt))
{
draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN, globalconf.font, globalconf.prompt,
globalconf.colors.focus);
MARGIN, globalconf.prompt, globalconf.styles.focus);
len = MARGIN * 2 + draw_textwidth(globalconf.display, globalconf.font, globalconf.prompt);
len = MARGIN * 2 + draw_textwidth(globalconf.display, globalconf.styles.focus.font, globalconf.prompt);
geometry.x += len;
geometry.width -= len;
}
draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN, globalconf.font, globalconf.text,
globalconf.colors.normal);
MARGIN, globalconf.text, globalconf.styles.normal);
len = MARGIN * 2 + MAX(draw_textwidth(globalconf.display, globalconf.font, globalconf.text),
len = MARGIN * 2 + MAX(draw_textwidth(globalconf.display, globalconf.styles.normal.font, globalconf.text),
geometry.width / 20);
geometry.x += len;
geometry.width -= len;
@ -416,7 +392,8 @@ redraw(void)
for(item = globalconf.items; item && geometry.width > 0; item = item->next)
if(item->match)
{
len = MARGIN + draw_textwidth(globalconf.display, globalconf.font, item->data);
style = item == globalconf.item_selected ? globalconf.styles.focus : globalconf.styles.normal;
len = MARGIN + draw_textwidth(globalconf.display, style.font, item->data);
if(item == globalconf.item_selected)
{
if(len > geometry.width)
@ -424,7 +401,8 @@ redraw(void)
else
selected_item_is_drawn = True;
}
draw_item(item, geometry);
draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN / 2, item->data, style);
geometry.x += len;
geometry.width -= len;
}
@ -437,25 +415,27 @@ redraw(void)
for(item = globalconf.item_selected; item; item = item_list_prev(&globalconf.items, item))
if(item->match)
{
style = item == globalconf.item_selected ? globalconf.styles.focus : globalconf.styles.normal;
x_of_previous_item = geometry.x;
geometry.width = MARGIN + draw_textwidth(globalconf.display, globalconf.font, item->data);
geometry.width = MARGIN + draw_textwidth(globalconf.display, style.font, item->data);
geometry.x -= geometry.width;
if(geometry.x < prompt_len)
break;
draw_item(item, geometry);
draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN / 2, item->data, style);
}
if(item)
{
geometry.x = prompt_len;
geometry.width = x_of_previous_item - prompt_len;
draw_rectangle(globalconf.ctx, geometry, True, globalconf.colors.normal.bg);
draw_rectangle(globalconf.ctx, geometry, True, globalconf.styles.normal.bg);
}
}
else if(geometry.width)
draw_rectangle(globalconf.ctx, geometry, True, globalconf.colors.normal.bg);
draw_rectangle(globalconf.ctx, geometry, True, globalconf.styles.normal.bg);
simplewindow_refresh_drawable(globalconf.sw, DefaultScreen(globalconf.display));
XSync(globalconf.display, False);
@ -651,7 +631,8 @@ main(int argc, char **argv)
/* Init the geometry */
if(!geometry.height)
geometry.height = globalconf.font->height * 1.5;
geometry.height = 1.5 * MAX(globalconf.styles.normal.font->height,
globalconf.styles.focus.font->height);
si = screensinfo_new(disp);
if(si->xinerama_is_active)

View File

@ -47,10 +47,8 @@ typedef struct
{
/** Display ref */
Display *display;
/** Font to use */
XftFont *font;
/** Colors */
colors_ctx_t colors;
/** Style */
style_t style;
} AwesomeMsgConf;
static AwesomeMsgConf globalconf;
@ -69,7 +67,7 @@ config_parse(const char *confpatharg)
{
int ret;
char *confpath;
cfg_t *cfg, *cfg_screen, *cfg_general, *cfg_colors;
cfg_t *cfg, *cfg_screen;
if(!confpatharg)
confpath = config_file();
@ -92,23 +90,19 @@ config_parse(const char *confpatharg)
return ret;
/* get global screen section */
/* XXX need to get the screen according to coords */
cfg_screen = cfg_getsec(cfg, "screen");
if(!cfg_screen)
eprint("parsing configuration file failed, no screen section found\n");
/* get colors and general section */
cfg_general = cfg_getsec(cfg_screen, "general");
cfg_colors = cfg_getsec(cfg_screen, "colors");
/* style */
draw_style_init(globalconf.display, DefaultScreen(globalconf.display),
cfg_getsec(cfg_getsec(cfg_screen, "styles"), "normal"),
&globalconf.style, NULL);
/* colors */
draw_colors_ctx_init(globalconf.display, DefaultScreen(globalconf.display),
cfg_getsec(cfg_colors, "normal"),
&globalconf.colors, NULL);
/* font */
globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display),
cfg_getstr(cfg_general, "font"));
if(!globalconf.style.font)
eprint("no default font available\n");
p_delete(&confpath);
@ -175,8 +169,8 @@ main(int argc, char **argv)
if((ret = config_parse(configfile)))
return ret;
geometry.width = draw_textwidth(disp, globalconf.font, argv[optind]);
geometry.height = globalconf.font->height * 1.5;
geometry.width = draw_textwidth(disp, globalconf.style.font, argv[optind]);
geometry.height = globalconf.style.font->height * 1.5;
if(argc - optind >= 2)
{
@ -185,7 +179,7 @@ main(int argc, char **argv)
eprint("invalid image\n");
else
geometry.width += icon_geometry.width
* ((double) globalconf.font->height / (double) icon_geometry.height);
* ((double) globalconf.style.font->height / (double) icon_geometry.height);
}
sw = simplewindow_new(disp, DefaultScreen(disp),
@ -197,14 +191,11 @@ main(int argc, char **argv)
geometry.width, geometry.height, sw->drawable);
geometry.x = geometry.y = 0;
draw_text(ctx, geometry, AlignRight,
0, globalconf.font, argv[optind],
globalconf.colors);
draw_text(ctx, geometry, AlignRight, 0,argv[optind], globalconf.style);
if(icon_geometry.width > 0 && icon_geometry.height > 0)
draw_image(ctx, 0, (geometry.height / 2) - (globalconf.font->height / 2),
globalconf.font->height,
argv[optind + 1]);
draw_image(ctx, 0, (geometry.height / 2) - (globalconf.style.font->height / 2),
globalconf.style.font->height, argv[optind + 1]);
p_delete(&ctx);

View File

@ -37,7 +37,7 @@ are described here.
screen
~~~~~~
This is the global section for a physical screen. It must have a title with screen number,
starting at 0. It contains several subsections, which are *general*, *tags*, *layouts*, *colors*,
starting at 0. It contains several subsections, which are *general*, *tags*, *layouts*, *styles*,
*padding* and *statusbar*.
general
@ -98,11 +98,13 @@ Layout is a section which define a layout. It has a title which is the algorithm
image::
Set the image path used to describe this layouts, useful in layoutinfo widget.
colors
styles
^^^^^^
Colors is a section containing the colors parameters which is composed of a normal, focus and urgent
Styles is a section containing the style parameters which is composed of a normal, focus and urgent
subsection each ones containing:
font::
The font to use.
fg::
Set the foreground color.
bg::
@ -382,12 +384,8 @@ This widget shows a list of running windows.
*mouse*::
Set mouse bindings.
*font*::
Font to use.
*bg*::
Background color.
*colors*::
Colors section with a focus and normal subsection.
*styles*::
Style section with a focus and normal subsection.
*text_align*::
Text alignement.
*show_icons*::
@ -409,8 +407,8 @@ This widget shows a text.
Font to use.
*width*::
Set width.
*colors*::
Colors section with a focus and normal subsection.
*styles*::
Styles section with a focus and normal subsection.
*text*::
Text to change.
*text_align*::
@ -538,7 +536,9 @@ Note: when there is no whitespace, quotes are optional.
<uicb-arg> -> prog, 3... (argument to a uicb function, where required)
<uicb-cmd> -> spawn, exec, client_tag... (see UICB FUNCTIONS above)
<{.., ...}> -> list of available options
<color section> -> a section with fg, bg, border, shadow and shadow_offset options.
<style section> -> a section with font, fg, bg, border, shadow and shadow_offset options.
{ font = <font> fg = <color> bg = <color> border = <color>
shadow = <color> shadow_offset = <integer> }
[MULTI] means, you can use an item multiple times.
@ -577,11 +577,11 @@ screen <integer> [MULTI]
spiral,tile,tileleft,
tilebottom,tiletop}> { image = <image> } [MULTI]
}
colors
styles
{
normal { <color section> }
focus { <color section> }
urgent { <color section> }
normal { <style section> }
focus { <style section> }
urgent { <style section> }
}
padding
{
@ -628,10 +628,10 @@ screen <integer> [MULTI]
}
tasklist <identifier>
{
colors
styles
{
normal { <color section> }
focus { <color section> }
normal { <style section> }
focus { <style section> }
}
font = <font>
show_icons = <boolean>
@ -646,10 +646,8 @@ screen <integer> [MULTI]
}
textbox <identifier> [MULTI]
{
style { <style section> }
text = <string>
bg = <color>
fg = <color>
font = <font>
width = <integer>
text_align = <{center,left,right}>
x = <integer> y = <integer>

View File

@ -1,28 +1,26 @@
screen 0
{
general
styles
{
colors
normal
{
normal
{
fg = "#eeeeee"
bg = "#111111"
border = "#6666ff"
}
focus
{
fg = "#ffffff"
bg = "#6666ff"
border = "#6666ff"
}
urgent
{
fg = "#ffffff"
bg = "#ff0000"
}
}
}
font = "vera-10"
fg = "#eeeeee"
bg = "#111111"
border = "#6666ff"
}
focus
{
fg = "#ffffff"
bg = "#6666ff"
border = "#6666ff"
}
urgent
{
fg = "#ffffff"
bg = "#ff0000"
}
}
tags
{
tag one { }

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.border.pixel);
globalconf.screens[c->screen].styles.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.focus.border.pixel);
globalconf.screens[screen].styles.focus.border.pixel);
XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime);
if(raise)
{
@ -281,7 +281,8 @@ 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.border.pixel);
XSetWindowBorder(globalconf.display, w,
globalconf.screens[screen].styles.normal.border.pixel);
/* propagates border_width, if size doesn't change */
window_configure(c->win, c->geometry, c->border);

View File

@ -76,27 +76,27 @@ cfg_opt_t general_opts[] =
CFG_BOOL((char *) "sloppy_focus_raise", cfg_false, CFGF_NONE),
CFG_BOOL((char *) "new_become_master", cfg_true, CFGF_NONE),
CFG_BOOL((char *) "new_get_focus", cfg_true, CFGF_NONE),
CFG_STR((char *) "font", (char *) "vera-10", CFGF_NONE),
CFG_INT((char *) "opacity_unfocused", -1, CFGF_NONE),
CFG_STR((char *) "floating_placement", (char *) "smart", CFGF_NONE),
CFG_FLOAT((char *) "mwfact_lower_limit", 0.1, CFGF_NONE),
CFG_FLOAT((char *) "mwfact_upper_limit", 0.9, CFGF_NONE),
CFG_AWESOME_END()
};
cfg_opt_t colors_opts[] =
cfg_opt_t style_opts[] =
{
CFG_STR((char *) "border", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "shadow", (char *) NULL, CFGF_NONE),
CFG_INT((char *) "shadow_offset", 0, CFGF_NONE),
CFG_STR((char *) "font", (char *) NULL, CFGF_NONE),
CFG_AWESOME_END()
};
cfg_opt_t screen_colors_opts[] =
cfg_opt_t styles_opts[] =
{
CFG_SEC((char *) "normal", colors_opts, CFGF_NONE),
CFG_SEC((char *) "focus", colors_opts, CFGF_NONE),
CFG_SEC((char *) "urgent", colors_opts, CFGF_NONE),
CFG_SEC((char *) "normal", style_opts, CFGF_NONE),
CFG_SEC((char *) "focus", style_opts, CFGF_NONE),
CFG_SEC((char *) "urgent", style_opts, CFGF_NONE),
CFG_AWESOME_END()
};
cfg_opt_t mouse_taglist_opts[] =
@ -150,7 +150,7 @@ cfg_opt_t widget_textbox_opts[] =
CFG_STR((char *) "text", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "font", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "text_align", (char *) "center", CFGF_NONE),
CFG_SEC((char *) "colors", colors_opts, CFGF_NONE),
CFG_SEC((char *) "style", style_opts, CFGF_NONE),
CFG_AWESOME_END()
};
cfg_opt_t widget_tasklist_opts[] =
@ -158,7 +158,7 @@ cfg_opt_t widget_tasklist_opts[] =
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
CFG_SEC((char *) "colors", screen_colors_opts, CFGF_NONE),
CFG_SEC((char *) "styles", styles_opts, CFGF_NONE),
CFG_STR((char *) "font", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "text_align", (char *) "left", CFGF_NONE),
CFG_STR((char *) "show", (char *) "tags", CFGF_NONE),
@ -265,7 +265,7 @@ cfg_opt_t screen_opts[] =
CFG_SEC((char *) "general", general_opts, CFGF_NONE),
CFG_SEC((char *) "statusbar", statusbar_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
CFG_SEC((char *) "tags", tags_opts, CFGF_NONE),
CFG_SEC((char *) "colors", screen_colors_opts, CFGF_NONE),
CFG_SEC((char *) "styles", styles_opts, CFGF_NONE),
CFG_SEC((char *) "layouts", layouts_opts, CFGF_NONE),
CFG_SEC((char *) "padding", padding_opts, CFGF_NONE),
CFG_AWESOME_END()
@ -323,7 +323,7 @@ cfg_opt_t menu_opts[] =
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
CFG_STR((char *) "font", NULL, CFGF_NONE),
CFG_SEC((char *) "colors", screen_colors_opts, CFGF_NONE),
CFG_SEC((char *) "styles", styles_opts, CFGF_NONE),
CFG_AWESOME_END()
};
cfg_opt_t awesome_opts[] =

View File

@ -130,15 +130,15 @@ draw_text(DrawCtx *ctx,
Area area,
Alignment align,
int padding,
XftFont *font, char *text,
colors_ctx_t colors_ctx)
char *text,
style_t style)
{
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, colors_ctx.bg);
draw_rectangle(ctx, area, True, style.bg);
if(!(len = olen = a_strlen(text)))
return;
@ -153,7 +153,7 @@ draw_text(DrawCtx *ctx,
buf = a_strdup(text);
/* check that the text is not too long */
while(len && (nw = (draw_textwidth(ctx->display, font, buf)) + padding * 2) > area.width)
while(len && (nw = (draw_textwidth(ctx->display, style.font, buf)) + padding * 2) > area.width)
{
len--;
/* we can't blindly null the char, we need to check if it's not part of
@ -175,12 +175,12 @@ draw_text(DrawCtx *ctx,
buf[len - 3] = '.';
}
font_face = cairo_ft_font_face_create_for_pattern(font->pattern);
font_face = cairo_ft_font_face_create_for_pattern(style.font->pattern);
cairo_set_font_face(ctx->cr, font_face);
cairo_set_font_size(ctx->cr, font->height);
cairo_set_font_size(ctx->cr, style.font->height);
x = area.x + padding;
y = area.y + font->ascent + (ctx->height - font->height) / 2;
y = area.y + style.font->ascent + (ctx->height - style.font->height) / 2;
switch(align)
{
@ -194,20 +194,20 @@ draw_text(DrawCtx *ctx,
break;
}
if(colors_ctx.shadow_offset > 0)
if(style.shadow_offset > 0)
{
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);
style.shadow.red / 65535.0,
style.shadow.green / 65535.0,
style.shadow.blue / 65535.0);
cairo_move_to(ctx->cr, x + style.shadow_offset, y + style.shadow_offset);
cairo_show_text(ctx->cr, buf);
}
cairo_set_source_rgb(ctx->cr,
colors_ctx.fg.red / 65535.0,
colors_ctx.fg.green / 65535.0,
colors_ctx.fg.blue / 65535.0);
style.fg.red / 65535.0,
style.fg.green / 65535.0,
style.fg.blue / 65535.0);
cairo_move_to(ctx->cr, x, y);
cairo_show_text(ctx->cr, buf);
@ -671,22 +671,33 @@ draw_color_new(Display *disp, int phys_screen, const char *colstr, XColor *color
}
void
draw_colors_ctx_init(Display *disp, int phys_screen, cfg_t *cfg_colors,
colors_ctx_t *c, colors_ctx_t *m)
draw_style_init(Display *disp, int phys_screen, cfg_t *cfg,
style_t *c, style_t *m)
{
char *buf;
if(m)
*c = *m;
draw_color_new(disp, phys_screen,
cfg_getstr(cfg_colors, "fg"), &c->fg);
draw_color_new(disp, phys_screen,
cfg_getstr(cfg_colors, "bg"), &c->bg);
draw_color_new(disp, phys_screen,
cfg_getstr(cfg_colors, "border"), &c->border);
draw_color_new(disp, phys_screen,
cfg_getstr(cfg_colors, "shadow"), &c->shadow);
if(!cfg)
return;
c->shadow_offset = cfg_getint(cfg_colors, "shadow_offset");
if((buf = cfg_getstr(cfg, "font")))
c->font = XftFontOpenName(disp, phys_screen, buf);
draw_color_new(disp, phys_screen,
cfg_getstr(cfg, "fg"), &c->fg);
draw_color_new(disp, phys_screen,
cfg_getstr(cfg, "bg"), &c->bg);
draw_color_new(disp, phys_screen,
cfg_getstr(cfg, "border"), &c->border);
draw_color_new(disp, phys_screen,
cfg_getstr(cfg, "shadow"), &c->shadow);
c->shadow_offset = cfg_getint(cfg, "shadow_offset");
}
/** Remove a area from a list of them,

View File

@ -93,7 +93,9 @@ typedef struct
XColor border;
/** Shadow offset */
int shadow_offset;
} colors_ctx_t;
/** Font */
XftFont *font;
} style_t;
typedef struct
{
@ -111,7 +113,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 *, colors_ctx_t);
void draw_text(DrawCtx *, Area, Alignment, int, char *, style_t);
void draw_rectangle(DrawCtx *, Area, Bool, XColor);
void draw_rectangle_gradient(DrawCtx *, Area, Bool, Area, XColor *, XColor *, XColor *);
@ -126,7 +128,7 @@ Drawable draw_rotate(DrawCtx *, int, double, int, int);
unsigned short draw_textwidth(Display *, XftFont *, char *);
Alignment draw_get_align(const char *);
Bool draw_color_new(Display *, int, const char *, XColor *);
void draw_colors_ctx_init(Display *, int, cfg_t *, colors_ctx_t *, colors_ctx_t *);
void draw_style_init(Display *, int, cfg_t *, style_t *, style_t *);
void area_list_remove(Area **, Area *);

View File

@ -281,9 +281,9 @@ config_parse_screen(cfg_t *cfg, int screen)
Layout *layout = NULL;
Tag *tag = NULL;
Statusbar *statusbar = NULL;
cfg_t *cfg_general, *cfg_colors, *cfg_screen, *cfg_tags,
cfg_t *cfg_general, *cfg_styles, *cfg_screen, *cfg_tags,
*cfg_layouts, *cfg_padding, *cfgsectmp,
*cfg_colors_normal, *cfg_colors_focus, *cfg_colors_urgent;
*cfg_styles_normal, *cfg_styles_focus, *cfg_styles_urgent;
VirtScreen *virtscreen = &globalconf.screens[screen];
int i, phys_screen = get_phys_screen(screen);
@ -301,7 +301,7 @@ config_parse_screen(cfg_t *cfg, int screen)
/* get screen specific sections */
cfg_tags = cfg_getsec(cfg_screen, "tags");
cfg_colors = cfg_getsec(cfg_screen, "colors");
cfg_styles = cfg_getsec(cfg_screen, "styles");
cfg_general = cfg_getsec(cfg_screen, "general");
cfg_layouts = cfg_getsec(cfg_screen, "layouts");
cfg_padding = cfg_getsec(cfg_screen, "padding");
@ -316,9 +316,6 @@ config_parse_screen(cfg_t *cfg, int screen)
virtscreen->new_become_master = cfg_getbool(cfg_general, "new_become_master");
virtscreen->new_get_focus = cfg_getbool(cfg_general, "new_get_focus");
virtscreen->opacity_unfocused = cfg_getint(cfg_general, "opacity_unfocused");
virtscreen->font = XftFontOpenName(globalconf.display,
phys_screen,
cfg_getstr(cfg_general, "font"));
virtscreen->floating_placement =
name_func_lookup(cfg_getstr(cfg_general, "floating_placement"),
FloatingPlacementList);
@ -353,29 +350,28 @@ config_parse_screen(cfg_t *cfg, int screen)
virtscreen->floating_placement = FloatingPlacementList[0].func;
}
if(!virtscreen->font)
eprint("cannot init font\n");
/* Colors */
if(!cfg_colors)
if(!cfg_styles)
eprint("no colors section found");
if(!(cfg_colors_normal = cfg_getsec(cfg_colors, "normal")))
eprint("no normal colors section found");
if(!(cfg_colors_focus = cfg_getsec(cfg_colors, "focus")))
eprint("no focus colors section found");
if(!(cfg_colors_urgent = cfg_getsec(cfg_colors, "urgent")))
eprint("no urgent colors section found");
if(!(cfg_styles_normal = cfg_getsec(cfg_styles, "normal")))
eprint("no normal colors section found\n");
if(!(cfg_styles_focus = cfg_getsec(cfg_styles, "focus")))
eprint("no focus colors section found\n");
if(!(cfg_styles_urgent = cfg_getsec(cfg_styles, "urgent")))
eprint("no urgent colors section found\n");
draw_colors_ctx_init(globalconf.display, phys_screen,
cfg_colors_normal, &virtscreen->colors.normal, NULL);
draw_colors_ctx_init(globalconf.display, phys_screen,
cfg_colors_focus, &virtscreen->colors.focus, NULL);
draw_colors_ctx_init(globalconf.display, phys_screen,
cfg_colors_urgent, &virtscreen->colors.urgent, NULL);
draw_style_init(globalconf.display, phys_screen,
cfg_styles_normal, &virtscreen->styles.normal, NULL);
draw_style_init(globalconf.display, phys_screen,
cfg_styles_focus, &virtscreen->styles.focus, &virtscreen->styles.normal);
draw_style_init(globalconf.display, phys_screen,
cfg_styles_urgent, &virtscreen->styles.urgent, &virtscreen->styles.normal);
if(!virtscreen->styles.normal.font)
eprint("no font available\n");
/* Statusbar */
statusbar_list_init(&virtscreen->statusbar);
for(i = cfg_size(cfg_screen, "statusbar") - 1; i >= 0; i--)
{

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.bg);
globalconf.screens[statusbar->screen].styles.normal.bg);
for(widget = statusbar->widgets; widget; widget = widget->next)
if (widget->alignment == AlignLeft)
@ -166,17 +166,11 @@ statusbar_display(Statusbar *statusbar)
void
statusbar_preinit(Statusbar *statusbar)
{
Widget *widget;
if(statusbar->height <= 0)
{
/* 1.5 as default factor, it fits nice but no one know why */
statusbar->height = globalconf.screens[statusbar->screen].font->height * 1.5;
for(widget = statusbar->widgets; widget; widget = widget->next)
if(widget->font)
statusbar->height = MAX(statusbar->height, widget->font->height * 1.5);
}
/* 1.5 as default factor, it fits nice but no one knows why */
statusbar->height = 1.5 * MAX(globalconf.screens[statusbar->screen].styles.normal.font->height,
MAX(globalconf.screens[statusbar->screen].styles.focus.font->height,
globalconf.screens[statusbar->screen].styles.urgent.font->height));
}
void

View File

@ -130,8 +130,6 @@ struct Widget
Area area;
/** Buttons bindings */
Button *buttons;
/** Font */
XftFont *font;
/** Cache */
struct
{
@ -285,10 +283,10 @@ typedef struct
/** Colors */
struct
{
colors_ctx_t normal;
colors_ctx_t focus;
colors_ctx_t urgent;
} colors;
style_t normal;
style_t focus;
style_t urgent;
} styles;
/** Transparency of unfocused clients */
int opacity_unfocused;
/** Tag list */
@ -299,8 +297,6 @@ typedef struct
Statusbar *statusbar;
/** Padding */
Padding padding;
/** Font */
XftFont *font;
} VirtScreen;
/** Main configuration structure */

View File

@ -435,7 +435,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.fg;
tmp_color = globalconf.screens[statusbar->screen].styles.normal.fg;
if((color = cfg_getstr(cfg, "fg_center")))
{
@ -503,7 +503,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.bg;
d->bg = globalconf.screens[statusbar->screen].styles.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.fg;
d->fg[i] = globalconf.screens[statusbar->screen].styles.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.fg;
d->bg[i] = globalconf.screens[statusbar->screen].styles.normal.bg;
if((color = cfg_getstr(cfg, "bordercolor")))
draw_color_new(globalconf.display, phys_screen, color, &d->bordercolor[i]);

View File

@ -68,16 +68,19 @@ taglist_draw(Widget *widget,
Client *sel = globalconf.focus->client;
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
int w = 0, flagsize;
colors_ctx_t colors;
style_t style;
Area area;
flagsize = (vscreen.font->height + 2) / 3;
flagsize = (vscreen.styles.normal.font->height + 2) / 3;
widget->area.width = 0;
for(tag = vscreen.tags; tag; tag = tag->next)
widget->area.width += draw_textwidth(ctx->display, vscreen.font, tag->name)
+ vscreen.font->height;
{
style = tag->selected ? vscreen.styles.focus : vscreen.styles.normal;
widget->area.width += draw_textwidth(ctx->display, style.font, tag->name)
+ style.font->height;
}
if(!widget->user_supplied_x)
widget->area.x = widget_calculate_offset(widget->statusbar->width,
@ -91,23 +94,22 @@ taglist_draw(Widget *widget,
widget->area.width = 0;
for(tag = vscreen.tags; tag; tag = tag->next)
{
w = draw_textwidth(ctx->display, vscreen.font, tag->name) + vscreen.font->height;
if(tag->selected)
colors = vscreen.colors.focus;
style = vscreen.styles.focus;
else if(isurgent(tag))
colors = vscreen.colors.urgent;
style = vscreen.styles.urgent;
else
colors = vscreen.colors.normal;
style = vscreen.styles.normal;
w = draw_textwidth(ctx->display, style.font, tag->name) + style.font->height;
area.x = widget->area.x + widget->area.width;
area.y = widget->area.y;
area.width = w;
area.height = widget->statusbar->height;
draw_text(ctx, area,
AlignCenter,
vscreen.font->height / 2,
vscreen.font,
style.font->height / 2,
tag->name,
colors);
style);
if(isoccupied(tag))
{
@ -116,7 +118,7 @@ taglist_draw(Widget *widget,
flagsize,
flagsize,
NULL, NULL };
draw_rectangle(ctx, rectangle, sel && is_client_tagged(sel, tag), colors.fg);
draw_rectangle(ctx, rectangle, sel && is_client_tagged(sel, tag), style.fg);
}
widget->area.width += w;
}
@ -133,17 +135,27 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
Tag *tag;
char buf[4];
int prev_width = 0, width = 0, i = 1;
style_t style;
for(b = widget->buttons; b; b = b->next)
if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func)
{
/* XXX this should be in a function */
if(tag->selected)
style = vscreen.styles.focus;
else if(isurgent(tag))
style = vscreen.styles.urgent;
else
style = vscreen.styles.normal;
switch(widget->statusbar->position)
{
case Top:
case Bottom:
for(tag = vscreen.tags; tag; tag = tag->next, i++)
{
width = draw_textwidth(globalconf.display, vscreen.font, tag->name)
+ vscreen.font->height;
width = draw_textwidth(globalconf.display, style.font, tag->name)
+ style.font->height;
if(ev->x >= widget->area.x + prev_width
&& ev->x < widget->area.x + prev_width + width)
{
@ -157,7 +169,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
case Right:
for(tag = vscreen.tags; tag; tag = tag->next, i++)
{
width = draw_textwidth(globalconf.display, vscreen.font, tag->name) + vscreen.font->height;
width = draw_textwidth(globalconf.display, style.font, tag->name) + style.font->height;
if(ev->y >= widget->area.x + prev_width
&& ev->y < widget->area.x + prev_width + width)
{
@ -171,7 +183,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
default:
for(tag = vscreen.tags; tag; tag = tag->next, i++)
{
width = draw_textwidth(globalconf.display, vscreen.font, tag->name) + vscreen.font->height;
width = draw_textwidth(globalconf.display, style.font, tag->name) + style.font->height;
if(widget->statusbar->width - ev->y >= widget->area.x + prev_width
&& widget->statusbar->width - ev->y < widget->area.x + prev_width + width)
{
@ -183,6 +195,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
}
break;
}
}
}
Widget *

View File

@ -45,9 +45,9 @@ typedef struct
Alignment align;
struct
{
colors_ctx_t normal;
colors_ctx_t focus;
} colors;
style_t normal;
style_t focus;
} styles;
} Data;
static inline Bool
@ -83,6 +83,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
Client *sel = focus_get_current_client(widget->statusbar->screen);
Rule *r;
Area area;
style_t style;
int n = 0, i = 0, box_width = 0, icon_width = 0, box_width_rest = 0;
NetWMIcon *icon;
@ -114,6 +115,8 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
{
icon_width = 0;
style = sel == c ? d->styles.focus : d->styles.normal;
if(d->show_icons)
{
/* draw a background for icons */
@ -121,10 +124,8 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
area.y = widget->area.y;
area.height = widget->statusbar->height;
area.width = box_width;
if(sel == c)
draw_rectangle(ctx, area, True, d->colors.focus.bg);
else
draw_rectangle(ctx, area, True, d->colors.normal.bg);
draw_rectangle(ctx, area, True, style.fg);
if((r = rule_matching_client(c)) && r->icon)
{
@ -163,28 +164,23 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
if(i == n - 1)
area.width += box_width_rest;
if(sel == c)
draw_text(ctx, area, d->align,
widget->font->height / 2, widget->font, c->name,
d->colors.focus);
else
draw_text(ctx, area, d->align,
widget->font->height / 2, widget->font, c->name,
d->colors.normal);
draw_text(ctx, area, d->align,
style.font->height / 2, c->name,
style);
if(c == globalconf.scratch.client)
{
area.x = widget->area.x + icon_width + box_width * i;
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->colors.normal.fg);
area.width = (style.font->height + 2) / 3;
area.height = (style.font->height + 2) / 3;
draw_rectangle(ctx, area, c->isfloating, style.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->colors.normal.fg);
(style.font->height + 2) / 4,
c->ismax, style.fg);
i++;
}
@ -268,7 +264,7 @@ tasklist_new(Statusbar *statusbar, cfg_t *config)
Widget *w;
Data *d;
char *buf;
cfg_t *cfg_colors;
cfg_t *cfg_styles;
int phys_screen = get_phys_screen(statusbar->screen);
w = p_new(Widget, 1);
@ -278,17 +274,17 @@ tasklist_new(Statusbar *statusbar, cfg_t *config)
w->alignment = AlignFlex;
w->data = d = p_new(Data, 1);
cfg_colors = cfg_getsec(config, "colors");
cfg_styles = cfg_getsec(config, "styles");
draw_colors_ctx_init(globalconf.display, phys_screen,
cfg_getsec(cfg_colors, "normal"),
&d->colors.normal,
&globalconf.screens[statusbar->screen].colors.normal);
draw_style_init(globalconf.display, phys_screen,
cfg_getsec(cfg_styles, "normal"),
&d->styles.normal,
&globalconf.screens[statusbar->screen].styles.normal);
draw_colors_ctx_init(globalconf.display, phys_screen,
cfg_getsec(cfg_colors, "focus"),
&d->colors.focus,
&globalconf.screens[statusbar->screen].colors.focus);
draw_style_init(globalconf.display, phys_screen,
cfg_getsec(cfg_styles, "focus"),
&d->styles.focus,
&globalconf.screens[statusbar->screen].styles.focus);
d->align = draw_get_align(cfg_getstr(config, "text_align"));
d->show_icons = cfg_getbool(config, "show_icons");
@ -301,12 +297,6 @@ tasklist_new(Statusbar *statusbar, cfg_t *config)
else
d->show = ShowFocus;
if((buf = cfg_getstr(config, "font")))
w->font = XftFontOpenName(globalconf.display, get_phys_screen(statusbar->screen), buf);
if(!w->font)
w->font = globalconf.screens[statusbar->screen].font;
/* Set cache property */
w->cache.flags = WIDGET_CACHE_CLIENTS;

View File

@ -30,7 +30,7 @@ typedef struct
char *text;
int width;
Alignment align;
colors_ctx_t colors;
style_t style;
} Data;
static int
@ -43,7 +43,7 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
else if(widget->alignment == AlignFlex)
widget->area.width = widget->statusbar->width - used;
else
widget->area.width = MIN(draw_textwidth(ctx->display, widget->font, d->text),
widget->area.width = MIN(draw_textwidth(ctx->display, d->style.font, d->text),
widget->statusbar->width - used);
widget->area.height = widget->statusbar->height;
@ -56,7 +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, d->colors);
draw_text(ctx, widget->area, d->align, 0, d->text, d->style);
return widget->area.width;
}
@ -77,12 +77,12 @@ textbox_tell(Widget *widget, char *property, char *command)
else if(!command)
return WIDGET_ERROR_NOVALUE;
else if(!a_strcmp(property, "fg"))
if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->colors.fg))
if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->style.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->colors.bg))
if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->style.bg))
return WIDGET_NOERROR;
else
return WIDGET_ERROR_FORMAT_COLOR;
@ -91,9 +91,9 @@ textbox_tell(Widget *widget, char *property, char *command)
if((newfont = XftFontOpenName(globalconf.display,
get_phys_screen(widget->statusbar->screen), command)))
{
if(widget->font != globalconf.screens[widget->statusbar->screen].font)
XftFontClose(globalconf.display, widget->font);
widget->font = newfont;
if(d->style.font != globalconf.screens[widget->statusbar->screen].styles.normal.font)
XftFontClose(globalconf.display, d->style.font);
d->style.font = newfont;
}
else
return WIDGET_ERROR_FORMAT_FONT;
@ -113,7 +113,6 @@ textbox_new(Statusbar *statusbar, cfg_t *config)
{
Widget *w;
Data *d;
char *buf;
int phys_screen = get_phys_screen(statusbar->screen);
w = p_new(Widget, 1);
@ -124,20 +123,14 @@ textbox_new(Statusbar *statusbar, cfg_t *config)
w->data = d = p_new(Data, 1);
draw_colors_ctx_init(globalconf.display, phys_screen,
cfg_getsec(config, "colors"),
&d->colors,
&globalconf.screens[statusbar->screen].colors.normal);
draw_style_init(globalconf.display, phys_screen,
cfg_getsec(config, "style"),
&d->style,
&globalconf.screens[statusbar->screen].styles.normal);
d->width = cfg_getint(config, "width");
d->align = draw_get_align(cfg_getstr(config, "text_align"));
if((buf = cfg_getstr(config, "font")))
w->font = XftFontOpenName(globalconf.display, phys_screen, buf);
if(!w->font)
w->font = globalconf.screens[statusbar->screen].font;
d->text = a_strdup(cfg_getstr(config, "text"));
return w;