i3 - improved tiling WM


Key binding to match any key

Patch status: needinfo

Patch by Ari Edelkind

Long description:

Use
    bindsym Any ...
or
    bindcode Any ...

to match any key.  Note that keys are matched in the order that they
appear in the configuration, so this command should be supplied last.
Options, such as '--release' and modifiers, work with this key binding
in a more or less intuitive way.

One caveat to note is that modifiers count as keys.  Therefore, you
might need to explicitly ignore a modifier if you want to be able to use
it elsewhere in your mode.  For example, if Mod1 is Alt, you might do:

    mode "stage2" {
        bindsym Mod1+y exec stuff; mode "default"
        bindsym Alt_L nop "ignore modifier"
        bindsym Alt_R nop "ignore modifier"
        bindsym Any mode "default"
    }
    bindsym Mod1+x mode "stage2"

or, alternatively:

    mode "stage2" {
        bindsym Mod1+y exec stuff
        bindsym --release Mod1+Any mode "default"
        bindsym --release Any mode "default"
    }
    bindsym Mod1+x mode "stage2"

Note that, in the latter case, Mod1+Any is matched upon release even
when Mod1+y is matched on key press.

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

b/src/bindings.c

46
@@ -55,7 +55,10 @@ Binding *configure_binding(const char *bindtype, const char *modifiers, const ch
47
     Binding *new_binding = scalloc(sizeof(Binding));
48
     DLOG("bindtype %s, modifiers %s, input code %s, release %s\n", bindtype, modifiers, input_code, release);
49
     new_binding->release = (release != NULL ? B_UPON_KEYRELEASE : B_UPON_KEYPRESS);
50
-    if (strcmp(bindtype, "bindsym") == 0) {
51
+    if (strcasecmp(input_code, "any") == 0) {
52
+        new_binding->input_type = B_KEYBOARD;
53
+        new_binding->keycode = XCB_GRAB_ANY;
54
+    } else if (strcmp(bindtype, "bindsym") == 0) {
55
         new_binding->input_type = (strncasecmp(input_code, "button", (sizeof("button") - 1)) == 0
56
             ? B_MOUSE
57
             : B_KEYBOARD);
58
@@ -118,7 +121,7 @@ void grab_all_keys(xcb_connection_t *conn, bool bind_mode_switch) {
59
             continue;
60
 
61
         /* The easy case: the user specified a keycode directly. */
62
-        if (bind->keycode > 0) {
63
+        if (!bind->symbol || bind->keycode > 0) {
64
             grab_keycode_for_binding(conn, bind, bind->keycode);
65
             continue;
66
         }
67
@@ -169,7 +172,7 @@ Binding *get_keyboard_binding(uint16_t modifiers, bool key_release, xcb_keycode_
68
                 continue;
69
         } else {
70
             /* This case is easier: The user specified a keycode */
71
-            if (bind->keycode != keycode)
72
+            if (bind->keycode != keycode && bind->keycode != XCB_GRAB_ANY)
73
                 continue;
74
         }
75
 
76
@@ -230,7 +233,7 @@ void translate_keysyms(void) {
77
             continue;
78
         }
79
 
80
-        if (bind->keycode > 0)
81
+        if (!bind->symbol)
82
             continue;
83
 
84
         /* We need to translate the symbol to a keycode */