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

View File

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

View File

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

View File

@ -1,11 +1,10 @@
screen 0 screen 0
{ {
general styles
{
colors
{ {
normal normal
{ {
font = "vera-10"
fg = "#eeeeee" fg = "#eeeeee"
bg = "#111111" bg = "#111111"
border = "#6666ff" border = "#6666ff"
@ -22,7 +21,6 @@ screen 0
bg = "#ff0000" bg = "#ff0000"
} }
} }
}
tags tags
{ {
tag one { } tag one { }

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.border.pixel); globalconf.screens[c->screen].styles.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.focus.border.pixel); globalconf.screens[screen].styles.focus.border.pixel);
XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime); XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime);
if(raise) if(raise)
{ {
@ -281,7 +281,8 @@ 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.border.pixel); XSetWindowBorder(globalconf.display, w,
globalconf.screens[screen].styles.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

@ -76,27 +76,27 @@ cfg_opt_t general_opts[] =
CFG_BOOL((char *) "sloppy_focus_raise", cfg_false, CFGF_NONE), CFG_BOOL((char *) "sloppy_focus_raise", cfg_false, CFGF_NONE),
CFG_BOOL((char *) "new_become_master", cfg_true, CFGF_NONE), CFG_BOOL((char *) "new_become_master", cfg_true, CFGF_NONE),
CFG_BOOL((char *) "new_get_focus", 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_INT((char *) "opacity_unfocused", -1, CFGF_NONE),
CFG_STR((char *) "floating_placement", (char *) "smart", 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_lower_limit", 0.1, CFGF_NONE),
CFG_FLOAT((char *) "mwfact_upper_limit", 0.9, CFGF_NONE), CFG_FLOAT((char *) "mwfact_upper_limit", 0.9, CFGF_NONE),
CFG_AWESOME_END() CFG_AWESOME_END()
}; };
cfg_opt_t colors_opts[] = cfg_opt_t style_opts[] =
{ {
CFG_STR((char *) "border", (char *) NULL, CFGF_NONE), CFG_STR((char *) "border", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "shadow", (char *) NULL, CFGF_NONE), CFG_STR((char *) "shadow", (char *) NULL, CFGF_NONE),
CFG_INT((char *) "shadow_offset", 0, CFGF_NONE), CFG_INT((char *) "shadow_offset", 0, CFGF_NONE),
CFG_STR((char *) "font", (char *) NULL, CFGF_NONE),
CFG_AWESOME_END() 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 *) "normal", style_opts, CFGF_NONE),
CFG_SEC((char *) "focus", colors_opts, CFGF_NONE), CFG_SEC((char *) "focus", style_opts, CFGF_NONE),
CFG_SEC((char *) "urgent", colors_opts, CFGF_NONE), CFG_SEC((char *) "urgent", style_opts, CFGF_NONE),
CFG_AWESOME_END() CFG_AWESOME_END()
}; };
cfg_opt_t mouse_taglist_opts[] = 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 *) "text", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "font", (char *) NULL, CFGF_NONE), CFG_STR((char *) "font", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "text_align", (char *) "center", 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_AWESOME_END()
}; };
cfg_opt_t widget_tasklist_opts[] = 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 *) "x", 0xffffffff, CFGF_NONE),
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE), CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI), 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 *) "font", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "text_align", (char *) "left", CFGF_NONE), CFG_STR((char *) "text_align", (char *) "left", CFGF_NONE),
CFG_STR((char *) "show", (char *) "tags", 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 *) "general", general_opts, CFGF_NONE),
CFG_SEC((char *) "statusbar", statusbar_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES), 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 *) "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 *) "layouts", layouts_opts, CFGF_NONE),
CFG_SEC((char *) "padding", padding_opts, CFGF_NONE), CFG_SEC((char *) "padding", padding_opts, CFGF_NONE),
CFG_AWESOME_END() CFG_AWESOME_END()
@ -323,7 +323,7 @@ cfg_opt_t menu_opts[] =
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE), CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE), CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
CFG_STR((char *) "font", NULL, 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_AWESOME_END()
}; };
cfg_opt_t awesome_opts[] = cfg_opt_t awesome_opts[] =

View File

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

View File

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

View File

