[client] introduce client_style_get() and use it in tasklist/titlebar

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-04-29 11:42:16 +02:00
parent 8603f0dac1
commit f0e29977d8
4 changed files with 32 additions and 21 deletions

View File

@ -812,6 +812,21 @@ client_updatesizehints(client_t *c)
return size; return size;
} }
/** Get the style related to a client: focus, urgent, normal.
* \param c The client.
* \return The style to apply for this client.
*/
style_t *
client_style_get(client_t *c)
{
if(globalconf.focus->client == c)
return &globalconf.screens[c->screen].styles.focus;
else if(c->isurgent)
return &globalconf.screens[c->screen].styles.urgent;
return &globalconf.screens[c->screen].styles.normal;
}
char * char *
client_markup_parse(client_t *c, const char *str, ssize_t len) client_markup_parse(client_t *c, const char *str, ssize_t len)
{ {

View File

@ -43,6 +43,7 @@ void client_saveprops(client_t *);
void client_kill(client_t *); void client_kill(client_t *);
void client_setfloating(client_t *, bool, layer_t); void client_setfloating(client_t *, bool, layer_t);
char * client_markup_parse(client_t *, const char *, ssize_t); char * client_markup_parse(client_t *, const char *, ssize_t);
style_t * client_style_get(client_t *);
uicb_t uicb_client_kill; uicb_t uicb_client_kill;
uicb_t uicb_client_moveresize; uicb_t uicb_client_moveresize;

View File

@ -182,6 +182,7 @@ titlebar_draw(client_t *c)
area_t geometry; area_t geometry;
xcb_screen_t *s; xcb_screen_t *s;
char *text; char *text;
style_t *style;
if(!c->titlebar.sw) if(!c->titlebar.sw)
return; return;
@ -219,7 +220,8 @@ titlebar_draw(client_t *c)
text = titlebar_text(c); text = titlebar_text(c);
geometry.x = geometry.y = 0; geometry.x = geometry.y = 0;
draw_text(ctx, geometry, text, globalconf.screens[c->screen].styles.normal); style = client_style_get(c);
draw_text(ctx, geometry, text, *style);
p_delete(&text); p_delete(&text);
switch(c->titlebar.position) switch(c->titlebar.position)

View File

@ -74,7 +74,7 @@ tasklist_draw(widget_t *widget, draw_context_t *ctx, int offset, int used)
char *text; char *text;
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;
style_t style; style_t *style;
if(used >= widget->statusbar->width) if(used >= widget->statusbar->width)
return (widget->area.width = 0); return (widget->area.width = 0);
@ -104,21 +104,14 @@ tasklist_draw(widget_t *widget, draw_context_t *ctx, int offset, int used)
{ {
icon_width = 0; icon_width = 0;
if(c->isurgent) style = client_style_get(c);
{
text = d->text_urgent; if(globalconf.focus->client == c)
style = globalconf.screens[c->screen].styles.urgent;
}
else if(globalconf.focus->client == c)
{
text = d->text_focus; text = d->text_focus;
style = globalconf.screens[c->screen].styles.focus; else if(c->isurgent)
} text = d->text_urgent;
else else
{
text = d->text_normal; text = d->text_normal;
style = globalconf.screens[c->screen].styles.normal;
}
text = client_markup_parse(c, text, a_strlen(text)); text = client_markup_parse(c, text, a_strlen(text));
@ -130,7 +123,7 @@ tasklist_draw(widget_t *widget, draw_context_t *ctx, int offset, int used)
area.height = widget->statusbar->height; area.height = widget->statusbar->height;
area.width = box_width; area.width = box_width;
draw_rectangle(ctx, area, 1.0, true, style.bg); draw_rectangle(ctx, area, 1.0, true, style->bg);
if((r = rule_matching_client(c)) && r->icon) if((r = rule_matching_client(c)) && r->icon)
{ {
@ -169,7 +162,7 @@ tasklist_draw(widget_t *widget, draw_context_t *ctx, int offset, int used)
if(i == n - 1) if(i == n - 1)
area.width += box_width_rest; area.width += box_width_rest;
draw_text(ctx, area, text, style); draw_text(ctx, area, text, *style);
p_delete(&text); p_delete(&text);
@ -177,15 +170,15 @@ tasklist_draw(widget_t *widget, draw_context_t *ctx, int offset, int used)
{ {
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 = (style.font->height + 2) / 3; area.width = (style->font->height + 2) / 3;
area.height = (style.font->height + 2) / 3; area.height = (style->font->height + 2) / 3;
draw_rectangle(ctx, area, 1.0, c->isfloating, style.fg); draw_rectangle(ctx, area, 1.0, 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,
(style.font->height + 2) / 4, (style->font->height + 2) / 4,
c->ismax, style.fg); c->ismax, style->fg);
i++; i++;
} }