From dbac129bf9e5147b7e9f0c993c228c826215a200 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Fri, 20 Jan 2012 19:56:15 +0100 Subject: [PATCH] Use global head for mousebind to free all at quit() --- src/barwin.c | 17 ----------------- src/barwin.h | 1 - src/config.c | 3 ++- src/mouse.c | 7 ++----- src/wmfs.c | 9 +++++++++ src/wmfs.h | 2 ++ 6 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/barwin.c b/src/barwin.c index d622d71..c573b3e 100644 --- a/src/barwin.c +++ b/src/barwin.c @@ -70,9 +70,6 @@ barwin_remove(struct barwin *b) XDestroyWindow(W->dpy, b->win); XFreePixmap(W->dpy, b->dr); - /* Free mousebinds */ - FREE_LIST(mousebind, b->mousebinds); - free(b); } @@ -95,20 +92,6 @@ barwin_resize(struct barwin *b, int w, int h) XResizeWindow(W->dpy, b->win, w, h); } -void -barwin_mousebind_new(struct barwin *b, unsigned int button, bool u, struct geo a, void (*func)(Uicb), Uicb cmd) -{ - struct mousebind *m = (struct mousebind*)xcalloc(1, sizeof(struct mousebind)); - - m->button = button; - m->use_area = u; - m->area = a; - m->func = func; - m->cmd = cmd; - - SLIST_INSERT_HEAD(&b->mousebinds, m, next); -} - /** Refresh the barwin Color * \param bw barwin pointer */ diff --git a/src/barwin.h b/src/barwin.h index 815f716..a010758 100644 --- a/src/barwin.h +++ b/src/barwin.h @@ -28,7 +28,6 @@ struct barwin* barwin_new(Window parent, int x, int y, int w, int h, Color fg, Color bg, bool entermask); void barwin_remove(struct barwin *b); void barwin_resize(struct barwin *b, int w, int h); -void barwin_mousebind_new(struct barwin *b, unsigned int button, bool u, struct geo a, void (*func)(Uicb), Uicb cmd); void barwin_refresh_color(struct barwin *b); #endif /* BARWIN_H */ diff --git a/src/config.c b/src/config.c index 066cf91..50310c9 100644 --- a/src/config.c +++ b/src/config.c @@ -25,10 +25,11 @@ config_mouse_section(struct mbhead *mousebinds, struct conf_sec **sec) m->button = fetch_opt_first(sec[i], "1", "button").num; m->func = uicb_name_func(fetch_opt_first(sec[i], "", "func").str); - m->cmd = fetch_opt_first(sec[i], "", "cmd").str; + m->cmd = xstrdup(fetch_opt_first(sec[i], "", "cmd").str); m->use_area = false; SLIST_INSERT_HEAD(mousebinds, m, next); + SLIST_INSERT_HEAD(&W->h.mousebind, m, globnext); } } diff --git a/src/mouse.c b/src/mouse.c index 0419997..1785518 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -133,14 +133,11 @@ mouse_move(struct client *c, void (*func)(struct client*, struct client*)) } while(ev.type != ButtonRelease); if(c2) - { - if(last == c2) - _REV_SBORDER(c2); - func(c, c2); - } else if(t && t != (struct tag*)c) tag_client(t, c); + else + _REV_SBORDER(c); } void diff --git a/src/wmfs.c b/src/wmfs.c index d14eb64..be73fae 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -391,6 +391,7 @@ wmfs_quit(void) struct rule *r; struct theme *t; struct client *c; + struct mousebind *m; /* Will free: * @@ -439,6 +440,14 @@ wmfs_quit(void) free(k); } + while(!SLIST_EMPTY(&W->h.mousebind)) + { + m = SLIST_FIRST(&W->h.mousebind); + SLIST_REMOVE_HEAD(&W->h.mousebind, globnext); + free((void*)m->cmd); + free(m); + } + /* FIFO stuffs */ if(W->fifo.fd > 0) { diff --git a/src/wmfs.h b/src/wmfs.h index d3f376a..c06162e 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -214,6 +214,7 @@ struct mousebind Uicb cmd; SLIST_ENTRY(mousebind) next; SLIST_ENTRY(mousebind) snext; + SLIST_ENTRY(mousebind) globnext; }; struct theme @@ -297,6 +298,7 @@ struct wmfs SLIST_HEAD(, barwin) barwin; SLIST_HEAD(, theme) theme; SLIST_HEAD(, rule) rule; + SLIST_HEAD(, mousebind) mousebind; } h; /*