@ -281,9 +281,9 @@ config_parse_screen(cfg_t *cfg, int screen)
Layout *layout = NULL; Layout *layout = NULL;
Tag *tag = NULL; Tag *tag = NULL;
Statusbar *statusbar = 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_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]; VirtScreen *virtscreen = &globalconf.screens[screen];
int i, phys_screen = get_phys_screen(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 */ /* get screen specific sections */
cfg_tags = cfg_getsec(cfg_screen, "tags"); 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_general = cfg_getsec(cfg_screen, "general");
cfg_layouts = cfg_getsec(cfg_screen, "layouts"); cfg_layouts = cfg_getsec(cfg_screen, "layouts");
cfg_padding = cfg_getsec(cfg_screen, "padding"); 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_become_master = cfg_getbool(cfg_general, "new_become_master");
virtscreen->new_get_focus = cfg_getbool(cfg_general, "new_get_focus"); virtscreen->new_get_focus = cfg_getbool(cfg_general, "new_get_focus");
virtscreen->opacity_unfocused = cfg_getint(cfg_general, "opacity_unfocused"); virtscreen->opacity_unfocused = cfg_getint(cfg_general, "opacity_unfocused");
virtscreen->font = XftFontOpenName(globalconf.display,
phys_screen,
cfg_getstr(cfg_general, "font"));
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);
@ -353,29 +350,28 @@ config_parse_screen(cfg_t *cfg, int screen)
virtscreen->floating_placement = FloatingPlacementList[0].func; virtscreen->floating_placement = FloatingPlacementList[0].func;
} }
if(!virtscreen->font)
eprint("cannot init font\n");
/* Colors */ /* Colors */
if(!cfg_colors) if(!cfg_styles)
eprint("no colors section found"); eprint("no colors section found");
if(!(cfg_colors_normal = cfg_getsec(cfg_colors, "normal"))) if(!(cfg_styles_normal = cfg_getsec(cfg_styles, "normal")))
eprint("no normal colors section found"); eprint("no normal colors section found\n");
if(!(cfg_colors_focus = cfg_getsec(cfg_colors, "focus"))) if(!(cfg_styles_focus = cfg_getsec(cfg_styles, "focus")))
eprint("no focus colors section found"); eprint("no focus colors section found\n");
if(!(cfg_colors_urgent = cfg_getsec(cfg_colors, "urgent"))) if(!(cfg_styles_urgent = cfg_getsec(cfg_styles, "urgent")))
eprint("no urgent colors section found"); eprint("no urgent colors section found\n");
draw_colors_ctx_init(globalconf.display, phys_screen, draw_style_init(globalconf.display, phys_screen,
cfg_colors_normal, &virtscreen->colors.normal, NULL); cfg_styles_normal, &virtscreen->styles.normal, NULL);
draw_colors_ctx_init(globalconf.display, phys_screen, draw_style_init(globalconf.display, phys_screen,
cfg_colors_focus, &virtscreen->colors.focus, NULL); cfg_styles_focus, &virtscreen->styles.focus, &virtscreen->styles.normal);
draw_colors_ctx_init(globalconf.display, phys_screen, draw_style_init(globalconf.display, phys_screen,
cfg_colors_urgent, &virtscreen->colors.urgent, NULL); cfg_styles_urgent, &virtscreen->styles.urgent, &virtscreen->styles.normal);
if(!virtscreen->styles.normal.font)
eprint("no font available\n");
/* Statusbar */ /* Statusbar */
statusbar_list_init(&virtscreen->statusbar); statusbar_list_init(&virtscreen->statusbar);
for(i = cfg_size(cfg_screen, "statusbar") - 1; i >= 0; i--) 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.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.bg); globalconf.screens[statusbar->screen].styles.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)
@ -166,17 +166,11 @@ statusbar_display(Statusbar *statusbar)
void void
statusbar_preinit(Statusbar *statusbar) statusbar_preinit(Statusbar *statusbar)
{ {
Widget *widget;
if(statusbar->height <= 0) if(statusbar->height <= 0)
{ /* 1.5 as default factor, it fits nice but no one knows why */
/* 1.5 as default factor, it fits nice but no one know why */ statusbar->height = 1.5 * MAX(globalconf.screens[statusbar->screen].styles.normal.font->height,
statusbar->height = globalconf.screens[statusbar->screen].font->height * 1.5; MAX(globalconf.screens[statusbar->screen].styles.focus.font->height,
globalconf.screens[statusbar->screen].styles.urgent.font->height));
for(widget = statusbar->widgets; widget; widget = widget->next)
if(widget->font)
statusbar->height = MAX(statusbar->height, widget->font->height * 1.5);
}
} }
void void

