Add client_*_statusline in theme section, improve status core

This commit is contained in:
Martin Duquesnoy 2012-01-23 01:59:14 +01:00
parent 38f3e3b6b0
commit 5a9d1f6e13
9 changed files with 60 additions and 23 deletions

View File

@ -51,6 +51,7 @@ barwin_new(Window parent, int x, int y, int w, int h, Color fg, Color bg, bool e
b->fg = fg; b->fg = fg;
SLIST_INIT(&b->mousebinds); SLIST_INIT(&b->mousebinds);
SLIST_INIT(&b->statusmousebinds);
/* Attach */ /* Attach */
SLIST_INSERT_HEAD(&W->h.barwin, b, next); SLIST_INSERT_HEAD(&W->h.barwin, b, next);

View File

@ -346,10 +346,17 @@ client_grabbuttons(struct client *c, bool focused)
#define _REMAINDER() \ #define _REMAINDER() \
if((rm = ((x + f) - (c->rgeo.w - c->border))) > 0) \ if((rm = ((x + f) - (c->rgeo.w - c->border))) > 0) \
f -= rm; f -= rm;
#define _STATUSLINE(C, b) \
sctx = (b ? &c->theme->client_s_sl : &c->theme->client_n_sl); \
sctx->barwin = C->titlebar; \
status_copy_mousebind(sctx); \
status_render(sctx);
void void
client_frame_update(struct client *c, struct colpair *cp) client_frame_update(struct client *c, struct colpair *cp)
{ {
struct client *cc; struct client *cc;
struct status_ctx *sctx;
int y, f, xt, rm, w, n = 1; int y, f, xt, rm, w, n = 1;
if(c->flags & CLIENT_TABBED) if(c->flags & CLIENT_TABBED)
@ -384,6 +391,9 @@ client_frame_update(struct client *c, struct colpair *cp)
barwin_move(c->titlebar, 0, 0); barwin_move(c->titlebar, 0, 0);
barwin_resize(c->titlebar, f, c->tbarw); barwin_resize(c->titlebar, f, c->tbarw);
barwin_refresh_color(c->titlebar); barwin_refresh_color(c->titlebar);
_STATUSLINE(c, (cp == &c->scol));
draw_text(c->titlebar->dr, c->theme, xt, y, cp->fg, c->title); draw_text(c->titlebar->dr, c->theme, xt, y, cp->fg, c->title);
barwin_refresh(c->titlebar); barwin_refresh(c->titlebar);
} }
@ -407,6 +417,8 @@ client_frame_update(struct client *c, struct colpair *cp)
barwin_resize(c->titlebar, f, c->tbarw); barwin_resize(c->titlebar, f, c->tbarw);
barwin_refresh_color(c->titlebar); barwin_refresh_color(c->titlebar);
_STATUSLINE(c, true);
draw_rect(c->titlebar->dr, &g, c->scol.bg); draw_rect(c->titlebar->dr, &g, c->scol.bg);
draw_text(c->titlebar->dr, c->theme, xt, y, cp->fg, c->title); draw_text(c->titlebar->dr, c->theme, xt, y, cp->fg, c->title);
barwin_refresh(c->titlebar); barwin_refresh(c->titlebar);
@ -423,6 +435,8 @@ client_frame_update(struct client *c, struct colpair *cp)
barwin_resize(cc->titlebar, f, c->tbarw - 2); barwin_resize(cc->titlebar, f, c->tbarw - 2);
barwin_refresh_color(cc->titlebar); barwin_refresh_color(cc->titlebar);
_STATUSLINE(cc, false);
draw_rect(cc->titlebar->dr, &g, c->scol.bg); draw_rect(cc->titlebar->dr, &g, c->scol.bg);
draw_text(cc->titlebar->dr, c->theme, xt, y - 1, c->ncol.fg, cc->title); draw_text(cc->titlebar->dr, c->theme, xt, y - 1, c->ncol.fg, cc->title);
barwin_refresh(cc->titlebar); barwin_refresh(cc->titlebar);

View File

@ -32,6 +32,7 @@ config_mouse_section(struct mbhead *mousebinds, struct conf_sec **sec)
m->cmd = xstrdup(p); m->cmd = xstrdup(p);
m->use_area = false; m->use_area = false;
m->flags = 0;
SLIST_INSERT_HEAD(mousebinds, m, next); SLIST_INSERT_HEAD(mousebinds, m, next);
SLIST_INSERT_HEAD(&W->h.mousebind, m, globnext); SLIST_INSERT_HEAD(&W->h.mousebind, m, globnext);
@ -103,6 +104,15 @@ config_theme(void)
t->client_titlebar_width = fetch_opt_first(ks[i], "12", "client_titlebar_width").num; t->client_titlebar_width = fetch_opt_first(ks[i], "12", "client_titlebar_width").num;
t->client_border_width = fetch_opt_first(ks[i], "1", "client_border_width").num; t->client_border_width = fetch_opt_first(ks[i], "1", "client_border_width").num;
/* status line */
t->client_n_sl = status_new_ctx(NULL, t);
t->client_s_sl = status_new_ctx(NULL, t);
if((t->client_n_sl.status = xstrdup(fetch_opt_first(ks[i], "", "client_normal_statusline").str)))
status_parse(&t->client_n_sl);
if((t->client_s_sl.status = xstrdup(fetch_opt_first(ks[i], "", "client_sel_statusline").str)))
status_parse(&t->client_s_sl);
SLIST_INSERT_TAIL(&W->h.theme, t, next, p); SLIST_INSERT_TAIL(&W->h.theme, t, next, p);
p = t; p = t;

View File

@ -13,6 +13,11 @@
#define EVDPY(e) (e)->xany.display #define EVDPY(e) (e)->xany.display
#define MOUSE_CHECK_BIND(m) \
if(m->button == ev->button) \
if(!m->use_area || (m->use_area && INAREA(ev->x, ev->y, m->area))) \
if(m->func) \
m->func(m->cmd);
static void static void
event_buttonpress(XEvent *e) event_buttonpress(XEvent *e)
{ {
@ -28,10 +33,10 @@ event_buttonpress(XEvent *e)
W->last_clicked_barwin = b; W->last_clicked_barwin = b;
SLIST_FOREACH(m, &b->mousebinds, next) SLIST_FOREACH(m, &b->mousebinds, next)
if(m->button == ev->button) MOUSE_CHECK_BIND(m);
if(!m->use_area || (m->use_area && INAREA(ev->x, ev->y, m->area)))
if(m->func) SLIST_FOREACH(m, &b->statusmousebinds, next)
m->func(m->cmd); MOUSE_CHECK_BIND(m);
break; break;
} }

View File

@ -117,7 +117,6 @@ infobar_elem_tag_update(struct element *e)
/* Manage status line */ /* Manage status line */
e->statusctx->barwin = b; e->statusctx->barwin = b;
status_flush_mousebind(e->statusctx);
status_copy_mousebind(e->statusctx); status_copy_mousebind(e->statusctx);
status_render(e->statusctx); status_render(e->statusctx);

View File

@ -50,14 +50,14 @@ status_free_ctx(struct status_ctx *ctx)
free(ctx->status); free(ctx->status);
if(ctx->barwin) if(ctx->barwin)
status_flush_mousebind(ctx); SLIST_INIT(&ctx->barwin->statusmousebinds);
status_flush_list(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, char *str)
{ {
struct mousebind *m; struct mousebind *m;
char *end, *arg[3] = { NULL }; char *end, *arg[3] = { NULL };
@ -76,9 +76,6 @@ status_parse_mouse(struct status_seq *sq, struct status_ctx *ctx, char *str)
m->cmd = (i > 1 ? xstrdup(arg[2]) : NULL); m->cmd = (i > 1 ? xstrdup(arg[2]) : NULL);
m->flags |= MOUSEBIND_STATUS; m->flags |= MOUSEBIND_STATUS;
if(ctx->barwin)
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;
@ -163,7 +160,7 @@ status_parse(struct status_ctx *ctx)
* Parse it while there is a mousebind sequence. * Parse it while there is a mousebind sequence.
*/ */
dstr = ++end; dstr = ++end;
while((*(dstr = status_parse_mouse(sq, ctx, dstr)) == '(')); while((*(dstr = status_parse_mouse(sq, dstr)) == '('));
prev = sq; prev = sq;
} }
@ -283,27 +280,27 @@ void
status_flush_list(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 */
while(!SLIST_EMPTY(&ctx->statushead)) while(!SLIST_EMPTY(&ctx->statushead))
{ {
sq = SLIST_FIRST(&ctx->statushead); sq = SLIST_FIRST(&ctx->statushead);
SLIST_REMOVE_HEAD(&ctx->statushead, next); SLIST_REMOVE_HEAD(&ctx->statushead, next);
while(!SLIST_EMPTY(&sq->mousebinds))
{
m = SLIST_FIRST(&sq->mousebinds);
SLIST_REMOVE_HEAD(&sq->mousebinds, snext);
free((void*)m->cmd);
free(m);
}
free(sq->str); free(sq->str);
free(sq); free(sq);
} }
} }
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 void
status_copy_mousebind(struct status_ctx *ctx) status_copy_mousebind(struct status_ctx *ctx)
{ {
@ -313,10 +310,13 @@ status_copy_mousebind(struct status_ctx *ctx)
if(!ctx->barwin) if(!ctx->barwin)
return; return;
/* Flush barwin head of status mousebinds */
SLIST_INIT(&ctx->barwin->statusmousebinds);
SLIST_FOREACH(sq, &ctx->statushead, next) SLIST_FOREACH(sq, &ctx->statushead, next)
{ {
SLIST_FOREACH(m, &sq->mousebinds, snext) SLIST_FOREACH(m, &sq->mousebinds, snext)
SLIST_INSERT_HEAD(&ctx->barwin->mousebinds, m, next); SLIST_INSERT_HEAD(&ctx->barwin->statusmousebinds, m, next);
} }
} }
@ -328,9 +328,9 @@ status_manage(struct status_ctx *ctx)
return; return;
status_flush_list(ctx); status_flush_list(ctx);
status_flush_mousebind(ctx);
status_parse(ctx); status_parse(ctx);
status_render(ctx); status_render(ctx);
status_copy_mousebind(ctx);
} }
/* Syntax: "<infobar name> <status string>" */ /* Syntax: "<infobar name> <status string>" */

