From: Tony Crisci Date: Sun, 27 Apr 2014 05:48:28 +0000 (-0400) Subject: Implement bindsym mouse configuration X-Git-Tag: 4.8~62 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3171d7ebe5e7165efe02083159d842d6a102d82b;p=i3%2Fi3 Implement bindsym mouse configuration If a `bindsym` config directive specifies a symbol beginning with "button", the binding will be given the type B_MOUSE for the indicated button number. Example: bindsym $mod+button2 exec echo 'button two' This will be interpreted as having input code (now `keycode`) 2 and type B_MOUSE. The mechanism to find and run mouse bindings on mouse events is not implemented. --- diff --git a/src/bindings.c b/src/bindings.c index 526c1a55..3d3dbd9c 100644 --- a/src/bindings.c +++ b/src/bindings.c @@ -50,10 +50,15 @@ Binding *configure_binding(const char *bindtype, const char *modifiers, const ch DLOG("bindtype %s, modifiers %s, input code %s, release %s\n", bindtype, modifiers, input_code, release); new_binding->release = (release != NULL ? B_UPON_KEYRELEASE : B_UPON_KEYPRESS); if (strcmp(bindtype, "bindsym") == 0) { + new_binding->input_type = (strncasecmp(input_code, "button", (sizeof("button") - 1)) == 0 + ? B_MOUSE + : B_KEYBOARD); + new_binding->symbol = sstrdup(input_code); } else { // TODO: strtol with proper error handling new_binding->keycode = atoi(input_code); + new_binding->input_type = B_KEYBOARD; if (new_binding->keycode == 0) { ELOG("Could not parse \"%s\" as an input code, ignoring this binding.\n", input_code); FREE(new_binding); @@ -62,7 +67,6 @@ Binding *configure_binding(const char *bindtype, const char *modifiers, const ch } new_binding->mods = modifiers_from_str(modifiers); new_binding->command = sstrdup(command); - new_binding->input_type = B_KEYBOARD; struct Mode *mode = mode_from_name(modename); TAILQ_INSERT_TAIL(mode->bindings, new_binding, bindings); @@ -194,7 +198,17 @@ void translate_keysyms(void) { max_keycode = xcb_get_setup(conn)->max_keycode; TAILQ_FOREACH(bind, bindings, bindings) { - if (bind->input_type != B_KEYBOARD || bind->keycode > 0) + if (bind->input_type == B_MOUSE) { + int button = atoi(bind->symbol + (sizeof("button") - 1)); + bind->keycode = button; + + if (button < 1) + ELOG("Could not translate string to button: \"%s\"\n", bind->symbol); + + continue; + } + + if (bind->keycode > 0) continue; /* We need to translate the symbol to a keycode */