From: Pierre Ossman Date: Fri, 20 Nov 2020 08:19:07 +0000 (+0100) Subject: Only handle Japanese keys when Japanese layout X-Git-Tag: v1.11.90~82^3~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f549170c4410f2e3811936c4db16503427d53622;p=tigervnc.git Only handle Japanese keys when Japanese layout Some of the virtual key codes for Japanese keys are used for other things on other layouts, so we need to make sure we only use this look up table when the layout is indeed set to Japanese. --- diff --git a/vncviewer/win32.c b/vncviewer/win32.c index 4213d3f1..63d59b82 100644 --- a/vncviewer/win32.c +++ b/vncviewer/win32.c @@ -42,6 +42,8 @@ static DWORD thread_id; static HHOOK hook = 0; static HWND target_wnd = 0; +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*a)) + static int is_system_hotkey(int vkCode) { switch (vkCode) { case VK_LWIN: @@ -131,6 +133,7 @@ void win32_disable_lowlevel_keyboard(HWND hwnd) thread = NULL; } +// Layout independent keys static const int vkey_map[][3] = { { VK_CANCEL, NoSymbol, XK_Break }, { VK_BACK, XK_BackSpace, NoSymbol }, @@ -218,7 +221,12 @@ static const int vkey_map[][3] = { { VK_MEDIA_PLAY_PAUSE, NoSymbol, XF86XK_AudioPlay }, { VK_LAUNCH_MAIL, NoSymbol, XF86XK_Mail }, { VK_LAUNCH_APP2, NoSymbol, XF86XK_Calculator }, - // Japanese keyboard support +}; + +// Layout dependent keys, but without useful symbols + +// Japanese +static const int vkey_map_jp[][3] = { { VK_OEM_ATTN, XK_Eisu_toggle, NoSymbol }, { VK_OEM_FINISH, XK_Katakana, NoSymbol }, { VK_OEM_COPY, XK_Hiragana, NoSymbol }, @@ -227,9 +235,27 @@ static const int vkey_map[][3] = { { VK_OEM_BACKTAB, XK_Romaji, NoSymbol }, }; +static int lookup_vkey_map(UINT vkey, int extended, const int map[][3], size_t size) +{ + size_t i; + + for (i = 0;i < size;i++) { + if (vkey != map[i][0]) + continue; + + if (extended) + return map[i][2]; + else + return map[i][1]; + } + + return NoSymbol; +} + int win32_vkey_to_keysym(UINT vkey, int extended) { - int i; + HKL layout; + WORD lang, primary_lang; BYTE state[256]; int ret; @@ -237,13 +263,20 @@ int win32_vkey_to_keysym(UINT vkey, int extended) // Start with keys that either don't generate a symbol, or // generate the same symbol as some other key. - for (i = 0;i < sizeof(vkey_map)/sizeof(vkey_map[0]);i++) { - if (vkey == vkey_map[i][0]) { - if (extended) - return vkey_map[i][2]; - else - return vkey_map[i][1]; - } + + ret = lookup_vkey_map(vkey, extended, vkey_map, ARRAY_SIZE(vkey_map)); + if (ret != NoSymbol) + return ret; + + layout = GetKeyboardLayout(0); + lang = LOWORD(layout); + primary_lang = PRIMARYLANGID(lang); + + if (primary_lang == LANG_JAPANESE) { + ret = lookup_vkey_map(vkey, extended, + vkey_map_jp, ARRAY_SIZE(vkey_map_jp)); + if (ret != NoSymbol) + return ret; } // Windows is not consistent in which virtual key it uses for