From 552c18858acc7d08bdb64422b6891074a598983e Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 15 Dec 2020 09:59:52 +0100 Subject: [PATCH] Fixed call to GetKeyboardLayout (cherry picked from commit 8b8016ec21509fda5dfd182cb1d1fb186d272d7a) --- client/Windows/wf_client.c | 5 +++-- libfreerdp/locale/keyboard.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/client/Windows/wf_client.c b/client/Windows/wf_client.c index d8646f8..f61f0c8 100644 --- a/client/Windows/wf_client.c +++ b/client/Windows/wf_client.c @@ -190,6 +190,7 @@ static BOOL wf_desktop_resize(rdpContext* context) static BOOL wf_pre_connect(freerdp* instance) { + UINT32 rc; wfContext* wfc; int desktopWidth; int desktopHeight; @@ -256,8 +257,8 @@ static BOOL wf_pre_connect(freerdp* instance) if (!freerdp_client_load_addins(context->channels, instance->settings)) return -1; - freerdp_set_param_uint32(settings, FreeRDP_KeyboardLayout, - (int)GetKeyboardLayout(0) & 0x0000FFFF); + rc = freerdp_keyboard_init(freerdp_settings_get_uint32(settings, FreeRDP_KeyboardLayout)); + freerdp_set_param_uint32(settings, FreeRDP_KeyboardLayout, rc); PubSub_SubscribeChannelConnected(instance->context->pubSub, wf_OnChannelConnectedEventHandler); PubSub_SubscribeChannelDisconnected(instance->context->pubSub, wf_OnChannelDisconnectedEventHandler); diff --git a/libfreerdp/locale/keyboard.c b/libfreerdp/locale/keyboard.c index de202d1..4ee955d 100644 --- a/libfreerdp/locale/keyboard.c +++ b/libfreerdp/locale/keyboard.c @@ -47,6 +47,22 @@ DWORD X11_KEYCODE_TO_VIRTUAL_SCANCODE[256]; int freerdp_detect_keyboard(DWORD* keyboardLayoutId) { +#if defined(_WIN32) + CHAR name[KL_NAMELENGTH + 1] = { 0 }; + if (GetKeyboardLayoutNameA(name)) + { + ULONG rc; + + errno = 0; + rc = strtoul(name, NULL, 16); + if (errno == 0) + *keyboardLayoutId = rc; + } + + if (*keyboardLayoutId == 0) + *keyboardLayoutId = ((DWORD)GetKeyboardLayout(0) >> 16) & 0x0000FFFF; +#endif + #ifdef WITH_X11 if (*keyboardLayoutId == 0) freerdp_detect_keyboard_layout_from_xkb(keyboardLayoutId); -- 2.7.4