From cfffa703647f2c2fbddce654322767fa95edffb3 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 2 Dec 2016 17:02:17 +0000 Subject: Fold unbinding functions into one for each, key and mouse; plugs a leak when unbinding a mouse button bound to a command. --- conf.c | 46 ++++++++++------------------------------------ 1 file changed, 10 insertions(+), 36 deletions(-) (limited to 'conf.c') diff --git a/conf.c b/conf.c index f147163..14213ff 100644 --- a/conf.c +++ b/conf.c @@ -35,9 +35,7 @@ static const char *conf_bind_getmask(const char *, unsigned int *); static void conf_cmd_remove(struct conf *, const char *); static void conf_unbind_key(struct conf *, struct bind_ctx *); -static void conf_unbind_key_all(struct conf *); static void conf_unbind_mouse(struct conf *, struct bind_ctx *); -static void conf_unbind_mouse_all(struct conf *); static int cursor_binds[] = { XC_left_ptr, /* CF_NORMAL */ @@ -516,7 +514,7 @@ conf_bind_key(struct conf *c, const char *bind, const char *cmd) unsigned int i; if ((strcmp(bind, "all") == 0) && (cmd == NULL)) { - conf_unbind_key_all(c); + conf_unbind_key(c, NULL); goto out; } kb = xmalloc(sizeof(*kb)); @@ -555,9 +553,9 @@ conf_unbind_key(struct conf *c, struct bind_ctx *unbind) struct bind_ctx *key = NULL, *keynxt; TAILQ_FOREACH_SAFE(key, &c->keybindq, entry, keynxt) { - if (key->modmask != unbind->modmask) - continue; - if (key->press.keysym == unbind->press.keysym) { + if ((unbind == NULL) || + ((key->modmask == unbind->modmask) && + (key->press.keysym == unbind->press.keysym))) { TAILQ_REMOVE(&c->keybindq, key, entry); if (key->context == CWM_CONTEXT_NONE) free(key->argument.c); @@ -566,19 +564,6 @@ conf_unbind_key(struct conf *c, struct bind_ctx *unbind) } } -static void -conf_unbind_key_all(struct conf *c) -{ - struct bind_ctx *key = NULL, *keynxt; - - TAILQ_FOREACH_SAFE(key, &c->keybindq, entry, keynxt) { - TAILQ_REMOVE(&c->keybindq, key, entry); - if (key->context == CWM_CONTEXT_NONE) - free(key->argument.c); - free(key); - } -} - int conf_bind_mouse(struct conf *c, const char *bind, const char *cmd) { @@ -587,7 +572,7 @@ conf_bind_mouse(struct conf *c, const char *bind, const char *cmd) unsigned int i; if ((strcmp(bind, "all") == 0) && (cmd == NULL)) { - conf_unbind_mouse_all(c); + conf_unbind_mouse(c, NULL); goto out; } mb = xmalloc(sizeof(*mb)); @@ -626,28 +611,17 @@ conf_unbind_mouse(struct conf *c, struct bind_ctx *unbind) struct bind_ctx *mb = NULL, *mbnxt; TAILQ_FOREACH_SAFE(mb, &c->mousebindq, entry, mbnxt) { - if (mb->modmask != unbind->modmask) - continue; - if (mb->press.button == unbind->press.button) { + if ((unbind == NULL) || + ((mb->modmask == unbind->modmask) && + (mb->press.button == unbind->press.button))) { TAILQ_REMOVE(&c->mousebindq, mb, entry); + if (mb->context == CWM_CONTEXT_NONE) + free(mb->argument.c); free(mb); } } } -static void -conf_unbind_mouse_all(struct conf *c) -{ - struct bind_ctx *mb = NULL, *mbnxt; - - TAILQ_FOREACH_SAFE(mb, &c->mousebindq, entry, mbnxt) { - TAILQ_REMOVE(&c->mousebindq, mb, entry); - if (mb->context == CWM_CONTEXT_NONE) - free(mb->argument.c); - free(mb); - } -} - void conf_grab_kbd(Window win) { -- cgit 1.4.1