From 8cae7ff0f6c01e32ef0e5b2ff21570f3b18debf7 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 6 Nov 2023 11:48:48 +0100 Subject: [PATCH] core: Ignore locked modifiers in keycombo machinery Locked modifiers should probably not have an effect on keybindings while toggled. this is most relevant for modifiers that can be either/both pressed or locked (e.g. Caps Lock key), if used in keybindings. Part-of: --- src/core/keybindings.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/core/keybindings.c b/src/core/keybindings.c index 39df9c094..1fbfca64c 100644 --- a/src/core/keybindings.c +++ b/src/core/keybindings.c @@ -1896,6 +1896,16 @@ meta_key_binding_has_handler_func (MetaKeyBinding *binding) return (!!binding->handler->func || !!binding->handler->default_func); } +static ClutterModifierType +get_modifiers (ClutterEvent *event) +{ + ClutterModifierType pressed, latched; + + clutter_event_get_key_state (event, &pressed, &latched, NULL); + + return pressed | latched; +} + static gboolean process_event (MetaDisplay *display, MetaWindow *window, @@ -1906,14 +1916,14 @@ process_event (MetaDisplay *display, (xkb_keycode_t) clutter_event_get_key_code ((ClutterEvent *) event); MetaResolvedKeyCombo resolved_combo = { &keycode, 1 }; MetaKeyBinding *binding; + ClutterModifierType modifiers; /* we used to have release-based bindings but no longer. */ if (clutter_event_type ((ClutterEvent *) event) == CLUTTER_KEY_RELEASE) return FALSE; - resolved_combo.mask = - mask_from_event_params (keys, - clutter_event_get_state ((ClutterEvent *) event)); + modifiers = get_modifiers ((ClutterEvent *) event); + resolved_combo.mask = mask_from_event_params (keys, modifiers); binding = get_keybinding (keys, &resolved_combo); @@ -1995,7 +2005,7 @@ process_special_modifier_key (MetaDisplay *display, hardware_keycode = clutter_event_get_key_code ((ClutterEvent *) event); time_ms = clutter_event_get_time ((ClutterEvent *) event); device = clutter_event_get_device ((ClutterEvent *) event); - modifiers = clutter_event_get_state ((ClutterEvent *) event); + modifiers = get_modifiers ((ClutterEvent *) event); if (*modifier_press_only) { @@ -2167,6 +2177,7 @@ process_iso_next_group (MetaDisplay *display, gboolean activate; xkb_keycode_t keycode = (xkb_keycode_t) clutter_event_get_key_code ((ClutterEvent *) event); + ClutterModifierType modifiers; xkb_mod_mask_t mask; int i, j; @@ -2174,8 +2185,8 @@ process_iso_next_group (MetaDisplay *display, return FALSE; activate = FALSE; - mask = mask_from_event_params (keys, - clutter_event_get_state ((ClutterEvent *) event)); + modifiers = get_modifiers ((ClutterEvent *) event); + mask = mask_from_event_params (keys, modifiers); for (i = 0; i < keys->n_iso_next_group_combos; ++i) { @@ -3954,15 +3965,15 @@ process_keybinding_key_event (MetaDisplay *display, MetaKeyBindingManager *keys = &display->key_binding_manager; xkb_keycode_t keycode = (xkb_keycode_t) clutter_event_get_key_code ((ClutterEvent *) event); + ClutterModifierType modifiers; MetaResolvedKeyCombo resolved_combo = { &keycode, 1 }; MetaKeyBinding *binding; if (clutter_event_type ((ClutterEvent *) event) == CLUTTER_KEY_RELEASE) return FALSE; - resolved_combo.mask = - mask_from_event_params (keys, - clutter_event_get_state ((ClutterEvent *) event)); + modifiers = get_modifiers ((ClutterEvent *) event); + resolved_combo.mask = mask_from_event_params (keys, modifiers); binding = get_keybinding (keys, &resolved_combo); if (!binding)