Add proposed patch to fix keyboard shortcuts with X11 backend
authorSimon McVittie <smcv@debian.org>
Sat, 17 Sep 2022 20:38:37 +0000 (21:38 +0100)
committerSimon McVittie <smcv@debian.org>
Sat, 17 Sep 2022 20:38:37 +0000 (21:38 +0100)
Closes: #1016927
debian/patches/build-Add-an-option-to-use-more-conservative-GResource-em.patch
debian/patches/gdkevents-Don-t-ignore-modifiers-that-are-not-currently-a.patch [new file with mode: 0644]
debian/patches/series

index 311aca8f03692af9713660c911eadaeca000d3ba..c1c067fa74454700250e56e546c7c7e635f0a1d1 100644 (file)
@@ -21,10 +21,10 @@ Signed-off-by: Simon McVittie <smcv@debian.org>
  2 files changed, 19 insertions(+), 1 deletion(-)
 
 diff --git a/gtk/meson.build b/gtk/meson.build
-index 2e404f2..46f886f 100644
+index 080bffe..12e4ad7 100644
 --- a/gtk/meson.build
 +++ b/gtk/meson.build
-@@ -866,15 +866,28 @@ if not fs.exists('theme/Default/Default-light.css')
+@@ -869,15 +869,28 @@ if not fs.exists('theme/Default/Default-light.css')
  endif
  
  
@@ -55,7 +55,7 @@ index 2e404f2..46f886f 100644
  
    # Create the resource blob
 diff --git a/meson_options.txt b/meson_options.txt
-index 2084ab8..078e76f 100644
+index c1df747..fe779aa 100644
 --- a/meson_options.txt
 +++ b/meson_options.txt
 @@ -78,6 +78,11 @@ option('f16c',
diff --git a/debian/patches/gdkevents-Don-t-ignore-modifiers-that-are-not-currently-a.patch b/debian/patches/gdkevents-Don-t-ignore-modifiers-that-are-not-currently-a.patch
new file mode 100644 (file)
index 0000000..3f4f0bf
--- /dev/null
@@ -0,0 +1,81 @@
+From: Simon McVittie <smcv@debian.org>
+Date: Sat, 17 Sep 2022 18:53:00 +0100
+Subject: gdkevents: Don't ignore modifiers that are not currently active
+
+The X11 backend can mark modifiers like Shift as consumed even if they
+aren't actually active, which seems to be something to do with making
+shortcuts like `<Control><Shift>plus` and `<Control>plus` work as
+intended regardless of whether the plus symbol is obtained by pressing
+Shift and a key (like `+/=` on American, British or French keyboards)
+or not (like `*/+` on German keyboards).
+
+However, this can go badly wrong when the modifier is *not* pressed.
+For example, terminals normally have separate bindings for `<Control>c`
+(send SIGINT) and `<Control><Shift>c` (copy). If we disregard the
+consumed modifiers completely, when the X11 backend marks Shift as
+consumed, pressing Ctrl+c would send SIGINT *and* copy to the clipboard,
+which is not what was intended.
+
+By masking out the members of `consumed` that are not in `state`, we
+get the same interpretation for X11 and Wayland, and ensure that
+keyboard shortcuts that explicitly mention Shift can only be triggered
+while holding Shift. It continues to be possible to trigger keyboard
+shortcuts that do not explicitly mention Shift (such as `<Control>plus`)
+while holding Shift, if the backend reports Shift as having been
+consumed in order to generate the plus keysym.
+
+Bug: https://gitlab.gnome.org/GNOME/gtk/-/issues/5095
+Bug-Debian: https://bugs.debian.org/1016927
+Signed-off-by: Simon McVittie <smcv@debian.org>
+Forwarded: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/5037
+---
+ gdk/gdkevents.c | 22 +++++++++++++++++++---
+ 1 file changed, 19 insertions(+), 3 deletions(-)
+
+diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
+index 4b61715..0daf475 100644
+--- a/gdk/gdkevents.c
++++ b/gdk/gdkevents.c
+@@ -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;
index 2fcc607beae9c48575a4014f38da508236268ed2..a0d37e4e5310dedf9790ee457c67f698133f8ac9 100644 (file)
@@ -1,3 +1,4 @@
+gdkevents-Don-t-ignore-modifiers-that-are-not-currently-a.patch
 build-Add-an-option-to-use-more-conservative-GResource-em.patch
 reftest_compare_surfaces-Report-how-much-the-images-diffe.patch
 reftests-Allow-minor-differences-to-be-tolerated.patch