Add tags_occupied color in theme and tags_*_statusline to draw status sequences in tags button in according to tag state (normal/selected/occupied)

This commit is contained in:
Martin Duquesnoy 2012-01-22 22:27:26 +01:00
parent feaa413951
commit 38f3e3b6b0
7 changed files with 112 additions and 17 deletions

View File

@ -10,6 +10,7 @@
#include "screen.h" #include "screen.h"
#include "infobar.h" #include "infobar.h"
#include "util.h" #include "util.h"
#include "status.h"
static void static void
config_mouse_section(struct mbhead *mousebinds, struct conf_sec **sec) 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_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.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_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_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; 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 */ /* Client / frame */
t->client_n.fg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "client_normal_fg").str); 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); t->client_n.bg = color_atoh(fetch_opt_first(ks[i], "#222222", "client_normal_bg").str);

View File

@ -49,6 +49,8 @@ infobar_elem_tag_init(struct element *e)
j = e->geo.x; j = e->geo.x;
e->geo.h -= (e->infobar->theme->tags_border_width << 1); 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) TAILQ_FOREACH(t, &e->infobar->screen->tags, next)
{ {
s = draw_textw(e->infobar->theme, t->name) + PAD; 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->fg = e->infobar->theme->tags_s.fg;
b->bg = e->infobar->theme->tags_s.bg; b->bg = e->infobar->theme->tags_s.bg;
e->statusctx = &e->infobar->theme->tags_s_sl;
} }
else else
{ {
b->fg = e->infobar->theme->tags_n.fg; if(SLIST_EMPTY(&t->clients))
b->bg = e->infobar->theme->tags_n.bg; {
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); 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), draw_text(b->dr, e->infobar->theme, (PAD >> 1),
TEXTY(e->infobar->theme, e->geo.h), b->fg, t->name); TEXTY(e->infobar->theme, e->geo.h), b->fg, t->name);

View File

@ -44,6 +44,17 @@ status_new_ctx(struct barwin *b, struct theme *t)
return ctx; 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: \<seq>[](button;func;cmd) */ /* Parse mousebind sequence next normal sequence: \<seq>[](button;func;cmd) */
static char* static char*
status_parse_mouse(struct status_seq *sq, struct status_ctx *ctx, char *str) 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->button = ATOI(arg[0]);
m->func = uicb_name_func(arg[1]); m->func = uicb_name_func(arg[1]);
m->cmd = (i > 1 ? xstrdup(arg[2]) : NULL); 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); SLIST_INSERT_HEAD(&sq->mousebinds, m, snext);
return end + 1; return end + 1;
@ -76,7 +90,7 @@ status_parse_mouse(struct status_seq *sq, struct status_ctx *ctx, char *str)
str = end + 2; \ str = end + 2; \
continue; \ continue; \
} }
static void void
status_parse(struct status_ctx *ctx) status_parse(struct status_ctx *ctx)
{ {
struct status_seq *sq, *prev = NULL; struct status_seq *sq, *prev = NULL;
@ -265,17 +279,12 @@ status_render(struct status_ctx *ctx)
barwin_refresh(ctx->barwin); barwin_refresh(ctx->barwin);
} }
/* Parse and render statustext */
void void
status_manage(struct status_ctx *ctx) status_flush_list(struct status_ctx *ctx)
{ {
struct status_seq *sq; struct status_seq *sq;
struct mousebind *m;
/* /* Flush previous linked list of status sequences */
* Flush previous linked list of status sequences
* and mousebind of status barwin
*/
while(!SLIST_EMPTY(&ctx->statushead)) while(!SLIST_EMPTY(&ctx->statushead))
{ {
sq = SLIST_FIRST(&ctx->statushead); sq = SLIST_FIRST(&ctx->statushead);
@ -283,13 +292,43 @@ status_manage(struct status_ctx *ctx)
free(sq->str); free(sq->str);
free(sq); 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_FOREACH(m, &sq->mousebinds, snext)
SLIST_REMOVE_HEAD(&ctx->barwin->mousebinds, next); SLIST_INSERT_HEAD(&ctx->barwin->mousebinds, m, next);
free((void*)m->cmd);
free(m);
} }
}
/* 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_parse(ctx);
status_render(ctx); status_render(ctx);
} }

View File

@ -9,6 +9,11 @@
#include "wmfs.h" #include "wmfs.h"
struct status_ctx status_new_ctx(struct barwin *b, struct theme *t); 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_render(struct status_ctx *ctx);
void status_manage(struct status_ctx *ctx); void status_manage(struct status_ctx *ctx);
void uicb_status(Uicb cmd); void uicb_status(Uicb cmd);

View File

@ -439,6 +439,9 @@ wmfs_quit(void)
{ {
r = SLIST_FIRST(&W->h.rule); r = SLIST_FIRST(&W->h.rule);
SLIST_REMOVE_HEAD(&W->h.rule, next); 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->class);
free(r->instance); free(r->instance);
free(r->role); free(r->role);

View File

@ -119,6 +119,7 @@ struct element
{ {
struct geo geo; struct geo geo;
struct infobar *infobar; struct infobar *infobar;
struct status_ctx *statusctx;
int type; int type;
enum position align; enum position align;
void (*func_init)(struct element *e); void (*func_init)(struct element *e);
@ -218,6 +219,8 @@ struct keybind
struct mousebind struct mousebind
{ {
struct geo area; struct geo area;
#define MOUSEBIND_STATUS 0x01
Flags flags;
unsigned int button; unsigned int button;
bool use_area; bool use_area;
void (*func)(Uicb); void (*func)(Uicb);
@ -243,7 +246,8 @@ struct theme
int bars_width; int bars_width;
/* struct elements */ /* 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; int tags_border_width;
Color tags_border_col; Color tags_border_col;

8
wmfsrc
View File

@ -22,8 +22,16 @@
# Element tags # Element tags
tags_normal_fg = "#AABBAA" tags_normal_fg = "#AABBAA"
tags_normal_bg = "#223322" tags_normal_bg = "#223322"
# tags_normal_statusline = ""
tags_sel_fg = "#223322" tags_sel_fg = "#223322"
tags_sel_bg = "#AABBAA" 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_color = "#112211"
tags_border_width = 1 tags_border_width = 1