i3 - improved tiling WM


Implement bindsym mouse configuration

Patch status: merged

Patch by Tony Crisci

Long description:

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.

To apply this patch, use:
curl http://cr.i3wm.org/patch/514/raw.patch | git am

b/src/bindings.c

26
@@ -50,10 +50,15 @@ Binding *configure_binding(const char *bindtype, const char *modifiers, const ch
27
     DLOG("bindtype %s, modifiers %s, input code %s, release %s\n", bindtype, modifiers, input_code, release);
28
     new_binding->release = (release != NULL ? B_UPON_KEYRELEASE : B_UPON_KEYPRESS);
29
     if (strcmp(bindtype, "bindsym") == 0) {
30
+        new_binding->input_type = (strncasecmp(input_code, "button", (sizeof("button") - 1)) == 0
31
+            ? B_MOUSE
32
+            : B_KEYBOARD);
33
+
34
         new_binding->symbol = sstrdup(input_code);
35
     } else {
36
         // TODO: strtol with proper error handling
37
         new_binding->keycode = atoi(input_code);
38
+        new_binding->input_type = B_KEYBOARD;
39
         if (new_binding->keycode == 0) {
40
             ELOG("Could not parse \"%s\" as an input code, ignoring this binding.\n", input_code);
41
             FREE(new_binding);
42
@@ -62,7 +67,6 @@ Binding *configure_binding(const char *bindtype, const char *modifiers, const ch
43
     }
44
     new_binding->mods = modifiers_from_str(modifiers);
45
     new_binding->command = sstrdup(command);
46
-    new_binding->input_type = B_KEYBOARD;
47
 
48
     struct Mode *mode = mode_from_name(modename);
49
     TAILQ_INSERT_TAIL(mode->bindings, new_binding, bindings);
50
@@ -194,7 +198,17 @@ void translate_keysyms(void) {
51
     max_keycode = xcb_get_setup(conn)->max_keycode;
52
 
53
     TAILQ_FOREACH(bind, bindings, bindings) {
54
-        if (bind->input_type != B_KEYBOARD || bind->keycode > 0)
55
+        if (bind->input_type == B_MOUSE) {
56
+            int button = atoi(bind->symbol + (sizeof("button") - 1));
57
+            bind->keycode = button;
58
+
59
+            if (button < 1)
60
+                ELOG("Could not translate string to button: \"%s\"\n", bind->symbol);
61
+
62
+            continue;
63
+        }
64
+
65
+        if (bind->keycode > 0)
66
             continue;
67
 
68
         /* We need to translate the symbol to a keycode */