[gtk/gtk-3-24: 7/8] gdk/win32: Fix modifiers sometimes being consumed for special keys




commit e658e3c449f4a7b2c706138ff5602c0b4ac86a77
Author: Philip Zander <philip zander gmail com>
Date:   Thu Dec 9 22:47:43 2021 +0100

    gdk/win32: Fix modifiers sometimes being consumed for special keys
    
    Windows keymaps contain some bogus mappings, e.g. Ctrl+Backspace=Delete.
    Previously, we correctly identified the key as Backspace, but the Ctrl
    was still consumed, so the Ctrl+Backspace keybinding did not work.

 gdk/win32/gdkkeys-win32-impl.c |  6 +++++
 gdk/win32/gdkkeys-win32.c      | 55 +++++++++++++++++++++---------------------
 2 files changed, 33 insertions(+), 28 deletions(-)
---
diff --git a/gdk/win32/gdkkeys-win32-impl.c b/gdk/win32/gdkkeys-win32-impl.c
index 9b74b22498..f792c4e24b 100644
--- a/gdk/win32/gdkkeys-win32-impl.c
+++ b/gdk/win32/gdkkeys-win32-impl.c
@@ -256,6 +256,12 @@ vk_to_char_fuzzy (GdkWin32KeymapLayoutInfo *info,
   int                n_levels;
   int                entry_size;
 
+  /* Initialize with defaults */
+  if (consumed_mod_bits)
+    *consumed_mod_bits = 0;
+  if (is_dead)
+    *is_dead = FALSE;
+
   g_return_val_if_fail (tables != NULL, WCH_NONE);
 
   wch_tables = tables->pVkToWcharTable.ptr;
diff --git a/gdk/win32/gdkkeys-win32.c b/gdk/win32/gdkkeys-win32.c
index 5e725b5cba..1a1e730026 100644
--- a/gdk/win32/gdkkeys-win32.c
+++ b/gdk/win32/gdkkeys-win32.c
@@ -356,41 +356,40 @@ vk_and_mod_bits_to_gdk_keysym (GdkWin32Keymap     *keymap,
   gunichar c;
   guint    sym;
 
-  c = vk_to_char_fuzzy (keymap, info, keystate, mod_bits,
-                        consumed_mod_bits, &is_dead, vk);
+  if (consumed_mod_bits)
+    *consumed_mod_bits = 0;
 
-  if (!is_dead)
+  /* Handle special key: Tab */
+  if (vk == VK_TAB)
     {
-      /* Special cases */
-      if (vk == VK_SHIFT)
-        return GDK_KEY_Shift_L;
-      if (vk == VK_CONTROL)
-        return GDK_KEY_Control_L;
-      if (vk == VK_MENU)
-        return GDK_KEY_Alt_L;
-      if (vk == VK_SNAPSHOT)
-        return GDK_KEY_Print;
-      if (vk == VK_TAB && !(mod_bits & KBDSHIFT))
-        return GDK_KEY_Tab;
-      if (vk == VK_TAB &&  (mod_bits & KBDSHIFT))
-        return GDK_KEY_ISO_Left_Tab;
-
-      /* Generic special keys */
-      switch (vk)
-        {
-          #define MAP(a_vk, a_gdk) case a_vk: return a_gdk;
-          DEFINE_SPECIAL (MAP)
-          #undef MAP
-        }
+      if (consumed_mod_bits)
+        *consumed_mod_bits = mod_bits & KBDSHIFT;
+      return (mod_bits & KBDSHIFT) ? GDK_KEY_ISO_Left_Tab : GDK_KEY_Tab;
     }
 
-  if (c == WCH_NONE)
+  /* Handle other special keys */
+  switch (vk)
     {
-      if (consumed_mod_bits)
-        *consumed_mod_bits = 0;
-      return GDK_KEY_VoidSymbol;
+      #define MAP(a_vk, a_gdk) case a_vk: return a_gdk;
+
+      DEFINE_SPECIAL (MAP)
+
+      /* Non-bijective mappings: */
+      MAP (VK_SHIFT,    GDK_KEY_Shift_L)
+      MAP (VK_CONTROL,  GDK_KEY_Control_L)
+      MAP (VK_MENU,     GDK_KEY_Alt_L)
+      MAP (VK_SNAPSHOT, GDK_KEY_Print)
+
+      #undef MAP
     }
 
+  /* Handle regular keys (including dead keys) */
+  c = vk_to_char_fuzzy (keymap, info, keystate, mod_bits,
+                        consumed_mod_bits, &is_dead, vk);
+
+  if (c == WCH_NONE)
+    return GDK_KEY_VoidSymbol;
+
   sym = gdk_unicode_to_keyval (c);
 
   if (is_dead)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]