]> git.sur5r.net Git - i3/i3/blobdiff - src/key_press.c
Refactor binding accessor
[i3/i3] / src / key_press.c
index ca5c3a0bbd7ab105d56e34ad36ce93c164dc2d60..65b8e5783c8897bc6b30d425102d45523b19db52 100644 (file)
@@ -4,7 +4,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
  *
  * key_press.c: key press handler
  *
@@ -51,17 +51,10 @@ static int json_end_map(void *ctx) {
 }
 
 static yajl_callbacks command_error_callbacks = {
-    NULL,
-    &json_boolean,
-    NULL,
-    NULL,
-    NULL,
-    NULL,
-    &json_start_map,
-    &json_map_key,
-    &json_end_map,
-    NULL,
-    NULL
+    .yajl_boolean = json_boolean,
+    .yajl_start_map = json_start_map,
+    .yajl_map_key = json_map_key,
+    .yajl_end_map = json_end_map,
 };
 
 /*
@@ -77,40 +70,11 @@ void handle_key_press(xcb_key_press_event_t *event) {
 
     DLOG("%s %d, state raw = %d\n", (key_release ? "KeyRelease" : "KeyPress"), event->detail, event->state);
 
-    /* Remove the numlock bit, all other bits are modifiers we can bind to */
-    uint16_t state_filtered = event->state & ~(xcb_numlock_mask | XCB_MOD_MASK_LOCK);
-    DLOG("(removed numlock, state = %d)\n", state_filtered);
-    /* Only use the lower 8 bits of the state (modifier masks) so that mouse
-     * button masks are filtered out */
-    state_filtered &= 0xFF;
-    DLOG("(removed upper 8 bits, state = %d)\n", state_filtered);
-
-    if (xkb_current_group == XkbGroup2Index)
-        state_filtered |= BIND_MODE_SWITCH;
-
-    DLOG("(checked mode_switch, state %d)\n", state_filtered);
-
-    /* Find the binding */
-    Binding *bind = get_binding(state_filtered, key_release, event->detail);
-
-    /* No match? Then the user has Mode_switch enabled but does not have a
-     * specific keybinding. Fall back to the default keybindings (without
-     * Mode_switch). Makes it much more convenient for users of a hybrid
-     * layout (like us, ru). */
-    if (bind == NULL) {
-        state_filtered &= ~(BIND_MODE_SWITCH);
-        DLOG("no match, new state_filtered = %d\n", state_filtered);
-        if ((bind = get_binding(state_filtered, key_release, event->detail)) == NULL) {
-            /* This is not a real error since we can have release and
-             * non-release keybindings. On a KeyPress event for which there is
-             * only a !release-binding, but no release-binding, the
-             * corresponding KeyRelease event will trigger this. No problem,
-             * though. */
-            DLOG("Could not lookup key binding (modifiers %d, keycode %d)\n",
-                 state_filtered, event->detail);
-            return;
-        }
-    }
+    Binding *bind = get_binding_from_xcb_event((xcb_generic_event_t *)event);
+
+    /* if we couldn't find a binding, we are done */
+    if (bind == NULL)
+        return;
 
     char *command_copy = sstrdup(bind->command);
     struct CommandResult *command_output = parse_command(command_copy);
@@ -145,6 +109,8 @@ void handle_key_press(xcb_key_press_event_t *event) {
             sasprintf(&pageraction, "i3-sensible-pager \"%s\"\n", errorfilename);
             char *argv[] = {
                 NULL, /* will be replaced by the executable path */
+                "-f",
+                config.font.pattern,
                 "-t",
                 "error",
                 "-m",