From 80d175465d5a656a15cc7a9899c77b3125429e9d Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Mon, 29 Aug 2011 18:51:58 +0200 Subject: [PATCH] Set keybind to tag element (and mouse events) --- wmfs2/src/barwin.c | 7 ++++--- wmfs2/src/barwin.h | 2 +- wmfs2/src/config.h | 1 + wmfs2/src/event.c | 15 ++++++++++++++- wmfs2/src/infobar.c | 32 ++++++++++++++++++++------------ wmfs2/src/tag.c | 13 +++++++++++++ wmfs2/src/tag.h | 1 + wmfs2/src/util.h | 3 +-- wmfs2/src/wmfs.c | 14 +++++--------- wmfs2/src/wmfs.h | 6 +++--- 10 files changed, 63 insertions(+), 31 deletions(-) diff --git a/wmfs2/src/barwin.c b/wmfs2/src/barwin.c index c697560..5345b42 100755 --- a/wmfs2/src/barwin.c +++ b/wmfs2/src/barwin.c @@ -66,7 +66,7 @@ barwin_remove(Barwin *b) XFreePixmap(W->dpy, b->dr); /* Free mousebinds */ - FREE_LIST(b->mousebinds, Mousebind); + FREE_LIST(Mousebind, b->mousebinds); free(b); } @@ -101,9 +101,10 @@ barwin_mousebind_new(Barwin *b, unsigned int button, bool u, Geo a, void (*func) m->use_area = u; m->area = a; m->func = func; - m->cmd = cmd; - SLIST_INSERT_HEAD(&b->mousebinds, m, next): + m->cmd = (cmd ? xstrdup(cmd) : NULL); + + SLIST_INSERT_HEAD(&b->mousebinds, m, next); } /** Refresh the Barwin Color diff --git a/wmfs2/src/barwin.h b/wmfs2/src/barwin.h index 974145f..ff49764 100755 --- a/wmfs2/src/barwin.h +++ b/wmfs2/src/barwin.h @@ -26,7 +26,7 @@ Barwin* barwin_new(Window parent, int x, int y, int w, int h, Color fg, Color bg, bool entermask); void barwin_remove(Barwin *b); void barwin_resize(Barwin *b, int w, int h); -void barwin_mousebind_new(Barwin *b, unsigned int button, bool u, Geo a, void (*func)(Uicb), Uicb cmd) +void barwin_mousebind_new(Barwin *b, unsigned int button, bool u, Geo a, void (*func)(Uicb), Uicb cmd); void barwin_refresh_color(Barwin *b); #endif /* BARWIN_H */ diff --git a/wmfs2/src/config.h b/wmfs2/src/config.h index 1de5c25..539c032 100755 --- a/wmfs2/src/config.h +++ b/wmfs2/src/config.h @@ -23,6 +23,7 @@ static const struct { char *name; void (*func)(Uicb cmd); } uicb_list[] = /* Tag */ { "tag_set", uicb_tag_set }, + { "tag", uicb_tag_set_with_name }, { "tag_next", uicb_tag_next }, { "tag_prev", uicb_tag_prev }, { NULL, NULL } diff --git a/wmfs2/src/event.c b/wmfs2/src/event.c index f902978..b66cdba 100755 --- a/wmfs2/src/event.c +++ b/wmfs2/src/event.c @@ -15,8 +15,21 @@ static void event_buttonpress(XEvent *e) { - /*XButtonEvent *ev = &e->xbutton;*/ + XButtonEvent *ev = &e->xbutton; + Mousebind *m; + Barwin *b; + SLIST_FOREACH(b, &W->h.barwin, next) + if(b->win == ev->window) + { + SLIST_FOREACH(m, &b->mousebinds, next) + 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); + + break; + } } static void diff --git a/wmfs2/src/infobar.c b/wmfs2/src/infobar.c index fc00732..b8a7e70 100755 --- a/wmfs2/src/infobar.c +++ b/wmfs2/src/infobar.c @@ -8,12 +8,11 @@ #include "infobar.h" #include "barwin.h" #include "util.h" +#include "tag.h" #define ELEM_DEFAULT_ORDER "tlsS" #define INFOBAR_DEF_W (12) -#define ELEMX(e, head) TAILQ_PREV(e, head, next)->geo. - static void infobar_elem_tag_init(Element *e); static void infobar_elem_tag_update(Element *e); @@ -49,7 +48,8 @@ infobar_elem_tag_init(Element *e) { Tag *t; Barwin *b, *prev; - int tmp, j; + Geo g = { 0, 0, 0, 0 }; + int s, j; infobar_elem_placement(e); @@ -57,20 +57,26 @@ infobar_elem_tag_init(Element *e) TAILQ_FOREACH(t, &e->infobar->screen->tags, next) { - tmp = draw_textw(t->name) + PAD; + s = draw_textw(t->name) + PAD; - b = barwin_new(e->infobar->bar->win, j, 0, tmp, e->geo.h, 0x009900, 0x777777, false); + /* Init barwin */ + b = barwin_new(e->infobar->bar->win, s, 0, tmp, e->geo.h, 0x009900, 0x777777, false); b->ptr = (void*)t; barwin_map(b); + /* TODO: refer to tag element configuration */ + barwin_mousebind_new(b, Button1, false, g, uicb_tag_set_with_name, (Uicb)t->name); + barwin_mousebind_new(b, Button4, false, g, uicb_tag_next, NULL); + barwin_mousebind_new(b, Button5, false, g, uicb_tag_prev, NULL); + + /* insert_tail with SLIST */ if(SLIST_EMPTY(&e->bars)) - SLIST_INSERT_HEAD(&e->bars, b, next); + SLIST_INSERT_HEAD(&e->bars, b, enext); else - SLIST_INSERT_AFTER(prev, b, next); + SLIST_INSERT_AFTER(prev, b, enext); prev = b; - b = NULL; - j += tmp; + j += s; } } @@ -80,11 +86,12 @@ infobar_elem_tag_update(Element *e) Tag *t, *sel = e->infobar->screen->seltag; Barwin *b; - SLIST_FOREACH(b, &e->bars, next) + SLIST_FOREACH(b, &e->bars, enext) { t = (Tag*)b->ptr; /* Selected */ + /* TODO: color from conf */ if(t == sel) { b->fg = 0x000000; @@ -104,7 +111,7 @@ infobar_elem_tag_update(Element *e) } } -void +static void infobar_elem_init(Infobar *i) { Element *e; @@ -155,7 +162,7 @@ infobar_elem_remove(Element *e) while(!SLIST_EMPTY(&e->bars)) { b = SLIST_FIRST(&e->bars); - SLIST_REMOVE_HEAD(&e->bars, next); + SLIST_REMOVE_HEAD(&e->bars, enext); barwin_remove(b); } } @@ -197,6 +204,7 @@ infobar_init(void) void infobar_refresh(Infobar *i) { + i->elemupdate |= FLAGINT(ElemTag); infobar_elem_update(i); barwin_refresh(i->bar); diff --git a/wmfs2/src/tag.c b/wmfs2/src/tag.c index 8b67162..6493c21 100755 --- a/wmfs2/src/tag.c +++ b/wmfs2/src/tag.c @@ -52,6 +52,19 @@ uicb_tag_set(Uicb cmd) } } +void +uicb_tag_set_with_name(Uicb cmd) +{ + Tag *t; + + TAILQ_FOREACH(t, &W->screen->tags, next) + if(!strcmp(cmd, t->name)) + { + tag_screen(W->screen, t); + return; + } +} + void uicb_tag_next(Uicb cmd) { diff --git a/wmfs2/src/tag.h b/wmfs2/src/tag.h index 4d8ef44..12c44cf 100755 --- a/wmfs2/src/tag.h +++ b/wmfs2/src/tag.h @@ -12,6 +12,7 @@ Tag *tag_new(Scr33n *s, char *name); void tag_screen(Scr33n *s, Tag *t); void tag_free(Scr33n *s); void uicb_tag_set(Uicb cmd); +void uicb_tag_set_with_name(Uicb cmd); void uicb_tag_next(Uicb cmd); void uicb_tag_prev(Uicb cmd); diff --git a/wmfs2/src/util.h b/wmfs2/src/util.h index 6e49145..78b6360 100755 --- a/wmfs2/src/util.h +++ b/wmfs2/src/util.h @@ -6,8 +6,6 @@ #ifndef UTIL_H #define UTIL_H -#include - #include "wmfs.h" /* Todo FREE_LIST(type, head, function_remove) */ @@ -25,6 +23,7 @@ #define LEN(x) (sizeof(x) / sizeof(*x)) #define FLAGINT(i) (1 << i) #define ATOI(s) strtol(s, NULL, 10) +#define INAREA(i, j, a) ((i) >= (a).x && (i) <= (a).x + (a).w && (j) >= (a).y && (j) <= (a).y + (a).h) void *xmalloc(size_t nmemb, size_t size); void *xcalloc(size_t nmemb, size_t size); diff --git a/wmfs2/src/wmfs.c b/wmfs2/src/wmfs.c index 81c3fb0..85d5b5c 100755 --- a/wmfs2/src/wmfs.c +++ b/wmfs2/src/wmfs.c @@ -120,6 +120,11 @@ wmfs_xinit(void) W->numlockmask = (1 << i); XFreeModifiermap(mm); + /* + * Barwin linked list + */ + SLIST_INIT(&W->h.barwin); + W->running = true; } @@ -245,7 +250,6 @@ wmfs_quit(void) XCloseDisplay(W->dpy); free(W->net_atom); - free(W->argv); free(W); /* Conf stuffs */ @@ -260,14 +264,7 @@ void uicb_reload(Uicb cmd) { (void)cmd; - char *command = xstrdup(W->argv[0]); - char **argv = W->argv; - wmfs_quit(); - - for(; command[0] && command[0] == ' '; ++command[0]); - - execvp(command, argv); } void @@ -282,7 +279,6 @@ main(int argc, char **argv) { W = (struct Wmfs*)xcalloc(1, sizeof(struct Wmfs)); - W->argv = argv; /* Get X display */ if(!(W->dpy = XOpenDisplay(NULL))) diff --git a/wmfs2/src/wmfs.h b/wmfs2/src/wmfs.h index eedaaea..4f50803 100755 --- a/wmfs2/src/wmfs.h +++ b/wmfs2/src/wmfs.h @@ -59,7 +59,8 @@ struct Barwin Flags flags; void *ptr; /* Special cases */ SLIST_HEAD(, Mousebind) mousebinds; - SLIST_ENTRY(Barwin) next; + SLIST_ENTRY(Barwin) next; /* global barwin */ + SLIST_ENTRY(Barwin) enext; /* element barwin */ }; /* Infobar's element */ @@ -136,7 +137,7 @@ struct Mousebind bool use_area; void (*func)(Uicb); Uicb cmd; - SLIST_ENTRY(Keybind) next; + SLIST_ENTRY(Mousebind) next; }; struct Config @@ -161,7 +162,6 @@ struct Wmfs Flags numlockmask; GC gc; Atom *net_atom; - char **argv; bool running; struct