Merge branch 'wip/smcv/shifted-shortcuts' into 'main'

gdkevents: Don't ignore modifiers that are not currently active

Closes #5095

See merge request GNOME/gtk!5037
This commit is contained in:
Matthias Clasen 2022-09-19 13:55:10 +00:00
commit 873c437235

View File

@ -1773,7 +1773,7 @@ gdk_key_event_matches (GdkEvent *event,
guint ev_keyval;
int layout;
int level;
GdkModifierType consumed_modifiers;
GdkModifierType ignored_modifiers;
GdkModifierType shift_group_mask;
gboolean group_mod_is_accel_mod = FALSE;
const GdkModifierType mask = GDK_CONTROL_MASK |
@ -1792,7 +1792,23 @@ gdk_key_event_matches (GdkEvent *event,
ev_keyval = self->translated[1].keyval;
layout = self->translated[1].layout;
level = self->translated[1].level;
consumed_modifiers = self->translated[1].consumed;
/*
* If a modifier is currently active (e.g. Shift is pressed) and was marked
* as consumed, we ignore it for the purposes of matching shortcuts.
* For example, when Ctrl+Shift+[plus/equals key] is translated into
* Ctrl+plus on a keyboard where Shift+equals is the plus sign, we want
* shortcuts for either <Control><Shift>plus or <Control>plus to match.
* (See https://bugzilla.gnome.org/show_bug.cgi?id=100439)
*
* If a modifier is *not* currently active, the X11 backend can sometimes
* mark it as consumed where the Wayland and Windows backends do not.
* In this case, we still want to pay attention to its state.
* For example, when Ctrl+x is translated into Ctrl+x, we only want to
* trigger shortcuts for <Control>x, not for <Control><Shift>x.
* (See https://gitlab.gnome.org/GNOME/gtk/-/issues/5095)
*/
ignored_modifiers = (self->translated[1].consumed & state);
/* if the group-toggling modifier is part of the default accel mod
* mask, and it is active, disable it for matching
@ -1804,7 +1820,7 @@ gdk_key_event_matches (GdkEvent *event,
if (mask & shift_group_mask)
group_mod_is_accel_mod = TRUE;
if ((modifiers & ~consumed_modifiers & mask) == (state & ~consumed_modifiers & mask))
if ((modifiers & ~ignored_modifiers & mask) == (state & ~ignored_modifiers & mask))
{
/* modifier match */
GdkKeymapKey *keys;