View File

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

View File

@ -435,7 +435,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.fg; tmp_color = globalconf.screens[statusbar->screen].styles.normal.fg;
if((color = cfg_getstr(cfg, "fg_center"))) if((color = cfg_getstr(cfg, "fg_center")))
{ {
@ -503,7 +503,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.bg; d->bg = globalconf.screens[statusbar->screen].styles.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.fg; d->fg[i] = globalconf.screens[statusbar->screen].styles.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.fg; d->bg[i] = globalconf.screens[statusbar->screen].styles.normal.bg;
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,16 +68,19 @@ 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;
colors_ctx_t colors; style_t style;
Area area; Area area;
flagsize = (vscreen.font->height + 2) / 3; flagsize = (vscreen.styles.normal.font->height + 2) / 3;
widget->area.width = 0; widget->area.width = 0;
for(tag = vscreen.tags; tag; tag = tag->next) 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) if(!widget->user_supplied_x)
widget->area.x = widget_calculate_offset(widget->statusbar->width, widget->area.x = widget_calculate_offset(widget->statusbar->width,
@ -91,23 +94,22 @@ taglist_draw(Widget *widget,
widget->area.width = 0; widget->area.width = 0;
for(tag = vscreen.tags; tag; tag = tag->next) for(tag = vscreen.tags; tag; tag = tag->next)
{ {
w = draw_textwidth(ctx->display, vscreen.font, tag->name) + vscreen.font->height;
if(tag->selected) if(tag->selected)
colors = vscreen.colors.focus; style = vscreen.styles.focus;
else if(isurgent(tag)) else if(isurgent(tag))
colors = vscreen.colors.urgent; style = vscreen.styles.urgent;
else 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.x = widget->area.x + widget->area.width;
area.y = widget->area.y; area.y = widget->area.y;
area.width = w; area.width = w;
area.height = widget->statusbar->height; area.height = widget->statusbar->height;
draw_text(ctx, area, draw_text(ctx, area,
AlignCenter, AlignCenter,
vscreen.font->height / 2, style.font->height / 2,
vscreen.font,
tag->name, tag->name,
colors); style);
if(isoccupied(tag)) if(isoccupied(tag))
{ {
@ -116,7 +118,7 @@ taglist_draw(Widget *widget,
flagsize, flagsize,
flagsize, flagsize,
NULL, NULL }; 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; widget->area.width += w;
} }
@ -133,17 +135,27 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
Tag *tag; Tag *tag;
char buf[4]; char buf[4];
int prev_width = 0, width = 0, i = 1; int prev_width = 0, width = 0, i = 1;
style_t style;
for(b = widget->buttons; b; b = b->next) for(b = widget->buttons; b; b = b->next)
if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func) 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) switch(widget->statusbar->position)
{ {
case Top: case Top:
case Bottom: case Bottom:
for(tag = vscreen.tags; tag; tag = tag->next, i++) for(tag = vscreen.tags; tag; tag = tag->next, i++)
{ {
width = draw_textwidth(globalconf.display, vscreen.font, tag->name) width = draw_textwidth(globalconf.display, style.font, tag->name)
+ vscreen.font->height; + style.font->height;
if(ev->x >= widget->area.x + prev_width if(ev->x >= widget->area.x + prev_width
&& ev->x < widget->area.x + prev_width + width) && ev->x < widget->area.x + prev_width + width)
{ {
@ -157,7 +169,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
case Right: case Right:
for(tag = vscreen.tags; tag; tag = tag->next, i++) 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 if(ev->y >= widget->area.x + prev_width
&& ev->y < widget->area.x + prev_width + width) && ev->y < widget->area.x + prev_width + width)
{ {
@ -171,7 +183,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
default: default:
for(tag = vscreen.tags; tag; tag = tag->next, i++) 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 if(widget->statusbar->width - ev->y >= widget->area.x + prev_width
&& widget->statusbar->width - ev->y < widget->area.x + prev_width + width) && widget->statusbar->width - ev->y < widget->area.x + prev_width + width)
{ {
@ -183,6 +195,7 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
} }
break; break;
} }
}
} }
Widget * Widget *

View File

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

View File

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