diff options
author | okan <okan> | 2016-12-02 17:02:17 +0000 |
---|---|---|
committer | okan <okan> | 2016-12-02 17:02:17 +0000 |
commit | cfffa703647f2c2fbddce654322767fa95edffb3 (patch) | |
tree | 94833eacc74f844f027ce6432fe17a374163bc6a /conf.c | |
parent | 5b7e66a13b79c1c8b7a4f2661912271f1777d892 (diff) | |
download | cwm-cfffa703647f2c2fbddce654322767fa95edffb3.tar.gz cwm-cfffa703647f2c2fbddce654322767fa95edffb3.tar.xz cwm-cfffa703647f2c2fbddce654322767fa95edffb3.zip |
Fold unbinding functions into one for each, key and mouse; plugs a leak when
unbinding a mouse button bound to a command.
Diffstat (limited to 'conf.c')
-rw-r--r-- | conf.c | 46 |
1 files changed, 10 insertions, 36 deletions
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) { |