From f0e29977d8efc1e768375b818849477f163de976 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 29 Apr 2008 11:42:16 +0200 Subject: [PATCH] [client] introduce client_style_get() and use it in tasklist/titlebar Signed-off-by: Julien Danjou --- client.c | 15 +++++++++++++++ client.h | 1 + titlebar.c | 4 +++- widgets/tasklist.c | 33 +++++++++++++-------------------- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/client.c b/client.c index 86ffb692..3cdf7581 100644 --- a/client.c +++ b/client.c @@ -812,6 +812,21 @@ client_updatesizehints(client_t *c) 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 * client_markup_parse(client_t *c, const char *str, ssize_t len) { diff --git a/client.h b/client.h index aab8646c..65468c5d 100644 --- a/client.h +++ b/client.h @@ -43,6 +43,7 @@ void client_saveprops(client_t *); void client_kill(client_t *); void client_setfloating(client_t *, bool, layer_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_moveresize; diff --git a/titlebar.c b/titlebar.c index fad7f007..a0d4e80c 100644 --- a/titlebar.c +++ b/titlebar.c @@ -182,6 +182,7 @@ titlebar_draw(client_t *c) area_t geometry; xcb_screen_t *s; char *text; + style_t *style; if(!c->titlebar.sw) return; @@ -219,7 +220,8 @@ titlebar_draw(client_t *c) text = titlebar_text(c); 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); switch(c->titlebar.position) diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 03858941..502bc3c9 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -74,7 +74,7 @@ tasklist_draw(widget_t *widget, draw_context_t *ctx, int offset, int used) char *text; int n = 0, i = 0, box_width = 0, icon_width = 0, box_width_rest = 0; NetWMIcon *icon; - style_t style; + style_t *style; if(used >= widget->statusbar->width) 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; - if(c->isurgent) - { - text = d->text_urgent; - style = globalconf.screens[c->screen].styles.urgent; - } - else if(globalconf.focus->client == c) - { + style = client_style_get(c); + + if(globalconf.focus->client == c) text = d->text_focus; - style = globalconf.screens[c->screen].styles.focus; - } + else if(c->isurgent) + text = d->text_urgent; else - { text = d->text_normal; - style = globalconf.screens[c->screen].styles.normal; - } 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.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) { @@ -169,7 +162,7 @@ tasklist_draw(widget_t *widget, draw_context_t *ctx, int offset, int used) if(i == n - 1) area.width += box_width_rest; - draw_text(ctx, area, text, style); + draw_text(ctx, area, text, *style); 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.y = widget->area.y; - area.width = (style.font->height + 2) / 3; - area.height = (style.font->height + 2) / 3; - draw_rectangle(ctx, area, 1.0, c->isfloating, style.fg); + area.width = (style->font->height + 2) / 3; + area.height = (style->font->height + 2) / 3; + draw_rectangle(ctx, area, 1.0, c->isfloating, style->fg); } else if(c->isfloating || c->ismax) draw_circle(ctx, widget->area.x + icon_width + box_width * i, widget->area.y, - (style.font->height + 2) / 4, - c->ismax, style.fg); + (style->font->height + 2) / 4, + c->ismax, style->fg); i++; }