From 38f3e3b6b07edc6d08c803fc432b347d4876de9a Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sun, 22 Jan 2012 22:27:26 +0100 Subject: [PATCH] Add tags_occupied color in theme and tags_*_statusline to draw status sequences in tags button in according to tag state (normal/selected/occupied) --- src/config.c | 16 ++++++++++++ src/infobar.c | 24 ++++++++++++++++-- src/status.c | 67 ++++++++++++++++++++++++++++++++++++++++----------- src/status.h | 5 ++++ src/wmfs.c | 3 +++ src/wmfs.h | 6 ++++- wmfsrc | 8 ++++++ 7 files changed, 112 insertions(+), 17 deletions(-) diff --git a/src/config.c b/src/config.c index 9d2a7a1..7b7b26a 100644 --- a/src/config.c +++ b/src/config.c @@ -10,6 +10,7 @@ #include "screen.h" #include "infobar.h" #include "util.h" +#include "status.h" static void config_mouse_section(struct mbhead *mousebinds, struct conf_sec **sec) @@ -75,9 +76,24 @@ config_theme(void) t->tags_n.bg = color_atoh(fetch_opt_first(ks[i], "#222222", "tags_normal_bg").str); t->tags_s.fg = color_atoh(fetch_opt_first(ks[i], "#222222", "tags_sel_fg").str); t->tags_s.bg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "tags_sel_bg").str); + t->tags_o.fg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "tags_occupied_fg").str); + t->tags_o.bg = color_atoh(fetch_opt_first(ks[i], "#444444", "tags_occupied_bg").str); t->tags_border_col = color_atoh(fetch_opt_first(ks[i], "#888888", "tags_border_color").str); t->tags_border_width = fetch_opt_first(ks[i], "0", "tags_border_width").num; + + /* status line */ + t->tags_n_sl = status_new_ctx(NULL, t); + t->tags_s_sl = status_new_ctx(NULL, t); + t->tags_o_sl = status_new_ctx(NULL, t); + + if((t->tags_n_sl.status = xstrdup(fetch_opt_first(ks[i], "", "tags_normal_statusline").str))) + status_parse(&t->tags_n_sl); + if((t->tags_s_sl.status = xstrdup(fetch_opt_first(ks[i], "", "tags_sel_statusline").str))) + status_parse(&t->tags_s_sl); + if((t->tags_o_sl.status = xstrdup(fetch_opt_first(ks[i], "", "tags_occupied_statusline").str))) + status_parse(&t->tags_o_sl); + /* Client / frame */ t->client_n.fg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "client_normal_fg").str); t->client_n.bg = color_atoh(fetch_opt_first(ks[i], "#222222", "client_normal_bg").str); diff --git a/src/infobar.c b/src/infobar.c index 521b58e..4c2d4a1 100644 --- a/src/infobar.c +++ b/src/infobar.c @@ -49,6 +49,8 @@ infobar_elem_tag_init(struct element *e) j = e->geo.x; e->geo.h -= (e->infobar->theme->tags_border_width << 1); + e->statusctx = &e->infobar->theme->tags_n_sl; + TAILQ_FOREACH(t, &e->infobar->screen->tags, next) { s = draw_textw(e->infobar->theme, t->name) + PAD; @@ -92,15 +94,33 @@ infobar_elem_tag_update(struct element *e) { b->fg = e->infobar->theme->tags_s.fg; b->bg = e->infobar->theme->tags_s.bg; + e->statusctx = &e->infobar->theme->tags_s_sl; } else { - b->fg = e->infobar->theme->tags_n.fg; - b->bg = e->infobar->theme->tags_n.bg; + if(SLIST_EMPTY(&t->clients)) + { + b->fg = e->infobar->theme->tags_n.fg; + b->bg = e->infobar->theme->tags_n.bg; + e->statusctx = &e->infobar->theme->tags_n_sl; + } + /* Occupied tag */ + else + { + b->fg = e->infobar->theme->tags_o.fg; + b->bg = e->infobar->theme->tags_o.bg; + e->statusctx = &e->infobar->theme->tags_o_sl; + } } barwin_refresh_color(b); + /* Manage status line */ + e->statusctx->barwin = b; + status_flush_mousebind(e->statusctx); + status_copy_mousebind(e->statusctx); + status_render(e->statusctx); + draw_text(b->dr, e->infobar->theme, (PAD >> 1), TEXTY(e->infobar->theme, e->geo.h), b->fg, t->name); diff --git a/src/status.c b/src/status.c index 288e994..0452566 100644 --- a/src/status.c +++ b/src/status.c @@ -44,6 +44,17 @@ status_new_ctx(struct barwin *b, struct theme *t) return ctx; } +void +status_free_ctx(struct status_ctx *ctx) +{ + free(ctx->status); + + if(ctx->barwin) + status_flush_mousebind(ctx); + + status_flush_list(ctx); +} + /* Parse mousebind sequence next normal sequence: \[](button;func;cmd) */ static char* status_parse_mouse(struct status_seq *sq, struct status_ctx *ctx, char *str) @@ -63,8 +74,11 @@ status_parse_mouse(struct status_seq *sq, struct status_ctx *ctx, char *str) m->button = ATOI(arg[0]); m->func = uicb_name_func(arg[1]); m->cmd = (i > 1 ? xstrdup(arg[2]) : NULL); + m->flags |= MOUSEBIND_STATUS; + + if(ctx->barwin) + SLIST_INSERT_HEAD(&ctx->barwin->mousebinds, m, next); - SLIST_INSERT_HEAD(&ctx->barwin->mousebinds, m, next); SLIST_INSERT_HEAD(&sq->mousebinds, m, snext); return end + 1; @@ -76,7 +90,7 @@ status_parse_mouse(struct status_seq *sq, struct status_ctx *ctx, char *str) str = end + 2; \ continue; \ } -static void +void status_parse(struct status_ctx *ctx) { struct status_seq *sq, *prev = NULL; @@ -265,17 +279,12 @@ status_render(struct status_ctx *ctx) barwin_refresh(ctx->barwin); } -/* Parse and render statustext */ void -status_manage(struct status_ctx *ctx) +status_flush_list(struct status_ctx *ctx) { struct status_seq *sq; - struct mousebind *m; - /* - * Flush previous linked list of status sequences - * and mousebind of status barwin - */ + /* Flush previous linked list of status sequences */ while(!SLIST_EMPTY(&ctx->statushead)) { sq = SLIST_FIRST(&ctx->statushead); @@ -283,13 +292,43 @@ status_manage(struct status_ctx *ctx) free(sq->str); free(sq); } - while(!SLIST_EMPTY(&ctx->barwin->mousebinds)) +} + +void +status_flush_mousebind(struct status_ctx *ctx) +{ + struct mousebind *m; + + SLIST_FOREACH(m, &ctx->barwin->mousebinds, next) + if(m->flags & MOUSEBIND_STATUS) + SLIST_REMOVE(&ctx->barwin->mousebinds, m, mousebind, next); +} + +void +status_copy_mousebind(struct status_ctx *ctx) +{ + struct mousebind *m; + struct status_seq *sq; + + if(!ctx->barwin) + return; + + SLIST_FOREACH(sq, &ctx->statushead, next) { - m = SLIST_FIRST(&ctx->barwin->mousebinds); - SLIST_REMOVE_HEAD(&ctx->barwin->mousebinds, next); - free((void*)m->cmd); - free(m); + SLIST_FOREACH(m, &sq->mousebinds, snext) + SLIST_INSERT_HEAD(&ctx->barwin->mousebinds, m, next); } +} + +/* Parse and render statustext */ +void +status_manage(struct status_ctx *ctx) +{ + if(!ctx->status) + return; + + status_flush_list(ctx); + status_flush_mousebind(ctx); status_parse(ctx); status_render(ctx); } diff --git a/src/status.h b/src/status.h index 4f1d592..ada712a 100644 --- a/src/status.h +++ b/src/status.h @@ -9,6 +9,11 @@ #include "wmfs.h" struct status_ctx status_new_ctx(struct barwin *b, struct theme *t); +void status_free_ctx(struct status_ctx *ctx); +void status_flush_list(struct status_ctx *ctx); +void status_flush_mousebind(struct status_ctx *ctx); +void status_copy_mousebind(struct status_ctx *ctx); +void status_parse(struct status_ctx *ctx); void status_render(struct status_ctx *ctx); void status_manage(struct status_ctx *ctx); void uicb_status(Uicb cmd); diff --git a/src/wmfs.c b/src/wmfs.c index b365283..edf0bfe 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -439,6 +439,9 @@ wmfs_quit(void) { r = SLIST_FIRST(&W->h.rule); SLIST_REMOVE_HEAD(&W->h.rule, next); + status_free_ctx(&t->tags_n_sl); + status_free_ctx(&t->tags_s_sl); + status_free_ctx(&t->tags_o_sl); free(r->class); free(r->instance); free(r->role); diff --git a/src/wmfs.h b/src/wmfs.h index ff22053..6ff9808 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -119,6 +119,7 @@ struct element { struct geo geo; struct infobar *infobar; + struct status_ctx *statusctx; int type; enum position align; void (*func_init)(struct element *e); @@ -218,6 +219,8 @@ struct keybind struct mousebind { struct geo area; +#define MOUSEBIND_STATUS 0x01 + Flags flags; unsigned int button; bool use_area; void (*func)(Uicb); @@ -243,7 +246,8 @@ struct theme int bars_width; /* struct elements */ - struct colpair tags_n, tags_s; /* normal / selected */ + struct colpair tags_n, tags_s, tags_o; /* normal / selected / occupied */ + struct status_ctx tags_n_sl, tags_s_sl, tags_o_sl; /* status line */ int tags_border_width; Color tags_border_col; diff --git a/wmfsrc b/wmfsrc index 663fa52..224a2a1 100644 --- a/wmfsrc +++ b/wmfsrc @@ -22,8 +22,16 @@ # Element tags tags_normal_fg = "#AABBAA" tags_normal_bg = "#223322" + # tags_normal_statusline = "" + tags_sel_fg = "#223322" tags_sel_bg = "#AABBAA" + # tags_sel_statusline = "" + + tags_occupied_fg = "#AABBAA" + tags_occupied_bg = "#445544" + tags_occupied_statusline = "\R[0;0;3;3;#AABBAA]" + tags_border_color = "#112211" tags_border_width = 1