From abbb955217168220016b6daf6edf52cdba3a963a Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Fri, 6 Jan 2012 17:30:46 +0100 Subject: [PATCH] Add status.c/h, status uicb cmd --- src/config.c | 2 +- src/config.h | 5 +++++ src/fifo.c | 7 +++++-- src/infobar.c | 24 +++------------------- src/status.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/status.h | 14 +++++++++++++ 6 files changed, 83 insertions(+), 24 deletions(-) create mode 100644 src/status.c create mode 100644 src/status.h diff --git a/src/config.c b/src/config.c index 86ef66e..6b957b9 100644 --- a/src/config.c +++ b/src/config.c @@ -94,7 +94,7 @@ config_bars(void) /* [bar] */ for(i = 0; i < n; ++i) { - name = fetch_opt_first(ks[i], "infobar", "name").str; + name = fetch_opt_first(ks[i], "default", "name").str; elem = fetch_opt_first(ks[i], "", "elements").str; screenid = fetch_opt_first(ks[i], "-1", "screen").num; t = name_to_theme(fetch_opt_first(ks[i], "default", "theme").str); diff --git a/src/config.h b/src/config.h index a15f3e3..cda3625 100644 --- a/src/config.h +++ b/src/config.h @@ -14,6 +14,7 @@ #include "util.h" #include "tag.h" #include "client.h" +#include "status.h" #define THEME_DEFAULT (SLIST_FIRST(&W->h.theme)) @@ -62,6 +63,10 @@ static const struct { char *name; void (*func)(Uicb cmd); } uicb_list[] = { "client_swap_next", uicb_client_swapsel_next }, { "client_swap_prev", uicb_client_swapsel_prev }, { "client_untab", uicb_client_untab }, + + /* Status */ + { "status" , uicb_status }, + { NULL, NULL } }; diff --git a/src/fifo.c b/src/fifo.c index bdc4e20..1454f36 100644 --- a/src/fifo.c +++ b/src/fifo.c @@ -34,7 +34,7 @@ static void fifo_parse(char *cmd) { void (*func)(Uicb); - char *p = NULL; + char *p = NULL, *arg; /* remove trailing newline */ if((p = strchr(cmd, '\n'))) @@ -44,9 +44,12 @@ fifo_parse(char *cmd) if((p = strchr(cmd, ' '))) *p = '\0'; + /* Avoid pointer out of bound if no arg */ + arg = ((p + 1 == 1) ? NULL : p + 1); + /* call the UICB function, p + 1 is command or NULL */ if((func = uicb_name_func(cmd))) - func(p + 1); + func(arg); XSync(W->dpy, false); } diff --git a/src/infobar.c b/src/infobar.c index 9f24f22..7104655 100644 --- a/src/infobar.c +++ b/src/infobar.c @@ -9,11 +9,11 @@ #include "barwin.h" #include "util.h" #include "tag.h" +#include "status.h" static void infobar_elem_tag_init(struct element *e); static void infobar_elem_tag_update(struct element *e); static void infobar_elem_status_init(struct element *e); -static void infobar_elem_status_update(struct element *e); const struct elem_funcs { @@ -22,8 +22,8 @@ const struct elem_funcs void (*func_update)(struct element *e); } elem_funcs[] = { - { 't', infobar_elem_tag_init, infobar_elem_tag_update }, - { 's', infobar_elem_status_init, infobar_elem_status_update }, + { 't', infobar_elem_tag_init, infobar_elem_tag_update }, + { 's', infobar_elem_status_init, status_manage }, /* { 'l', infobar_elem_layout_init, infobar_elem_layout_update }, { 'S', infobar_elem_selbar_init, infobar_elem_selbar_update }, @@ -138,24 +138,6 @@ infobar_elem_status_init(struct element *e) e->infobar->status = strdup("wmfs2"); } -static void -infobar_elem_status_update(struct element *e) -{ - struct barwin *b = SLIST_FIRST(&e->bars); - int l; - - barwin_refresh_color(b); - - /* TODO: status_manage, status.c */ - if(e->infobar->status) - { - l = draw_textw(e->infobar->theme, e->infobar->status); - draw_text(b->dr, e->infobar->theme, e->geo.w - l, - TEXTY(e->infobar->theme, e->geo.h), b->fg, e->infobar->status); - barwin_refresh(b); - } -} - #define ELEM_INIT(a) \ do { \ e = xcalloc(1, sizeof(struct element)); \ diff --git a/src/status.c b/src/status.c new file mode 100644 index 0000000..25fa0b9 --- /dev/null +++ b/src/status.c @@ -0,0 +1,55 @@ +/* + * wmfs2 by Martin Duquesnoy { for(i = 2011; i < 2111; ++i) ©(i); } + * For license, see COPYING. + */ + +#include "status.h" +#include "barwin.h" +#include "infobar.h" +#include "util.h" + +void +status_manage(struct element *e) +{ + struct barwin *b = SLIST_FIRST(&e->bars); + int l; + + barwin_refresh_color(b); + + if(e->infobar->status) + { + l = draw_textw(e->infobar->theme, e->infobar->status); + draw_text(b->dr, e->infobar->theme, e->geo.w - l, + TEXTY(e->infobar->theme, e->geo.h), b->fg, e->infobar->status); + barwin_refresh(b); + } +} + +/* Syntax: " " */ +void +uicb_status(Uicb cmd) +{ + struct infobar *ib; + struct screen *s; + int i = 0; + char si[128] = { 0 }; + + if(!cmd) + return; + + /* Get infobar name */ + while(cmd[i] && cmd[i] != ' ') + si[i] = cmd[i++]; + ++i; + + SLIST_FOREACH(s, &W->h.screen, next) + { + SLIST_FOREACH(ib, &s->infobars, next) + if(!strcmp(si, ib->name)) + { + free(ib->status); + ib->status = xstrdup(cmd + i); + infobar_elem_screen_update(s, ElemStatus); + } + } +} diff --git a/src/status.h b/src/status.h new file mode 100644 index 0000000..b107c86 --- /dev/null +++ b/src/status.h @@ -0,0 +1,14 @@ +/* + * wmfs2 by Martin Duquesnoy { for(i = 2011; i < 2111; ++i) ©(i); } + * For license, see COPYING. + */ + +#ifndef STATUS_H +#define STATUS_H + +#include "wmfs.h" + +void status_manage(struct element *e); +void uicb_status(Uicb cmd); + +#endif /* STATUS_H */