]> git.sur5r.net Git - i3/i3/blobdiff - src/bindings.c
i3-nagbar: explicitly set cursor using libxcursor if available
[i3/i3] / src / bindings.c
index 471e4783decab4958a9eb940139eba6d2b404229..3463f8315304957f9d823a9bba6a6b4e94d3b36b 100644 (file)
@@ -164,6 +164,10 @@ void regrab_all_buttons(xcb_connection_t *conn) {
         xcb_grab_buttons(conn, con->window->id, grab_scrollwheel);
     }
 
+    /* Also grab the root window to allow bindings to work on there as well. */
+    xcb_ungrab_button(conn, XCB_BUTTON_INDEX_ANY, root, XCB_BUTTON_MASK_ANY);
+    xcb_grab_buttons(conn, root, grab_scrollwheel);
+
     xcb_ungrab_server(conn);
 }
 
@@ -186,18 +190,28 @@ static Binding *get_binding(i3_event_state_mask_t state_filtered, bool is_releas
         }
     }
 
+    const uint32_t xkb_group_state = (state_filtered & 0xFFFF0000);
+    const uint32_t modifiers_state = (state_filtered & 0x0000FFFF);
     TAILQ_FOREACH(bind, bindings, bindings) {
-        bool state_matches;
-        if ((bind->event_state_mask & 0xFFFF) == 0) {
+        const uint32_t xkb_group_mask = (bind->event_state_mask & 0xFFFF0000);
+        /* modifiers_mask is a special case: a value of 0 does not mean “match all”,
+         * but rather “match exactly when no modifiers are present”. */
+        const uint32_t modifiers_mask = (bind->event_state_mask & 0x0000FFFF);
+        const bool groups_match = ((xkb_group_state & xkb_group_mask) == xkb_group_mask);
+        bool mods_match;
+        if (modifiers_mask == 0) {
             /* Verify no modifiers are pressed. A bitwise AND would lead to
              * false positives, see issue #2002. */
-            state_matches = (state_filtered == bind->event_state_mask);
+            mods_match = (modifiers_state == 0);
         } else {
-            state_matches = ((state_filtered & bind->event_state_mask) == bind->event_state_mask);
+            mods_match = ((modifiers_state & modifiers_mask) == modifiers_mask);
         }
+        const bool state_matches = (groups_match && mods_match);
 
-        DLOG("binding with event_state_mask 0x%x, state_filtered 0x%x, match: %s\n",
-             bind->event_state_mask, state_filtered, (state_matches ? "yes" : "no"));
+        DLOG("binding groups_match = %s, mods_match = %s, state_matches = %s\n",
+             (groups_match ? "yes" : "no"),
+             (mods_match ? "yes" : "no"),
+             (state_matches ? "yes" : "no"));
         /* First compare the state_filtered (unless this is a
          * B_UPON_KEYRELEASE_IGNORE_MODS binding and this is a KeyRelease
          * event) */
@@ -629,8 +643,8 @@ void binding_free(Binding *bind) {
 /*
  * Runs the given binding and handles parse errors. If con is passed, it will
  * execute the command binding with that container selected by criteria.
- * Returns a CommandResult for running the binding's command. Caller should
- * render tree if needs_tree_render is true. Free with command_result_free().
+ * Returns a CommandResult for running the binding's command. Free with
+ * command_result_free().
  *
  */
 CommandResult *run_binding(Binding *bind, Con *con) {