]> git.mdlowis.com Git - proto/labwc.git/commitdiff
keyboard: include pressed modifiers in bound set
authorJohn Lindgren <john@jlindgren.net>
Sat, 11 Nov 2023 04:43:46 +0000 (23:43 -0500)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 12 Nov 2023 17:37:30 +0000 (17:37 +0000)
This prevents applications from seeing and handling the release event
for a modifier key that was part of a keybinding (e.g. Firefox displays
its menu bar for a lone Alt press + release).

include/input/key-state.h
src/input/key-state.c
src/input/keyboard.c

index 1fd83523d4a3a70b9c2da9204957f7009b44190f..1b5b7ed22d875562f65944815a00745d6304cdf3 100644 (file)
@@ -19,7 +19,7 @@
 uint32_t *key_state_pressed_sent_keycodes(void);
 int key_state_nr_pressed_sent_keycodes(void);
 
-void key_state_set_pressed(uint32_t keycode, bool ispressed);
+void key_state_set_pressed(uint32_t keycode, bool is_pressed, bool is_modifier);
 void key_state_store_pressed_key_as_bound(uint32_t keycode);
 bool key_state_corresponding_press_event_was_bound(uint32_t keycode);
 void key_state_bound_key_remove(uint32_t keycode);
index 193022a7eb27052147e0e22100eb7595aa7b218c..603b8c5af7a0c7a3205ca0ac17e168f070cbc34e 100644 (file)
@@ -11,7 +11,7 @@ struct key_array {
        int nr_keys;
 };
 
-static struct key_array pressed, bound, pressed_sent;
+static struct key_array pressed, pressed_mods, bound, pressed_sent;
 
 static bool
 key_present(struct key_array *array, uint32_t keycode)
@@ -69,12 +69,16 @@ key_state_nr_pressed_sent_keycodes(void)
 }
 
 void
-key_state_set_pressed(uint32_t keycode, bool ispressed)
+key_state_set_pressed(uint32_t keycode, bool is_pressed, bool is_modifier)
 {
-       if (ispressed) {
+       if (is_pressed) {
                add_key(&pressed, keycode);
+               if (is_modifier) {
+                       add_key(&pressed_mods, keycode);
+               }
        } else {
                remove_key(&pressed, keycode);
+               remove_key(&pressed_mods, keycode);
        }
 }
 
@@ -82,6 +86,15 @@ void
 key_state_store_pressed_key_as_bound(uint32_t keycode)
 {
        add_key(&bound, keycode);
+       /*
+        * Also store any pressed modifiers as bound. This prevents
+        * applications from seeing and handling the release event for
+        * a modifier key that was part of a keybinding (e.g. Firefox
+        * displays its menu bar for a lone Alt press + release).
+        */
+       for (int i = 0; i < pressed_mods.nr_keys; ++i) {
+               add_key(&bound, pressed_mods.keys[i]);
+       }
 }
 
 bool
index e3526b7f3b0dacf5932e079fcc389bec70d66f18..078209a6b15e4a6619ede344cc80586be0630b61 100644 (file)
@@ -237,7 +237,7 @@ handle_compositor_keybindings(struct keyboard *keyboard,
        }
 
        key_state_set_pressed(event->keycode,
-               event->state == WL_KEYBOARD_KEY_STATE_PRESSED);
+               event->state == WL_KEYBOARD_KEY_STATE_PRESSED, is_modifier);
 
        if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
                /*