mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
Fold unbinding functions into one for each, key and mouse; plugs a leak when
unbinding a mouse button bound to a command.
This commit is contained in:
44
conf.c
44
conf.c
@@ -35,9 +35,7 @@
|
|||||||
static const char *conf_bind_getmask(const char *, unsigned int *);
|
static const char *conf_bind_getmask(const char *, unsigned int *);
|
||||||
static void conf_cmd_remove(struct conf *, const char *);
|
static void conf_cmd_remove(struct conf *, const char *);
|
||||||
static void conf_unbind_key(struct conf *, struct bind_ctx *);
|
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(struct conf *, struct bind_ctx *);
|
||||||
static void conf_unbind_mouse_all(struct conf *);
|
|
||||||
|
|
||||||
static int cursor_binds[] = {
|
static int cursor_binds[] = {
|
||||||
XC_left_ptr, /* CF_NORMAL */
|
XC_left_ptr, /* CF_NORMAL */
|
||||||
@@ -516,7 +514,7 @@ conf_bind_key(struct conf *c, const char *bind, const char *cmd)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
if ((strcmp(bind, "all") == 0) && (cmd == NULL)) {
|
if ((strcmp(bind, "all") == 0) && (cmd == NULL)) {
|
||||||
conf_unbind_key_all(c);
|
conf_unbind_key(c, NULL);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
kb = xmalloc(sizeof(*kb));
|
kb = xmalloc(sizeof(*kb));
|
||||||
@@ -555,9 +553,9 @@ conf_unbind_key(struct conf *c, struct bind_ctx *unbind)
|
|||||||
struct bind_ctx *key = NULL, *keynxt;
|
struct bind_ctx *key = NULL, *keynxt;
|
||||||
|
|
||||||
TAILQ_FOREACH_SAFE(key, &c->keybindq, entry, keynxt) {
|
TAILQ_FOREACH_SAFE(key, &c->keybindq, entry, keynxt) {
|
||||||
if (key->modmask != unbind->modmask)
|
if ((unbind == NULL) ||
|
||||||
continue;
|
((key->modmask == unbind->modmask) &&
|
||||||
if (key->press.keysym == unbind->press.keysym) {
|
(key->press.keysym == unbind->press.keysym))) {
|
||||||
TAILQ_REMOVE(&c->keybindq, key, entry);
|
TAILQ_REMOVE(&c->keybindq, key, entry);
|
||||||
if (key->context == CWM_CONTEXT_NONE)
|
if (key->context == CWM_CONTEXT_NONE)
|
||||||
free(key->argument.c);
|
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
|
int
|
||||||
conf_bind_mouse(struct conf *c, const char *bind, const char *cmd)
|
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;
|
unsigned int i;
|
||||||
|
|
||||||
if ((strcmp(bind, "all") == 0) && (cmd == NULL)) {
|
if ((strcmp(bind, "all") == 0) && (cmd == NULL)) {
|
||||||
conf_unbind_mouse_all(c);
|
conf_unbind_mouse(c, NULL);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
mb = xmalloc(sizeof(*mb));
|
mb = xmalloc(sizeof(*mb));
|
||||||
@@ -626,27 +611,16 @@ conf_unbind_mouse(struct conf *c, struct bind_ctx *unbind)
|
|||||||
struct bind_ctx *mb = NULL, *mbnxt;
|
struct bind_ctx *mb = NULL, *mbnxt;
|
||||||
|
|
||||||
TAILQ_FOREACH_SAFE(mb, &c->mousebindq, entry, mbnxt) {
|
TAILQ_FOREACH_SAFE(mb, &c->mousebindq, entry, mbnxt) {
|
||||||
if (mb->modmask != unbind->modmask)
|
if ((unbind == NULL) ||
|
||||||
continue;
|
((mb->modmask == unbind->modmask) &&
|
||||||
if (mb->press.button == unbind->press.button) {
|
(mb->press.button == unbind->press.button))) {
|
||||||
TAILQ_REMOVE(&c->mousebindq, mb, entry);
|
|
||||||
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);
|
TAILQ_REMOVE(&c->mousebindq, mb, entry);
|
||||||
if (mb->context == CWM_CONTEXT_NONE)
|
if (mb->context == CWM_CONTEXT_NONE)
|
||||||
free(mb->argument.c);
|
free(mb->argument.c);
|
||||||
free(mb);
|
free(mb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
conf_grab_kbd(Window win)
|
conf_grab_kbd(Window win)
|
||||||
|
Reference in New Issue
Block a user