From e658e3c449f4a7b2c706138ff5602c0b4ac86a77 Mon Sep 17 00:00:00 2001 From: Philip Zander Date: Thu, 9 Dec 2021 22:47:43 +0100 Subject: [PATCH] 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 | 59 +++++++++++++++++----------------- 2 files changed, 35 insertions(+), 30 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,40 +356,39 @@ vk_and_mod_bits_to_gdk_keysym (GdkWin32Keymap *keymap, gunichar c; guint sym; + if (consumed_mod_bits) + *consumed_mod_bits = 0; + + /* Handle special key: Tab */ + if (vk == VK_TAB) + { + if (consumed_mod_bits) + *consumed_mod_bits = mod_bits & KBDSHIFT; + return (mod_bits & KBDSHIFT) ? GDK_KEY_ISO_Left_Tab : GDK_KEY_Tab; + } + + /* Handle other special keys */ + switch (vk) + { + #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 (!is_dead) - { - /* 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 (c == WCH_NONE) - { - if (consumed_mod_bits) - *consumed_mod_bits = 0; - return GDK_KEY_VoidSymbol; - } + return GDK_KEY_VoidSymbol; sym = gdk_unicode_to_keyval (c);