keyboard: include pressed modifiers in bound set

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).
This commit is contained in:
John Lindgren 2023-11-10 23:43:46 -05:00 committed by Johan Malm
parent fe9491443c
commit 98bf316ee6
3 changed files with 18 additions and 5 deletions

View file

@ -19,7 +19,7 @@
uint32_t *key_state_pressed_sent_keycodes(void); uint32_t *key_state_pressed_sent_keycodes(void);
int key_state_nr_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); void key_state_store_pressed_key_as_bound(uint32_t keycode);
bool key_state_corresponding_press_event_was_bound(uint32_t keycode); bool key_state_corresponding_press_event_was_bound(uint32_t keycode);
void key_state_bound_key_remove(uint32_t keycode); void key_state_bound_key_remove(uint32_t keycode);

View file

@ -11,7 +11,7 @@ struct key_array {
int nr_keys; int nr_keys;
}; };
static struct key_array pressed, bound, pressed_sent; static struct key_array pressed, pressed_mods, bound, pressed_sent;
static bool static bool
key_present(struct key_array *array, uint32_t keycode) key_present(struct key_array *array, uint32_t keycode)
@ -69,12 +69,16 @@ key_state_nr_pressed_sent_keycodes(void)
} }
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); add_key(&pressed, keycode);
if (is_modifier) {
add_key(&pressed_mods, keycode);
}
} else { } else {
remove_key(&pressed, keycode); remove_key(&pressed, keycode);
remove_key(&pressed_mods, keycode);
} }
} }
@ -82,6 +86,15 @@ void
key_state_store_pressed_key_as_bound(uint32_t keycode) key_state_store_pressed_key_as_bound(uint32_t keycode)
{ {
add_key(&bound, 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 bool

View file

@ -237,7 +237,7 @@ handle_compositor_keybindings(struct keyboard *keyboard,
} }
key_state_set_pressed(event->keycode, 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) { if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
/* /*