View File

@ -442,6 +442,8 @@ wmfs_quit(void)
status_free_ctx(&t->tags_n_sl); status_free_ctx(&t->tags_n_sl);
status_free_ctx(&t->tags_s_sl); status_free_ctx(&t->tags_s_sl);
status_free_ctx(&t->tags_o_sl); status_free_ctx(&t->tags_o_sl);
status_free_ctx(&t->client_n_sl);
status_free_ctx(&t->client_s_sl);
free(r->class); free(r->class);
free(r->instance); free(r->instance);
free(r->role); free(r->role);

View File

@ -92,6 +92,7 @@ struct barwin
Color fg, bg; Color fg, bg;
void *ptr; /* Special cases */ void *ptr; /* Special cases */
SLIST_HEAD(mbhead, mousebind) mousebinds; SLIST_HEAD(mbhead, mousebind) mousebinds;
SLIST_HEAD(, mousebind) statusmousebinds;
SLIST_ENTRY(barwin) next; /* global barwin */ SLIST_ENTRY(barwin) next; /* global barwin */
SLIST_ENTRY(barwin) enext; /* element barwin */ SLIST_ENTRY(barwin) enext; /* element barwin */
}; };
@ -253,6 +254,7 @@ struct theme
/* client / frame */ /* client / frame */
struct colpair client_n, client_s; struct colpair client_n, client_s;
struct status_ctx client_n_sl, client_s_sl;
Color frame_bg; Color frame_bg;
int client_titlebar_width; int client_titlebar_width;
int client_border_width; int client_border_width;

4
wmfsrc
View File

@ -38,8 +38,12 @@
# Frame / Client # Frame / Client
client_normal_fg = "#AABBAA" client_normal_fg = "#AABBAA"
client_normal_bg = "#223322" client_normal_bg = "#223322"
client_normal_statusline = "\s[left;#ff0000; x](1;client_close)"
client_sel_fg = "#223322" client_sel_fg = "#223322"
client_sel_bg = "#AABBAA" client_sel_bg = "#AABBAA"
client_sel_statusline = "\s[left;#ff0000; x](1;client_close)"
frame_bg = "#555555" frame_bg = "#555555"
client_titlebar_width = 12 client_titlebar_width = 12
client_border_width = 1 client_border_width = 1