]> git.sur5r.net Git - i3/i3/blobdiff - src/bindings.c
Introduce --exclude-titlebar flag for mouse bindings. (#2703)
[i3/i3] / src / bindings.c
index 7a056adf397250c3a6e647afa642ece70d9a9c80..36bcc5d175bbc0c75bef8209c3a0bdfcbd3e4985 100644 (file)
@@ -32,8 +32,9 @@ static struct Mode *mode_from_name(const char *name, bool pango_markup) {
 
     /* Try to find the mode in the list of modes and return it */
     SLIST_FOREACH(mode, &modes, modes) {
-        if (strcmp(mode->name, name) == 0)
+        if (strcmp(mode->name, name) == 0) {
             return mode;
+        }
     }
 
     /* If the mode was not found, create a new one */
@@ -55,12 +56,14 @@ static struct Mode *mode_from_name(const char *name, bool pango_markup) {
  */
 Binding *configure_binding(const char *bindtype, const char *modifiers, const char *input_code,
                            const char *release, const char *border, const char *whole_window,
-                           const char *command, const char *modename, bool pango_markup) {
+                           const char *exclude_titlebar, const char *command, const char *modename,
+                           bool pango_markup) {
     Binding *new_binding = scalloc(1, sizeof(Binding));
     DLOG("Binding %p bindtype %s, modifiers %s, input code %s, release %s\n", new_binding, bindtype, modifiers, input_code, release);
     new_binding->release = (release != NULL ? B_UPON_KEYRELEASE : B_UPON_KEYPRESS);
     new_binding->border = (border != NULL);
     new_binding->whole_window = (whole_window != NULL);
+    new_binding->exclude_titlebar = (exclude_titlebar != NULL);
     if (strcmp(bindtype, "bindsym") == 0) {
         new_binding->input_type = (strncasecmp(input_code, "button", (sizeof("button") - 1)) == 0
                                        ? B_MOUSE
@@ -368,6 +371,7 @@ struct resolve {
  */
 static void add_keycode_if_matches(struct xkb_keymap *keymap, xkb_keycode_t key, void *data) {
     const struct resolve *resolving = data;
+    struct xkb_state *numlock_state = resolving->xkb_state_numlock;
     xkb_keysym_t sym = xkb_state_key_get_one_sym(resolving->xkb_state, key);
     if (sym != resolving->keysym) {
         /* Check if Shift was specified, and try resolving the symbol without
@@ -377,6 +381,11 @@ static void add_keycode_if_matches(struct xkb_keymap *keymap, xkb_keycode_t key,
             return;
         if (xkb_state_key_get_level(resolving->xkb_state, key, layout) > 1)
             return;
+        /* Skip the Shift fallback for keypad keys, otherwise one cannot bind
+         * KP_1 independent of KP_End. */
+        if (sym >= XKB_KEY_KP_Space && sym <= XKB_KEY_KP_Equal)
+            return;
+        numlock_state = resolving->xkb_state_numlock_no_shift;
         sym = xkb_state_key_get_one_sym(resolving->xkb_state_no_shift, key);
         if (sym != resolving->keysym)
             return;
@@ -403,9 +412,8 @@ static void add_keycode_if_matches(struct xkb_keymap *keymap, xkb_keycode_t key,
          * active. If so, grab the key with NumLock as well, so that users don’t
          * need to duplicate every key binding with an additional Mod2 specified.
          */
-        xkb_keysym_t sym_numlock = xkb_state_key_get_one_sym(resolving->xkb_state_numlock, key);
-        xkb_keysym_t sym_numlock_no_shift = xkb_state_key_get_one_sym(resolving->xkb_state_numlock_no_shift, key);
-        if (sym_numlock == resolving->keysym || sym_numlock_no_shift == resolving->keysym) {
+        xkb_keysym_t sym_numlock = xkb_state_key_get_one_sym(numlock_state, key);
+        if (sym_numlock == resolving->keysym) {
             /* Also bind the key with active NumLock */
             ADD_TRANSLATED_KEY(bind->event_state_mask | xcb_numlock_mask);
 
@@ -976,7 +984,7 @@ int *bindings_get_buttons_to_grab(void) {
         }
 
         /* Avoid duplicates. */
-        for (int i = 0; i < num_max; i++) {
+        for (int i = 0; i < num; i++) {
             if (buffer[i] == button)
                 continue;
         }