aboutsummaryrefslogtreecommitdiffstats
path: root/conf.c
diff options
context:
space:
mode:
authorokan2014-01-20 19:06:04 +0000
committerokan2014-01-20 19:06:04 +0000
commitbc4622e632abd877c52d5baa8359e834325a4f23 (patch)
treeb37ca7ac8f01fb72ba177f4c753d2b5f1f10ce48 /conf.c
parent749175e23624a43a35824edada4545a6115dd4d1 (diff)
downloadcwm-bc4622e632abd877c52d5baa8359e834325a4f23.tar.gz
- remove redundant range check for buttons in conf_bind_mouse.
- make conf_bind_kbd return error on non-matches to match what conf_bind_mouse does. - rename some variables while here for clarity. - constify bind and cmd. from Tiago Cunha.
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c114
1 files changed, 52 insertions, 62 deletions
diff --git a/conf.c b/conf.c
index cf5796f..83db444 100644
--- a/conf.c
+++ b/conf.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: conf.c,v 1.155 2014/01/03 15:29:06 okan Exp $
+ * $OpenBSD: conf.c,v 1.156 2014/01/20 19:06:04 okan Exp $
*/
#include <sys/param.h>
@@ -472,48 +472,50 @@ conf_bind_getmask(const char *name, unsigned int *mask)
return (dash + 1);
}
-void
-conf_bind_kbd(struct conf *c, char *name, char *binding)
+int
+conf_bind_kbd(struct conf *c, const char *bind, const char *cmd)
{
- struct keybinding *current_binding;
- const char *substring;
- unsigned int i, mask;
-
- current_binding = xcalloc(1, sizeof(*current_binding));
- substring = conf_bind_getmask(name, &mask);
- current_binding->modmask |= mask;
-
- current_binding->keysym = XStringToKeysym(substring);
- if (current_binding->keysym == NoSymbol) {
- free(current_binding);
- return;
+ struct keybinding *kb;
+ const char *key;
+ unsigned int i, mask;
+
+ kb = xcalloc(1, sizeof(*kb));
+ key = conf_bind_getmask(bind, &mask);
+ kb->modmask |= mask;
+
+ kb->keysym = XStringToKeysym(key);
+ if (kb->keysym == NoSymbol) {
+ warnx("unknown symbol: %s", key);
+ free(kb);
+ return (0);
}
/* We now have the correct binding, remove duplicates. */
- conf_unbind_kbd(c, current_binding);
+ conf_unbind_kbd(c, kb);
- if (strcmp("unmap", binding) == 0) {
- free(current_binding);
- return;
+ if (strcmp("unmap", cmd) == 0) {
+ free(kb);
+ return (1);
}
for (i = 0; i < nitems(name_to_kbfunc); i++) {
- if (strcmp(name_to_kbfunc[i].tag, binding) != 0)
+ if (strcmp(name_to_kbfunc[i].tag, cmd) != 0)
continue;
- current_binding->callback = name_to_kbfunc[i].handler;
- current_binding->flags = name_to_kbfunc[i].flags;
- current_binding->argument = name_to_kbfunc[i].argument;
- current_binding->argtype |= ARG_INT;
- TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
- return;
+ kb->callback = name_to_kbfunc[i].handler;
+ kb->flags = name_to_kbfunc[i].flags;
+ kb->argument = name_to_kbfunc[i].argument;
+ kb->argtype |= ARG_INT;
+ TAILQ_INSERT_TAIL(&c->keybindingq, kb, entry);
+ return (1);
}
- current_binding->callback = kbfunc_cmdexec;
- current_binding->flags = 0;
- current_binding->argument.c = xstrdup(binding);
- current_binding->argtype |= ARG_CHAR;
- TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
+ kb->callback = kbfunc_cmdexec;
+ kb->flags = 0;
+ kb->argument.c = xstrdup(cmd);
+ kb->argtype |= ARG_CHAR;
+ TAILQ_INSERT_TAIL(&c->keybindingq, kb, entry);
+ return (1);
}
static void
@@ -555,52 +557,40 @@ static struct {
{ "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT, {0} },
};
-static unsigned int mouse_btns[] = {
- Button1, Button2, Button3, Button4, Button5
-};
-
int
-conf_bind_mouse(struct conf *c, char *name, char *binding)
+conf_bind_mouse(struct conf *c, const char *bind, const char *cmd)
{
- struct mousebinding *current_binding;
- const char *errstr, *substring;
- unsigned int button, i, mask;
-
- current_binding = xcalloc(1, sizeof(*current_binding));
- substring = conf_bind_getmask(name, &mask);
- current_binding->modmask |= mask;
+ struct mousebinding *mb;
+ const char *button, *errstr;
+ unsigned int i, mask;
- button = strtonum(substring, 1, 5, &errstr);
- if (errstr)
- warnx("button number is %s: %s", errstr, substring);
+ mb = xcalloc(1, sizeof(*mb));
+ button = conf_bind_getmask(bind, &mask);
+ mb->modmask |= mask;
- for (i = 0; i < nitems(mouse_btns); i++) {
- if (button == mouse_btns[i]) {
- current_binding->button = button;
- break;
- }
- }
- if (!current_binding->button || errstr) {
- free(current_binding);
+ mb->button = strtonum(button, Button1, Button5, &errstr);
+ if (errstr) {
+ warnx("button number is %s: %s", errstr, button);
+ free(mb);
return (0);
}
/* We now have the correct binding, remove duplicates. */
- conf_unbind_mouse(c, current_binding);
+ conf_unbind_mouse(c, mb);
- if (strcmp("unmap", binding) == 0) {
- free(current_binding);
+ if (strcmp("unmap", cmd) == 0) {
+ free(mb);
return (1);
}
for (i = 0; i < nitems(name_to_mousefunc); i++) {
- if (strcmp(name_to_mousefunc[i].tag, binding) != 0)
+ if (strcmp(name_to_mousefunc[i].tag, cmd) != 0)
continue;
- current_binding->callback = name_to_mousefunc[i].handler;
- current_binding->flags = name_to_mousefunc[i].flags;
- current_binding->argument = name_to_mousefunc[i].argument;
- TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry);
+ mb->callback = name_to_mousefunc[i].handler;
+ mb->flags = name_to_mousefunc[i].flags;
+ mb->argument = name_to_mousefunc[i].argument;
+ TAILQ_INSERT_TAIL(&c->mousebindingq, mb, entry);
return (1);
}