summaryrefslogtreecommitdiffstats
path: root/libfreerdp/locale
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libfreerdp/locale/CMakeLists.txt94
-rw-r--r--libfreerdp/locale/keyboard.c422
-rw-r--r--libfreerdp/locale/keyboard_apple.c241
-rw-r--r--libfreerdp/locale/keyboard_apple.h28
-rw-r--r--libfreerdp/locale/keyboard_layout.c1031
-rw-r--r--libfreerdp/locale/keyboard_sun.c284
-rw-r--r--libfreerdp/locale/keyboard_sun.h27
-rw-r--r--libfreerdp/locale/keyboard_x11.c139
-rw-r--r--libfreerdp/locale/keyboard_x11.h27
-rw-r--r--libfreerdp/locale/keyboard_xkbfile.c495
-rw-r--r--libfreerdp/locale/keyboard_xkbfile.h30
-rw-r--r--libfreerdp/locale/liblocale.h47
-rw-r--r--libfreerdp/locale/locale.c855
-rw-r--r--libfreerdp/locale/xkb_layout_ids.c864
-rw-r--r--libfreerdp/locale/xkb_layout_ids.h28
15 files changed, 4612 insertions, 0 deletions
diff --git a/libfreerdp/locale/CMakeLists.txt b/libfreerdp/locale/CMakeLists.txt
new file mode 100644
index 0000000..c190b9f
--- /dev/null
+++ b/libfreerdp/locale/CMakeLists.txt
@@ -0,0 +1,94 @@
+# FreeRDP: A Remote Desktop Protocol Implementation
+# libfreerdp-locale cmake build script
+#
+# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set(MODULE_NAME "freerdp-locale")
+set(MODULE_PREFIX "FREERDP_LOCALE")
+
+set(SRCS
+ keyboard_layout.c
+ keyboard.c
+ locale.c
+ liblocale.h)
+
+set(X11_SRCS
+ keyboard_x11.c
+ keyboard_x11.h
+ xkb_layout_ids.c
+ xkb_layout_ids.h)
+
+set(XKBFILE_SRCS
+ keyboard_xkbfile.c
+ keyboard_xkbfile.h)
+
+set(SUN_SRCS
+ keyboard_sun.c
+ keyboard_sun.h)
+
+set(APPLE_SRCS
+ keyboard_apple.c
+ keyboard_apple.h)
+
+if(CMAKE_SYSTEM_NAME MATCHES Solaris)
+ set(WITH_SUN true)
+endif()
+
+if(APPLE AND (NOT IOS))
+ list(APPEND SRCS
+ ${APPLE_SRCS})
+ find_library(CARBON Carbon)
+ freerdp_library_add(${CARBON})
+endif()
+
+if (APPLE)
+ FIND_LIBRARY(CORE_FOUNDATION CoreFoundation REQUIRED)
+ freerdp_library_add(${CORE_FOUNDATION})
+endif()
+
+if(WITH_X11)
+ find_package(X11 REQUIRED)
+
+ freerdp_definition_add(-DWITH_X11)
+ freerdp_include_directory_add(${X11_INCLUDE_DIR})
+ list( APPEND SRCS
+ ${X11_SRCS})
+ freerdp_library_add(${X11_LIBRARIES})
+
+ if(WITH_SUN)
+ freerdp_definition_add(-DWITH_SUN)
+ list(APPEND SRCS
+ ${SUN_SRCS})
+ endif()
+
+ if( X11_Xkbfile_FOUND AND (NOT APPLE))
+ freerdp_definition_add(-DWITH_XKBFILE)
+ freerdp_include_directory_add(${X11_Xkbfile_INCLUDE_PATH})
+ list(APPEND SRCS
+ ${XKBFILE_SRCS}
+ )
+ freerdp_library_add(${X11_Xkbfile_LIB})
+ else()
+ list(APPEND SRCS
+ ${X11_KEYMAP_SRCS}
+ )
+ endif()
+endif()
+
+if(WITH_WAYLAND)
+ freerdp_definition_add(-DWITH_WAYLAND)
+endif()
+
+freerdp_module_add(${SRCS})
diff --git a/libfreerdp/locale/keyboard.c b/libfreerdp/locale/keyboard.c
new file mode 100644
index 0000000..4c4dd19
--- /dev/null
+++ b/libfreerdp/locale/keyboard.c
@@ -0,0 +1,422 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * Keyboard Localization
+ *
+ * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <freerdp/config.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include <winpr/crt.h>
+
+#include <freerdp/types.h>
+#include <freerdp/locale/keyboard.h>
+#include <freerdp/locale/locale.h>
+
+#include <freerdp/log.h>
+
+#include "liblocale.h"
+
+#if defined(__MACOSX__)
+#include "keyboard_apple.h"
+#endif
+
+#define TAG FREERDP_TAG("locale.keyboard")
+
+#ifdef WITH_X11
+#include "keyboard_x11.h"
+
+#ifdef WITH_XKBFILE
+#include "keyboard_xkbfile.h"
+#endif
+
+#endif
+
+static WINPR_KEYCODE_TYPE maptype = WINPR_KEYCODE_TYPE_NONE;
+static DWORD VIRTUAL_SCANCODE_TO_X11_KEYCODE[256][2] = { 0 };
+static DWORD X11_KEYCODE_TO_VIRTUAL_SCANCODE[256] = { 0 };
+static DWORD REMAPPING_TABLE[0x10000] = { 0 };
+
+struct scancode_map_entry
+{
+ DWORD scancode;
+ const char* name;
+};
+
+static const struct scancode_map_entry RDP_SCANCODE_MAP[] = {
+ { RDP_SCANCODE_ESCAPE, "VK_ESCAPE" },
+ { RDP_SCANCODE_KEY_1, "VK_KEY_1" },
+ { RDP_SCANCODE_KEY_2, "VK_KEY_2" },
+ { RDP_SCANCODE_KEY_3, "VK_KEY_3" },
+ { RDP_SCANCODE_KEY_4, "VK_KEY_4" },
+ { RDP_SCANCODE_KEY_5, "VK_KEY_5" },
+ { RDP_SCANCODE_KEY_6, "VK_KEY_6" },
+ { RDP_SCANCODE_KEY_7, "VK_KEY_7" },
+ { RDP_SCANCODE_KEY_8, "VK_KEY_8" },
+ { RDP_SCANCODE_KEY_9, "VK_KEY_9" },
+ { RDP_SCANCODE_KEY_0, "VK_KEY_0" },
+ { RDP_SCANCODE_OEM_MINUS, "VK_OEM_MINUS" },
+ { RDP_SCANCODE_OEM_PLUS, "VK_OEM_PLUS" },
+ { RDP_SCANCODE_BACKSPACE, "VK_BACK Backspace" },
+ { RDP_SCANCODE_TAB, "VK_TAB" },
+ { RDP_SCANCODE_KEY_Q, "VK_KEY_Q" },
+ { RDP_SCANCODE_KEY_W, "VK_KEY_W" },
+ { RDP_SCANCODE_KEY_E, "VK_KEY_E" },
+ { RDP_SCANCODE_KEY_R, "VK_KEY_R" },
+ { RDP_SCANCODE_KEY_T, "VK_KEY_T" },
+ { RDP_SCANCODE_KEY_Y, "VK_KEY_Y" },
+ { RDP_SCANCODE_KEY_U, "VK_KEY_U" },
+ { RDP_SCANCODE_KEY_I, "VK_KEY_I" },
+ { RDP_SCANCODE_KEY_O, "VK_KEY_O" },
+ { RDP_SCANCODE_KEY_P, "VK_KEY_P" },
+ { RDP_SCANCODE_OEM_4, "VK_OEM_4 '[' on US" },
+ { RDP_SCANCODE_OEM_6, "VK_OEM_6 ']' on US" },
+ { RDP_SCANCODE_RETURN, "VK_RETURN Normal Enter" },
+ { RDP_SCANCODE_LCONTROL, "VK_LCONTROL" },
+ { RDP_SCANCODE_KEY_A, "VK_KEY_A" },
+ { RDP_SCANCODE_KEY_S, "VK_KEY_S" },
+ { RDP_SCANCODE_KEY_D, "VK_KEY_D" },
+ { RDP_SCANCODE_KEY_F, "VK_KEY_F" },
+ { RDP_SCANCODE_KEY_G, "VK_KEY_G" },
+ { RDP_SCANCODE_KEY_H, "VK_KEY_H" },
+ { RDP_SCANCODE_KEY_J, "VK_KEY_J" },
+ { RDP_SCANCODE_KEY_K, "VK_KEY_K" },
+ { RDP_SCANCODE_KEY_L, "VK_KEY_L" },
+ { RDP_SCANCODE_OEM_1, "VK_OEM_1 ';' on US" },
+ { RDP_SCANCODE_OEM_7, "VK_OEM_7 on US" },
+ { RDP_SCANCODE_OEM_3, "VK_OEM_3 Top left, '`' on US, JP DBE_SBCSCHAR" },
+ { RDP_SCANCODE_LSHIFT, "VK_LSHIFT" },
+ { RDP_SCANCODE_OEM_5, "VK_OEM_5 Next to Enter, '\' on US" },
+ { RDP_SCANCODE_KEY_Z, "VK_KEY_Z" },
+ { RDP_SCANCODE_KEY_X, "VK_KEY_X" },
+ { RDP_SCANCODE_KEY_C, "VK_KEY_C" },
+ { RDP_SCANCODE_KEY_V, "VK_KEY_V" },
+ { RDP_SCANCODE_KEY_B, "VK_KEY_B" },
+ { RDP_SCANCODE_KEY_N, "VK_KEY_N" },
+ { RDP_SCANCODE_KEY_M, "VK_KEY_M" },
+ { RDP_SCANCODE_OEM_COMMA, "VK_OEM_COMMA" },
+ { RDP_SCANCODE_OEM_PERIOD, "VK_OEM_PERIOD" },
+ { RDP_SCANCODE_OEM_2, "VK_OEM_2 '/' on US" },
+ { RDP_SCANCODE_RSHIFT, "VK_RSHIFT" },
+ { RDP_SCANCODE_MULTIPLY, "VK_MULTIPLY Numerical" },
+ { RDP_SCANCODE_LMENU, "VK_LMENU Left 'Alt' key" },
+ { RDP_SCANCODE_SPACE, "VK_SPACE" },
+ { RDP_SCANCODE_CAPSLOCK, "VK_CAPITAL 'Caps Lock', JP DBE_ALPHANUMERIC" },
+ { RDP_SCANCODE_F1, "VK_F1" },
+ { RDP_SCANCODE_F2, "VK_F2" },
+ { RDP_SCANCODE_F3, "VK_F3" },
+ { RDP_SCANCODE_F4, "VK_F4" },
+ { RDP_SCANCODE_F5, "VK_F5" },
+ { RDP_SCANCODE_F6, "VK_F6" },
+ { RDP_SCANCODE_F7, "VK_F7" },
+ { RDP_SCANCODE_F8, "VK_F8" },
+ { RDP_SCANCODE_F9, "VK_F9" },
+ { RDP_SCANCODE_F10, "VK_F10" },
+ { RDP_SCANCODE_NUMLOCK, "VK_NUMLOCK" },
+ { RDP_SCANCODE_SCROLLLOCK, "VK_SCROLL 'Scroll Lock', JP OEM_SCROLL" },
+ { RDP_SCANCODE_NUMPAD7, "VK_NUMPAD7" },
+ { RDP_SCANCODE_NUMPAD8, "VK_NUMPAD8" },
+ { RDP_SCANCODE_NUMPAD9, "VK_NUMPAD9" },
+ { RDP_SCANCODE_SUBTRACT, "VK_SUBTRACT" },
+ { RDP_SCANCODE_NUMPAD4, "VK_NUMPAD4" },
+ { RDP_SCANCODE_NUMPAD5, "VK_NUMPAD5" },
+ { RDP_SCANCODE_NUMPAD6, "VK_NUMPAD6" },
+ { RDP_SCANCODE_ADD, "VK_ADD" },
+ { RDP_SCANCODE_NUMPAD1, "VK_NUMPAD1" },
+ { RDP_SCANCODE_NUMPAD2, "VK_NUMPAD2" },
+ { RDP_SCANCODE_NUMPAD3, "VK_NUMPAD3" },
+ { RDP_SCANCODE_NUMPAD0, "VK_NUMPAD0" },
+ { RDP_SCANCODE_DECIMAL, "VK_DECIMAL Numerical, '.' on US" },
+ { RDP_SCANCODE_SYSREQ, "Sys Req" },
+ { RDP_SCANCODE_OEM_102, "VK_OEM_102 Lower left '\' on US" },
+ { RDP_SCANCODE_F11, "VK_F11" },
+ { RDP_SCANCODE_F12, "VK_F12" },
+ { RDP_SCANCODE_SLEEP, "VK_SLEEP OEM_8 on FR (undocumented?)" },
+ { RDP_SCANCODE_ZOOM, "VK_ZOOM (undocumented?)" },
+ { RDP_SCANCODE_HELP, "VK_HELP (undocumented?)" },
+ { RDP_SCANCODE_F13, "VK_F13" },
+ { RDP_SCANCODE_F14, "VK_F14" },
+ { RDP_SCANCODE_F15, "VK_F15" },
+ { RDP_SCANCODE_F16, "VK_F16" },
+ { RDP_SCANCODE_F17, "VK_F17" },
+ { RDP_SCANCODE_F18, "VK_F18" },
+ { RDP_SCANCODE_F19, "VK_F19" },
+ { RDP_SCANCODE_F20, "VK_F20" },
+ { RDP_SCANCODE_F21, "VK_F21" },
+ { RDP_SCANCODE_F22, "VK_F22" },
+ { RDP_SCANCODE_F23, "VK_F23" },
+ { RDP_SCANCODE_F24, "VK_F24" },
+ { RDP_SCANCODE_HIRAGANA, "JP DBE_HIRAGANA" },
+ { RDP_SCANCODE_HANJA_KANJI, "VK_HANJA / VK_KANJI (undocumented?)" },
+ { RDP_SCANCODE_KANA_HANGUL, "VK_KANA / VK_HANGUL (undocumented?)" },
+ { RDP_SCANCODE_ABNT_C1, "VK_ABNT_C1 JP OEM_102" },
+ { RDP_SCANCODE_F24_JP, "JP F24" },
+ { RDP_SCANCODE_CONVERT_JP, "JP VK_CONVERT" },
+ { RDP_SCANCODE_NONCONVERT_JP, "JP VK_NONCONVERT" },
+ { RDP_SCANCODE_TAB_JP, "JP TAB" },
+ { RDP_SCANCODE_BACKSLASH_JP, "JP OEM_5 ('\')" },
+ { RDP_SCANCODE_ABNT_C2, "VK_ABNT_C2, JP" },
+ { RDP_SCANCODE_HANJA, "KR VK_HANJA" },
+ { RDP_SCANCODE_HANGUL, "KR VK_HANGUL" },
+ { RDP_SCANCODE_RETURN_KP, "not RDP_SCANCODE_RETURN Numerical Enter" },
+ { RDP_SCANCODE_RCONTROL, "VK_RCONTROL" },
+ { RDP_SCANCODE_DIVIDE, "VK_DIVIDE Numerical" },
+ { RDP_SCANCODE_PRINTSCREEN, "VK_EXECUTE/VK_PRINT/VK_SNAPSHOT Print Screen" },
+ { RDP_SCANCODE_RMENU, "VK_RMENU Right 'Alt' / 'Alt Gr'" },
+ { RDP_SCANCODE_PAUSE, "VK_PAUSE Pause / Break (Slightly special handling)" },
+ { RDP_SCANCODE_HOME, "VK_HOME" },
+ { RDP_SCANCODE_UP, "VK_UP" },
+ { RDP_SCANCODE_PRIOR, "VK_PRIOR 'Page Up'" },
+ { RDP_SCANCODE_LEFT, "VK_LEFT" },
+ { RDP_SCANCODE_RIGHT, "VK_RIGHT" },
+ { RDP_SCANCODE_END, "VK_END" },
+ { RDP_SCANCODE_DOWN, "VK_DOWN" },
+ { RDP_SCANCODE_NEXT, "VK_NEXT 'Page Down'" },
+ { RDP_SCANCODE_INSERT, "VK_INSERT" },
+ { RDP_SCANCODE_DELETE, "VK_DELETE" },
+ { RDP_SCANCODE_NULL, "<00>" },
+ { RDP_SCANCODE_HELP2, "Help - documented, different from VK_HELP" },
+ { RDP_SCANCODE_LWIN, "VK_LWIN" },
+ { RDP_SCANCODE_RWIN, "VK_RWIN" },
+ { RDP_SCANCODE_APPS, "VK_APPS Application" },
+ { RDP_SCANCODE_POWER_JP, "JP POWER" },
+ { RDP_SCANCODE_SLEEP_JP, "JP SLEEP" },
+ { RDP_SCANCODE_NUMLOCK_EXTENDED, "should be RDP_SCANCODE_NUMLOCK" },
+ { RDP_SCANCODE_RSHIFT_EXTENDED, "should be RDP_SCANCODE_RSHIFT" },
+ { RDP_SCANCODE_VOLUME_MUTE, "VK_VOLUME_MUTE" },
+ { RDP_SCANCODE_VOLUME_DOWN, "VK_VOLUME_DOWN" },
+ { RDP_SCANCODE_VOLUME_UP, "VK_VOLUME_UP" },
+ { RDP_SCANCODE_MEDIA_NEXT_TRACK, "VK_MEDIA_NEXT_TRACK" },
+ { RDP_SCANCODE_MEDIA_PREV_TRACK, "VK_MEDIA_PREV_TRACK" },
+ { RDP_SCANCODE_MEDIA_STOP, "VK_MEDIA_MEDIA_STOP" },
+ { RDP_SCANCODE_MEDIA_PLAY_PAUSE, "VK_MEDIA_MEDIA_PLAY_PAUSE" },
+ { RDP_SCANCODE_BROWSER_BACK, "VK_BROWSER_BACK" },
+ { RDP_SCANCODE_BROWSER_FORWARD, "VK_BROWSER_FORWARD" },
+ { RDP_SCANCODE_BROWSER_REFRESH, "VK_BROWSER_REFRESH" },
+ { RDP_SCANCODE_BROWSER_STOP, "VK_BROWSER_STOP" },
+ { RDP_SCANCODE_BROWSER_SEARCH, "VK_BROWSER_SEARCH" },
+ { RDP_SCANCODE_BROWSER_FAVORITES, "VK_BROWSER_FAVORITES" },
+ { RDP_SCANCODE_BROWSER_HOME, "VK_BROWSER_HOME" },
+ { RDP_SCANCODE_LAUNCH_MAIL, "VK_LAUNCH_MAIL" },
+ { RDP_SCANCODE_LAUNCH_MEDIA_SELECT, "VK_LAUNCH_MEDIA_SELECT" },
+ { RDP_SCANCODE_LAUNCH_APP1, "VK_LAUNCH_APP1" },
+ { RDP_SCANCODE_LAUNCH_APP2, "VK_LAUNCH_APP2" },
+};
+
+static 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
+
+#if defined(__MACOSX__)
+ if (*keyboardLayoutId == 0)
+ freerdp_detect_keyboard_layout_from_cf(keyboardLayoutId);
+#endif
+
+#ifdef WITH_X11
+ if (*keyboardLayoutId == 0)
+ freerdp_detect_keyboard_layout_from_xkb(keyboardLayoutId);
+#endif
+
+ if (*keyboardLayoutId == 0)
+ freerdp_detect_keyboard_layout_from_system_locale(keyboardLayoutId);
+
+ if (*keyboardLayoutId == 0)
+ *keyboardLayoutId = ENGLISH_UNITED_STATES;
+
+ return 0;
+}
+
+static int freerdp_keyboard_init_apple(DWORD* keyboardLayoutId, DWORD* x11_keycode_to_rdp_scancode,
+ size_t count)
+{
+ WINPR_ASSERT(x11_keycode_to_rdp_scancode);
+ WINPR_ASSERT(keyboardLayoutId);
+
+ for (size_t keycode = 8; keycode < count; keycode++)
+ {
+ const DWORD vkcode = GetVirtualKeyCodeFromKeycode(keycode - 8u, WINPR_KEYCODE_TYPE_APPLE);
+ x11_keycode_to_rdp_scancode[keycode] =
+ GetVirtualScanCodeFromVirtualKeyCode(vkcode, WINPR_KBD_TYPE_IBM_ENHANCED);
+ }
+
+ maptype = WINPR_KEYCODE_TYPE_APPLE;
+ return 0;
+}
+
+static int freerdp_keyboard_init_x11_evdev(DWORD* keyboardLayoutId,
+ DWORD* x11_keycode_to_rdp_scancode, size_t count)
+{
+ WINPR_ASSERT(keyboardLayoutId);
+ WINPR_ASSERT(x11_keycode_to_rdp_scancode);
+ for (size_t keycode = 0; keycode < count; keycode++)
+ {
+ const DWORD vkcode = GetVirtualKeyCodeFromKeycode(keycode, WINPR_KEYCODE_TYPE_EVDEV);
+ x11_keycode_to_rdp_scancode[keycode] =
+ GetVirtualScanCodeFromVirtualKeyCode(vkcode, WINPR_KBD_TYPE_IBM_ENHANCED);
+ }
+ maptype = WINPR_KEYCODE_TYPE_EVDEV;
+
+ return 0;
+}
+
+DWORD freerdp_keyboard_init(DWORD keyboardLayoutId)
+{
+ int status = -1;
+
+#if defined(__APPLE__)
+ if (status < 0)
+ status = freerdp_keyboard_init_apple(&keyboardLayoutId, X11_KEYCODE_TO_VIRTUAL_SCANCODE,
+ ARRAYSIZE(X11_KEYCODE_TO_VIRTUAL_SCANCODE));
+#endif
+
+#if defined(WITH_X11) || defined(WITH_WAYLAND)
+
+#ifdef WITH_XKBFILE
+ if (status < 0)
+ {
+ status = freerdp_keyboard_init_xkbfile(&keyboardLayoutId, X11_KEYCODE_TO_VIRTUAL_SCANCODE,
+ ARRAYSIZE(X11_KEYCODE_TO_VIRTUAL_SCANCODE));
+ if (status >= 0)
+ maptype = WINPR_KEYCODE_TYPE_XKB;
+ }
+#endif
+
+ if (status < 0)
+ status = freerdp_keyboard_init_x11_evdev(&keyboardLayoutId, X11_KEYCODE_TO_VIRTUAL_SCANCODE,
+ ARRAYSIZE(X11_KEYCODE_TO_VIRTUAL_SCANCODE));
+
+#endif
+
+ if (status < 0)
+ WLog_DBG(TAG, "Platform keyboard detection failed, trying autodetection");
+
+ freerdp_detect_keyboard(&keyboardLayoutId);
+
+ ZeroMemory(VIRTUAL_SCANCODE_TO_X11_KEYCODE, sizeof(VIRTUAL_SCANCODE_TO_X11_KEYCODE));
+
+ for (size_t keycode = 0; keycode < ARRAYSIZE(VIRTUAL_SCANCODE_TO_X11_KEYCODE); keycode++)
+ {
+ const DWORD x11 = X11_KEYCODE_TO_VIRTUAL_SCANCODE[keycode];
+ const DWORD sc = RDP_SCANCODE_CODE(x11);
+ const BOOL ex = RDP_SCANCODE_EXTENDED(x11);
+ VIRTUAL_SCANCODE_TO_X11_KEYCODE[sc][ex ? 1 : 0] = keycode;
+ }
+
+ return keyboardLayoutId;
+}
+
+DWORD freerdp_keyboard_init_ex(DWORD keyboardLayoutId, const char* keyboardRemappingList)
+{
+ DWORD res = freerdp_keyboard_init(keyboardLayoutId);
+
+ memset(REMAPPING_TABLE, 0, sizeof(REMAPPING_TABLE));
+ if (keyboardRemappingList)
+ {
+ char* copy = _strdup(keyboardRemappingList);
+ char* context = NULL;
+ char* token = NULL;
+ if (!copy)
+ goto fail;
+ token = strtok_s(copy, ",", &context);
+ while (token)
+ {
+ DWORD key = 0;
+ DWORD value = 0;
+ int rc = sscanf(token, "%" PRIu32 "=%" PRIu32, &key, &value);
+ if (rc != 2)
+ rc = sscanf(token, "%" PRIx32 "=%" PRIx32 "", &key, &value);
+ if (rc != 2)
+ rc = sscanf(token, "%" PRIu32 "=%" PRIx32, &key, &value);
+ if (rc != 2)
+ rc = sscanf(token, "%" PRIx32 "=%" PRIu32, &key, &value);
+ if (rc != 2)
+ goto fail;
+ if (key >= ARRAYSIZE(REMAPPING_TABLE))
+ goto fail;
+ REMAPPING_TABLE[key] = value;
+ token = strtok_s(NULL, ",", &context);
+ }
+ fail:
+ free(copy);
+ }
+ return res;
+}
+
+DWORD freerdp_keyboard_get_rdp_scancode_from_x11_keycode(DWORD keycode)
+{
+ const DWORD scancode = X11_KEYCODE_TO_VIRTUAL_SCANCODE[keycode];
+ const DWORD remapped = REMAPPING_TABLE[scancode];
+#if defined(WITH_DEBUG_KBD)
+ const BOOL ex = RDP_SCANCODE_EXTENDED(scancode);
+ const DWORD sc = RDP_SCANCODE_CODE(scancode);
+#endif
+
+ DEBUG_KBD("x11 keycode: %02" PRIX32 " -> rdp code: [%04" PRIx16 "] %02" PRIX8 "%s", keycode,
+ scancode, sc, ex ? " extended" : "");
+
+ if (remapped != 0)
+ {
+#if defined(WITH_DEBUG_KBD)
+ const DWORD rsc = RDP_SCANCODE_CODE(remapped);
+ const BOOL rex = RDP_SCANCODE_EXTENDED(remapped);
+#endif
+
+ DEBUG_KBD("remapped scancode: [%04" PRIx16 "] %02" PRIX8 "[%s] -> [%04" PRIx16 "] %02" PRIX8
+ "[%s]",
+ scancode, sc, ex ? " extended" : "", remapped, rsc, rex ? " extended" : "");
+ return remapped;
+ }
+ return scancode;
+}
+
+DWORD freerdp_keyboard_get_x11_keycode_from_rdp_scancode(DWORD scancode, BOOL extended)
+{
+ const DWORD* x11 = VIRTUAL_SCANCODE_TO_X11_KEYCODE[scancode];
+ WINPR_ASSERT(x11);
+
+ if (extended)
+ return x11[1];
+ else
+ return x11[0];
+}
+
+const char* freerdp_keyboard_scancode_name(DWORD scancode)
+{
+ for (size_t x = 0; x < ARRAYSIZE(RDP_SCANCODE_MAP); x++)
+ {
+ const struct scancode_map_entry* entry = &RDP_SCANCODE_MAP[x];
+ if (entry->scancode == scancode)
+ return entry->name;
+ }
+
+ return NULL;
+}
diff --git a/libfreerdp/locale/keyboard_apple.c b/libfreerdp/locale/keyboard_apple.c
new file mode 100644
index 0000000..b9a385f
--- /dev/null
+++ b/libfreerdp/locale/keyboard_apple.c
@@ -0,0 +1,241 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * Apple Core Foundation Keyboard Mapping
+ *
+ * Copyright 2021 Thincast Technologies GmbH
+ * Copyright 2021 Martin Fleisz <martin.fleisz@thincast.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <freerdp/config.h>
+
+#include <Carbon/Carbon.h>
+#include <string.h>
+
+#include "liblocale.h"
+
+#include <freerdp/locale/locale.h>
+#include <freerdp/locale/keyboard.h>
+
+#include "keyboard_apple.h"
+
+struct KEYBOARD_LAYOUT_MAPPING_
+{
+ const char* inputSourceId; /* Apple input source id (com.apple.keylayout or inputmethod) */
+ DWORD code; /* mapped rdp keyboard layout id */
+};
+typedef struct KEYBOARD_LAYOUT_MAPPING_ KEYBOARD_LAYOUT_MAPPING;
+
+static const KEYBOARD_LAYOUT_MAPPING KEYBOARD_MAPPING_TABLE[] = {
+ { "com.apple.inputmethod.Kotoeri.Japanese", JAPANESE },
+ { "com.apple.inputmethod.Kotoeri.Japanese.FullWidthRoman", JAPANESE },
+ { "com.apple.inputmethod.Kotoeri.Japanese.HalfWidthKana", JAPANESE },
+ { "com.apple.inputmethod.Kotoeri.Japanese.Katakana", JAPANESE },
+ { "com.apple.inputmethod.Kotoeri.Katakana", JAPANESE },
+ { "com.apple.inputmethod.Kotoeri.Roman", JAPANESE },
+ { "com.apple.inputmethod.kotoeri.Ainu", JAPANESE },
+ { "com.apple.keylayout.2SetHangul", KOREAN },
+ { "com.apple.keylayout.390Hangul", KOREAN },
+ { "com.apple.keylayout.3SetHangul", KOREAN },
+ { "com.apple.keylayout.AfghanDari", KBD_PERSIAN },
+ { "com.apple.keylayout.AfghanPashto", PASHTO },
+ { "com.apple.keylayout.AfghanUzbek", UZBEK_LATIN },
+ { "com.apple.keylayout.Arabic", ARABIC_SAUDI_ARABIA },
+ { "com.apple.keylayout.Arabic-QWERTY", ARABIC_EGYPT },
+ { "com.apple.keylayout.ArabicPC", ARABIC_EGYPT },
+ { "com.apple.keylayout.Armenian-HMQWERTY", ARMENIAN },
+ { "com.apple.keylayout.Armenian-WesternQWERTY", ARMENIAN },
+ { "com.apple.keylayout.Australian", ENGLISH_AUSTRALIAN },
+ { "com.apple.keylayout.Austrian", GERMAN_STANDARD },
+ { "com.apple.keylayout.Azeri", AZERI_LATIN },
+ { "com.apple.keylayout.Bangla", KBD_BANGLA },
+ { "com.apple.keylayout.Bangla-QWERTY", KBD_BANGLA },
+ { "com.apple.keylayout.Belgian", DUTCH_BELGIAN },
+ { "com.apple.keylayout.Brazilian", PORTUGUESE_BRAZILIAN },
+ { "com.apple.keylayout.British", ENGLISH_UNITED_KINGDOM },
+ { "com.apple.keylayout.British-PC", ENGLISH_UNITED_KINGDOM },
+ { "com.apple.keylayout.Bulgarian", BULGARIAN },
+ { "com.apple.keylayout.Bulgarian-Phonetic", KBD_BULGARIAN_PHONETIC },
+ { "com.apple.keylayout.Byelorussian", BELARUSIAN },
+ { "com.apple.keylayout.Canadian", ENGLISH_UNITED_STATES },
+ { "com.apple.keylayout.Canadian-CSA", KBD_CANADIAN_MULTILINGUAL_STANDARD },
+ { "com.apple.keylayout.CangjieKeyboard", CHINESE_TAIWAN },
+ { "com.apple.keylayout.Cherokee-Nation", CHEROKEE },
+ { "com.apple.keylayout.Cherokee-QWERTY", ENGLISH_UNITED_STATES },
+ { "com.apple.keylayout.Colemak", ENGLISH_UNITED_STATES },
+ { "com.apple.keylayout.Croatian", CROATIAN },
+ { "com.apple.keylayout.Croatian-PC", CROATIAN },
+ { "com.apple.keylayout.Czech", CZECH },
+ { "com.apple.keylayout.Czech-QWERTY", KBD_CZECH_QWERTY },
+ { "com.apple.keylayout.DVORAK-QWERTYCMD", KBD_UNITED_STATES_DVORAK },
+ { "com.apple.keylayout.Danish", DANISH },
+ { "com.apple.keylayout.Devanagari", HINDI },
+ { "com.apple.keylayout.Devanagari-QWERTY", HINDI },
+ { "com.apple.keylayout.Dutch", KBD_UNITED_STATES_INTERNATIONAL },
+ { "com.apple.keylayout.Dvorak", KBD_UNITED_STATES_DVORAK },
+ { "com.apple.keylayout.Dvorak-Left", KBD_UNITED_STATES_DVORAK_FOR_LEFT_HAND },
+ { "com.apple.keylayout.Dvorak-Right", KBD_UNITED_STATES_DVORAK_FOR_RIGHT_HAND },
+ { "com.apple.keylayout.Estonian", ESTONIAN },
+ { "com.apple.keylayout.Faroese", FAEROESE },
+ { "com.apple.keylayout.Finnish", FINNISH },
+ { "com.apple.keylayout.FinnishExtended", KBD_SAMI_EXTENDED_FINLAND_SWEDEN },
+ { "com.apple.keylayout.FinnishSami-PC", KBD_FINNISH_WITH_SAMI },
+ { "com.apple.keylayout.French", KBD_BELGIAN_FRENCH },
+ { "com.apple.keylayout.French-PC", FRENCH_STANDARD },
+ { "com.apple.keylayout.French-numerical", KBD_BELGIAN_FRENCH },
+ { "com.apple.keylayout.GJCRomaja", ENGLISH_UNITED_STATES },
+ { "com.apple.keylayout.Georgian-QWERTY", KBD_GEORGIAN_QUERTY },
+ { "com.apple.keylayout.German", GERMAN_STANDARD },
+ { "com.apple.keylayout.Greek", GREEK },
+ { "com.apple.keylayout.GreekPolytonic", KBD_GREEK_POLYTONIC },
+ { "com.apple.keylayout.Gujarati", GUJARATI },
+ { "com.apple.keylayout.Gujarati-QWERTY", GUJARATI },
+ { "com.apple.keylayout.Gurmukhi", PUNJABI },
+ { "com.apple.keylayout.Gurmukhi-QWERTY", PUNJABI },
+ { "com.apple.keylayout.HNCRomaja", ENGLISH_UNITED_STATES },
+ { "com.apple.keylayout.Hawaiian", HAWAIIAN },
+ { "com.apple.keylayout.Hebrew", HEBREW },
+ { "com.apple.keylayout.Hebrew-PC", HEBREW },
+ { "com.apple.keylayout.Hebrew-QWERTY", HEBREW },
+ { "com.apple.keylayout.Hungarian", HUNGARIAN },
+ { "com.apple.keylayout.Hungarian-QWERTY", HUNGARIAN },
+ { "com.apple.keylayout.Icelandic", ICELANDIC },
+ { "com.apple.keylayout.Inuktitut-Nunavut", INUKTITUT },
+ { "com.apple.keylayout.Inuktitut-Nutaaq", INUKTITUT },
+ { "com.apple.keylayout.Inuktitut-QWERTY", INUKTITUT },
+ { "com.apple.keylayout.InuttitutNunavik", INUKTITUT },
+ { "com.apple.keylayout.Irish", ENGLISH_IRELAND },
+ { "com.apple.keylayout.IrishExtended", KBD_IRISH },
+ { "com.apple.keylayout.Italian", ITALIAN_STANDARD },
+ { "com.apple.keylayout.Italian-Pro", ITALIAN_STANDARD },
+ { "com.apple.keylayout.Jawi-QWERTY", ARABIC_SAUDI_ARABIA },
+ { "com.apple.keylayout.Kannada", KANNADA },
+ { "com.apple.keylayout.Kannada-QWERTY", KANNADA },
+ { "com.apple.keylayout.Kazakh", KAZAKH },
+ { "com.apple.keylayout.Khmer", KBD_KHMER },
+ { "com.apple.keylayout.Latvian", LATVIAN },
+ { "com.apple.keylayout.Lithuanian", LITHUANIAN },
+ { "com.apple.keylayout.Macedonian", MACEDONIAN },
+ { "com.apple.keylayout.Malayalam", MALAYALAM },
+ { "com.apple.keylayout.Malayalam-QWERTY", MALAYALAM },
+ { "com.apple.keylayout.Maltese", MALTESE },
+ { "com.apple.keylayout.Maori", MAORI },
+ { "com.apple.keylayout.Myanmar-QWERTY", MYANMAR },
+ { "com.apple.keylayout.Nepali", NEPALI },
+ { "com.apple.keylayout.NorthernSami", SAMI_NORTHERN_NORWAY },
+ { "com.apple.keylayout.Norwegian", NORWEGIAN_BOKMAL },
+ { "com.apple.keylayout.NorwegianExtended", NORWEGIAN_BOKMAL },
+ { "com.apple.keylayout.NorwegianSami-PC", NORWEGIAN_BOKMAL },
+ { "com.apple.keylayout.Oriya", ORIYA },
+ { "com.apple.keylayout.Persian", KBD_PERSIAN },
+ { "com.apple.keylayout.Persian-ISIRI2901", KBD_PERSIAN },
+ { "com.apple.keylayout.Polish", KBD_POLISH_214 },
+ { "com.apple.keylayout.PolishPro", KBD_POLISH_PROGRAMMERS },
+ { "com.apple.keylayout.Portuguese", PORTUGUESE_STANDARD },
+ { "com.apple.keylayout.Romanian", KBD_ROMANIAN },
+ { "com.apple.keylayout.Romanian-Standard", KBD_ROMANIAN_STANDARD },
+ { "com.apple.keylayout.Russian", RUSSIAN },
+ { "com.apple.keylayout.Russian-Phonetic", KBD_RUSSIAN_PHONETIC },
+ { "com.apple.keylayout.RussianWin", RUSSIAN },
+ { "com.apple.keylayout.Sami-PC", KBD_SAMI_EXTENDED_FINLAND_SWEDEN },
+ { "com.apple.keylayout.Serbian", KBD_SERBIAN_CYRILLIC },
+ { "com.apple.keylayout.Serbian-Latin", KBD_SERBIAN_LATIN },
+ { "com.apple.keylayout.Sinhala", SINHALA },
+ { "com.apple.keylayout.Sinhala-QWERTY", SINHALA },
+ { "com.apple.keylayout.Slovak", SLOVAK },
+ { "com.apple.keylayout.Slovak-QWERTY", KBD_SLOVAK_QWERTY },
+ { "com.apple.keylayout.Slovenian", SLOVENIAN },
+ { "com.apple.keylayout.Spanish", SPANISH_TRADITIONAL_SORT },
+ { "com.apple.keylayout.Spanish-ISO", KBD_SPANISH },
+ { "com.apple.keylayout.Swedish", SWEDISH },
+ { "com.apple.keylayout.Swedish-Pro", SWEDISH },
+ { "com.apple.keylayout.SwedishSami-PC", SWEDISH },
+ { "com.apple.keylayout.SwissFrench", FRENCH_SWISS },
+ { "com.apple.keylayout.SwissGerman", GERMAN_SWISS },
+ { "com.apple.keylayout.Telugu", TELUGU },
+ { "com.apple.keylayout.Telugu-QWERTY", TELUGU },
+ { "com.apple.keylayout.Thai", THAI },
+ { "com.apple.keylayout.Thai-PattaChote", KBD_THAI_PATTACHOTE },
+ { "com.apple.keylayout.Tibetan-QWERTY", TIBETAN_PRC },
+ { "com.apple.keylayout.Tibetan-Wylie", TIBETAN_PRC },
+ { "com.apple.keylayout.TibetanOtaniUS", TIBETAN_PRC },
+ { "com.apple.keylayout.Turkish", KBD_TURKISH_F },
+ { "com.apple.keylayout.Turkish-QWERTY", TURKISH },
+ { "com.apple.keylayout.Turkish-QWERTY-PC", TURKISH },
+ { "com.apple.keylayout.US", ENGLISH_UNITED_STATES },
+ { "com.apple.keylayout.USExtended", ENGLISH_UNITED_STATES },
+ { "com.apple.keylayout.USInternational-PC", ENGLISH_UNITED_STATES },
+ { "com.apple.keylayout.Ukrainian", UKRAINIAN },
+ { "com.apple.keylayout.Ukrainian-PC", UKRAINIAN },
+ { "com.apple.keylayout.UnicodeHexInput", ENGLISH_UNITED_STATES },
+ { "com.apple.keylayout.Urdu", URDU },
+ { "com.apple.keylayout.Uyghur", UIGHUR },
+ { "com.apple.keylayout.Vietnamese", VIETNAMESE },
+ { "com.apple.keylayout.Welsh", WELSH }
+};
+
+int freerdp_detect_keyboard_layout_from_cf(DWORD* keyboardLayoutId)
+{
+ CFIndex length;
+ char* inputSourceId = NULL;
+ CFStringRef inputSourceIdRef;
+ TISInputSourceRef inputSrc = TISCopyCurrentKeyboardLayoutInputSource();
+ if (!inputSrc)
+ {
+ DEBUG_KBD("Failed to get current keyboard layout input source!");
+ return 0;
+ }
+
+ /* get current input source id */
+ inputSourceIdRef = (CFStringRef)TISGetInputSourceProperty(inputSrc, kTISPropertyInputSourceID);
+ if (!inputSourceIdRef)
+ {
+ DEBUG_KBD("Failed to get input source id!");
+ goto done;
+ }
+
+ /* convert it to a C-string */
+ length = CFStringGetLength(inputSourceIdRef);
+ length = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
+ inputSourceId = (char*)malloc(length);
+ if (!inputSourceId)
+ {
+ DEBUG_KBD("Failed to allocate string buffer!");
+ goto done;
+ }
+
+ if (!CFStringGetCString(inputSourceIdRef, inputSourceId, length, kCFStringEncodingUTF8))
+ {
+ DEBUG_KBD("Failed to convert CFString to C-string!");
+ goto done;
+ }
+
+ /* Search for the id in the mapping table */
+ for (size_t i = 0; i < ARRAYSIZE(KEYBOARD_MAPPING_TABLE); ++i)
+ {
+ if (strcmp(inputSourceId, KEYBOARD_MAPPING_TABLE[i].inputSourceId) == 0)
+ {
+ *keyboardLayoutId = KEYBOARD_MAPPING_TABLE[i].code;
+ break;
+ }
+ }
+
+done:
+ free(inputSourceId);
+ CFRelease(inputSrc);
+ if (*keyboardLayoutId > 0)
+ return *keyboardLayoutId;
+
+ return 0;
+}
diff --git a/libfreerdp/locale/keyboard_apple.h b/libfreerdp/locale/keyboard_apple.h
new file mode 100644
index 0000000..cd3c3e7
--- /dev/null
+++ b/libfreerdp/locale/keyboard_apple.h
@@ -0,0 +1,28 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * Apple Core Foundation Keyboard Mapping
+ *
+ * Copyright 2021 Thincast Technologies GmbH
+ * Copyright 2021 Martin Fleisz <martin.fleisz@thincast.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FREERDP_LOCALE_KEYBOARD_APPLE_H
+#define FREERDP_LOCALE_KEYBOARD_APPLE_H
+
+#include <freerdp/api.h>
+
+FREERDP_LOCAL int freerdp_detect_keyboard_layout_from_cf(DWORD* keyboardLayoutId);
+
+#endif /* FREERDP_LOCALE_KEYBOARD_APPLE_H */
diff --git a/libfreerdp/locale/keyboard_layout.c b/libfreerdp/locale/keyboard_layout.c
new file mode 100644
index 0000000..d94de55
--- /dev/null
+++ b/libfreerdp/locale/keyboard_layout.c
@@ -0,0 +1,1031 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * Keyboard Layouts
+ *
+ * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <freerdp/config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <winpr/crt.h>
+
+#include "liblocale.h"
+
+#include <freerdp/types.h>
+#include <freerdp/scancode.h>
+#include <freerdp/locale/keyboard.h>
+
+struct LanguageIdentifier
+{
+ /* LanguageIdentifier = (SublangaugeIdentifier<<2) | PrimaryLanguageIdentifier
+ * The table at
+ * https://docs.microsoft.com/en-us/windows/win32/intl/language-identifier-constants-and-strings
+ * is sometimes missing one or both of the entries.
+ */
+ const char* locale; /* en_US type strings for the locale */
+ UINT16 LanguageIdentifier;
+ const char* PrimaryLanguage;
+ UINT8 PrimaryLanguageIdentifier;
+ const char* PrimaryLanguageSymbol;
+ const char* Sublanguage;
+ UINT8 SublangaugeIdentifier;
+ const char* SublanguageSymbol;
+};
+
+static const struct LanguageIdentifier language_identifiers[] = {
+ /* [Language identifier] [Primary language] [Prim. lang. identifier] [Prim.
+ lang. symbol] [Sublanguage] [Sublang. identifier] [Sublang. symbol] */
+ { "", 0xc00, "Default custom locale language", 0x0, "LANG_NEUTRAL",
+ "Default custom sublanguage", 0x3, "SUBLANG_CUSTOM_DEFAULT" },
+ { "", 0x1400, "Default custom MUI locale language", 0x0, "LANG_NEUTRAL",
+ "Default custom MUI sublanguage", 0x5, "SUBLANG_UI_CUSTOM_DEFAULT" },
+ { "", 0x7f, "Invariant locale language", 0x7f, "LANG_INVARIANT", "Invariant sublanguage", 0x0,
+ "SUBLANG_NEUTRAL" },
+ { "", 0x0, "Neutral locale language", 0x0, "LANG_NEUTRAL", "Neutral sublanguage", 0x0,
+ "SUBLANG_NEUTRAL" },
+ { "", 0x800, "System default locale language", 0x2, "LANG_SYSTEM_DEFAULT",
+ "System default sublanguage", 0x2, "SUBLANG_SYS_DEFAULT" },
+ { "", 0x1000, "Unspecified custom locale language", 0x0, "LANG_NEUTRAL",
+ "Unspecified custom sublanguage", 0x4, "SUBLANG_CUSTOM_UNSPECIFIED" },
+ { "", 0x400, "User default locale language", 0x0, "LANG_USER_DEFAULT",
+ "User default sublanguage", 0x1, "SUBLANG_DEFAULT" },
+ { "af_ZA", 0x436, "Afrikaans (af)", 0x36, "LANG_AFRIKAANS", "South Africa (ZA)", 0x1,
+ "SUBLANG_AFRIKAANS_SOUTH_AFRICA" },
+ { "sq_AL", 0x41c, "Albanian (sq)", 0x1c, "LANG_ALBANIAN", "Albania (AL)", 0x1,
+ "SUBLANG_ALBANIAN_ALBANIA" },
+ { "gsw_FR", 0x484, "Alsatian (gsw)", 0x84, "LANG_ALSATIAN", "France (FR)", 0x1,
+ "SUBLANG_ALSATIAN_FRANCE" },
+ { "am_ET", 0x45e, "Amharic (am)", 0x5e, "LANG_AMHARIC", "Ethiopia (ET)", 0x1,
+ "SUBLANG_AMHARIC_ETHIOPIA" },
+ { "ar_DZ", 0x1401, "Arabic (ar)", 0x1, "LANG_ARABIC", "Algeria (DZ)", 0x5,
+ "SUBLANG_ARABIC_ALGERIA" },
+ { "ar_BH", 0x3c01, "Arabic (ar)", 0x01, "LANG_ARABIC", "Bahrain (BH)", 0xf,
+ "SUBLANG_ARABIC_BAHRAIN" },
+ { "ar_EG", 0xc01, "Arabic (ar)", 0x01, "LANG_ARABIC", "Egypt (EG)", 0x3,
+ "SUBLANG_ARABIC_EGYPT" },
+ { "ar_IQ", 0x801, "Arabic (ar)", 0x01, "LANG_ARABIC", "Iraq (IQ)", 0x2, "SUBLANG_ARABIC_IRAQ" },
+ { "ar_JO", 0x2c01, "Arabic (ar)", 0x01, "LANG_ARABIC", "Jordan (JO)", 0xb,
+ "SUBLANG_ARABIC_JORDAN" },
+ { "ar_KW", 0x3401, "Arabic (ar)", 0x01, "LANG_ARABIC", "Kuwait (KW)", 0xd,
+ "SUBLANG_ARABIC_KUWAIT" },
+ { "ar_LB", 0x3001, "Arabic (ar)", 0x01, "LANG_ARABIC", "Lebanon (LB)", 0xc,
+ "SUBLANG_ARABIC_LEBANON" },
+ { "ar_LY", 0x1001, "Arabic (ar)", 0x01, "LANG_ARABIC", "Libya (LY)", 0x4,
+ "SUBLANG_ARABIC_LIBYA" },
+ { "ar_MA", 0x1801, "Arabic (ar)", 0x01, "LANG_ARABIC", "Morocco (MA)", 0x6,
+ "SUBLANG_ARABIC_MOROCCO" },
+ { "ar_OM", 0x2001, "Arabic (ar)", 0x01, "LANG_ARABIC", "Oman (OM)", 0x8,
+ "SUBLANG_ARABIC_OMAN" },
+ { "ar_QA", 0x4001, "Arabic (ar)", 0x01, "LANG_ARABIC", "Qatar (QA)", 0x10,
+ "SUBLANG_ARABIC_QATAR" },
+ { "ar_SA", 0x401, "Arabic (ar)", 0x01, "LANG_ARABIC", "Saudi Arabia (SA)", 0x1,
+ "SUBLANG_ARABIC_SAUDI_ARABIA" },
+ { "ar_SY", 0x2801, "Arabic (ar)", 0x01, "LANG_ARABIC", "Syria (SY)", 0xa,
+ "SUBLANG_ARABIC_SYRIA" },
+ { "ar_TN", 0x1c01, "Arabic (ar)", 0x01, "LANG_ARABIC", "Tunisia (TN)", 0x7,
+ "SUBLANG_ARABIC_TUNISIA" },
+ { "ar_AE", 0x3801, "Arabic (ar)", 0x01, "LANG_ARABIC", "U.A.E. (AE)", 0xe,
+ "SUBLANG_ARABIC_UAE" },
+ { "ar_YE", 0x2401, "Arabic (ar)", 0x01, "LANG_ARABIC", "Yemen (YE)", 0x9,
+ "SUBLANG_ARABIC_YEMEN" },
+ { "hy_AM", 0x42b, "Armenian (hy)", 0x2b, "LANG_ARMENIAN", "Armenia (AM)", 0x1,
+ "SUBLANG_ARMENIAN_ARMENIA" },
+ { "as_IN", 0x44d, "Assamese (as)", 0x4d, "LANG_ASSAMESE", "India (IN)", 0x1,
+ "SUBLANG_ASSAMESE_INDIA" },
+ { "az_AZ", 0x82c, "Azerbaijani (az)", 0x2c, "LANG_AZERI", "Azerbaijan, Cyrillic (AZ)", 0x2,
+ "SUBLANG_AZERI_CYRILLIC" },
+ { "az_AZ", 0x42c, "Azerbaijani (az)", 0x2c, "LANG_AZERI", "Azerbaijan, Latin (AZ)", 0x1,
+ "SUBLANG_AZERI_LATIN" },
+ { "bn_BD", 0x445, "Bangla (bn)", 0x45, "LANG_BANGLA", "Bangladesh (BD)", 0x2,
+ "SUBLANG_BANGLA_BANGLADESH" },
+ { "bn_IN", 0x445, "Bangla (bn)", 0x45, "LANG_BANGLA", "India (IN)", 0x1,
+ "SUBLANG_BANGLA_INDIA" },
+ { "ba_RU", 0x46d, "Bashkir (ba)", 0x6d, "LANG_BASHKIR", "Russia (RU)", 0x1,
+ "SUBLANG_BASHKIR_RUSSIA" },
+ { "", 0x42d, "Basque (Basque)", 0x2d, "LANG_BASQUE", "Basque (Basque)", 0x1,
+ "SUBLANG_BASQUE_BASQUE" },
+ { "be_BY", 0x423, "Belarusian (be)", 0x23, "LANG_BELARUSIAN", "Belarus (BY)", 0x1,
+ "SUBLANG_BELARUSIAN_BELARUS" },
+ { "bs", 0x781a, "Bosnian (bs)", 0x1a, "LANG_BOSNIAN_NEUTRAL", "Neutral", 0x1E, "" },
+ { "bs_BA", 0x201a, "Bosnian (bs)", 0x1a, "LANG_BOSNIAN",
+ "Bosnia and Herzegovina, Cyrillic (BA)", 0x8, "SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC" },
+ { "bs_BA", 0x141a, "Bosnian (bs)", 0x1a, "LANG_BOSNIAN", "Bosnia and Herzegovina, Latin (BA)",
+ 0x5, "SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN" },
+ { "br_FR", 0x47e, "Breton (br)", 0x7e, "LANG_BRETON", "France (FR)", 0x1,
+ "SUBLANG_BRETON_FRANCE" },
+ { "bg_BG", 0x402, "Bulgarian (bg)", 0x2, "LANG_BULGARIAN", "Bulgaria (BG)", 0x1,
+ "SUBLANG_BULGARIAN_BULGARIA" },
+ { "ku_IQ", 0x492, "Central Kurdish (ku)", 0x92, "LANG_CENTRAL_KURDISH", "Iraq (IQ)", 0x1,
+ "SUBLANG_CENTRAL_KURDISH_IRAQ" },
+ { "chr_US", 0x45c, "Cherokee (chr)", 0x5c, "LANG_CHEROKEE", "Cherokee (Cher)", 0x1,
+ "SUBLANG_CHEROKEE_CHEROKEE" },
+ { "ca_ES", 0x403, "Catalan (ca)", 0x3, "LANG_CATALAN", "Spain (ES)", 0x1,
+ "SUBLANG_CATALAN_CATALAN" },
+ { "zh_HK", 0xc04, "Chinese (zh)", 0x04, "LANG_CHINESE", "Hong Kong SAR, PRC (HK)", 0x3,
+ "SUBLANG_CHINESE_HONGKONG" },
+ { "zh_MO", 0x1404, "Chinese (zh)", 0x04, "LANG_CHINESE", "Macao SAR (MO)", 0x5,
+ "SUBLANG_CHINESE_MACAU" },
+ { "zh_SG", 0x1004, "Chinese (zh)", 0x04, "LANG_CHINESE", "Singapore (SG)", 0x4,
+ "SUBLANG_CHINESE_SINGAPORE" },
+ { "zh_CN", 0x4, "Chinese (zh)", 0x4, "LANG_CHINESE_SIMPLIFIED", "Simplified (Hans)", 0x2,
+ "SUBLANG_CHINESE_SIMPLIFIED" },
+ { "zh_CN", 0x7c04, "Chinese (zh)", 0x04, "LANG_CHINESE_TRADITIONAL", "Traditional (Hant)", 0x1,
+ "SUBLANG_CHINESE_TRADITIONAL" },
+ { "co_FR", 0x483, "Corsican (co)", 0x83, "LANG_CORSICAN", "France (FR)", 0x1,
+ "SUBLANG_CORSICAN_FRANCE" },
+ { "hr", 0x1a, "Croatian (hr)", 0x1a, "LANG_CROATIAN", "Neutral", 0x00, "" },
+ { "hr_BA", 0x101a, "Croatian (hr)", 0x1a, "LANG_CROATIAN", "Bosnia and Herzegovina, Latin (BA)",
+ 0x4, "SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN" },
+ { "hr_HR", 0x41a, "Croatian (hr)", 0x1a, "LANG_CROATIAN", "Croatia (HR)", 0x1,
+ "SUBLANG_CROATIAN_CROATIA" },
+ { "cs_CZ", 0x405, "Czech (cs)", 0x5, "LANG_CZECH", "Czech Republic (CZ)", 0x1,
+ "SUBLANG_CZECH_CZECH_REPUBLIC" },
+ { "da_DK", 0x406, "Danish (da)", 0x6, "LANG_DANISH", "Denmark (DK)", 0x1,
+ "SUBLANG_DANISH_DENMARK" },
+ { "prs_AF", 0x48c, "Dari (prs)", 0x8c, "LANG_DARI", "Afghanistan (AF)", 0x1,
+ "SUBLANG_DARI_AFGHANISTAN" },
+ { "dv_MV", 0x465, "Divehi (dv)", 0x65, "LANG_DIVEHI", "Maldives (MV)", 0x1,
+ "SUBLANG_DIVEHI_MALDIVES" },
+ { "nl_BE", 0x813, "Dutch (nl)", 0x13, "LANG_DUTCH", "Belgium (BE)", 0x2,
+ "SUBLANG_DUTCH_BELGIAN" },
+ { "nl_NL", 0x413, "Dutch (nl)", 0x13, "LANG_DUTCH", "Netherlands (NL)", 0x1, "SUBLANG_DUTCH" },
+ { "en_AU", 0xc09, "English (en)", 0x9, "LANG_ENGLISH", "Australia (AU)", 0x3,
+ "SUBLANG_ENGLISH_AUS" },
+ { "en_BZ", 0x2809, "English (en)", 0x09, "LANG_ENGLISH", "Belize (BZ)", 0xa,
+ "SUBLANG_ENGLISH_BELIZE" },
+ { "en_CA", 0x1009, "English (en)", 0x09, "LANG_ENGLISH", "Canada (CA)", 0x4,
+ "SUBLANG_ENGLISH_CAN" },
+ { "en_CB", 0x2409, "English (en)", 0x09, "LANG_ENGLISH", "Caribbean (029)", 0x9,
+ "SUBLANG_ENGLISH_CARIBBEAN" },
+ { "en_IN", 0x4009, "English (en)", 0x09, "LANG_ENGLISH", "India (IN)", 0x10,
+ "SUBLANG_ENGLISH_INDIA" },
+ { "en_IE", 0x1809, "English (en)", 0x09, "LANG_ENGLISH", "Ireland (IE)", 0x6,
+ "SUBLANG_ENGLISH_EIRE" },
+ { "en_IE", 0x1809, "English (en)", 0x09, "LANG_ENGLISH", "Ireland (IE)", 0x6,
+ "SUBLANG_ENGLISH_IRELAND" },
+ { "en_JM", 0x2009, "English (en)", 0x09, "LANG_ENGLISH", "Jamaica (JM)", 0x8,
+ "SUBLANG_ENGLISH_JAMAICA" },
+ { "en_MY", 0x4409, "English (en)", 0x09, "LANG_ENGLISH", "Malaysia (MY)", 0x11,
+ "SUBLANG_ENGLISH_MALAYSIA" },
+ { "en_NZ", 0x1409, "English (en)", 0x09, "LANG_ENGLISH", "New Zealand (NZ)", 0x5,
+ "SUBLANG_ENGLISH_NZ" },
+ { "en_PH", 0x3409, "English (en)", 0x09, "LANG_ENGLISH", "Philippines (PH)", 0xd,
+ "SUBLANG_ENGLISH_PHILIPPINES" },
+ { "en_SG", 0x4809, "English (en)", 0x09, "LANG_ENGLISH", "Singapore (SG)", 0x12,
+ "SUBLANG_ENGLISH_SINGAPORE" },
+ { "en_ZA", 0x1c09, "English (en)", 0x09, "LANG_ENGLISH", "South Africa (ZA)", 0x7,
+ "SUBLANG_ENGLISH_SOUTH_AFRICA" },
+ { "en_TT", 0x2c09, "English (en)", 0x09, "LANG_ENGLISH", "Trinidad and Tobago (TT)", 0xb,
+ "SUBLANG_ENGLISH_TRINIDAD" },
+ { "en_GB", 0x809, "English (en)", 0x09, "LANG_ENGLISH", "United Kingdom (GB)", 0x2,
+ "SUBLANG_ENGLISH_UK" },
+ { "en_US", 0x409, "English (en)", 0x09, "LANG_ENGLISH", "United States (US)", 0x1,
+ "SUBLANG_ENGLISH_US" },
+ { "en_ZW", 0x3009, "English (en)", 0x09, "LANG_ENGLISH", "Zimbabwe (ZW)", 0xc,
+ "SUBLANG_ENGLISH_ZIMBABWE" },
+ { "et_EE", 0x425, "Estonian (et)", 0x25, "LANG_ESTONIAN", "Estonia (EE)", 0x1,
+ "SUBLANG_ESTONIAN_ESTONIA" },
+ { "fo_FO", 0x438, "Faroese (fo)", 0x38, "LANG_FAEROESE", "Faroe Islands (FO)", 0x1,
+ "SUBLANG_FAEROESE_FAROE_ISLANDS" },
+ { "fil_PH", 0x464, "Filipino (fil)", 0x64, "LANG_FILIPINO", "Philippines (PH)", 0x1,
+ "SUBLANG_FILIPINO_PHILIPPINES" },
+ { "fi_FI", 0x40b, "Finnish (fi)", 0xb, "LANG_FINNISH", "Finland (FI)", 0x1,
+ "SUBLANG_FINNISH_FINLAND" },
+ { "fr_BE", 0x80c, "French (fr)", 0xc, "LANG_FRENCH", "Belgium (BE)", 0x2,
+ "SUBLANG_FRENCH_BELGIAN" },
+ { "fr_CA", 0xc0c, "French (fr)", 0x0c, "LANG_FRENCH", "Canada (CA)", 0x3,
+ "SUBLANG_FRENCH_CANADIAN" },
+ { "fr_FR", 0x40c, "French (fr)", 0x0c, "LANG_FRENCH", "France (FR)", 0x1, "SUBLANG_FRENCH" },
+ { "fr_LU", 0x140c, "French (fr)", 0x0c, "LANG_FRENCH", "Luxembourg (LU)", 0x5,
+ "SUBLANG_FRENCH_LUXEMBOURG" },
+ { "fr_MC", 0x180c, "French (fr)", 0x0c, "LANG_FRENCH", "Monaco (MC)", 0x6,
+ "SUBLANG_FRENCH_MONACO" },
+ { "fr_CH", 0x100c, "French (fr)", 0x0c, "LANG_FRENCH", "Switzerland (CH)", 0x4,
+ "SUBLANG_FRENCH_SWISS" },
+ { "fy_NL", 0x462, "Frisian (fy)", 0x62, "LANG_FRISIAN", "Netherlands (NL)", 0x1,
+ "SUBLANG_FRISIAN_NETHERLANDS" },
+ { "gl_ES", 0x456, "Galician (gl)", 0x56, "LANG_GALICIAN", "Spain (ES)", 0x1,
+ "SUBLANG_GALICIAN_GALICIAN" },
+ { "ka_GE", 0x437, "Georgian (ka)", 0x37, "LANG_GEORGIAN", "Georgia (GE)", 0x1,
+ "SUBLANG_GEORGIAN_GEORGIA" },
+ { "de_AT", 0xc07, "German (de)", 0x7, "LANG_GERMAN", "Austria (AT)", 0x3,
+ "SUBLANG_GERMAN_AUSTRIAN" },
+ { "de_DE", 0x407, "German (de)", 0x07, "LANG_GERMAN", "Germany (DE)", 0x1, "SUBLANG_GERMAN" },
+ { "de_LI", 0x1407, "German (de)", 0x07, "LANG_GERMAN", "Liechtenstein (LI)", 0x5,
+ "SUBLANG_GERMAN_LIECHTENSTEIN" },
+ { "de_LU", 0x1007, "German (de)", 0x07, "LANG_GERMAN", "Luxembourg (LU)", 0x4,
+ "SUBLANG_GERMAN_LUXEMBOURG" },
+ { "de_CH", 0x807, "German (de)", 0x07, "LANG_GERMAN", "Switzerland (CH)", 0x2,
+ "SUBLANG_GERMAN_SWISS" },
+ { "el_GR", 0x408, "Greek (el)", 0x8, "LANG_GREEK", "Greece (GR)", 0x1, "SUBLANG_GREEK_GREECE" },
+ { "kl_GL", 0x46f, "Greenlandic (kl)", 0x6f, "LANG_GREENLANDIC", "Greenland (GL)", 0x1,
+ "SUBLANG_GREENLANDIC_GREENLAND" },
+ { "gu_IN", 0x447, "Gujarati (gu)", 0x47, "LANG_GUJARATI", "India (IN)", 0x1,
+ "SUBLANG_GUJARATI_INDIA" },
+ { "ha_NG", 0x468, "Hausa (ha)", 0x68, "LANG_HAUSA", "Nigeria (NG)", 0x1,
+ "SUBLANG_HAUSA_NIGERIA_LATIN" },
+ { "haw_US", 0x475, "Hawiian (haw)", 0x75, "LANG_HAWAIIAN", "United States (US)", 0x1,
+ "SUBLANG_HAWAIIAN_US" },
+ { "he_IL", 0x40d, "Hebrew (he)", 0xd, "LANG_HEBREW", "Israel (IL)", 0x1,
+ "SUBLANG_HEBREW_ISRAEL" },
+ { "hi_IN", 0x439, "Hindi (hi)", 0x39, "LANG_HINDI", "India (IN)", 0x1, "SUBLANG_HINDI_INDIA" },
+ { "hu_HU", 0x40e, "Hungarian (hu)", 0xe, "LANG_HUNGARIAN", "Hungary (HU)", 0x1,
+ "SUBLANG_HUNGARIAN_HUNGARY" },
+ { "is_IS", 0x40f, "Icelandic (is)", 0xf, "LANG_ICELANDIC", "Iceland (IS)", 0x1,
+ "SUBLANG_ICELANDIC_ICELAND" },
+ { "ig_NG", 0x470, "Igbo (ig)", 0x70, "LANG_IGBO", "Nigeria (NG)", 0x1, "SUBLANG_IGBO_NIGERIA" },
+ { "id_ID", 0x421, "Indonesian (id)", 0x21, "LANG_INDONESIAN", "Indonesia (ID)", 0x1,
+ "SUBLANG_INDONESIAN_INDONESIA" },
+ { "iu_CA", 0x85d, "Inuktitut (iu)", 0x5d, "LANG_INUKTITUT", "Canada (CA), Latin", 0x2,
+ "SUBLANG_INUKTITUT_CANADA_LATIN" },
+ { "iu_CA", 0x45d, "Inuktitut (iu)", 0x5d, "LANG_INUKTITUT", "Canada (CA), Canadian Syllabics",
+ 0x1, "SUBLANG_INUKTITUT_CANADA" },
+ { "ga_IE", 0x83c, "Irish (ga)", 0x3c, "LANG_IRISH", "Ireland (IE)", 0x2,
+ "SUBLANG_IRISH_IRELAND" },
+ { "xh_ZA", 0x434, "isiXhosa (xh)", 0x34, "LANG_XHOSA", "South Africa (ZA)", 0x1,
+ "SUBLANG_XHOSA_SOUTH_AFRICA" },
+ { "zu_ZA", 0x435, "isiZulu (zu)", 0x35, "LANG_ZULU", "South Africa (ZA)", 0x1,
+ "SUBLANG_ZULU_SOUTH_AFRICA" },
+ { "it_IT", 0x410, "Italian (it)", 0x10, "LANG_ITALIAN", "Italy (IT)", 0x1, "SUBLANG_ITALIAN" },
+ { "it_CH", 0x810, "Italian (it)", 0x10, "LANG_ITALIAN", "Switzerland (CH)", 0x2,
+ "SUBLANG_ITALIAN_SWISS" },
+ { "ja_JP", 0x411, "Japanese (ja)", 0x11, "LANG_JAPANESE", "Japan (JP)", 0x1,
+ "SUBLANG_JAPANESE_JAPAN" },
+ { "kn_IN", 0x44b, "Kannada (kn)", 0x4b, "LANG_KANNADA", "India (IN)", 0x1,
+ "SUBLANG_KANNADA_INDIA" },
+ { "kk_KZ", 0x43f, "Kazakh (kk)", 0x3f, "LANG_KAZAK", "Kazakhstan (KZ)", 0x1,
+ "SUBLANG_KAZAK_KAZAKHSTAN" },
+ { "kh_KH", 0x453, "Khmer (kh)", 0x53, "LANG_KHMER", "Cambodia (KH)", 0x1,
+ "SUBLANG_KHMER_CAMBODIA" },
+ { "qut_GT", 0x486, "K'iche (qut)", 0x86, "LANG_KICHE", "Guatemala (GT)", 0x1,
+ "SUBLANG_KICHE_GUATEMALA" },
+ { "rw_RW", 0x487, "Kinyarwanda (rw)", 0x87, "LANG_KINYARWANDA", "Rwanda (RW)", 0x1,
+ "SUBLANG_KINYARWANDA_RWANDA" },
+ { "kok_IN", 0x457, "Konkani (kok)", 0x57, "LANG_KONKANI", "India (IN)", 0x1,
+ "SUBLANG_KONKANI_INDIA" },
+ { "ko_KR", 0x412, "Korean (ko)", 0x12, "LANG_KOREAN", "Korea (KR)", 0x1, "SUBLANG_KOREAN" },
+ { "ky_KG", 0x440, "Kyrgyz (ky)", 0x40, "LANG_KYRGYZ", "Kyrgyzstan (KG)", 0x1,
+ "SUBLANG_KYRGYZ_KYRGYZSTAN" },
+ { "lo_LA", 0x454, "Lao (lo)", 0x54, "LANG_LAO", "Lao PDR (LA)", 0x1, "SUBLANG_LAO_LAO" },
+ { "lv_LV", 0x426, "Latvian (lv)", 0x26, "LANG_LATVIAN", "Latvia (LV)", 0x1,
+ "SUBLANG_LATVIAN_LATVIA" },
+ { "lt_LT", 0x427, "Lithuanian (lt)", 0x27, "LANG_LITHUANIAN", "Lithuanian (LT)", 0x1,
+ "SUBLANG_LITHUANIAN_LITHUANIA" },
+ { "dsb_DE", 0x82e, "Lower Sorbian (dsb)", 0x2e, "LANG_LOWER_SORBIAN", "Germany (DE)", 0x2,
+ "SUBLANG_LOWER_SORBIAN_GERMANY" },
+ { "lb_LU", 0x46e, "Luxembourgish (lb)", 0x6e, "LANG_LUXEMBOURGISH", "Luxembourg (LU)", 0x1,
+ "SUBLANG_LUXEMBOURGISH_LUXEMBOURG" },
+ { "mk_MK", 0x42f, "Macedonian (mk)", 0x2f, "LANG_MACEDONIAN", "Macedonia (FYROM) (MK)", 0x1,
+ "SUBLANG_MACEDONIAN_MACEDONIA" },
+ { "ms_BN", 0x83e, "Malay (ms)", 0x3e, "LANG_MALAY", "Brunei Darassalam (BN)", 0x2,
+ "SUBLANG_MALAY_BRUNEI_DARUSSALAM" },
+ { "ms_MY", 0x43e, "Malay (ms)", 0x3e, "LANG_MALAY", "Malaysia (MY)", 0x1,
+ "SUBLANG_MALAY_MALAYSIA" },
+ { "ml_IN", 0x44c, "Malayalam (ml)", 0x4c, "LANG_MALAYALAM", "India (IN)", 0x1,
+ "SUBLANG_MALAYALAM_INDIA" },
+ { "mt_MT", 0x43a, "Maltese (mt)", 0x3a, "LANG_MALTESE", "Malta (MT)", 0x1,
+ "SUBLANG_MALTESE_MALTA" },
+ { "mi_NZ", 0x481, "Maori (mi)", 0x81, "LANG_MAORI", "New Zealand (NZ)", 0x1,
+ "SUBLANG_MAORI_NEW_ZEALAND" },
+ { "arn_CL", 0x47a, "Mapudungun (arn)", 0x7a, "LANG_MAPUDUNGUN", "Chile (CL)", 0x1,
+ "SUBLANG_MAPUDUNGUN_CHILE" },
+ { "mr_IN", 0x44e, "Marathi (mr)", 0x4e, "LANG_MARATHI", "India (IN)", 0x1,
+ "SUBLANG_MARATHI_INDIA" },
+ { "moh_CA", 0x47c, "Mohawk (moh)", 0x7c, "LANG_MOHAWK", "Canada (CA)", 0x1,
+ "SUBLANG_MOHAWK_MOHAWK" },
+ { "mn_MN", 0x450, "Mongolian (mn)", 0x50, "LANG_MONGOLIAN", "Mongolia, Cyrillic (MN)", 0x1,
+ "SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA" },
+ { "mn_MN", 0x850, "Mongolian (mn)", 0x50, "LANG_MONGOLIAN", "Mongolia, Mong (MN)", 0x2,
+ "SUBLANG_MONGOLIAN_PRC" },
+ { "ne_NP", 0x461, "Nepali (ne)", 0x61, "LANG_NEPALI", "Nepal (NP)", 0x1,
+ "SUBLANG_NEPALI_NEPAL" },
+ { "ne_IN", 0x861, "Nepali (ne)", 0x61, "LANG_NEPALI", "India (IN)", 0x2,
+ "SUBLANG_NEPALI_INDIA" },
+ { "no_NO", 0x414, "Norwegian (no)", 0x14, "LANG_NORWEGIAN", "Bokmål, Norway (NO)", 0x1,
+ "SUBLANG_NORWEGIAN_BOKMAL" },
+ { "no_NO", 0x814, "Norwegian (no)", 0x14, "LANG_NORWEGIAN", "Nynorsk, Norway (NO)", 0x2,
+ "SUBLANG_NORWEGIAN_NYNORSK" },
+ { "oc_FR", 0x482, "Occitan (oc)", 0x82, "LANG_OCCITAN", "France (FR)", 0x1,
+ "SUBLANG_OCCITAN_FRANCE" },
+ { "or_IN", 0x448, "Odia (or)", 0x48, "LANG_ORIYA", "India (IN)", 0x1, "SUBLANG_ORIYA_INDIA" },
+ { "ps_AF", 0x463, "Pashto (ps)", 0x63, "LANG_PASHTO", "Afghanistan (AF)", 0x1,
+ "SUBLANG_PASHTO_AFGHANISTAN" },
+ { "fa_IR", 0x429, "Persian (fa)", 0x29, "LANG_PERSIAN", "Iran (IR)", 0x1,
+ "SUBLANG_PERSIAN_IRAN" },
+ { "pl_PL", 0x415, "Polish (pl)", 0x15, "LANG_POLISH", "Poland (PL)", 0x1,
+ "SUBLANG_POLISH_POLAND" },
+ { "pt_BR", 0x416, "Portuguese (pt)", 0x16, "LANG_PORTUGUESE", "Brazil (BR)", 0x1,
+ "SUBLANG_PORTUGUESE_BRAZILIAN" },
+ { "pt_PT", 0x816, "Portuguese (pt)", 0x16, "LANG_PORTUGUESE", "Portugal (PT)", 0x2,
+ "SUBLANG_PORTUGUESE" },
+ { "ff_SN", 0x867, "Pular (ff)", 0x67, "LANG_PULAR", "Senegal (SN)", 0x2,
+ "SUBLANG_PULAR_SENEGAL" },
+ { "pa_IN", 0x446, "Punjabi (pa)", 0x46, "LANG_PUNJABI", "India, Gurmukhi script (IN)", 0x1,
+ "SUBLANG_PUNJABI_INDIA" },
+ { "pa_PK", 0x846, "Punjabi (pa)", 0x46, "LANG_PUNJABI", "Pakistan, Arabic script(PK)", 0x2,
+ "SUBLANG_PUNJABI_PAKISTAN" },
+ { "quz_BO", 0x46b, "Quechua (quz)", 0x6b, "LANG_QUECHUA", "Bolivia (BO)", 0x1,
+ "SUBLANG_QUECHUA_BOLIVIA" },
+ { "quz_EC", 0x86b, "Quechua (quz)", 0x6b, "LANG_QUECHUA", "Ecuador (EC)", 0x2,
+ "SUBLANG_QUECHUA_ECUADOR" },
+ { "quz_PE", 0xc6b, "Quechua (quz)", 0x6b, "LANG_QUECHUA", "Peru (PE)", 0x3,
+ "SUBLANG_QUECHUA_PERU" },
+ { "ro_RO", 0x418, "Romanian (ro)", 0x18, "LANG_ROMANIAN", "Romania (RO)", 0x1,
+ "SUBLANG_ROMANIAN_ROMANIA" },
+ { "rm_CH", 0x417, "Romansh (rm)", 0x17, "LANG_ROMANSH", "Switzerland (CH)", 0x1,
+ "SUBLANG_ROMANSH_SWITZERLAND" },
+ { "ru_RU", 0x419, "Russian (ru)", 0x19, "LANG_RUSSIAN", "Russia (RU)", 0x1,
+ "SUBLANG_RUSSIAN_RUSSIA" },
+ { "sah_RU", 0x485, "Sakha (sah)", 0x85, "LANG_SAKHA", "Russia (RU)", 0x1,
+ "SUBLANG_SAKHA_RUSSIA" },
+ { "smn_FI", 0x243b, "Sami (smn)", 0x3b, "LANG_SAMI", "Inari, Finland (FI)", 0x9,
+ "SUBLANG_SAMI_INARI_FINLAND" },
+ { "smj_NO", 0x103b, "Sami (smj)", 0x3b, "LANG_SAMI", "Lule, Norway (NO)", 0x4,
+ "SUBLANG_SAMI_LULE_NORWAY" },
+ { "smj_SE", 0x143b, "Sami (smj)", 0x3b, "LANG_SAMI", "Lule, Sweden (SE)", 0x5,
+ "SUBLANG_SAMI_LULE_SWEDEN" },
+ { "se_FI", 0xc3b, "Sami (se)", 0x3b, "LANG_SAMI", "Northern, Finland (FI)", 0x3,
+ "SUBLANG_SAMI_NORTHERN_FINLAND" },
+ { "se_NO", 0x43b, "Sami (se)", 0x3b, "LANG_SAMI", "Northern, Norway (NO)", 0x1,
+ "SUBLANG_SAMI_NORTHERN_NORWAY" },
+ { "se_SE", 0x83b, "Sami (se)", 0x3b, "LANG_SAMI", "Northern, Sweden (SE)", 0x2,
+ "SUBLANG_SAMI_NORTHERN_SWEDEN" },
+ { "sms_FI", 0x203b, "Sami (sms)", 0x3b, "LANG_SAMI", "Skolt, Finland (FI)", 0x8,
+ "SUBLANG_SAMI_SKOLT_FINLAND" },
+ { "sma_NO", 0x183b, "Sami (sma)", 0x3b, "LANG_SAMI", "Southern, Norway (NO)", 0x6,
+ "SUBLANG_SAMI_SOUTHERN_NORWAY" },
+ { "sma_SE", 0x1c3b, "Sami (sma)", 0x3b, "LANG_SAMI", "Southern, Sweden (SE)", 0x7,
+ "SUBLANG_SAMI_SOUTHERN_SWEDEN" },
+ { "sa_IN", 0x44f, "Sanskrit (sa)", 0x4f, "LANG_SANSKRIT", "India (IN)", 0x1,
+ "SUBLANG_SANSKRIT_INDIA" },
+ { "sr", 0x7c1a, "Serbian (sr)", 0x1a, "LANG_SERBIAN_NEUTRAL", "Neutral", 0x00, "" },
+ { "sr_BA", 0x1c1a, "Serbian (sr)", 0x1a, "LANG_SERBIAN",
+ "Bosnia and Herzegovina, Cyrillic (BA)", 0x7, "SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_CYRILLIC" },
+ { "sr_BA", 0x181a, "Serbian (sr)", 0x1a, "LANG_SERBIAN", "Bosnia and Herzegovina, Latin (BA)",
+ 0x6, "SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_LATIN" },
+ { "sr_HR", 0x41a, "Serbian (sr)", 0x1a, "LANG_SERBIAN", "Croatia (HR)", 0x1,
+ "SUBLANG_SERBIAN_CROATIA" },
+ { "sr_CS", 0xc1a, "Serbian (sr)", 0x1a, "LANG_SERBIAN",
+ "Serbia and Montenegro (former), Cyrillic (CS)", 0x3, "SUBLANG_SERBIAN_CYRILLIC" },
+ { "sr_CS", 0x81a, "Serbian (sr)", 0x1a, "LANG_SERBIAN",
+ "Serbia and Montenegro (former), Latin (CS)", 0x2, "SUBLANG_SERBIAN_LATIN" },
+ { "nso_ZA", 0x46c, "Sesotho sa Leboa (nso)", 0x6c, "LANG_SOTHO", "South Africa (ZA)", 0x1,
+ "SUBLANG_SOTHO_NORTHERN_SOUTH_AFRICA" },
+ { "tn_BW", 0x832, "Setswana / Tswana (tn)", 0x32, "LANG_TSWANA", "Botswana (BW)", 0x2,
+ "SUBLANG_TSWANA_BOTSWANA" },
+ { "tn_ZA", 0x432, "Setswana / Tswana (tn)", 0x32, "LANG_TSWANA", "South Africa (ZA)", 0x1,
+ "SUBLANG_TSWANA_SOUTH_AFRICA" },
+ { "", 0x859, "(reserved)", 0x59, "LANG_SINDHI", "(reserved)", 0x2,
+ "SUBLANG_SINDHI_AFGHANISTAN" },
+ { "", 0x459, "(reserved)", 0x59, "LANG_SINDHI", "(reserved)", 0x1, "SUBLANG_SINDHI_INDIA" },
+ { "sd_PK", 0x859, "Sindhi (sd)", 0x59, "LANG_SINDHI", "Pakistan (PK)", 0x2,
+ "SUBLANG_SINDHI_PAKISTAN" },
+ { "si_LK", 0x45b, "Sinhala (si)", 0x5b, "LANG_SINHALESE", "Sri Lanka (LK)", 0x1,
+ "SUBLANG_SINHALESE_SRI_LANKA" },
+ { "sk_SK", 0x41b, "Slovak (sk)", 0x1b, "LANG_SLOVAK", "Slovakia (SK)", 0x1,
+ "SUBLANG_SLOVAK_SLOVAKIA" },
+ { "sl_SI", 0x424, "Slovenian (sl)", 0x24, "LANG_SLOVENIAN", "Slovenia (SI)", 0x1,
+ "SUBLANG_SLOVENIAN_SLOVENIA" },
+ { "es_AR", 0x2c0a, "Spanish (es)", 0xa, "LANG_SPANISH", "Argentina (AR)", 0xb,
+ "SUBLANG_SPANISH_ARGENTINA" },
+ { "es_BO", 0x400a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Bolivia (BO)", 0x10,
+ "SUBLANG_SPANISH_BOLIVIA" },
+ { "es_CL", 0x340a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Chile (CL)", 0xd,
+ "SUBLANG_SPANISH_CHILE" },
+ { "es_CO", 0x240a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Colombia (CO)", 0x9,
+ "SUBLANG_SPANISH_COLOMBIA" },
+ { "es_CR", 0x140a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Costa Rica (CR)", 0x5,
+ "SUBLANG_SPANISH_COSTA_RICA" },
+ { "es_DO", 0x1c0a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Dominican Republic (DO)", 0x7,
+ "SUBLANG_SPANISH_DOMINICAN_REPUBLIC" },
+ { "es_EC", 0x300a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Ecuador (EC)", 0xc,
+ "SUBLANG_SPANISH_ECUADOR" },
+ { "es_SV", 0x440a, "Spanish (es)", 0x0a, "LANG_SPANISH", "El Salvador (SV)", 0x11,
+ "SUBLANG_SPANISH_EL_SALVADOR" },
+ { "es_GT", 0x100a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Guatemala (GT)", 0x4,
+ "SUBLANG_SPANISH_GUATEMALA" },
+ { "es_HN", 0x480a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Honduras (HN)", 0x12,
+ "SUBLANG_SPANISH_HONDURAS" },
+ { "es_MX", 0x80a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Mexico (MX)", 0x2,
+ "SUBLANG_SPANISH_MEXICAN" },
+ { "es_NI", 0x4c0a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Nicaragua (NI)", 0x13,
+ "SUBLANG_SPANISH_NICARAGUA" },
+ { "es_PA", 0x180a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Panama (PA)", 0x6,
+ "SUBLANG_SPANISH_PANAMA" },
+ { "es_PY", 0x3c0a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Paraguay (PY)", 0xf,
+ "SUBLANG_SPANISH_PARAGUAY" },
+ { "es_PE", 0x280a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Peru (PE)", 0xa,
+ "SUBLANG_SPANISH_PERU" },
+ { "es_PR", 0x500a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Puerto Rico (PR)", 0x14,
+ "SUBLANG_SPANISH_PUERTO_RICO" },
+ { "es_ES", 0xc0a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Spain, Modern Sort (ES)", 0x3,
+ "SUBLANG_SPANISH_MODERN" },
+ { "es_ES", 0x40a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Spain, Traditional Sort (ES)", 0x1,
+ "SUBLANG_SPANISH" },
+ { "es_US", 0x540a, "Spanish (es)", 0x0a, "LANG_SPANISH", "United States (US)", 0x15,
+ "SUBLANG_SPANISH_US" },
+ { "es_UY", 0x380a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Uruguay (UY)", 0xe,
+ "SUBLANG_SPANISH_URUGUAY" },
+ { "es_VE", 0x200a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Venezuela (VE)", 0x8,
+ "SUBLANG_SPANISH_VENEZUELA" },
+ { "sw_KE", 0x441, "Swahili (sw)", 0x41, "LANG_SWAHILI", "Kenya (KE)", 0x1, "SUBLANG_SWAHILI" },
+ { "sv_FI", 0x81d, "Swedish (sv)", 0x1d, "LANG_SWEDISH", "Finland (FI)", 0x2,
+ "SUBLANG_SWEDISH_FINLAND" },
+ { "sv_SE", 0x41d, "Swedish (sv)", 0x1d, "LANG_SWEDISH", "Sweden (SE);", 0x1,
+ "SUBLANG_SWEDISH" },
+ { "sv_SE", 0x41d, "Swedish (sv)", 0x1d, "LANG_SWEDISH", "Sweden (SE);", 0x1,
+ "SUBLANG_SWEDISH_SWEDEN" },
+ { "syr_SY", 0x45a, "Syriac (syr)", 0x5a, "LANG_SYRIAC", "Syria (SY)", 0x1, "SUBLANG_SYRIAC" },
+ { "tg_TJ", 0x428, "Tajik (tg)", 0x28, "LANG_TAJIK", "Tajikistan, Cyrillic (TJ)", 0x1,
+ "SUBLANG_TAJIK_TAJIKISTAN" },
+ { "tzm_DZ", 0x85f, "Tamazight (tzm)", 0x5f, "LANG_TAMAZIGHT", "Algeria, Latin (DZ)", 0x2,
+ "SUBLANG_TAMAZIGHT_ALGERIA_LATIN" },
+ { "ta_IN", 0x449, "Tamil (ta)", 0x49, "LANG_TAMIL", "India (IN)", 0x1, "SUBLANG_TAMIL_INDIA" },
+ { "ta_LK", 0x849, "Tamil (ta)", 0x49, "LANG_TAMIL", "Sri Lanka (LK)", 0x2,
+ "SUBLANG_TAMIL_SRI_LANKA" },
+ { "tt_RU", 0x444, "Tatar (tt)", 0x44, "LANG_TATAR", "Russia (RU)", 0x1,
+ "SUBLANG_TATAR_RUSSIA" },
+ { "te_IN", 0x44a, "Telugu (te)", 0x4a, "LANG_TELUGU", "India (IN)", 0x1,
+ "SUBLANG_TELUGU_INDIA" },
+ { "th_TH", 0x41e, "Thai (th)", 0x1e, "LANG_THAI", "Thailand (TH)", 0x1,
+ "SUBLANG_THAI_THAILAND" },
+ { "bo_CN", 0x451, "Tibetan (bo)", 0x51, "LANG_TIBETAN", "PRC (CN)", 0x1,
+ "SUBLANG_TIBETAN_PRC" },
+ { "ti_ER", 0x873, "Tigrinya (ti)", 0x73, "LANG_TIGRINYA", "Eritrea (ER)", 0x2,
+ "SUBLANG_TIGRINYA_ERITREA" },
+ { "ti_ET", 0x473, "Tigrinya (ti)", 0x73, "LANG_TIGRIGNA", "Ethiopia (ET)", 0x1,
+ "SUBLANG_TIGRINYA_ETHIOPIA" },
+ { "tr_TR", 0x41f, "Turkish (tr)", 0x1f, "LANG_TURKISH", "Turkey (TR)", 0x1,
+ "SUBLANG_TURKISH_TURKEY" },
+ { "tk_KM", 0x442, "Turkmen (tk)", 0x42, "LANG_TURKMEN", "Turkmenistan (TM)", 0x1,
+ "SUBLANG_TURKMEN_TURKMENISTAN" },
+ { "uk_UA", 0x422, "Ukrainian (uk)", 0x22, "LANG_UKRAINIAN", "Ukraine (UA)", 0x1,
+ "SUBLANG_UKRAINIAN_UKRAINE" },
+ { "hsb_DE", 0x42e, "Upper Sorbian (hsb)", 0x2e, "LANG_UPPER_SORBIAN", "Germany (DE)", 0x1,
+ "SUBLANG_UPPER_SORBIAN_GERMANY" },
+ { "ur", 0x820, "Urdu (ur)", 0x20, "LANG_URDU", "(reserved)", 0x2, "SUBLANG_URDU_INDIA" },
+ { "ur_PK", 0x420, "Urdu (ur)", 0x20, "LANG_URDU", "Pakistan (PK)", 0x1,
+ "SUBLANG_URDU_PAKISTAN" },
+ { "ug_CN", 0x480, "Uyghur (ug)", 0x80, "LANG_UIGHUR", "PRC (CN)", 0x1, "SUBLANG_UIGHUR_PRC" },
+ { "uz_UZ", 0x843, "Uzbek (uz)", 0x43, "LANG_UZBEK", "Uzbekistan, Cyrillic (UZ)", 0x2,
+ "SUBLANG_UZBEK_CYRILLIC" },
+ { "uz_UZ", 0x443, "Uzbek (uz)", 0x43, "LANG_UZBEK", "Uzbekistan, Latin (UZ)", 0x1,
+ "SUBLANG_UZBEK_LATIN" },
+ { "ca", 0x803, "Valencian (ca)", 0x3, "LANG_VALENCIAN", "Valencia (ES-Valencia)", 0x2,
+ "SUBLANG_VALENCIAN_VALENCIA" },
+ { "vi_VN", 0x42a, "Vietnamese (vi)", 0x2a, "LANG_VIETNAMESE", "Vietnam (VN)", 0x1,
+ "SUBLANG_VIETNAMESE_VIETNAM" },
+ { "cy_GB", 0x452, "Welsh (cy)", 0x52, "LANG_WELSH", "United Kingdom (GB)", 0x1,
+ "SUBLANG_WELSH_UNITED_KINGDOM" },
+ { "wo_SN", 0x488, "Wolof (wo)", 0x88, "LANG_WOLOF", "Senegal (SN)", 0x1,
+ "SUBLANG_WOLOF_SENEGAL" },
+ { "ii_CN", 0x478, "Yi (ii)", 0x78, "LANG_YI", "PRC (CN)", 0x1, "SUBLANG_YI_PRC" },
+ { "yu_NG", 0x46a, "Yoruba (yo)", 0x6a, "LANG_YORUBA", "Nigeria (NG)", 0x1,
+ "SUBLANG_YORUBA_NIGERIA" },
+};
+
+/*
+ * In Windows XP, this information is available in the system registry at
+ * HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet001/Control/Keyboard Layouts/
+ * https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-language-pack-default-values
+ */
+static const RDP_KEYBOARD_LAYOUT RDP_KEYBOARD_LAYOUT_TABLE[] = {
+ { 0x0000041c, "Albanian" },
+ { 0x00000401, "Arabic (101)" },
+ { 0x00010401, "Arabic (102)" },
+ { 0x00020401, "Arabic (102) AZERTY" },
+ { 0x0000042b, "Armenian Eastern" },
+ { 0x0002042b, "Armenian Phonetic" },
+ { 0x0003042b, "Armenian Typewriter" },
+ { 0x0001042b, "Armenian Western" },
+ { 0x0000044d, "Assamese - Inscript" },
+ { 0x0001042c, "Azerbaijani (Standard)" },
+ { 0x0000082c, "Azerbaijani Cyrillic" },
+ { 0x0000042c, "Azerbaijani Latin" },
+ { 0x0000046d, "Bashkir" },
+ { 0x00000423, "Belarusian" },
+ { 0x0001080c, "Belgian (Comma)" },
+ { 0x00000813, "Belgian (Period)" },
+ { 0x0000080c, "Belgian French" },
+ { 0x00000445, "Bangla (Bangladesh)" },
+ { 0x00020445, "Bangla (India)" },
+ { 0x00010445, "Bangla (India - Legacy)" },
+ { 0x0000201a, "Bosnian (Cyrillic)" },
+ { 0x000b0c00, "Buginese" },
+ { 0x00030402, "Bulgarian" },
+ { 0x00010402, "Bulgarian (Latin)" },
+ { 0x00020402, "Bulgarian (phonetic layout)" },
+ { 0x00040402, "Bulgarian (phonetic traditional)" },
+ { 0x00000402, "Bulgarian (Typewriter)" },
+ { 0x00001009, "Canadian French" },
+ { 0x00000c0c, "Canadian French (Legacy)" },
+ { 0x00011009, "Canadian Multilingual Standard" },
+ { 0x0000085f, "Central Atlas Tamazight" },
+ { 0x00000429, "Central Kurdish" },
+ { 0x0000045c, "Cherokee Nation" },
+ { 0x0001045c, "Cherokee Nation Phonetic" },
+ { 0x00000804, "Chinese (Simplified) - US Keyboard" },
+ { 0x00000404, "Chinese (Traditional) - US Keyboard" },
+ { 0x00000c04, "Chinese (Traditional, Hong Kong S.A.R.)" },
+ { 0x00001404, "Chinese (Traditional Macao S.A.R.) US Keyboard" },
+ { 0x00001004, "Chinese (Simplified, Singapore) - US keyboard" },
+ { 0x0000041a, "Croatian" },
+ { 0x00000405, "Czech" },
+ { 0x00010405, "Czech (QWERTY)" },
+ { 0x00020405, "Czech Programmers" },
+ { 0x00000406, "Danish" },
+ { 0x00000439, "Devanagari-INSCRIPT" },
+ { 0x00000465, "Divehi Phonetic" },
+ { 0x00010465, "Divehi Typewriter" },
+ { 0x00000413, "Dutch" },
+ { 0x00000c51, "Dzongkha" },
+ { 0x00000425, "Estonian" },
+ { 0x00000438, "Faeroese" },
+ { 0x0000040b, "Finnish" },
+ { 0x0001083b, "Finnish with Sami" },
+ { 0x0000040c, "French" },
+ { 0x00120c00, "Futhark" },
+ { 0x00000437, "Georgian" },
+ { 0x00020437, "Georgian (Ergonomic)" },
+ { 0x00010437, "Georgian (QWERTY)" },
+ { 0x00030437, "Georgian Ministry of Education and Science Schools" },
+ { 0x00040437, "Georgian (Old Alphabets)" },
+ { 0x00000407, "German" },
+ { 0x00010407, "German (IBM)" },
+ { 0x000c0c00, "Gothic" },
+ { 0x00000408, "Greek" },
+ { 0x00010408, "Greek (220)" },
+ { 0x00030408, "Greek (220) Latin" },
+ { 0x00020408, "Greek (319)" },
+ { 0x00040408, "Greek (319) Latin" },
+ { 0x00050408, "Greek Latin" },
+ { 0x00060408, "Greek Polytonic" },
+ { 0x0000046f, "Greenlandic" },
+ { 0x00000474, "Guarani" },
+ { 0x00000447, "Gujarati" },
+ { 0x00000468, "Hausa" },
+ { 0x0000040d, "Hebrew" },
+ { 0x00010439, "Hindi Traditional" },
+ { 0x0000040e, "Hungarian" },
+ { 0x0001040e, "Hungarian 101-key" },
+ { 0x0000040f, "Icelandic" },
+ { 0x00000470, "Igbo" },
+ { 0x00004009, "India" },
+ { 0x0000085d, "Inuktitut - Latin" },
+ { 0x0001045d, "Inuktitut - Naqittaut" },
+ { 0x00001809, "Irish" },
+ { 0x00000410, "Italian" },
+ { 0x00010410, "Italian (142)" },
+ { 0x00000411, "Japanese" },
+ { 0x00110c00, "Javanese" },
+ { 0x0000044b, "Kannada" },
+ { 0x0000043f, "Kazakh" },
+ { 0x00000453, "Khmer" },
+ { 0x00010453, "Khmer (NIDA)" },
+ { 0x00000412, "Korean" },
+ { 0x00000440, "Kyrgyz Cyrillic" },
+ { 0x00000454, "Lao" },
+ { 0x0000080a, "Latin American" },
+ { 0x00020426, "Latvian (Standard)" },
+ { 0x00010426, "Latvian (Legacy)" },
+ { 0x00070c00, "Lisu (Basic)" },
+ { 0x00080c00, "Lisu (Standard)" },
+ { 0x00010427, "Lithuanian" },
+ { 0x00000427, "Lithuanian IBM" },
+ { 0x00020427, "Lithuanian Standard" },
+ { 0x0000046e, "Luxembourgish" },
+ { 0x0000042f, "Macedonia (FYROM)" },
+ { 0x0001042f, "Macedonia (FYROM) - Standard" },
+ { 0x0000044c, "Malayalam" },
+ { 0x0000043a, "Maltese 47-Key" },
+ { 0x0001043a, "Maltese 48-key" },
+ { 0x00000481, "Maori" },
+ { 0x0000044e, "Marathi" },
+ { 0x00000850, "Mongolian (Mongolian Script - Legacy)" },
+ { 0x00020850, "Mongolian (Mongolian Script - Standard)" },
+ { 0x00000450, "Mongolian Cyrillic" },
+ { 0x00010c00, "Myanmar" },
+ { 0x00090c00, "N'ko" },
+ { 0x00000461, "Nepali" },
+ { 0x00020c00, "New Tai Lue" },
+ { 0x00000414, "Norwegian" },
+ { 0x0000043b, "Norwegian with Sami" },
+ { 0x00000448, "Odia" },
+ { 0x000d0c00, "Ol Chiki" },
+ { 0x000f0c00, "Old Italic" },
+ { 0x000e0c00, "Osmanya" },
+ { 0x00000463, "Pashto (Afghanistan)" },
+ { 0x00000429, "Persian" },
+ { 0x00050429, "Persian (Standard)" },
+ { 0x000a0c00, "Phags-pa" },
+ { 0x00010415, "Polish (214)" },
+ { 0x00000415, "Polish (Programmers)" },
+ { 0x00000816, "Portuguese" },
+ { 0x00000416, "Portuguese (Brazilian ABNT)" },
+ { 0x00010416, "Portuguese (Brazilian ABNT2)" },
+ { 0x00000446, "Punjabi" },
+ { 0x00000418, "Romanian (Legacy)" },
+ { 0x00020418, "Romanian (Programmers)" },
+ { 0x00010418, "Romanian (Standard)" },
+ { 0x00000419, "Russian" },
+ { 0x00020419, "Russian - Mnemonic" },
+ { 0x00010419, "Russian (Typewriter)" },
+ { 0x00000485, "Sakha" },
+ { 0x0002083b, "Sami Extended Finland-Sweden" },
+ { 0x0001043b, "Sami Extended Norway" },
+ { 0x00011809, "Scottish Gaelic" },
+ { 0x00000c1a, "Serbian (Cyrillic)" },
+ { 0x0000081a, "Serbian (Latin)" },
+ { 0x0000046c, "Sesotho sa Leboa" },
+ { 0x00000432, "Setswana" },
+ { 0x0000045b, "Sinhala" },
+ { 0x0001045b, "Sinhala - wij 9" },
+ { 0x0000041b, "Slovak" },
+ { 0x0001041b, "Slovak (QWERTY)" },
+ { 0x00000424, "Slovenian" },
+ { 0x00100c00, "Sora" },
+ { 0x0001042e, "Sorbian Extended" },
+ { 0x0002042e, "Sorbian Standard" },
+ { 0x0000042e, "Sorbian Standard (Legacy)" },
+ { 0x0000040a, "Spanish" },
+ { 0x0001040a, "Spanish Variation" },
+ { 0x0000041d, "Swedish" },
+ { 0x0000083b, "Swedish with Sami" },
+ { 0x0000100c, "Swiss French" },
+ { 0x00000807, "Swiss German" },
+ { 0x0000045a, "Syriac" },
+ { 0x0001045a, "Syriac Phonetic" },
+ { 0x00030c00, "Tai Le" },
+ { 0x00000428, "Tajik" },
+ { 0x00000449, "Tamil" },
+ { 0x00010444, "Tatar" },
+ { 0x00000444, "Tatar (Legacy)" },
+ { 0x0000044a, "Telugu" },
+ { 0x0000041e, "Thai Kedmanee" },
+ { 0x0002041e, "Thai Kedmanee (non-ShiftLock)" },
+ { 0x0001041e, "Thai Pattachote" },
+ { 0x0003041e, "Thai Pattachote (non-ShiftLock)" },
+ { 0x00010451, "Tibetan (PRC - Standard)" },
+ { 0x00000451, "Tibetan (PRC - Legacy)" },
+ { 0x00050c00, "Tifinagh (Basic)" },
+ { 0x00060c00, "Tifinagh (Full)" },
+ { 0x0001041f, "Turkish F" },
+ { 0x0000041f, "Turkish Q" },
+ { 0x00000442, "Turkmen" },
+ { 0x00010408, "Uyghur" },
+ { 0x00000480, "Uyghur (Legacy)" },
+ { 0x00000422, "Ukrainian" },
+ { 0x00020422, "Ukrainian (Enhanced)" },
+ { 0x00000809, "United Kingdom" },
+ { 0x00000452, "United Kingdom Extended" },
+ { 0x00010409, "United States - Dvorak" },
+ { 0x00020409, "United States - International" },
+ { 0x00030409, "United States-Dvorak for left hand" },
+ { 0x00040409, "United States-Dvorak for right hand" },
+ { 0x00000409, "United States - English" },
+ { 0x00000420, "Urdu" },
+ { 0x00010480, "Uyghur" },
+ { 0x00000843, "Uzbek Cyrillic" },
+ { 0x0000042a, "Vietnamese" },
+ { 0x00000488, "Wolof" },
+ { 0x00000485, "Yakut" },
+ { 0x0000046a, "Yoruba" },
+};
+
+typedef struct
+{
+ DWORD code; /* Keyboard layout code */
+ DWORD id; /* Keyboard variant ID */
+ const char* name; /* Keyboard layout variant name */
+} RDP_KEYBOARD_LAYOUT_VARIANT;
+
+static const RDP_KEYBOARD_LAYOUT_VARIANT RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[] = {
+ { KBD_ARABIC_102, 0x0028, "Arabic (102)" },
+ { KBD_BULGARIAN_LATIN, 0x0004, "Bulgarian (Latin)" },
+ { KBD_CZECH_QWERTY, 0x0005, "Czech (QWERTY)" },
+ { KBD_GERMAN_IBM, 0x0012, "German (IBM)" },
+ { KBD_GREEK_220, 0x0016, "Greek (220)" },
+ { KBD_UNITED_STATES_DVORAK, 0x0002, "United States-Dvorak" },
+ { KBD_SPANISH_VARIATION, 0x0086, "Spanish Variation" },
+ { KBD_HUNGARIAN_101_KEY, 0x0006, "Hungarian 101-key" },
+ { KBD_ITALIAN_142, 0x0003, "Italian (142)" },
+ { KBD_POLISH_214, 0x0007, "Polish (214)" },
+ { KBD_PORTUGUESE_BRAZILIAN_ABNT2, 0x001D, "Portuguese (Brazilian ABNT2)" },
+ { KBD_RUSSIAN_TYPEWRITER, 0x0008, "Russian (Typewriter)" },
+ { KBD_SLOVAK_QWERTY, 0x0013, "Slovak (QWERTY)" },
+ { KBD_THAI_PATTACHOTE, 0x0021, "Thai Pattachote" },
+ { KBD_TURKISH_F, 0x0014, "Turkish F" },
+ { KBD_LATVIAN_QWERTY, 0x0015, "Latvian (QWERTY)" },
+ { KBD_LITHUANIAN, 0x0027, "Lithuanian" },
+ { KBD_ARMENIAN_WESTERN, 0x0025, "Armenian Western" },
+ { KBD_HINDI_TRADITIONAL, 0x000C, "Hindi Traditional" },
+ { KBD_MALTESE_48_KEY, 0x002B, "Maltese 48-key" },
+ { KBD_SAMI_EXTENDED_NORWAY, 0x002C, "Sami Extended Norway" },
+ { KBD_BENGALI_INSCRIPT, 0x002A, "Bengali (Inscript)" },
+ { KBD_SYRIAC_PHONETIC, 0x000E, "Syriac Phonetic" },
+ { KBD_DIVEHI_TYPEWRITER, 0x000D, "Divehi Typewriter" },
+ { KBD_BELGIAN_COMMA, 0x001E, "Belgian (Comma)" },
+ { KBD_FINNISH_WITH_SAMI, 0x002D, "Finnish with Sami" },
+ { KBD_CANADIAN_MULTILINGUAL_STANDARD, 0x0020, "Canadian Multilingual Standard" },
+ { KBD_GAELIC, 0x0026, "Gaelic" },
+ { KBD_ARABIC_102_AZERTY, 0x0029, "Arabic (102) AZERTY" },
+ { KBD_CZECH_PROGRAMMERS, 0x000A, "Czech Programmers" },
+ { KBD_GREEK_319, 0x0018, "Greek (319)" },
+ { KBD_UNITED_STATES_INTERNATIONAL, 0x0001, "United States-International" },
+ { KBD_THAI_KEDMANEE_NON_SHIFTLOCK, 0x0022, "Thai Kedmanee (non-ShiftLock)" },
+ { KBD_SAMI_EXTENDED_FINLAND_SWEDEN, 0x002E, "Sami Extended Finland-Sweden" },
+ { KBD_GREEK_220_LATIN, 0x0017, "Greek (220) Latin" },
+ { KBD_UNITED_STATES_DVORAK_FOR_LEFT_HAND, 0x001A, "United States-Dvorak for left hand" },
+ { KBD_THAI_PATTACHOTE_NON_SHIFTLOCK, 0x0023, "Thai Pattachote (non-ShiftLock)" },
+ { KBD_GREEK_319_LATIN, 0x0011, "Greek (319) Latin" },
+ { KBD_UNITED_STATES_DVORAK_FOR_RIGHT_HAND, 0x001B, "United States-Dvorak for right hand" },
+ { KBD_UNITED_STATES_DVORAK_PROGRAMMER, 0x001C, "United States-Programmer Dvorak" },
+ { KBD_GREEK_LATIN, 0x0019, "Greek Latin" },
+ { KBD_US_ENGLISH_TABLE_FOR_IBM_ARABIC_238_L, 0x000B, "US English Table for IBM Arabic 238_L" },
+ { KBD_GREEK_POLYTONIC, 0x001F, "Greek Polytonic" },
+ { KBD_FRENCH_BEPO, 0x00C0, "French Bépo" },
+ { KBD_GERMAN_NEO, 0x00C0, "German Neo" }
+};
+
+/* Input Method Editor (IME) */
+
+typedef struct
+{
+ DWORD code; /* Keyboard layout code */
+ const char* file; /* IME file */
+ const char* name; /* Keyboard layout name */
+} RDP_KEYBOARD_IME;
+
+/* Global Input Method Editors (IME) */
+
+static const RDP_KEYBOARD_IME RDP_KEYBOARD_IME_TABLE[] = {
+ { KBD_CHINESE_TRADITIONAL_PHONETIC, "phon.ime", "Chinese (Traditional) - Phonetic" },
+ { KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002, "imjp81.ime", "Japanese Input System (MS-IME2002)" },
+ { KBD_KOREAN_INPUT_SYSTEM_IME_2000, "imekr61.ime", "Korean Input System (IME 2000)" },
+ { KBD_CHINESE_SIMPLIFIED_QUANPIN, "winpy.ime", "Chinese (Simplified) - QuanPin" },
+ { KBD_CHINESE_TRADITIONAL_CHANGJIE, "chajei.ime", "Chinese (Traditional) - ChangJie" },
+ { KBD_CHINESE_SIMPLIFIED_SHUANGPIN, "winsp.ime", "Chinese (Simplified) - ShuangPin" },
+ { KBD_CHINESE_TRADITIONAL_QUICK, "quick.ime", "Chinese (Traditional) - Quick" },
+ { KBD_CHINESE_SIMPLIFIED_ZHENGMA, "winzm.ime", "Chinese (Simplified) - ZhengMa" },
+ { KBD_CHINESE_TRADITIONAL_BIG5_CODE, "winime.ime", "Chinese (Traditional) - Big5 Code" },
+ { KBD_CHINESE_TRADITIONAL_ARRAY, "winar30.ime", "Chinese (Traditional) - Array" },
+ { KBD_CHINESE_SIMPLIFIED_NEIMA, "wingb.ime", "Chinese (Simplified) - NeiMa" },
+ { KBD_CHINESE_TRADITIONAL_DAYI, "dayi.ime", "Chinese (Traditional) - DaYi" },
+ { KBD_CHINESE_TRADITIONAL_UNICODE, "unicdime.ime", "Chinese (Traditional) - Unicode" },
+ { KBD_CHINESE_TRADITIONAL_NEW_PHONETIC, "TINTLGNT.IME",
+ "Chinese (Traditional) - New Phonetic" },
+ { KBD_CHINESE_TRADITIONAL_NEW_CHANGJIE, "CINTLGNT.IME",
+ "Chinese (Traditional) - New ChangJie" },
+ { KBD_CHINESE_TRADITIONAL_MICROSOFT_PINYIN_IME_3, "pintlgnt.ime",
+ "Chinese (Traditional) - Microsoft Pinyin IME 3.0" },
+ { KBD_CHINESE_TRADITIONAL_ALPHANUMERIC, "romanime.ime", "Chinese (Traditional) - Alphanumeric" }
+};
+
+void freerdp_keyboard_layouts_free(RDP_KEYBOARD_LAYOUT* layouts, size_t count)
+{
+ if (!layouts)
+ return;
+
+ for (size_t x = 0; x < count; x++)
+ {
+ RDP_KEYBOARD_LAYOUT* current = &layouts[x];
+ free(current->name);
+ current++;
+ }
+
+ free(layouts);
+}
+
+RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(DWORD types, size_t* count)
+{
+ size_t num = 0;
+ RDP_KEYBOARD_LAYOUT* layouts = NULL;
+
+ num = 0;
+
+ WINPR_ASSERT(count);
+ *count = 0;
+
+ if ((types & RDP_KEYBOARD_LAYOUT_TYPE_STANDARD) != 0)
+ {
+ const size_t length = ARRAYSIZE(RDP_KEYBOARD_LAYOUT_TABLE);
+ RDP_KEYBOARD_LAYOUT* new = (RDP_KEYBOARD_LAYOUT*)realloc(
+ layouts, (num + length + 1) * sizeof(RDP_KEYBOARD_LAYOUT));
+
+ if (!new)
+ goto fail;
+
+ layouts = new;
+
+ for (size_t i = 0; i < length; i++, num++)
+ {
+ layouts[num].code = RDP_KEYBOARD_LAYOUT_TABLE[i].code;
+ layouts[num].name = _strdup(RDP_KEYBOARD_LAYOUT_TABLE[i].name);
+
+ if (!layouts[num].name)
+ goto fail;
+ }
+ }
+
+ if ((types & RDP_KEYBOARD_LAYOUT_TYPE_VARIANT) != 0)
+ {
+ const size_t length = ARRAYSIZE(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE);
+ RDP_KEYBOARD_LAYOUT* new = (RDP_KEYBOARD_LAYOUT*)realloc(
+ layouts, (num + length + 1) * sizeof(RDP_KEYBOARD_LAYOUT));
+
+ if (!new)
+ goto fail;
+
+ layouts = new;
+
+ for (size_t i = 0; i < length; i++, num++)
+ {
+ layouts[num].code = RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i].code;
+ layouts[num].name = _strdup(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i].name);
+
+ if (!layouts[num].name)
+ goto fail;
+ }
+ }
+
+ if ((types & RDP_KEYBOARD_LAYOUT_TYPE_IME) != 0)
+ {
+ const size_t length = ARRAYSIZE(RDP_KEYBOARD_IME_TABLE);
+ RDP_KEYBOARD_LAYOUT* new = (RDP_KEYBOARD_LAYOUT*)realloc(
+ layouts, (num + length + 1) * sizeof(RDP_KEYBOARD_LAYOUT));
+
+ if (!new)
+ goto fail;
+
+ layouts = new;
+
+ for (size_t i = 0; i < length; i++, num++)
+ {
+ layouts[num].code = RDP_KEYBOARD_IME_TABLE[i].code;
+ layouts[num].name = _strdup(RDP_KEYBOARD_IME_TABLE[i].name);
+
+ if (!layouts[num].name)
+ goto fail;
+ }
+ }
+
+ *count = num;
+ return layouts;
+fail:
+ freerdp_keyboard_layouts_free(layouts, num);
+ return NULL;
+}
+
+const char* freerdp_keyboard_get_layout_name_from_id(DWORD keyboardLayoutID)
+{
+ for (size_t i = 0; i < ARRAYSIZE(RDP_KEYBOARD_LAYOUT_TABLE); i++)
+ {
+ if (RDP_KEYBOARD_LAYOUT_TABLE[i].code == keyboardLayoutID)
+ return RDP_KEYBOARD_LAYOUT_TABLE[i].name;
+ }
+
+ for (size_t i = 0; i < ARRAYSIZE(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE); i++)
+ {
+ if (RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i].code == keyboardLayoutID)
+ return RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i].name;
+ }
+
+ for (size_t i = 0; i < ARRAYSIZE(RDP_KEYBOARD_IME_TABLE); i++)
+ {
+ if (RDP_KEYBOARD_IME_TABLE[i].code == keyboardLayoutID)
+ return RDP_KEYBOARD_IME_TABLE[i].name;
+ }
+
+ return "unknown";
+}
+
+DWORD freerdp_keyboard_get_layout_id_from_name(const char* name)
+{
+ for (size_t i = 0; i < ARRAYSIZE(RDP_KEYBOARD_LAYOUT_TABLE); i++)
+ {
+ if (strcmp(RDP_KEYBOARD_LAYOUT_TABLE[i].name, name) == 0)
+ return RDP_KEYBOARD_LAYOUT_TABLE[i].code;
+ }
+
+ for (size_t i = 0; i < ARRAYSIZE(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE); i++)
+ {
+ if (strcmp(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i].name, name) == 0)
+ return RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i].code;
+ }
+
+ for (size_t i = 0; i < ARRAYSIZE(RDP_KEYBOARD_IME_TABLE); i++)
+ {
+ if (strcmp(RDP_KEYBOARD_IME_TABLE[i].name, name) == 0)
+ return RDP_KEYBOARD_IME_TABLE[i].code;
+ }
+
+ return 0;
+}
+
+static void copy(const struct LanguageIdentifier* id, RDP_CODEPAGE* cp)
+{
+ cp->id = id->LanguageIdentifier;
+ cp->subId = id->SublangaugeIdentifier;
+ cp->primaryId = id->PrimaryLanguageIdentifier;
+ if (id->locale)
+ strncpy(cp->locale, id->locale, ARRAYSIZE(cp->locale) - 1);
+ if (id->PrimaryLanguage)
+ strncpy(cp->primaryLanguage, id->PrimaryLanguage, ARRAYSIZE(cp->primaryLanguage) - 1);
+ if (id->PrimaryLanguageSymbol)
+ strncpy(cp->primaryLanguageSymbol, id->PrimaryLanguageSymbol,
+ ARRAYSIZE(cp->primaryLanguageSymbol) - 1);
+ if (id->Sublanguage)
+ strncpy(cp->subLanguage, id->Sublanguage, ARRAYSIZE(cp->subLanguage) - 1);
+ if (id->SublanguageSymbol)
+ strncpy(cp->subLanguageSymbol, id->SublanguageSymbol, ARRAYSIZE(cp->subLanguageSymbol) - 1);
+}
+
+static BOOL copyOnMatch(DWORD column, const char* filter, const struct LanguageIdentifier* cur,
+ RDP_CODEPAGE* dst)
+{
+ const char* what = NULL;
+ switch (column)
+ {
+ case 0:
+ what = cur->locale;
+ break;
+ case 1:
+ what = cur->PrimaryLanguage;
+ break;
+ case 2:
+ what = cur->PrimaryLanguageSymbol;
+ break;
+ case 3:
+ what = cur->Sublanguage;
+ break;
+ case 4:
+ what = cur->SublanguageSymbol;
+ break;
+ default:
+ return FALSE;
+ }
+
+ if (filter)
+ {
+ if (!strstr(what, filter))
+ return FALSE;
+ }
+ copy(cur, dst);
+ return TRUE;
+}
+
+RDP_CODEPAGE* freerdp_keyboard_get_matching_codepages(DWORD column, const char* filter,
+ size_t* count)
+{
+ size_t cnt = 0;
+ const size_t c = ARRAYSIZE(language_identifiers);
+ RDP_CODEPAGE* pages = calloc(ARRAYSIZE(language_identifiers), sizeof(RDP_CODEPAGE));
+
+ if (!pages)
+ return NULL;
+
+ if (count)
+ *count = 0;
+
+ if (column > 4)
+ goto fail;
+
+ for (size_t x = 0; x < c; x++)
+ {
+ const struct LanguageIdentifier* cur = &language_identifiers[x];
+ if (copyOnMatch(column, filter, cur, &pages[cnt]))
+ cnt++;
+ }
+
+ if (cnt == 0)
+ goto fail;
+
+ if (count)
+ *count = cnt;
+
+ return pages;
+fail:
+ freerdp_codepages_free(pages);
+ return NULL;
+}
+
+void freerdp_codepages_free(RDP_CODEPAGE* pages)
+{
+ free(pages);
+}
diff --git a/libfreerdp/locale/keyboard_sun.c b/libfreerdp/locale/keyboard_sun.c
new file mode 100644
index 0000000..094ed5b
--- /dev/null
+++ b/libfreerdp/locale/keyboard_sun.c
@@ -0,0 +1,284 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * Solaris Keyboard Mapping
+ *
+ * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <freerdp/config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <winpr/crt.h>
+
+#include "liblocale.h"
+
+#include <freerdp/locale/keyboard.h>
+
+#include "keyboard_x11.h"
+
+#include "keyboard_sun.h"
+
+/* OpenSolaris 2008.11 and 2009.06 keyboard layouts
+ *
+ * While OpenSolaris comes with Xorg and XKB, it maintains a set of keyboard layout
+ * names that map directly to a particular keyboard layout in XKB. Fortunately for us,
+ * this way of doing things comes from Solaris, which is XKB unaware. The same keyboard
+ * layout naming system is used in Solaris, so we can use the same XKB configuration as
+ * we would on OpenSolaris and get an accurate keyboard layout detection :)
+ *
+ * We can check for the current keyboard layout using the "kbd -l" command:
+ *
+ * type=6
+ * layout=33 (0x21)
+ * delay(ms)=500
+ * rate(ms)=40
+ *
+ * We can check at runtime if the kbd utility is present, parse the output, and use the
+ * keyboard layout indicated by the index given (in this case, 33, or US-English).
+ */
+
+typedef struct
+{
+ UINT32 type; /* Solaris keyboard type */
+ UINT32 layout; /* Layout */
+ char* xkbType; /* XKB keyboard */
+ UINT32 keyboardLayoutId; /* XKB keyboard layout */
+} SOLARIS_KEYBOARD;
+
+static const SOLARIS_KEYBOARD SOLARIS_KEYBOARD_TABLE[] = {
+ { 4, 0, "sun(type4)", KBD_US }, /* US4 */
+ { 4, 1, "sun(type4)", KBD_US }, /* US4 */
+ { 4, 2, "sun(type4tuv)", KBD_FRENCH }, /* FranceBelg4 */
+ { 4, 3, "sun(type4_ca)", KBD_US }, /* Canada4 */
+ { 4, 4, "sun(type4tuv)", KBD_DANISH }, /* Denmark4 */
+ { 4, 5, "sun(type4tuv)", KBD_GERMAN }, /* Germany4 */
+ { 4, 6, "sun(type4tuv)", KBD_ITALIAN }, /* Italy4 */
+ { 4, 7, "sun(type4tuv)", KBD_DUTCH }, /* Netherland4 */
+ { 4, 8, "sun(type4tuv)", KBD_NORWEGIAN }, /* Norway4 */
+ { 4, 9, "sun(type4tuv)", KBD_PORTUGUESE }, /* Portugal4 */
+ { 4, 10, "sun(type4tuv)", KBD_SPANISH }, /* SpainLatAm4 */
+ { 4, 11, "sun(type4tuv)", KBD_SWEDISH }, /* SwedenFin4 */
+ { 4, 12, "sun(type4tuv)", KBD_SWISS_FRENCH }, /* Switzer_Fr4 */
+ { 4, 13, "sun(type4tuv)", KBD_SWISS_GERMAN }, /* Switzer_Ge4 */
+ { 4, 14, "sun(type4tuv)", KBD_UNITED_KINGDOM }, /* UK4 */
+ { 4, 16, "sun(type4)", KBD_KOREAN_INPUT_SYSTEM_IME_2000 }, /* Korea4 */
+ { 4, 17, "sun(type4)", KBD_CHINESE_TRADITIONAL_PHONETIC }, /* Taiwan4 */
+ { 4, 32, "sun(type4jp)", KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002 }, /* Japan4 */
+ { 4, 19, "sun(type5)", KBD_US }, /* US101A_PC */
+ { 4, 33, "sun(type5)", KBD_US }, /* US5 */
+ { 4, 34, "sun(type5unix)", KBD_US }, /* US_UNIX5 */
+ { 4, 35, "sun(type5tuv)", KBD_FRENCH }, /* France5 */
+ { 4, 36, "sun(type5tuv)", KBD_DANISH }, /* Denmark5 */
+ { 4, 37, "sun(type5tuv)", KBD_GERMAN }, /* Germany5 */
+ { 4, 38, "sun(type5tuv)", KBD_ITALIAN }, /* Italy5 */
+ { 4, 39, "sun(type5tuv)", KBD_DUTCH }, /* Netherland5 */
+ { 4, 40, "sun(type5tuv)", KBD_NORWEGIAN }, /* Norway5 */
+ { 4, 41, "sun(type5tuv)", KBD_PORTUGUESE }, /* Portugal5 */
+ { 4, 42, "sun(type5tuv)", KBD_SPANISH }, /* Spain5 */
+ { 4, 43, "sun(type5tuv)", KBD_SWEDISH }, /* Sweden5 */
+ { 4, 44, "sun(type5tuv)", KBD_SWISS_FRENCH }, /* Switzer_Fr5 */
+ { 4, 45, "sun(type5tuv)", KBD_SWISS_GERMAN }, /* Switzer_Ge5 */
+ { 4, 46, "sun(type5tuv)", KBD_UNITED_KINGDOM }, /* UK5 */
+ { 4, 47, "sun(type5)", KBD_KOREAN_INPUT_SYSTEM_IME_2000 }, /* Korea5 */
+ { 4, 48, "sun(type5)", KBD_CHINESE_TRADITIONAL_PHONETIC }, /* Taiwan5 */
+ { 4, 49, "sun(type5jp)", KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002 }, /* Japan5 */
+ { 4, 50, "sun(type5tuv)", KBD_CANADIAN_FRENCH }, /* Canada_Fr5 */
+ { 4, 51, "sun(type5tuv)", KBD_HUNGARIAN }, /* Hungary5 */
+ { 4, 52, "sun(type5tuv)", KBD_POLISH_214 }, /* Poland5 */
+ { 4, 53, "sun(type5tuv)", KBD_CZECH }, /* Czech5 */
+ { 4, 54, "sun(type5tuv)", KBD_RUSSIAN }, /* Russia5 */
+ { 4, 55, "sun(type5tuv)", KBD_LATVIAN }, /* Latvia5 */
+ { 4, 57, "sun(type5tuv)", KBD_GREEK }, /* Greece5 */
+ { 4, 59, "sun(type5tuv)", KBD_LITHUANIAN }, /* Lithuania5 */
+ { 4, 63, "sun(type5tuv)", KBD_CANADIAN_FRENCH }, /* Canada_Fr5_TBITS5 */
+ { 4, 56, "sun(type5tuv)", KBD_TURKISH_Q }, /* TurkeyQ5 */
+ { 4, 58, "sun(type5tuv)", KBD_ARABIC_101 }, /* Arabic5 */
+ { 4, 60, "sun(type5tuv)", KBD_BELGIAN_FRENCH }, /* Belgian5 */
+ { 4, 62, "sun(type5tuv)", KBD_TURKISH_F }, /* TurkeyF5 */
+ { 4, 80, "sun(type5hobo)", KBD_US }, /* US5_Hobo */
+ { 4, 81, "sun(type5hobo)", KBD_US }, /* US_UNIX5_Hobo */
+ { 4, 82, "sun(type5tuvhobo)", KBD_FRENCH }, /* France5_Hobo */
+ { 4, 83, "sun(type5tuvhobo)", KBD_DANISH }, /* Denmark5_Hobo */
+ { 4, 84, "sun(type5tuvhobo)", KBD_GERMAN }, /* Germany5_Hobo */
+ { 4, 85, "sun(type5tuvhobo)", KBD_ITALIAN }, /* Italy5_Hobo */
+ { 4, 86, "sun(type5tuvhobo)", KBD_DUTCH }, /* Netherland5_Hobo */
+ { 4, 87, "sun(type5tuvhobo)", KBD_NORWEGIAN }, /* Norway5_Hobo */
+ { 4, 88, "sun(type5tuvhobo)", KBD_PORTUGUESE }, /* Portugal5_Hobo */
+ { 4, 89, "sun(type5tuvhobo)", KBD_SPANISH }, /* Spain5_Hobo */
+ { 4, 90, "sun(type5tuvhobo)", KBD_SWEDISH }, /* Sweden5_Hobo */
+ { 4, 91, "sun(type5tuvhobo)", KBD_SWISS_FRENCH }, /* Switzer_Fr5_Hobo */
+ { 4, 92, "sun(type5tuvhobo)", KBD_SWISS_GERMAN }, /* Switzer_Ge5_Hobo */
+ { 4, 93, "sun(type5tuvhobo)", KBD_UNITED_KINGDOM }, /* UK5_Hobo */
+ { 4, 94, "sun(type5hobo)", KBD_KOREAN_INPUT_SYSTEM_IME_2000 }, /* Korea5_Hobo */
+ { 4, 95, "sun(type5hobo)", KBD_CHINESE_TRADITIONAL_PHONETIC }, /* Taiwan5_Hobo */
+ { 4, 96, "sun(type5jphobo)", KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002 }, /* Japan5_Hobo */
+ { 4, 97, "sun(type5tuvhobo)", KBD_CANADIAN_FRENCH }, /* Canada_Fr5_Hobo */
+ { 101, 1, "digital_vndr/pc(pc104)", KBD_US }, /* US101A_x86 */
+ { 101, 34, "digital_vndr/pc(pc104)", KBD_US }, /* J3100_x86 */
+ { 101, 35, "digital_vndr/pc(pc104)", KBD_FRENCH }, /* France_x86 */
+ { 101, 36, "digital_vndr/pc(pc104)", KBD_DANISH }, /* Denmark_x86 */
+ { 101, 37, "digital_vndr/pc(pc104)", KBD_GERMAN }, /* Germany_x86 */
+ { 101, 38, "digital_vndr/pc(pc104)", KBD_ITALIAN }, /* Italy_x86 */
+ { 101, 39, "digital_vndr/pc(pc104)", KBD_DUTCH }, /* Netherland_x86 */
+ { 101, 40, "digital_vndr/pc(pc104)", KBD_NORWEGIAN }, /* Norway_x86 */
+ { 101, 41, "digital_vndr/pc(pc104)", KBD_PORTUGUESE }, /* Portugal_x86 */
+ { 101, 42, "digital_vndr/pc(pc104)", KBD_SPANISH }, /* Spain_x86 */
+ { 101, 43, "digital_vndr/pc(pc104)", KBD_SWEDISH }, /* Sweden_x86 */
+ { 101, 44, "digital_vndr/pc(pc104)", KBD_SWISS_FRENCH }, /* Switzer_Fr_x86 */
+ { 101, 45, "digital_vndr/pc(pc104)", KBD_SWISS_GERMAN }, /* Switzer_Ge_x86 */
+ { 101, 46, "digital_vndr/pc(pc104)", KBD_UNITED_KINGDOM }, /* UK_x86 */
+ { 101, 47, "digital_vndr/pc(pc104)", KBD_KOREAN_INPUT_SYSTEM_IME_2000 }, /* Korea_x86 */
+ { 101, 48, "digital_vndr/pc(pc104)", KBD_CHINESE_TRADITIONAL_PHONETIC }, /* Taiwan_x86 */
+ { 101, 49, "digital_vndr/pc(lk411jj)", KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002 }, /* Japan_x86 */
+ { 101, 50, "digital_vndr/pc(pc104)", KBD_CANADIAN_FRENCH }, /* Canada_Fr2_x86 */
+ { 101, 51, "digital_vndr/pc(pc104)", KBD_HUNGARIAN }, /* Hungary_x86 */
+ { 101, 52, "digital_vndr/pc(pc104)", KBD_POLISH_214 }, /* Poland_x86 */
+ { 101, 53, "digital_vndr/pc(pc104)", KBD_CZECH }, /* Czech_x86 */
+ { 101, 54, "digital_vndr/pc(pc104)", KBD_RUSSIAN }, /* Russia_x86 */
+ { 101, 55, "digital_vndr/pc(pc104)", KBD_LATVIAN }, /* Latvia_x86 */
+ { 101, 56, "digital_vndr/pc(pc104)", KBD_TURKISH_Q }, /* Turkey_x86 */
+ { 101, 57, "digital_vndr/pc(pc104)", KBD_GREEK }, /* Greece_x86 */
+ { 101, 59, "digital_vndr/pc(pc104)", KBD_LITHUANIAN }, /* Lithuania_x86 */
+ { 101, 1001, "digital_vndr/pc(pc104)", KBD_US }, /* MS_US101A_x86 */
+ { 6, 6, "sun(type6tuv)", KBD_DANISH }, /* Denmark6_usb */
+ { 6, 7, "sun(type6tuv)", KBD_FINNISH }, /* Finnish6_usb */
+ { 6, 8, "sun(type6tuv)", KBD_FRENCH }, /* France6_usb */
+ { 6, 9, "sun(type6tuv)", KBD_GERMAN }, /* Germany6_usb */
+ { 6, 14, "sun(type6tuv)", KBD_ITALIAN }, /* Italy6_usb */
+ { 6, 15, "sun(type6jp)", KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002 }, /* Japan7_usb */
+ { 6, 16, "sun(type6)", KBD_KOREAN_INPUT_SYSTEM_IME_2000 }, /* Korea6_usb */
+ { 6, 18, "sun(type6tuv)", KBD_DUTCH }, /* Netherland6_usb */
+ { 6, 19, "sun(type6tuv)", KBD_NORWEGIAN }, /* Norway6_usb */
+ { 6, 22, "sun(type6tuv)", KBD_PORTUGUESE }, /* Portugal6_usb */
+ { 6, 23, "sun(type6tuv)", KBD_RUSSIAN }, /* Russia6_usb */
+ { 6, 25, "sun(type6tuv)", KBD_SPANISH }, /* Spain6_usb */
+ { 6, 26, "sun(type6tuv)", KBD_SWEDISH }, /* Sweden6_usb */
+ { 6, 27, "sun(type6tuv)", KBD_SWISS_FRENCH }, /* Switzer_Fr6_usb */
+ { 6, 28, "sun(type6tuv)", KBD_SWISS_GERMAN }, /* Switzer_Ge6_usb */
+ { 6, 30, "sun(type6)", KBD_CHINESE_TRADITIONAL_PHONETIC }, /* Taiwan6_usb */
+ { 6, 32, "sun(type6tuv)", KBD_UNITED_KINGDOM }, /* UK6_usb */
+ { 6, 33, "sun(type6)", KBD_US }, /* US6_usb */
+ { 6, 1, "sun(type6tuv)", KBD_ARABIC_101 }, /* Arabic6_usb */
+ { 6, 2, "sun(type6tuv)", KBD_BELGIAN_FRENCH }, /* Belgian6_usb */
+ { 6, 31, "sun(type6tuv)", KBD_TURKISH_Q }, /* TurkeyQ6_usb */
+ { 6, 35, "sun(type6tuv)", KBD_TURKISH_F }, /* TurkeyF6_usb */
+ { 6, 271, "sun(type6jp)", KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002 }, /* Japan6_usb */
+ { 6, 264, "sun(type6tuv)", KBD_ALBANIAN }, /* Albanian6_usb */
+ { 6, 261, "sun(type6tuv)", KBD_BELARUSIAN }, /* Belarusian6_usb */
+ { 6, 260, "sun(type6tuv)", KBD_BULGARIAN }, /* Bulgarian6_usb */
+ { 6, 259, "sun(type6tuv)", KBD_CROATIAN }, /* Croatian6_usb */
+ { 6, 5, "sun(type6tuv)", KBD_CZECH }, /* Czech6_usb */
+ { 6, 4, "sun(type6tuv)", KBD_CANADIAN_FRENCH }, /* French-Canadian6_usb */
+ { 6, 12, "sun(type6tuv)", KBD_HUNGARIAN }, /* Hungarian6_usb */
+ { 6, 10, "sun(type6tuv)", KBD_GREEK }, /* Greek6_usb */
+ { 6, 17, "sun(type6)", KBD_LATIN_AMERICAN }, /* Latin-American6_usb */
+ { 6, 265, "sun(type6tuv)", KBD_LITHUANIAN }, /* Lithuanian6_usb */
+ { 6, 266, "sun(type6tuv)", KBD_LATVIAN }, /* Latvian6_usb */
+ { 6, 267, "sun(type6tuv)", KBD_FYRO_MACEDONIAN }, /* Macedonian6_usb */
+ { 6, 263, "sun(type6tuv)", KBD_MALTESE_47_KEY }, /* Malta_UK6_usb */
+ { 6, 262, "sun(type6tuv)", KBD_MALTESE_48_KEY }, /* Malta_US6_usb */
+ { 6, 21, "sun(type6tuv)", KBD_POLISH_214 }, /* Polish6_usb */
+ { 6, 257, "sun(type6tuv)", KBD_SERBIAN_LATIN }, /* Serbia-And-Montenegro6_usb */
+ { 6, 256, "sun(type6tuv)", KBD_SLOVENIAN }, /* Slovenian6_usb */
+ { 6, 24, "sun(type6tuv)", KBD_SLOVAK }, /* Slovakian6_usb */
+ { 6, 3, "sun(type6)", KBD_CANADIAN_MULTILINGUAL_STANDARD }, /* Canada_Bi6_usb */
+ { 6, 272, "sun(type6)", KBD_PORTUGUESE_BRAZILIAN_ABNT } /* Brazil6_usb */
+};
+
+int freerdp_get_solaris_keyboard_layout_and_type(int* type, int* layout)
+{
+ FILE* kbd;
+ char* pch;
+ char* beg;
+ char* end;
+ int rc = -1;
+ char buffer[1024];
+ /*
+ Sample output for "kbd -t -l" :
+
+ USB keyboard
+ type=6
+ layout=3 (0x03)
+ delay(ms)=500
+ rate(ms)=40
+ */
+ *type = 0;
+ *layout = 0;
+ kbd = popen("kbd -t -l", "r");
+
+ if (!kbd)
+ return -1;
+
+ while (fgets(buffer, sizeof(buffer), kbd) != NULL)
+ {
+ long val;
+
+ if ((pch = strstr(buffer, "type=")) != NULL)
+ {
+ beg = pch + sizeof("type=") - 1;
+ end = strchr(beg, '\n');
+ end[0] = '\0';
+ errno = 0;
+ val = strtol(beg, NULL, 0);
+
+ if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
+ goto fail;
+
+ *type = val;
+ }
+ else if ((pch = strstr(buffer, "layout=")) != NULL)
+ {
+ beg = pch + sizeof("layout=") - 1;
+ end = strchr(beg, ' ');
+ end[0] = '\0';
+ errno = 0;
+ val = strtol(beg, NULL, 0);
+
+ if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
+ goto fail;
+
+ *layout = val;
+ }
+ }
+
+ rc = 0;
+fail:
+ pclose(kbd);
+ return rc;
+}
+
+DWORD freerdp_detect_solaris_keyboard_layout()
+{
+ int type;
+ int layout;
+
+ if (freerdp_get_solaris_keyboard_layout_and_type(&type, &layout) < 0)
+ return 0;
+
+ for (size_t i = 0; i < ARRAYSIZE(SOLARIS_KEYBOARD_TABLE); i++)
+ {
+ if (SOLARIS_KEYBOARD_TABLE[i].type == type)
+ {
+ if (SOLARIS_KEYBOARD_TABLE[i].layout == layout)
+ return SOLARIS_KEYBOARD_TABLE[i].keyboardLayoutId;
+ }
+ }
+
+ return 0;
+}
diff --git a/libfreerdp/locale/keyboard_sun.h b/libfreerdp/locale/keyboard_sun.h
new file mode 100644
index 0000000..840d2ab
--- /dev/null
+++ b/libfreerdp/locale/keyboard_sun.h
@@ -0,0 +1,27 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * Solaris Keyboard Mapping
+ *
+ * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FREERDP_LOCALE_KEYBOARD_SUN_H
+#define FREERDP_LOCALE_KEYBOARD_SUN_H
+
+#include <freerdp/api.h>
+
+FREERDP_LOCAL DWORD freerdp_detect_solaris_keyboard_layout();
+
+#endif /* FREERDP_LOCALE_KEYBOARD_SUN_H */
diff --git a/libfreerdp/locale/keyboard_x11.c b/libfreerdp/locale/keyboard_x11.c
new file mode 100644
index 0000000..3f3f574
--- /dev/null
+++ b/libfreerdp/locale/keyboard_x11.c
@@ -0,0 +1,139 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * X11 Keyboard Mapping
+ *
+ * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ * Copyright 2023 Bernhard Miklautz <bernhard.miklautz@thincast.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+
+#include <X11/X.h>
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+
+#include "liblocale.h"
+#include "keyboard_x11.h"
+#include "xkb_layout_ids.h"
+
+static BOOL parse_xkb_rule_names(char* xkb_rule, unsigned long num_bytes, char** layout,
+ char** variant)
+{
+ /* Sample output for "Canadian Multilingual Standard"
+ *
+ * _XKB_RULES_NAMES_BACKUP(STRING) = "xorg", "pc105", "ca", "multi", "magic"
+ *
+ * Format: "rules", "model", "layout", "variant", "options"
+ *
+ * Where "xorg" is the set of rules
+ * "pc105" the keyboard model
+ * "ca" the keyboard layout(s) (can also be something like 'us,uk')
+ * "multi" the keyboard layout variant(s) (in the examples, “,winkeys” - which means first
+ * layout uses some “default” variant and second uses “winkeys” variant)
+ * "magic" - configuration option (in the examples,
+ * “eurosign:e,lv3:ralt_switch,grp:rctrl_toggle”
+ * - three options)
+ */
+ for (size_t i = 0, index = 0; i < num_bytes; i++, index++)
+ {
+ char* ptr = xkb_rule + i;
+
+ switch (index)
+ {
+ case 0: // rules
+ break;
+ case 1: // model
+ break;
+ case 2: // layout
+ {
+ /* If multiple languages are present we just take the first one */
+ char* delimiter = strchr(ptr, ',');
+ if (delimiter)
+ *delimiter = '\0';
+ *layout = ptr;
+ break;
+ }
+ case 3: // variant
+ *variant = ptr;
+ break;
+ case 4: // option
+ break;
+ default:
+ break;
+ }
+ i += strlen(ptr);
+ }
+ return TRUE;
+}
+
+static DWORD kbd_layout_id_from_x_property(Display* display, Window root, char* property_name)
+{
+ char* layout = NULL;
+ char* variant = NULL;
+ char* rule = NULL;
+ Atom property = None;
+ Atom type = None;
+ int item_size = 0;
+ unsigned long items = 0;
+ unsigned long unread_items = 0;
+ DWORD layout_id = 0;
+
+ property = XInternAtom(display, property_name, False);
+
+ if (XGetWindowProperty(display, root, property, 0, 1024, False, XA_STRING, &type, &item_size,
+ &items, &unread_items, (unsigned char**)&rule) != Success)
+ {
+ return 0;
+ }
+
+ if (type != XA_STRING || item_size != 8 || unread_items != 0)
+ {
+ XFree(rule);
+ return 0;
+ }
+
+ parse_xkb_rule_names(rule, items, &layout, &variant);
+
+ DEBUG_KBD("%s layout: %s, variant: %s", property_name, layout, variant);
+ layout_id = find_keyboard_layout_in_xorg_rules(layout, variant);
+
+ XFree(rule);
+
+ return layout_id;
+}
+
+int freerdp_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId)
+{
+ Display* display = XOpenDisplay(NULL);
+
+ if (!display)
+ return 0;
+
+ Window root = DefaultRootWindow(display);
+ if (!root)
+ return 0;
+
+ /* We start by looking for _XKB_RULES_NAMES_BACKUP which appears to be used by libxklavier */
+ DWORD id = kbd_layout_id_from_x_property(display, root, "_XKB_RULES_NAMES_BACKUP");
+
+ if (0 == id)
+ id = kbd_layout_id_from_x_property(display, root, "_XKB_RULES_NAMES");
+
+ if (0 != id)
+ *keyboardLayoutId = id;
+
+ XCloseDisplay(display);
+ return (int)id;
+}
diff --git a/libfreerdp/locale/keyboard_x11.h b/libfreerdp/locale/keyboard_x11.h
new file mode 100644
index 0000000..0d6123d
--- /dev/null
+++ b/libfreerdp/locale/keyboard_x11.h
@@ -0,0 +1,27 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * X11 Keyboard Mapping
+ *
+ * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FREERDP_LOCALE_KEYBOARD_X11_H
+#define FREERDP_LOCALE_KEYBOARD_X11_H
+
+#include <freerdp/api.h>
+
+FREERDP_LOCAL int freerdp_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId);
+
+#endif /* FREERDP_LOCALE_KEYBOARD_X11_H */
diff --git a/libfreerdp/locale/keyboard_xkbfile.c b/libfreerdp/locale/keyboard_xkbfile.c
new file mode 100644
index 0000000..a64cac9
--- /dev/null
+++ b/libfreerdp/locale/keyboard_xkbfile.c
@@ -0,0 +1,495 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * XKB Keyboard Mapping
+ *
+ * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <freerdp/config.h>
+
+#include "keyboard_xkbfile.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <winpr/crt.h>
+#include <winpr/input.h>
+
+#include <freerdp/locale/keyboard.h>
+
+#include "keyboard_x11.h"
+#include "xkb_layout_ids.h"
+#include "liblocale.h"
+
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/XKBlib.h>
+#include <X11/extensions/XKBfile.h>
+#include <X11/extensions/XKBrules.h>
+
+typedef struct
+{
+ const char* xkb_keyname; /* XKB keyname */
+ DWORD rdp_scancode;
+} XKB_KEY_NAME_SCANCODE;
+
+static const XKB_KEY_NAME_SCANCODE XKB_KEY_NAME_SCANCODE_TABLE[] = {
+ { "AB00", RDP_SCANCODE_LSHIFT },
+ { "AB01", RDP_SCANCODE_KEY_Z }, // evdev 52
+ { "AB02", RDP_SCANCODE_KEY_X }, // evdev 53
+ { "AB03", RDP_SCANCODE_KEY_C }, // evdev 54
+ { "AB04", RDP_SCANCODE_KEY_V }, // evdev 55
+ { "AB05", RDP_SCANCODE_KEY_B }, // evdev 56
+ { "AB06", RDP_SCANCODE_KEY_N }, // evdev 57
+ { "AB07", RDP_SCANCODE_KEY_M }, // evdev 58
+ { "AB08", RDP_SCANCODE_OEM_COMMA }, // evdev 59
+ { "AB09", RDP_SCANCODE_OEM_PERIOD }, // evdev 60
+ { "AB10", RDP_SCANCODE_OEM_2 }, // evdev 61. Not KP, not RDP_SCANCODE_DIVIDE
+ { "AB11", RDP_SCANCODE_ABNT_C1 }, // evdev 97. Brazil backslash/underscore.
+ { "AC01", RDP_SCANCODE_KEY_A }, // evdev 38
+ { "AC02", RDP_SCANCODE_KEY_S }, // evdev 39
+ { "AC03", RDP_SCANCODE_KEY_D }, // evdev 40
+ { "AC04", RDP_SCANCODE_KEY_F }, // evdev 41
+ { "AC05", RDP_SCANCODE_KEY_G }, // evdev 42
+ { "AC06", RDP_SCANCODE_KEY_H }, // evdev 43
+ { "AC07", RDP_SCANCODE_KEY_J }, // evdev 44
+ { "AC08", RDP_SCANCODE_KEY_K }, // evdev 45
+ { "AC09", RDP_SCANCODE_KEY_L }, // evdev 46
+ { "AC10", RDP_SCANCODE_OEM_1 }, // evdev 47
+ { "AC11", RDP_SCANCODE_OEM_7 }, // evdev 48
+ { "AC12", RDP_SCANCODE_OEM_5 }, // alias of evdev 51 backslash
+ { "AD01", RDP_SCANCODE_KEY_Q }, // evdev 24
+ { "AD02", RDP_SCANCODE_KEY_W }, // evdev 25
+ { "AD03", RDP_SCANCODE_KEY_E }, // evdev 26
+ { "AD04", RDP_SCANCODE_KEY_R }, // evdev 27
+ { "AD05", RDP_SCANCODE_KEY_T }, // evdev 28
+ { "AD06", RDP_SCANCODE_KEY_Y }, // evdev 29
+ { "AD07", RDP_SCANCODE_KEY_U }, // evdev 30
+ { "AD08", RDP_SCANCODE_KEY_I }, // evdev 31
+ { "AD09", RDP_SCANCODE_KEY_O }, // evdev 32
+ { "AD10", RDP_SCANCODE_KEY_P }, // evdev 33
+ { "AD11", RDP_SCANCODE_OEM_4 }, // evdev 34
+ { "AD12", RDP_SCANCODE_OEM_6 }, // evdev 35
+ { "AE00", RDP_SCANCODE_OEM_3 },
+ { "AE01", RDP_SCANCODE_KEY_1 }, // evdev 10
+ { "AE02", RDP_SCANCODE_KEY_2 }, // evdev 11
+ { "AE03", RDP_SCANCODE_KEY_3 }, // evdev 12
+ { "AE04", RDP_SCANCODE_KEY_4 }, // evdev 13
+ { "AE05", RDP_SCANCODE_KEY_5 }, // evdev 14
+ { "AE06", RDP_SCANCODE_KEY_6 }, // evdev 15
+ { "AE07", RDP_SCANCODE_KEY_7 }, // evdev 16
+ { "AE08", RDP_SCANCODE_KEY_8 }, // evdev 17
+ { "AE09", RDP_SCANCODE_KEY_9 }, // evdev 18
+ { "AE10", RDP_SCANCODE_KEY_0 }, // evdev 19
+ { "AE11", RDP_SCANCODE_OEM_MINUS }, // evdev 20
+ { "AE12", RDP_SCANCODE_OEM_PLUS }, // evdev 21
+ { "AE13", RDP_SCANCODE_BACKSLASH_JP }, // JP 132 Yen next to backspace
+ // { "AGAI", RDP_SCANCODE_ }, // evdev 137
+ { "ALGR", RDP_SCANCODE_RMENU }, // alias of evdev 108 RALT
+ { "ALT", RDP_SCANCODE_LMENU }, // evdev 204, fake keycode for virtual key
+ { "BKSL", RDP_SCANCODE_OEM_5 }, // evdev 51
+ { "BKSP", RDP_SCANCODE_BACKSPACE }, // evdev 22
+ // { "BRK", RDP_SCANCODE_ }, // evdev 419
+ { "CAPS", RDP_SCANCODE_CAPSLOCK }, // evdev 66
+ { "COMP", RDP_SCANCODE_APPS }, // evdev 135
+ // { "COPY", RDP_SCANCODE_ }, // evdev 141
+ // { "CUT", RDP_SCANCODE_ }, // evdev 145
+ { "DELE", RDP_SCANCODE_DELETE }, // evdev 119
+ { "DOWN", RDP_SCANCODE_DOWN }, // evdev 116
+ { "END", RDP_SCANCODE_END }, // evdev 115
+ { "ESC", RDP_SCANCODE_ESCAPE }, // evdev 9
+ // { "FIND", RDP_SCANCODE_ }, // evdev 144
+ { "FK01", RDP_SCANCODE_F1 }, // evdev 67
+ { "FK02", RDP_SCANCODE_F2 }, // evdev 68
+ { "FK03", RDP_SCANCODE_F3 }, // evdev 69
+ { "FK04", RDP_SCANCODE_F4 }, // evdev 70
+ { "FK05", RDP_SCANCODE_F5 }, // evdev 71
+ { "FK06", RDP_SCANCODE_F6 }, // evdev 72
+ { "FK07", RDP_SCANCODE_F7 }, // evdev 73
+ { "FK08", RDP_SCANCODE_F8 }, // evdev 74
+ { "FK09", RDP_SCANCODE_F9 }, // evdev 75
+ { "FK10", RDP_SCANCODE_F10 }, // evdev 76
+ { "FK11", RDP_SCANCODE_F11 }, // evdev 95
+ { "FK12", RDP_SCANCODE_F12 }, // evdev 96
+ { "FK13", RDP_SCANCODE_F13 }, // evdev 191
+ { "FK14", RDP_SCANCODE_F14 }, // evdev 192
+ { "FK15", RDP_SCANCODE_F15 }, // evdev 193
+ { "FK16", RDP_SCANCODE_F16 }, // evdev 194
+ { "FK17", RDP_SCANCODE_F17 }, // evdev 195
+ { "FK18", RDP_SCANCODE_F18 }, // evdev 196
+ { "FK19", RDP_SCANCODE_F19 }, // evdev 197
+ { "FK20", RDP_SCANCODE_F20 }, // evdev 198
+ { "FK21", RDP_SCANCODE_F21 }, // evdev 199
+ { "FK22", RDP_SCANCODE_F22 }, // evdev 200
+ { "FK23", RDP_SCANCODE_F23 }, // evdev 201
+ { "FK24", RDP_SCANCODE_F24 }, // evdev 202
+ // { "FRNT", RDP_SCANCODE_ }, // evdev 140
+ { "HANJ", RDP_SCANCODE_HANJA },
+ { "HELP", RDP_SCANCODE_HELP }, // evdev 146
+ { "HENK", RDP_SCANCODE_CONVERT_JP }, // JP evdev 100 Henkan
+ { "HIRA", RDP_SCANCODE_HIRAGANA }, // JP evdev 99 Hiragana
+ { "HJCV", RDP_SCANCODE_HANJA }, // KR evdev 131 Hangul->Hanja
+ { "HKTG", RDP_SCANCODE_HIRAGANA }, // JP evdev 101 Hiragana/Katakana toggle
+ { "HNGL", RDP_SCANCODE_HANGUL }, // KR evdev 130 Hangul/Latin toggle
+ { "HOME", RDP_SCANCODE_HOME }, // evdev 110
+ { "HYPR", RDP_SCANCODE_LWIN }, // evdev 207, fake keycode for virtual key
+ { "HZTG", RDP_SCANCODE_OEM_3 }, // JP alias of evdev 49
+ // { "I120", RDP_SCANCODE_ }, // evdev 120 KEY_MACRO
+ // { "I126", RDP_SCANCODE_ }, // evdev 126 KEY_KPPLUSMINUS
+ // { "I128", RDP_SCANCODE_ }, // evdev 128 KEY_SCALE
+ { "I129", RDP_SCANCODE_ABNT_C2 }, // evdev 129 KEY_KPCOMMA Brazil
+ // { "I147", RDP_SCANCODE_ }, // evdev 147 KEY_MENU
+ // { "I148", RDP_SCANCODE_ }, // evdev 148 KEY_CALC
+ // { "I149", RDP_SCANCODE_ }, // evdev 149 KEY_SETUP
+ { "I150", RDP_SCANCODE_SLEEP }, // evdev 150 KEY_SLEEP
+ // { "I151", RDP_SCANCODE_ }, // evdev 151 KEY_WAKEUP
+ // { "I152", RDP_SCANCODE_ }, // evdev 152 KEY_FILE
+ // { "I153", RDP_SCANCODE_ }, // evdev 153 KEY_SENDFILE
+ // { "I154", RDP_SCANCODE_ }, // evdev 154 KEY_DELETEFILE
+ // { "I155", RDP_SCANCODE_ }, // evdev 155 KEY_XFER
+ // { "I156", RDP_SCANCODE_ }, // evdev 156 KEY_PROG1 VK_LAUNCH_APP1
+ // { "I157", RDP_SCANCODE_ }, // evdev 157 KEY_PROG2 VK_LAUNCH_APP2
+ // { "I158", RDP_SCANCODE_ }, // evdev 158 KEY_WWW
+ // { "I159", RDP_SCANCODE_ }, // evdev 159 KEY_MSDOS
+ // { "I160", RDP_SCANCODE_ }, // evdev 160 KEY_COFFEE
+ // { "I161", RDP_SCANCODE_ }, // evdev 161 KEY_DIRECTION
+ // { "I162", RDP_SCANCODE_ }, // evdev 162 KEY_CYCLEWINDOWS
+ { "I163", RDP_SCANCODE_LAUNCH_MAIL }, // evdev 163 KEY_MAIL
+ { "I164", RDP_SCANCODE_BROWSER_FAVORITES }, // evdev 164 KEY_BOOKMARKS
+ // { "I165", RDP_SCANCODE_ }, // evdev 165 KEY_COMPUTER
+ { "I166", RDP_SCANCODE_BROWSER_BACK }, // evdev 166 KEY_BACK
+ { "I167", RDP_SCANCODE_BROWSER_FORWARD }, // evdev 167 KEY_FORWARD
+ // { "I168", RDP_SCANCODE_ }, // evdev 168 KEY_CLOSECD
+ // { "I169", RDP_SCANCODE_ }, // evdev 169 KEY_EJECTCD
+ // { "I170", RDP_SCANCODE_ }, // evdev 170 KEY_EJECTCLOSECD
+ { "I171", RDP_SCANCODE_MEDIA_NEXT_TRACK }, // evdev 171 KEY_NEXTSONG
+ { "I172", RDP_SCANCODE_MEDIA_PLAY_PAUSE }, // evdev 172 KEY_PLAYPAUSE
+ { "I173", RDP_SCANCODE_MEDIA_PREV_TRACK }, // evdev 173 KEY_PREVIOUSSONG
+ { "I174", RDP_SCANCODE_MEDIA_STOP }, // evdev 174 KEY_STOPCD
+ // { "I175", RDP_SCANCODE_ }, // evdev 175 KEY_RECORD 167
+ // { "I176", RDP_SCANCODE_ }, // evdev 176 KEY_REWIND
+ // { "I177", RDP_SCANCODE_ }, // evdev 177 KEY_PHONE
+ // { "I178", RDP_SCANCODE_ }, // evdev 178 KEY_ISO
+ // { "I179", RDP_SCANCODE_ }, // evdev 179 KEY_CONFIG
+ { "I180", RDP_SCANCODE_BROWSER_HOME }, // evdev 180 KEY_HOMEPAGE
+ { "I181", RDP_SCANCODE_BROWSER_REFRESH }, // evdev 181 KEY_REFRESH
+ // { "I182", RDP_SCANCODE_ }, // evdev 182 KEY_EXIT
+ // { "I183", RDP_SCANCODE_ }, // evdev 183 KEY_MOVE
+ // { "I184", RDP_SCANCODE_ }, // evdev 184 KEY_EDIT
+ // { "I185", RDP_SCANCODE_ }, // evdev 185 KEY_SCROLLUP
+ // { "I186", RDP_SCANCODE_ }, // evdev 186 KEY_SCROLLDOWN
+ // { "I187", RDP_SCANCODE_ }, // evdev 187 KEY_KPLEFTPAREN
+ // { "I188", RDP_SCANCODE_ }, // evdev 188 KEY_KPRIGHTPAREN
+ // { "I189", RDP_SCANCODE_ }, // evdev 189 KEY_NEW
+ // { "I190", RDP_SCANCODE_ }, // evdev 190 KEY_REDO
+ // { "I208", RDP_SCANCODE_ }, // evdev 208 KEY_PLAYCD
+ // { "I209", RDP_SCANCODE_ }, // evdev 209 KEY_PAUSECD
+ // { "I210", RDP_SCANCODE_ }, // evdev 210 KEY_PROG3
+ // { "I211", RDP_SCANCODE_ }, // evdev 211 KEY_PROG4
+ // { "I212", RDP_SCANCODE_ }, // evdev 212 KEY_DASHBOARD
+ // { "I213", RDP_SCANCODE_ }, // evdev 213 KEY_SUSPEND
+ // { "I214", RDP_SCANCODE_ }, // evdev 214 KEY_CLOSE
+ // { "I215", RDP_SCANCODE_ }, // evdev 215 KEY_PLAY
+ // { "I216", RDP_SCANCODE_ }, // evdev 216 KEY_FASTFORWARD
+ // { "I217", RDP_SCANCODE_ }, // evdev 217 KEY_BASSBOOST
+ // { "I218", RDP_SCANCODE_ }, // evdev 218 KEY_PRINT
+ // { "I219", RDP_SCANCODE_ }, // evdev 219 KEY_HP
+ // { "I220", RDP_SCANCODE_ }, // evdev 220 KEY_CAMERA
+ // { "I221", RDP_SCANCODE_ }, // evdev 221 KEY_SOUND
+ // { "I222", RDP_SCANCODE_ }, // evdev 222 KEY_QUESTION
+ // { "I223", RDP_SCANCODE_ }, // evdev 223 KEY_EMAIL
+ // { "I224", RDP_SCANCODE_ }, // evdev 224 KEY_CHAT
+ { "I225", RDP_SCANCODE_BROWSER_SEARCH }, // evdev 225 KEY_SEARCH
+ // { "I226", RDP_SCANCODE_ }, // evdev 226 KEY_CONNECT
+ // { "I227", RDP_SCANCODE_ }, // evdev 227 KEY_FINANCE
+ // { "I228", RDP_SCANCODE_ }, // evdev 228 KEY_SPORT
+ // { "I229", RDP_SCANCODE_ }, // evdev 229 KEY_SHOP
+ // { "I230", RDP_SCANCODE_ }, // evdev 230 KEY_ALTERASE
+ // { "I231", RDP_SCANCODE_ }, // evdev 231 KEY_CANCEL
+ // { "I232", RDP_SCANCODE_ }, // evdev 232 KEY_BRIGHTNESSDOWN
+ // { "I233", RDP_SCANCODE_ }, // evdev 233 KEY_BRIGHTNESSUP
+ // { "I234", RDP_SCANCODE_ }, // evdev 234 KEY_MEDIA
+ // { "I235", RDP_SCANCODE_ }, // evdev 235 KEY_SWITCHVIDEOMODE
+ // { "I236", RDP_SCANCODE_ }, // evdev 236 KEY_KBDILLUMTOGGLE
+ // { "I237", RDP_SCANCODE_ }, // evdev 237 KEY_KBDILLUMDOWN
+ // { "I238", RDP_SCANCODE_ }, // evdev 238 KEY_KBDILLUMUP
+ // { "I239", RDP_SCANCODE_ }, // evdev 239 KEY_SEND
+ // { "I240", RDP_SCANCODE_ }, // evdev 240 KEY_REPLY
+ // { "I241", RDP_SCANCODE_ }, // evdev 241 KEY_FORWARDMAIL
+ // { "I242", RDP_SCANCODE_ }, // evdev 242 KEY_SAVE
+ // { "I243", RDP_SCANCODE_ }, // evdev 243 KEY_DOCUMENTS
+ // { "I244", RDP_SCANCODE_ }, // evdev 244 KEY_BATTERY
+ // { "I245", RDP_SCANCODE_ }, // evdev 245 KEY_BLUETOOTH
+ // { "I246", RDP_SCANCODE_ }, // evdev 246 KEY_WLAN
+ // { "I247", RDP_SCANCODE_ }, // evdev 247 KEY_UWB
+ // { "I248", RDP_SCANCODE_ }, // evdev 248 KEY_UNKNOWN
+ // { "I249", RDP_SCANCODE_ }, // evdev 249 KEY_VIDEO_NEXT
+ // { "I250", RDP_SCANCODE_ }, // evdev 250 KEY_VIDEO_PREV
+ // { "I251", RDP_SCANCODE_ }, // evdev 251 KEY_BRIGHTNESS_CYCLE
+ // { "I252", RDP_SCANCODE_ }, // evdev 252 KEY_BRIGHTNESS_ZERO
+ // { "I253", RDP_SCANCODE_ }, // evdev 253 KEY_DISPLAY_OFF
+ { "INS", RDP_SCANCODE_INSERT }, // evdev 118
+ // { "JPCM", RDP_SCANCODE_ }, // evdev 103 KPJPComma
+ // { "KATA", RDP_SCANCODE_ }, // evdev 98 Katakana VK_DBE_KATAKANA
+ { "KP0", RDP_SCANCODE_NUMPAD0 }, // evdev 90
+ { "KP1", RDP_SCANCODE_NUMPAD1 }, // evdev 87
+ { "KP2", RDP_SCANCODE_NUMPAD2 }, // evdev 88
+ { "KP3", RDP_SCANCODE_NUMPAD3 }, // evdev 89
+ { "KP4", RDP_SCANCODE_NUMPAD4 }, // evdev 83
+ { "KP5", RDP_SCANCODE_NUMPAD5 }, // evdev 84
+ { "KP6", RDP_SCANCODE_NUMPAD6 }, // evdev 85
+ { "KP7", RDP_SCANCODE_NUMPAD7 }, // evdev 79
+ { "KP8", RDP_SCANCODE_NUMPAD8 }, // evdev 80
+ { "KP9", RDP_SCANCODE_NUMPAD9 }, // evdev 81
+ { "KPAD", RDP_SCANCODE_ADD }, // evdev 86
+ { "KPDL", RDP_SCANCODE_DECIMAL }, // evdev 91
+ { "KPDV", RDP_SCANCODE_DIVIDE }, // evdev 106
+ { "KPEN", RDP_SCANCODE_RETURN_KP }, // evdev 104 KP!
+ // { "KPEQ", RDP_SCANCODE_ }, // evdev 125
+ { "KPMU", RDP_SCANCODE_MULTIPLY }, // evdev 63
+ { "KPPT", RDP_SCANCODE_ABNT_C2 }, // BR alias of evdev 129
+ { "KPSU", RDP_SCANCODE_SUBTRACT }, // evdev 82
+ { "LALT", RDP_SCANCODE_LMENU }, // evdev 64
+ { "LCTL", RDP_SCANCODE_LCONTROL }, // evdev 37
+ { "LEFT", RDP_SCANCODE_LEFT }, // evdev 113
+ { "LFSH", RDP_SCANCODE_LSHIFT }, // evdev 50
+ { "LMTA", RDP_SCANCODE_LWIN }, // alias of evdev 133 LWIN
+ // { "LNFD", RDP_SCANCODE_ }, // evdev 109 KEY_LINEFEED
+ { "LSGT", RDP_SCANCODE_OEM_102 }, // evdev 94
+ { "LVL3", RDP_SCANCODE_RMENU }, // evdev 92, fake keycode for virtual key
+ { "LWIN", RDP_SCANCODE_LWIN }, // evdev 133
+ { "MDSW", RDP_SCANCODE_RMENU }, // evdev 203, fake keycode for virtual key
+ { "MENU", RDP_SCANCODE_APPS }, // alias of evdev 135 COMP
+ { "META", RDP_SCANCODE_LMENU }, // evdev 205, fake keycode for virtual key
+ { "MUHE", RDP_SCANCODE_NONCONVERT_JP }, // JP evdev 102 Muhenkan
+ { "MUTE", RDP_SCANCODE_VOLUME_MUTE }, // evdev 121
+ { "NFER", RDP_SCANCODE_NONCONVERT_JP }, // JP alias of evdev 102 Muhenkan
+ { "NMLK", RDP_SCANCODE_NUMLOCK }, // evdev 77
+ // { "OPEN", RDP_SCANCODE_ }, // evdev 142
+ // { "PAST", RDP_SCANCODE_ }, // evdev 143
+ { "PAUS", RDP_SCANCODE_PAUSE }, // evdev 127
+ { "PGDN", RDP_SCANCODE_NEXT }, // evdev 117
+ { "PGUP", RDP_SCANCODE_PRIOR }, // evdev 112
+ // { "POWR", RDP_SCANCODE_ }, // evdev 124
+ // { "PROP", RDP_SCANCODE_ }, // evdev 138
+ { "PRSC", RDP_SCANCODE_PRINTSCREEN }, // evdev 107
+ { "RALT", RDP_SCANCODE_RMENU }, // evdev 108 RALT
+ { "RCTL", RDP_SCANCODE_RCONTROL }, // evdev 105
+ { "RGHT", RDP_SCANCODE_RIGHT }, // evdev 114
+ { "RMTA", RDP_SCANCODE_RWIN }, // alias of evdev 134 RWIN
+ // { "RO", RDP_SCANCODE_ }, // JP evdev 97 Romaji
+ { "RTRN", RDP_SCANCODE_RETURN }, // not KP, evdev 36
+ { "RTSH", RDP_SCANCODE_RSHIFT }, // evdev 62
+ { "RWIN", RDP_SCANCODE_RWIN }, // evdev 134
+ { "SCLK", RDP_SCANCODE_SCROLLLOCK }, // evdev 78
+ { "SPCE", RDP_SCANCODE_SPACE }, // evdev 65
+ { "STOP", RDP_SCANCODE_BROWSER_STOP }, // evdev 136
+ { "SUPR", RDP_SCANCODE_LWIN }, // evdev 206, fake keycode for virtual key
+ { "SYRQ", RDP_SCANCODE_SYSREQ }, // evdev 107
+ { "TAB", RDP_SCANCODE_TAB }, // evdev 23
+ { "TLDE", RDP_SCANCODE_OEM_3 }, // evdev 49
+ // { "UNDO", RDP_SCANCODE_ }, // evdev 139
+ { "UP", RDP_SCANCODE_UP }, // evdev 111
+ { "VOL-", RDP_SCANCODE_VOLUME_DOWN }, // evdev 122
+ { "VOL+", RDP_SCANCODE_VOLUME_UP }, // evdev 123
+ { "XFER", RDP_SCANCODE_CONVERT_JP }, // JP alias of evdev 100 Henkan
+};
+
+static int detect_keyboard_layout_from_xkbfile(void* display, DWORD* keyboardLayoutId);
+static int freerdp_keyboard_load_map_from_xkbfile(void* display, DWORD* x11_keycode_to_rdp_scancode,
+ size_t count);
+
+static void* freerdp_keyboard_xkb_init(void)
+{
+ int status = 0;
+
+ Display* display = XOpenDisplay(NULL);
+
+ if (!display)
+ return NULL;
+
+ status = XkbQueryExtension(display, NULL, NULL, NULL, NULL, NULL);
+
+ if (!status)
+ return NULL;
+
+ return (void*)display;
+}
+
+int freerdp_keyboard_init_xkbfile(DWORD* keyboardLayoutId, DWORD* x11_keycode_to_rdp_scancode,
+ size_t count)
+{
+ WINPR_ASSERT(keyboardLayoutId);
+ WINPR_ASSERT(x11_keycode_to_rdp_scancode);
+ ZeroMemory(x11_keycode_to_rdp_scancode, sizeof(DWORD) * count);
+
+ void* display = freerdp_keyboard_xkb_init();
+
+ if (!display)
+ {
+ DEBUG_KBD("Error initializing xkb");
+ return -1;
+ }
+
+ if (*keyboardLayoutId == 0)
+ {
+ detect_keyboard_layout_from_xkbfile(display, keyboardLayoutId);
+ DEBUG_KBD("detect_keyboard_layout_from_xkb: %" PRIu32 " (0x%08" PRIX32 ")",
+ *keyboardLayoutId, *keyboardLayoutId);
+ }
+
+ const int rc =
+ freerdp_keyboard_load_map_from_xkbfile(display, x11_keycode_to_rdp_scancode, count);
+
+ XCloseDisplay(display);
+
+ return rc;
+}
+
+/* return substring starting after nth comma, ending at following comma */
+static char* comma_substring(char* s, size_t n)
+{
+ char* p = NULL;
+
+ if (!s)
+ return "";
+
+ while (n-- > 0)
+ {
+ if (!(p = strchr(s, ',')))
+ break;
+
+ s = p + 1;
+ }
+
+ if ((p = strchr(s, ',')))
+ *p = 0;
+
+ return s;
+}
+
+int detect_keyboard_layout_from_xkbfile(void* display, DWORD* keyboardLayoutId)
+{
+ DEBUG_KBD("display: %p", display);
+ if (!display)
+ return -2;
+
+ char* rules = NULL;
+ XkbRF_VarDefsRec rules_names = { 0 };
+ const Bool rc = XkbRF_GetNamesProp(display, &rules, &rules_names);
+ if (!rc)
+ {
+ DEBUG_KBD("XkbRF_GetNamesProp == False");
+ }
+ else
+ {
+ DEBUG_KBD("rules: %s", rules ? rules : "");
+ DEBUG_KBD("model: %s", rules_names.model ? rules_names.model : "");
+ DEBUG_KBD("layouts: %s", rules_names.layout ? rules_names.layout : "");
+ DEBUG_KBD("variants: %s", rules_names.variant ? rules_names.variant : "");
+
+ DWORD group = 0;
+ XkbStateRec state = { 0 };
+ XKeyboardState coreKbdState = { 0 };
+ XGetKeyboardControl(display, &coreKbdState);
+
+ if (XkbGetState(display, XkbUseCoreKbd, &state) == Success)
+ group = state.group;
+
+ DEBUG_KBD("group: %u", state.group);
+
+ const char* layout = comma_substring(rules_names.layout, group);
+ const char* variant = comma_substring(rules_names.variant, group);
+
+ DEBUG_KBD("layout: %s", layout ? layout : "");
+ DEBUG_KBD("variant: %s", variant ? variant : "");
+
+ *keyboardLayoutId = find_keyboard_layout_in_xorg_rules(layout, variant);
+ }
+ free(rules_names.model);
+ free(rules_names.layout);
+ free(rules_names.variant);
+ free(rules_names.options);
+ free(rules);
+
+ return 0;
+}
+
+int freerdp_keyboard_load_map_from_xkbfile(void* display, DWORD* x11_keycode_to_rdp_scancode,
+ size_t count)
+{
+ int status = -1;
+
+ if (!display)
+ return -2;
+
+ XkbDescPtr xkb = XkbGetMap(display, 0, XkbUseCoreKbd);
+ if (!xkb)
+ {
+ DEBUG_KBD("XkbGetMap() == NULL");
+ return -3;
+ }
+
+ if (XkbGetNames(display, XkbKeyNamesMask, xkb) != Success)
+ {
+ DEBUG_KBD("XkbGetNames() != Success");
+ }
+ else
+ {
+ char xkb_keyname[XkbKeyNameLength + 1] = { 42, 42, 42, 42,
+ 0 }; /* end-of-string at index 5 */
+
+ DEBUG_KBD("XkbGetNames() == Success, min=%" PRIu8 ", max=%" PRIu8, xkb->min_key_code,
+ xkb->max_key_code);
+ for (size_t i = xkb->min_key_code; i <= MIN(xkb->max_key_code, count); i++)
+ {
+ BOOL found = FALSE;
+ strncpy(xkb_keyname, xkb->names->keys[i].name, XkbKeyNameLength);
+
+ DEBUG_KBD("KeyCode %" PRIuz " -> %s", i, xkb_keyname);
+ if (strnlen(xkb_keyname, ARRAYSIZE(xkb_keyname)) < 1)
+ continue;
+
+ for (size_t j = 0; j < ARRAYSIZE(XKB_KEY_NAME_SCANCODE_TABLE); j++)
+ {
+ if (!strcmp(xkb_keyname, XKB_KEY_NAME_SCANCODE_TABLE[j].xkb_keyname))
+ {
+ DEBUG_KBD("%4s: keycode: 0x%02X -> rdp scancode: 0x%08" PRIX32 "", xkb_keyname,
+ i, XKB_KEY_NAME_SCANCODE_TABLE[j].rdp_scancode);
+
+ if (found)
+ {
+ DEBUG_KBD("Internal error! duplicate key %s!", xkb_keyname);
+ }
+
+ x11_keycode_to_rdp_scancode[i] = XKB_KEY_NAME_SCANCODE_TABLE[j].rdp_scancode;
+ found = TRUE;
+ }
+ }
+
+ if (!found)
+ {
+ DEBUG_KBD("%4s: keycode: 0x%02X -> no RDP scancode found", xkb_keyname, i);
+ }
+ else
+ status = 0;
+ }
+ }
+
+ XkbFreeKeyboard(xkb, 0, 1);
+
+ return status;
+}
diff --git a/libfreerdp/locale/keyboard_xkbfile.h b/libfreerdp/locale/keyboard_xkbfile.h
new file mode 100644
index 0000000..69f437b
--- /dev/null
+++ b/libfreerdp/locale/keyboard_xkbfile.h
@@ -0,0 +1,30 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * XKB Keyboard Mapping
+ *
+ * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FREERDP_LIB_LOCALE_KEYBOARD_XKB_H
+#define FREERDP_LIB_LOCALE_KEYBOARD_XKB_H
+
+#include <freerdp/types.h>
+#include <freerdp/locale/keyboard.h>
+#include <freerdp/api.h>
+
+FREERDP_LOCAL int freerdp_keyboard_init_xkbfile(DWORD* keyboardLayoutId,
+ DWORD* x11_keycode_to_rdp_scancode, size_t count);
+
+#endif /* FREERDP_LIB_LOCALE_KEYBOARD_XKB_H */
diff --git a/libfreerdp/locale/liblocale.h b/libfreerdp/locale/liblocale.h
new file mode 100644
index 0000000..7f9ae99
--- /dev/null
+++ b/libfreerdp/locale/liblocale.h
@@ -0,0 +1,47 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * RDP Localization
+ *
+ * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FREERDP_LIB_LOCALE_LIB_H
+#define FREERDP_LIB_LOCALE_LIB_H
+
+#include <freerdp/config.h>
+
+#include <freerdp/log.h>
+
+#define KBD_TAG FREERDP_TAG("locale")
+#ifdef WITH_DEBUG_KBD
+#define DEBUG_KBD(...) WLog_DBG(KBD_TAG, __VA_ARGS__)
+#else
+#define DEBUG_KBD(...) \
+ do \
+ { \
+ } while (0)
+#endif
+
+#define TIMEZONE_TAG FREERDP_TAG("timezone")
+#ifdef WITH_DEBUG_TIMEZONE
+#define DEBUG_TIMEZONE(...) WLog_DBG(TIMEZONE_TAG, __VA_ARGS__)
+#else
+#define DEBUG_TIMEZONE(...) \
+ do \
+ { \
+ } while (0)
+#endif
+
+#endif /* FREERDP_LIB_LOCALE_LIB_H */
diff --git a/libfreerdp/locale/locale.c b/libfreerdp/locale/locale.c
new file mode 100644
index 0000000..a97594d
--- /dev/null
+++ b/libfreerdp/locale/locale.c
@@ -0,0 +1,855 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * Microsoft Locales
+ *
+ * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ * Copyright 2021 Thincast Technologies GmbH
+ * Copyright 2021 Martin Fleisz <martin.fleisz@thincast.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <freerdp/config.h>
+
+#if defined(__APPLE__)
+#include <CoreFoundation/CFString.h>
+#include <CoreFoundation/CFLocale.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <winpr/crt.h>
+#include <winpr/assert.h>
+#include <winpr/environment.h>
+
+#include "liblocale.h"
+
+#include <freerdp/locale/locale.h>
+
+#define LOCALE_LANGUAGE_LEN 6
+#define LOCALE_COUNTRY_LEN 10
+
+typedef struct
+{
+ char language[LOCALE_LANGUAGE_LEN]; /* Two or three letter language code */
+ char country[LOCALE_COUNTRY_LEN]; /* Two or three letter country code (Sometimes with Cyrl_
+ prefix) */
+ DWORD code; /* 32-bit unsigned integer corresponding to the locale */
+} SYSTEM_LOCALE;
+
+/*
+ * Refer to MSDN article "Locale Identifier Constants and Strings":
+ * http://msdn.microsoft.com/en-us/library/ms776260.aspx
+ */
+
+static const SYSTEM_LOCALE SYSTEM_LOCALE_TABLE[] = {
+ { "af", "ZA", AFRIKAANS }, /* Afrikaans (South Africa) */
+ { "sq", "AL", ALBANIAN }, /* Albanian (Albania) */
+ { "gsw", "FR", ALSATIAN }, /* Windows Vista and later: Alsatian (France) */
+ { "am", "ET", AMHARIC }, /* Windows Vista and later: Amharic (Ethiopia) */
+ { "ar", "DZ", ARABIC_ALGERIA }, /* Arabic (Algeria) */
+ { "ar", "BH", ARABIC_BAHRAIN }, /* Arabic (Bahrain) */
+ { "ar", "EG", ARABIC_EGYPT }, /* Arabic (Egypt) */
+ { "ar", "IQ", ARABIC_IRAQ }, /* Arabic (Iraq) */
+ { "ar", "JO", ARABIC_JORDAN }, /* Arabic (Jordan) */
+ { "ar", "KW", ARABIC_KUWAIT }, /* Arabic (Kuwait) */
+ { "ar", "LB", ARABIC_LEBANON }, /* Arabic (Lebanon) */
+ { "ar", "LY", ARABIC_LIBYA }, /* Arabic (Libya) */
+ { "ar", "MA", ARABIC_MOROCCO }, /* Arabic (Morocco) */
+ { "ar", "OM", ARABIC_OMAN }, /* Arabic (Oman) */
+ { "ar", "QA", ARABIC_QATAR }, /* Arabic (Qatar) */
+ { "ar", "SA", ARABIC_SAUDI_ARABIA }, /* Arabic (Saudi Arabia) */
+ { "ar", "SY", ARABIC_SYRIA }, /* Arabic (Syria) */
+ { "ar", "TN", ARABIC_TUNISIA }, /* Arabic (Tunisia) */
+ { "ar", "AE", ARABIC_UAE }, /* Arabic (U.A.E.) */
+ { "ar", "YE", ARABIC_YEMEN }, /* Arabic (Yemen) */
+ { "az", "AZ", AZERI_LATIN }, /* Azeri (Latin) */
+ { "az", "Cyrl_AZ", AZERI_CYRILLIC }, /* Azeri (Cyrillic) */
+ { "hy", "AM", ARMENIAN }, /* Windows 2000 and later: Armenian (Armenia) */
+ { "as", "IN", ASSAMESE }, /* Windows Vista and later: Assamese (India) */
+ { "ba", "RU", BASHKIR }, /* Windows Vista and later: Bashkir (Russia) */
+ { "eu", "ES", BASQUE }, /* Basque (Basque) */
+ { "be", "BY", BELARUSIAN }, /* Belarusian (Belarus) */
+ { "bn", "IN", BENGALI_INDIA }, /* Windows XP SP2 and later: Bengali (India) */
+ { "br", "FR", BRETON }, /* Breton (France) */
+ { "bs", "BA", BOSNIAN_LATIN }, /* Bosnian (Latin) */
+ { "bg", "BG", BULGARIAN }, /* Bulgarian (Bulgaria) */
+ { "ca", "ES", CATALAN }, /* Catalan (Catalan) */
+ { "zh", "HK", CHINESE_HONG_KONG }, /* Chinese (Hong Kong SAR, PRC) */
+ { "zh", "MO", CHINESE_MACAU }, /* Windows 98/Me, Windows XP and later: Chinese (Macao SAR) */
+ { "zh", "CN", CHINESE_PRC }, /* Chinese (PRC) */
+ { "zh", "SG", CHINESE_SINGAPORE }, /* Chinese (Singapore) */
+ { "zh", "TW", CHINESE_TAIWAN }, /* Chinese (Taiwan) */
+ { "hr", "BA", CROATIAN_BOSNIA_HERZEGOVINA }, /* Windows XP SP2 and later: Croatian (Bosnia and
+ Herzegovina, Latin) */
+ { "hr", "HR", CROATIAN }, /* Croatian (Croatia) */
+ { "cs", "CZ", CZECH }, /* Czech (Czech Republic) */
+ { "da", "DK", DANISH }, /* Danish (Denmark) */
+ { "prs", "AF", DARI }, /* Windows XP and later: Dari (Afghanistan) */
+ { "dv", "MV", DIVEHI }, /* Windows XP and later: Divehi (Maldives) */
+ { "nl", "BE", DUTCH_BELGIAN }, /* Dutch (Belgium) */
+ { "nl", "NL", DUTCH_STANDARD }, /* Dutch (Netherlands) */
+ { "en", "AU", ENGLISH_AUSTRALIAN }, /* English (Australia) */
+ { "en", "BZ", ENGLISH_BELIZE }, /* English (Belize) */
+ { "en", "CA", ENGLISH_CANADIAN }, /* English (Canada) */
+ { "en", "CB", ENGLISH_CARIBBEAN }, /* English (Carribean) */
+ { "en", "IN", ENGLISH_INDIA }, /* Windows Vista and later: English (India) */
+ { "en", "IE", ENGLISH_IRELAND }, /* English (Ireland) */
+ { "en", "JM", ENGLISH_JAMAICA }, /* English (Jamaica) */
+ { "en", "MY", ENGLISH_MALAYSIA }, /* Windows Vista and later: English (Malaysia) */
+ { "en", "NZ", ENGLISH_NEW_ZEALAND }, /* English (New Zealand) */
+ { "en", "PH",
+ ENGLISH_PHILIPPINES }, /* Windows 98/Me, Windows 2000 and later: English (Philippines) */
+ { "en", "SG", ENGLISH_SINGAPORE }, /* Windows Vista and later: English (Singapore) */
+ { "en", "ZA", ENGLISH_SOUTH_AFRICA }, /* English (South Africa) */
+ { "en", "TT", ENGLISH_TRINIDAD }, /* English (Trinidad and Tobago) */
+ { "en", "GB", ENGLISH_UNITED_KINGDOM }, /* English (United Kingdom) */
+ { "en", "US", ENGLISH_UNITED_STATES }, /* English (United States) */
+ { "en", "ZW",
+ ENGLISH_ZIMBABWE }, /* Windows 98/Me, Windows 2000 and later: English (Zimbabwe) */
+ { "et", "EE", ESTONIAN }, /* Estonian (Estonia) */
+ { "fo", "FO", FAEROESE }, /* Faroese (Faroe Islands) */
+ { "fil", "PH", FILIPINO }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
+ Filipino (Philippines) */
+ { "fi", "FI", FINNISH }, /* Finnish (Finland) */
+ { "fr", "BE", FRENCH_BELGIAN }, /* French (Belgium) */
+ { "fr", "CA", FRENCH_CANADIAN }, /* French (Canada) */
+ { "fr", "FR", FRENCH_STANDARD }, /* French (France) */
+ { "fr", "LU", FRENCH_LUXEMBOURG }, /* French (Luxembourg) */
+ { "fr", "MC", FRENCH_MONACO }, /* French (Monaco) */
+ { "fr", "CH", FRENCH_SWISS }, /* French (Switzerland) */
+ { "fy", "NL", FRISIAN }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
+ Frisian (Netherlands) */
+ { "gl", "ES", GALICIAN }, /* Windows XP and later: Galician (Spain) */
+ { "ka", "GE", GEORGIAN }, /* Windows 2000 and later: Georgian (Georgia) */
+ { "de", "AT", GERMAN_AUSTRIAN }, /* German (Austria) */
+ { "de", "DE", GERMAN_STANDARD }, /* German (Germany) */
+ { "de", "LI", GERMAN_LIECHTENSTEIN }, /* German (Liechtenstein) */
+ { "de", "LU", GERMAN_LUXEMBOURG }, /* German (Luxembourg) */
+ { "de", "CH", GERMAN_SWISS }, /* German (Switzerland) */
+ { "el", "GR", GREEK }, /* Greek (Greece) */
+ { "kl", "GL", GREENLANDIC }, /* Windows Vista and later: Greenlandic (Greenland) */
+ { "gu", "IN", GUJARATI }, /* Windows XP and later: Gujarati (India) */
+ { "he", "IL", HEBREW }, /* Hebrew (Israel) */
+ { "hi", "IN", HINDI }, /* Windows 2000 and later: Hindi (India) */
+ { "hu", "HU", HUNGARIAN }, /* Hungarian (Hungary) */
+ { "is", "IS", ICELANDIC }, /* Icelandic (Iceland) */
+ { "ig", "NG", IGBO }, /* Igbo (Nigeria) */
+ { "id", "ID", INDONESIAN }, /* Indonesian (Indonesia) */
+ { "ga", "IE", IRISH }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
+ Irish (Ireland) */
+ { "it", "IT", ITALIAN_STANDARD }, /* Italian (Italy) */
+ { "it", "CH", ITALIAN_SWISS }, /* Italian (Switzerland) */
+ { "ja", "JP", JAPANESE }, /* Japanese (Japan) */
+ { "kn", "IN", KANNADA }, /* Windows XP and later: Kannada (India) */
+ { "kk", "KZ", KAZAKH }, /* Windows 2000 and later: Kazakh (Kazakhstan) */
+ { "kh", "KH", KHMER }, /* Windows Vista and later: Khmer (Cambodia) */
+ { "qut", "GT", KICHE }, /* Windows Vista and later: K'iche (Guatemala) */
+ { "rw", "RW", KINYARWANDA }, /* Windows Vista and later: Kinyarwanda (Rwanda) */
+ { "kok", "IN", KONKANI }, /* Windows 2000 and later: Konkani (India) */
+ { "ko", "KR", KOREAN }, /* Korean (Korea) */
+ { "ky", "KG", KYRGYZ }, /* Windows XP and later: Kyrgyz (Kyrgyzstan) */
+ { "lo", "LA", LAO }, /* Windows Vista and later: Lao (Lao PDR) */
+ { "lv", "LV", LATVIAN }, /* Latvian (Latvia) */
+ { "lt", "LT", LITHUANIAN }, /* Lithuanian (Lithuania) */
+ { "dsb", "DE", LOWER_SORBIAN }, /* Windows Vista and later: Lower Sorbian (Germany) */
+ { "lb", "LU", LUXEMBOURGISH }, /* Windows XP SP2 and later (downloadable); Windows Vista and
+ later: Luxembourgish (Luxembourg) */
+ { "mk", "MK", MACEDONIAN }, /* Windows 2000 and later: Macedonian (Macedonia, FYROM) */
+ { "ms", "BN", MALAY_BRUNEI_DARUSSALAM }, /* Windows 2000 and later: Malay (Brunei Darussalam) */
+ { "ms", "MY", MALAY_MALAYSIA }, /* Windows 2000 and later: Malay (Malaysia) */
+ { "ml", "IN", MALAYALAM }, /* Windows XP SP2 and later: Malayalam (India) */
+ { "mt", "MT", MALTESE }, /* Windows XP SP2 and later: Maltese (Malta) */
+ { "mi", "NZ", MAORI }, /* Windows XP SP2 and later: Maori (New Zealand) */
+ { "arn", "CL", MAPUDUNGUN }, /* Windows XP SP2 and later (downloadable); Windows Vista and
+ later: Mapudungun (Chile) */
+ { "mr", "IN", MARATHI }, /* Windows 2000 and later: Marathi (India) */
+ { "moh", "CA", MOHAWK }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
+ Mohawk (Canada) */
+ { "mn", "MN", MONGOLIAN }, /* Mongolian */
+ { "ne", "NP", NEPALI }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
+ Nepali (Nepal) */
+ { "nb", "NO", NORWEGIAN_BOKMAL }, /* Norwegian (Bokmal, Norway) */
+ { "nn", "NO", NORWEGIAN_NYNORSK }, /* Norwegian (Nynorsk, Norway) */
+ { "oc", "FR", OCCITAN }, /* Occitan (France) */
+ { "or", "IN", ORIYA }, /* Oriya (India) */
+ { "ps", "AF", PASHTO }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
+ Pashto (Afghanistan) */
+ { "fa", "IR", FARSI }, /* Persian (Iran) */
+ { "pl", "PL", POLISH }, /* Polish (Poland) */
+ { "pt", "BR", PORTUGUESE_BRAZILIAN }, /* Portuguese (Brazil) */
+ { "pt", "PT", PORTUGUESE_STANDARD }, /* Portuguese (Portugal) */
+ { "pa", "IN", PUNJABI }, /* Windows XP and later: Punjabi (India) */
+ { "quz", "BO", QUECHUA_BOLIVIA }, /* Windows XP SP2 and later: Quechua (Bolivia) */
+ { "quz", "EC", QUECHUA_ECUADOR }, /* Windows XP SP2 and later: Quechua (Ecuador) */
+ { "quz", "PE", QUECHUA_PERU }, /* Windows XP SP2 and later: Quechua (Peru) */
+ { "ro", "RO", ROMANIAN }, /* Romanian (Romania) */
+ { "rm", "CH", ROMANSH }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
+ Romansh (Switzerland) */
+ { "ru", "RU", RUSSIAN }, /* Russian (Russia) */
+ { "smn", "FI", SAMI_INARI }, /* Windows XP SP2 and later: Sami (Inari, Finland) */
+ { "smj", "NO", SAMI_LULE_NORWAY }, /* Windows XP SP2 and later: Sami (Lule, Norway) */
+ { "smj", "SE", SAMI_LULE_SWEDEN }, /* Windows XP SP2 and later: Sami (Lule, Sweden) */
+ { "se", "FI", SAMI_NORTHERN_FINLAND }, /* Windows XP SP2 and later: Sami (Northern, Finland) */
+ { "se", "NO", SAMI_NORTHERN_NORWAY }, /* Windows XP SP2 and later: Sami (Northern, Norway) */
+ { "se", "SE", SAMI_NORTHERN_SWEDEN }, /* Windows XP SP2 and later: Sami (Northern, Sweden) */
+ { "sms", "FI", SAMI_SKOLT }, /* Windows XP SP2 and later: Sami (Skolt, Finland) */
+ { "sma", "NO", SAMI_SOUTHERN_NORWAY }, /* Windows XP SP2 and later: Sami (Southern, Norway) */
+ { "sma", "SE", SAMI_SOUTHERN_SWEDEN }, /* Windows XP SP2 and later: Sami (Southern, Sweden) */
+ { "sa", "IN", SANSKRIT }, /* Windows 2000 and later: Sanskrit (India) */
+ { "sr", "SP", SERBIAN_LATIN }, /* Serbian (Latin) */
+ { "sr", "SIH",
+ SERBIAN_LATIN_BOSNIA_HERZEGOVINA }, /* Serbian (Latin) (Bosnia and Herzegovina) */
+ { "sr", "Cyrl_SP", SERBIAN_CYRILLIC }, /* Serbian (Cyrillic) */
+ { "sr", "Cyrl_SIH",
+ SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA }, /* Serbian (Cyrillic) (Bosnia and Herzegovina) */
+ { "ns", "ZA", SESOTHO_SA_LEBOA }, /* Windows XP SP2 and later: Sesotho sa Leboa/Northern Sotho
+ (South Africa) */
+ { "tn", "ZA", TSWANA }, /* Windows XP SP2 and later: Setswana/Tswana (South Africa) */
+ { "si", "LK", SINHALA }, /* Windows Vista and later: Sinhala (Sri Lanka) */
+ { "sk", "SK", SLOVAK }, /* Slovak (Slovakia) */
+ { "sl", "SI", SLOVENIAN }, /* Slovenian (Slovenia) */
+ { "es", "AR", SPANISH_ARGENTINA }, /* Spanish (Argentina) */
+ { "es", "BO", SPANISH_BOLIVIA }, /* Spanish (Bolivia) */
+ { "es", "CL", SPANISH_CHILE }, /* Spanish (Chile) */
+ { "es", "CO", SPANISH_COLOMBIA }, /* Spanish (Colombia) */
+ { "es", "CR", SPANISH_COSTA_RICA }, /* Spanish (Costa Rica) */
+ { "es", "DO", SPANISH_DOMINICAN_REPUBLIC }, /* Spanish (Dominican Republic) */
+ { "es", "EC", SPANISH_ECUADOR }, /* Spanish (Ecuador) */
+ { "es", "SV", SPANISH_EL_SALVADOR }, /* Spanish (El Salvador) */
+ { "es", "GT", SPANISH_GUATEMALA }, /* Spanish (Guatemala) */
+ { "es", "HN", SPANISH_HONDURAS }, /* Spanish (Honduras) */
+ { "es", "MX", SPANISH_MEXICAN }, /* Spanish (Mexico) */
+ { "es", "NI", SPANISH_NICARAGUA }, /* Spanish (Nicaragua) */
+ { "es", "PA", SPANISH_PANAMA }, /* Spanish (Panama) */
+ { "es", "PY", SPANISH_PARAGUAY }, /* Spanish (Paraguay) */
+ { "es", "PE", SPANISH_PERU }, /* Spanish (Peru) */
+ { "es", "PR", SPANISH_PUERTO_RICO }, /* Spanish (Puerto Rico) */
+ { "es", "ES", SPANISH_MODERN_SORT }, /* Spanish (Spain) */
+ { "es", "ES", SPANISH_TRADITIONAL_SORT }, /* Spanish (Spain, Traditional Sort) */
+ { "es", "US", SPANISH_UNITED_STATES }, /* Windows Vista and later: Spanish (United States) */
+ { "es", "UY", SPANISH_URUGUAY }, /* Spanish (Uruguay) */
+ { "es", "VE", SPANISH_VENEZUELA }, /* Spanish (Venezuela) */
+ { "sw", "KE", SWAHILI }, /* Windows 2000 and later: Swahili (Kenya) */
+ { "sv", "FI", SWEDISH_FINLAND }, /* Swedish (Finland) */
+ { "sv", "SE", SWEDISH }, /* Swedish (Sweden) */
+ { "syr", "SY", SYRIAC }, /* Windows XP and later: Syriac (Syria) */
+ { "ta", "IN", TAMIL }, /* Windows 2000 and later: Tamil (India) */
+ { "tt", "RU", TATAR }, /* Windows XP and later: Tatar (Russia) */
+ { "te", "IN", TELUGU }, /* Windows XP and later: Telugu (India) */
+ { "th", "TH", THAI }, /* Thai (Thailand) */
+ { "bo", "BT", TIBETAN_BHUTAN }, /* Windows Vista and later: Tibetan (Bhutan) */
+ { "bo", "CN", TIBETAN_PRC }, /* Windows Vista and later: Tibetan (PRC) */
+ { "tr", "TR", TURKISH }, /* Turkish (Turkey) */
+ { "tk", "TM", TURKMEN }, /* Windows Vista and later: Turkmen (Turkmenistan) */
+ { "ug", "CN", UIGHUR }, /* Windows Vista and later: Uighur (PRC) */
+ { "uk", "UA", UKRAINIAN }, /* Ukrainian (Ukraine) */
+ { "wen", "DE", UPPER_SORBIAN }, /* Windows Vista and later: Upper Sorbian (Germany) */
+ { "tr", "IN", URDU_INDIA }, /* Urdu (India) */
+ { "ur", "PK", URDU }, /* Windows 98/Me, Windows 2000 and later: Urdu (Pakistan) */
+ { "uz", "UZ", UZBEK_LATIN }, /* Uzbek (Latin) */
+ { "uz", "Cyrl_UZ", UZBEK_CYRILLIC }, /* Uzbek (Cyrillic) */
+ { "vi", "VN", VIETNAMESE }, /* Windows 98/Me, Windows NT 4.0 and later: Vietnamese (Vietnam) */
+ { "cy", "GB", WELSH }, /* Windows XP SP2 and later: Welsh (United Kingdom) */
+ { "wo", "SN", WOLOF }, /* Windows Vista and later: Wolof (Senegal) */
+ { "xh", "ZA", XHOSA }, /* Windows XP SP2 and later: Xhosa/isiXhosa (South Africa) */
+ { "sah", "RU", YAKUT }, /* Windows Vista and later: Yakut (Russia) */
+ { "ii", "CN", YI }, /* Windows Vista and later: Yi (PRC) */
+ { "yo", "NG", YORUBA }, /* Windows Vista and later: Yoruba (Nigeria) */
+ { "zu", "ZA", ZULU } /* Windows XP SP2 and later: Zulu/isiZulu (South Africa) */
+};
+
+typedef struct
+{
+ DWORD localeId;
+ const char* name;
+} LOCALE_NAME;
+
+static const LOCALE_NAME LOCALE_NAME_TABLE[] = {
+ { AFRIKAANS, "AFRIKAANS" },
+ { ALBANIAN, "ALBANIAN" },
+ { ALSATIAN, "ALSATIAN" },
+ { AMHARIC, "AMHARIC" },
+ { ARABIC_SAUDI_ARABIA, "ARABIC_SAUDI_ARABIA" },
+ { ARABIC_IRAQ, "ARABIC_IRAQ" },
+ { ARABIC_EGYPT, "ARABIC_EGYPT" },
+ { ARABIC_LIBYA, "ARABIC_LIBYA" },
+ { ARABIC_ALGERIA, "ARABIC_ALGERIA" },
+ { ARABIC_MOROCCO, "ARABIC_MOROCCO" },
+ { ARABIC_TUNISIA, "ARABIC_TUNISIA" },
+ { ARABIC_OMAN, "ARABIC_OMAN" },
+ { ARABIC_YEMEN, "ARABIC_YEMEN" },
+ { ARABIC_SYRIA, "ARABIC_SYRIA" },
+ { ARABIC_JORDAN, "ARABIC_JORDAN" },
+ { ARABIC_LEBANON, "ARABIC_LEBANON" },
+ { ARABIC_KUWAIT, "ARABIC_KUWAIT" },
+ { ARABIC_UAE, "ARABIC_UAE" },
+ { ARABIC_BAHRAIN, "ARABIC_BAHRAIN" },
+ { ARABIC_QATAR, "ARABIC_QATAR" },
+ { ARMENIAN, "ARMENIAN" },
+ { ASSAMESE, "ASSAMESE" },
+ { AZERI_LATIN, "AZERI_LATIN" },
+ { AZERI_CYRILLIC, "AZERI_CYRILLIC" },
+ { BASHKIR, "BASHKIR" },
+ { BASQUE, "BASQUE" },
+ { BELARUSIAN, "BELARUSIAN" },
+ { BENGALI_INDIA, "BENGALI_INDIA" },
+ { BOSNIAN_LATIN, "BOSNIAN_LATIN" },
+ { BRETON, "BRETON" },
+ { BULGARIAN, "BULGARIAN" },
+ { CATALAN, "CATALAN" },
+ { CHINESE_TAIWAN, "CHINESE_TAIWAN" },
+ { CHINESE_PRC, "CHINESE_PRC" },
+ { CHINESE_HONG_KONG, "CHINESE_HONG_KONG" },
+ { CHINESE_SINGAPORE, "CHINESE_SINGAPORE" },
+ { CHINESE_MACAU, "CHINESE_MACAU" },
+ { CROATIAN, "CROATIAN" },
+ { CROATIAN_BOSNIA_HERZEGOVINA, "CROATIAN_BOSNIA_HERZEGOVINA" },
+ { CZECH, "CZECH" },
+ { DANISH, "DANISH" },
+ { DARI, "DARI" },
+ { DIVEHI, "DIVEHI" },
+ { DUTCH_STANDARD, "DUTCH_STANDARD" },
+ { DUTCH_BELGIAN, "DUTCH_BELGIAN" },
+ { ENGLISH_UNITED_STATES, "ENGLISH_UNITED_STATES" },
+ { ENGLISH_UNITED_KINGDOM, "ENGLISH_UNITED_KINGDOM" },
+ { ENGLISH_AUSTRALIAN, "ENGLISH_AUSTRALIAN" },
+ { ENGLISH_CANADIAN, "ENGLISH_CANADIAN" },
+ { ENGLISH_NEW_ZEALAND, "ENGLISH_NEW_ZEALAND" },
+ { ENGLISH_INDIA, "ENGLISH_INDIA" },
+ { ENGLISH_IRELAND, "ENGLISH_IRELAND" },
+ { ENGLISH_MALAYSIA, "ENGLISH_MALAYSIA" },
+ { ENGLISH_SOUTH_AFRICA, "ENGLISH_SOUTH_AFRICA" },
+ { ENGLISH_JAMAICA, "ENGLISH_JAMAICA" },
+ { ENGLISH_CARIBBEAN, "ENGLISH_CARIBBEAN" },
+ { ENGLISH_BELIZE, "ENGLISH_BELIZE" },
+ { ENGLISH_TRINIDAD, "ENGLISH_TRINIDAD" },
+ { ENGLISH_ZIMBABWE, "ENGLISH_ZIMBABWE" },
+ { ENGLISH_PHILIPPINES, "ENGLISH_PHILIPPINES" },
+ { ENGLISH_SINGAPORE, "ENGLISH_SINGAPORE" },
+ { ESTONIAN, "ESTONIAN" },
+ { FAEROESE, "FAEROESE" },
+ { FARSI, "FARSI" },
+ { FILIPINO, "FILIPINO" },
+ { FINNISH, "FINNISH" },
+ { FRENCH_STANDARD, "FRENCH_STANDARD" },
+ { FRENCH_BELGIAN, "FRENCH_BELGIAN" },
+ { FRENCH_CANADIAN, "FRENCH_CANADIAN" },
+ { FRENCH_SWISS, "FRENCH_SWISS" },
+ { FRENCH_LUXEMBOURG, "FRENCH_LUXEMBOURG" },
+ { FRENCH_MONACO, "FRENCH_MONACO" },
+ { FRISIAN, "FRISIAN" },
+ { GEORGIAN, "GEORGIAN" },
+ { GALICIAN, "GALICIAN" },
+ { GERMAN_STANDARD, "GERMAN_STANDARD" },
+ { GERMAN_SWISS, "GERMAN_SWISS" },
+ { GERMAN_AUSTRIAN, "GERMAN_AUSTRIAN" },
+ { GERMAN_LUXEMBOURG, "GERMAN_LUXEMBOURG" },
+ { GERMAN_LIECHTENSTEIN, "GERMAN_LIECHTENSTEIN" },
+ { GREEK, "GREEK" },
+ { GREENLANDIC, "GREENLANDIC" },
+ { GUJARATI, "GUJARATI" },
+ { HEBREW, "HEBREW" },
+ { HINDI, "HINDI" },
+ { HUNGARIAN, "HUNGARIAN" },
+ { ICELANDIC, "ICELANDIC" },
+ { IGBO, "IGBO" },
+ { INDONESIAN, "INDONESIAN" },
+ { IRISH, "IRISH" },
+ { ITALIAN_STANDARD, "ITALIAN_STANDARD" },
+ { ITALIAN_SWISS, "ITALIAN_SWISS" },
+ { JAPANESE, "JAPANESE" },
+ { KANNADA, "KANNADA" },
+ { KAZAKH, "KAZAKH" },
+ { KHMER, "KHMER" },
+ { KICHE, "KICHE" },
+ { KINYARWANDA, "KINYARWANDA" },
+ { KONKANI, "KONKANI" },
+ { KOREAN, "KOREAN" },
+ { KYRGYZ, "KYRGYZ" },
+ { LAO, "LAO" },
+ { LATVIAN, "LATVIAN" },
+ { LITHUANIAN, "LITHUANIAN" },
+ { LOWER_SORBIAN, "LOWER_SORBIAN" },
+ { LUXEMBOURGISH, "LUXEMBOURGISH" },
+ { MACEDONIAN, "MACEDONIAN" },
+ { MALAY_MALAYSIA, "MALAY_MALAYSIA" },
+ { MALAY_BRUNEI_DARUSSALAM, "MALAY_BRUNEI_DARUSSALAM" },
+ { MALAYALAM, "MALAYALAM" },
+ { MALTESE, "MALTESE" },
+ { MAPUDUNGUN, "MAPUDUNGUN" },
+ { MAORI, "MAORI" },
+ { MARATHI, "MARATHI" },
+ { MOHAWK, "MOHAWK" },
+ { MONGOLIAN, "MONGOLIAN" },
+ { NEPALI, "NEPALI" },
+ { NORWEGIAN_BOKMAL, "NORWEGIAN_BOKMAL" },
+ { NORWEGIAN_NYNORSK, "NORWEGIAN_NYNORSK" },
+ { OCCITAN, "OCCITAN" },
+ { ORIYA, "ORIYA" },
+ { PASHTO, "PASHTO" },
+ { POLISH, "POLISH" },
+ { PORTUGUESE_BRAZILIAN, "PORTUGUESE_BRAZILIAN" },
+ { PORTUGUESE_STANDARD, "PORTUGUESE_STANDARD" },
+ { PUNJABI, "PUNJABI" },
+ { QUECHUA_BOLIVIA, "QUECHUA_BOLIVIA" },
+ { QUECHUA_ECUADOR, "QUECHUA_ECUADOR" },
+ { QUECHUA_PERU, "QUECHUA_PERU" },
+ { ROMANIAN, "ROMANIAN" },
+ { ROMANSH, "ROMANSH" },
+ { RUSSIAN, "RUSSIAN" },
+ { SAMI_INARI, "SAMI_INARI" },
+ { SAMI_LULE_NORWAY, "SAMI_LULE_NORWAY" },
+ { SAMI_LULE_SWEDEN, "SAMI_LULE_SWEDEN" },
+ { SAMI_NORTHERN_FINLAND, "SAMI_NORTHERN_FINLAND" },
+ { SAMI_NORTHERN_NORWAY, "SAMI_NORTHERN_NORWAY" },
+ { SAMI_NORTHERN_SWEDEN, "SAMI_NORTHERN_SWEDEN" },
+ { SAMI_SKOLT, "SAMI_SKOLT" },
+ { SAMI_SOUTHERN_NORWAY, "SAMI_SOUTHERN_NORWAY" },
+ { SAMI_SOUTHERN_SWEDEN, "SAMI_SOUTHERN_SWEDEN" },
+ { SANSKRIT, "SANSKRIT" },
+ { SERBIAN_LATIN, "SERBIAN_LATIN" },
+ { SERBIAN_LATIN_BOSNIA_HERZEGOVINA, "SERBIAN_LATIN_BOSNIA_HERZEGOVINA" },
+ { SERBIAN_CYRILLIC, "SERBIAN_CYRILLIC" },
+ { SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA, "SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA" },
+ { SESOTHO_SA_LEBOA, "SESOTHO_SA_LEBOA" },
+ { SINHALA, "SINHALA" },
+ { SLOVAK, "SLOVAK" },
+ { SLOVENIAN, "SLOVENIAN" },
+ { SPANISH_TRADITIONAL_SORT, "SPANISH_TRADITIONAL_SORT" },
+ { SPANISH_MEXICAN, "SPANISH_MEXICAN" },
+ { SPANISH_MODERN_SORT, "SPANISH_MODERN_SORT" },
+ { SPANISH_GUATEMALA, "SPANISH_GUATEMALA" },
+ { SPANISH_COSTA_RICA, "SPANISH_COSTA_RICA" },
+ { SPANISH_PANAMA, "SPANISH_PANAMA" },
+ { SPANISH_DOMINICAN_REPUBLIC, "SPANISH_DOMINICAN_REPUBLIC" },
+ { SPANISH_VENEZUELA, "SPANISH_VENEZUELA" },
+ { SPANISH_COLOMBIA, "SPANISH_COLOMBIA" },
+ { SPANISH_PERU, "SPANISH_PERU" },
+ { SPANISH_ARGENTINA, "SPANISH_ARGENTINA" },
+ { SPANISH_ECUADOR, "SPANISH_ECUADOR" },
+ { SPANISH_CHILE, "SPANISH_CHILE" },
+ { SPANISH_UNITED_STATES, "SPANISH_UNITED_STATES" },
+ { SPANISH_URUGUAY, "SPANISH_URUGUAY" },
+ { SPANISH_PARAGUAY, "SPANISH_PARAGUAY" },
+ { SPANISH_BOLIVIA, "SPANISH_BOLIVIA" },
+ { SPANISH_EL_SALVADOR, "SPANISH_EL_SALVADOR" },
+ { SPANISH_HONDURAS, "SPANISH_HONDURAS" },
+ { SPANISH_NICARAGUA, "SPANISH_NICARAGUA" },
+ { SPANISH_PUERTO_RICO, "SPANISH_PUERTO_RICO" },
+ { SWAHILI, "SWAHILI" },
+ { SWEDISH, "SWEDISH" },
+ { SWEDISH_FINLAND, "SWEDISH_FINLAND" },
+ { SYRIAC, "SYRIAC" },
+ { TAMIL, "TAMIL" },
+ { TATAR, "TATAR" },
+ { TELUGU, "TELUGU" },
+ { THAI, "THAI" },
+ { TIBETAN_BHUTAN, "TIBETAN_BHUTAN" },
+ { TIBETAN_PRC, "TIBETAN_PRC" },
+ { TSWANA, "TSWANA" },
+ { UKRAINIAN, "UKRAINIAN" },
+ { TURKISH, "TURKISH" },
+ { TURKMEN, "TURKMEN" },
+ { UIGHUR, "UIGHUR" },
+ { UPPER_SORBIAN, "UPPER_SORBIAN" },
+ { URDU, "URDU" },
+ { URDU_INDIA, "URDU_INDIA" },
+ { UZBEK_LATIN, "UZBEK_LATIN" },
+ { UZBEK_CYRILLIC, "UZBEK_CYRILLIC" },
+ { VIETNAMESE, "VIETNAMESE" },
+ { WELSH, "WELSH" },
+ { WOLOF, "WOLOF" },
+ { XHOSA, "XHOSA" },
+ { YAKUT, "YAKUT" },
+ { YI, "YI" },
+ { YORUBA, "YORUBA" },
+ { ZULU, "ZULU" }
+};
+
+typedef struct
+{
+ DWORD locale; /* Locale ID */
+ DWORD keyboardLayouts[5]; /* array of associated keyboard layouts */
+} LOCALE_KEYBOARD_LAYOUTS;
+
+/* TODO: Use KBD_* defines instead of hardcoded values */
+
+static const LOCALE_KEYBOARD_LAYOUTS LOCALE_KEYBOARD_LAYOUTS_TABLE[] = {
+ { AFRIKAANS, { 0x00000409, 0x00000409, 0x0, 0x0, 0x0 } },
+ { ALBANIAN, { 0x0000041c, 0x00000409, 0x0, 0x0, 0x0 } },
+ { ARABIC_SAUDI_ARABIA, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
+ { ARABIC_IRAQ, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
+ { ARABIC_EGYPT, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
+ { ARABIC_LIBYA, { 0x0000040c, 0x00020401, 0x0, 0x0, 0x0 } },
+ { ARABIC_ALGERIA, { 0x0000040c, 0x00020401, 0x0, 0x0, 0x0 } },
+ { ARABIC_MOROCCO, { 0x0000040c, 0x00020401, 0x0, 0x0, 0x0 } },
+ { ARABIC_TUNISIA, { 0x0000040c, 0x00020401, 0x0, 0x0, 0x0 } },
+ { ARABIC_OMAN, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
+ { ARABIC_YEMEN, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
+ { ARABIC_SYRIA, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
+ { ARABIC_JORDAN, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
+ { ARABIC_LEBANON, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
+ { ARABIC_KUWAIT, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
+ { ARABIC_UAE, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
+ { ARABIC_BAHRAIN, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
+ { ARABIC_QATAR, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
+ { ARMENIAN, { 0x0000042b, 0x00000409, 0x00000419, 0x0, 0x0 } },
+ { AZERI_LATIN, { 0x0000042c, 0x0000082c, 0x00000419, 0x0, 0x0 } },
+ { AZERI_CYRILLIC, { 0x0000082c, 0x0000042c, 0x00000419, 0x0, 0x0 } },
+ { BASQUE, { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { BELARUSIAN, { 0x00000423, 0x00000409, 0x00000419, 0x0, 0x0 } },
+ { BENGALI_INDIA, { 0x00000445, 0x00000409, 0x0, 0x0, 0x0 } },
+ { BOSNIAN_LATIN, { 0x0000141A, 0x00000409, 0x0, 0x0, 0x0 } },
+ { BULGARIAN, { 0x00000402, 0x00000409, 0x0, 0x0, 0x0 } },
+ { CATALAN, { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { CHINESE_TAIWAN, { 0x00000404, 0xe0080404, 0xE0010404, 0x0, 0x0 } },
+ { CHINESE_PRC, { 0x00000804, 0xe00e0804, 0xe0010804, 0xe0030804, 0xe0040804 } },
+ { CHINESE_HONG_KONG, { 0x00000409, 0xe0080404, 0x0, 0x0, 0x0 } },
+ { CHINESE_SINGAPORE, { 0x00000409, 0xe00e0804, 0xe0010804, 0xe0030804, 0xe0040804 } },
+ { CHINESE_MACAU, { 0x00000409, 0xe00e0804, 0xe0020404, 0xe0080404 } },
+ { CROATIAN, { 0x0000041a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { CROATIAN_BOSNIA_HERZEGOVINA, { 0x0000041a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { CZECH, { 0x00000405, 0x00000409, 0x0, 0x0, 0x0 } },
+ { DANISH, { 0x00000406, 0x00000409, 0x0, 0x0, 0x0 } },
+ { DIVEHI, { 0x00000409, 0x00000465, 0x0, 0x0, 0x0 } },
+ { DUTCH_STANDARD, { 0x00020409, 0x00000413, 0x00000409, 0x0, 0x0 } },
+ { DUTCH_BELGIAN, { 0x00000813, 0x00000409, 0x0, 0x0, 0x0 } },
+ { ENGLISH_UNITED_STATES, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { ENGLISH_UNITED_KINGDOM, { 0x00000809, 0x0, 0x0, 0x0, 0x0 } },
+ { ENGLISH_AUSTRALIAN, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { ENGLISH_CANADIAN, { 0x00000409, 0x00011009, 0x00001009, 0x0, 0x0 } },
+ { ENGLISH_NEW_ZEALAND, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { ENGLISH_IRELAND, { 0x00001809, 0x00011809, 0x0, 0x0, 0x0 } },
+ { ENGLISH_SOUTH_AFRICA, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { ENGLISH_JAMAICA, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { ENGLISH_CARIBBEAN, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { ENGLISH_BELIZE, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { ENGLISH_TRINIDAD, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { ENGLISH_ZIMBABWE, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { ENGLISH_PHILIPPINES, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { ESTONIAN, { 0x00000425, 0x0, 0x0, 0x0, 0x0 } },
+ { FAEROESE, { 0x00000406, 0x00000409, 0x0, 0x0, 0x0 } },
+ { FARSI, { 0x00000409, 0x00000429, 0x00000401, 0x0, 0x0 } },
+ { FINNISH, { 0x0000040b, 0x00000409, 0x0, 0x0, 0x0 } },
+ { FRENCH_STANDARD, { 0x0000040c, 0x00000409, 0x0, 0x0, 0x0 } },
+ { FRENCH_BELGIAN, { 0x0000080c, 0x00000409, 0x0, 0x0, 0x0 } },
+ { FRENCH_CANADIAN, { 0x00000C0C, 0x00011009, 0x00000409, 0x0, 0x0 } },
+ { FRENCH_SWISS, { 0x0000100c, 0x00000409, 0x0, 0x0, 0x0 } },
+ { FRENCH_LUXEMBOURG, { 0x0000040c, 0x00000409, 0x0, 0x0, 0x0 } },
+ { FRENCH_MONACO, { 0x0000040c, 0x00000409, 0x0, 0x0, 0x0 } },
+ { GEORGIAN, { 0x00000437, 0x00000409, 0x00000419, 0x0, 0x0 } },
+ { GALICIAN, { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { GERMAN_STANDARD, { 0x00000407, 0x00000409, 0x0, 0x0, 0x0 } },
+ { GERMAN_SWISS, { 0x00000807, 0x00000409, 0x0, 0x0, 0x0 } },
+ { GERMAN_AUSTRIAN, { 0x00000407, 0x00000409, 0x0, 0x0, 0x0 } },
+ { GERMAN_LUXEMBOURG, { 0x00000407, 0x00000409, 0x0, 0x0, 0x0 } },
+ { GERMAN_LIECHTENSTEIN, { 0x00000407, 0x00000409, 0x0, 0x0, 0x0 } },
+ { GREEK, { 0x00000408, 0x00000409, 0x0, 0x0, 0x0 } },
+ { GUJARATI, { 0x00000409, 0x00000447, 0x00010439, 0x0, 0x0 } },
+ { HEBREW, { 0x00000409, 0x0000040d, 0x0, 0x0, 0x0 } },
+ { HINDI, { 0x00000409, 0x00010439, 0x00000439, 0x0, 0x0 } },
+ { HUNGARIAN, { 0x0000040e, 0x00000409, 0x0, 0x0, 0x0 } },
+ { ICELANDIC, { 0x0000040f, 0x00000409, 0x0, 0x0, 0x0 } },
+ { INDONESIAN, { 0x00000409, 0x00000409, 0x0, 0x0, 0x0 } },
+ { ITALIAN_STANDARD, { 0x00000410, 0x00000409, 0x0, 0x0, 0x0 } },
+ { ITALIAN_SWISS, { 0x00000410, 0x00000409, 0x0, 0x0, 0x0 } },
+ { JAPANESE, { 0xe0010411, 0x0, 0x0, 0x0, 0x0 } },
+ { KANNADA, { 0x00000409, 0x0000044b, 0x00010439, 0x0, 0x0 } },
+ { KAZAKH, { 0x0000043f, 0x00000409, 0x00000419, 0x0, 0x0 } },
+ { KONKANI, { 0x00000409, 0x00000439, 0x0, 0x0, 0x0 } },
+ { KOREAN, { 0xE0010412, 0x0, 0x0, 0x0, 0x0 } },
+ { KYRGYZ, { 0x00000440, 0x00000409, 0x0, 0x0, 0x0 } },
+ { LATVIAN, { 0x00010426, 0x0, 0x0, 0x0, 0x0 } },
+ { LITHUANIAN, { 0x00010427, 0x0, 0x0, 0x0, 0x0 } },
+ { MACEDONIAN, { 0x0000042f, 0x00000409, 0x0, 0x0, 0x0 } },
+ { MALAY_MALAYSIA, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { MALAY_BRUNEI_DARUSSALAM, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { MALAYALAM, { 0x00000409, 0x0000044c, 0x0, 0x0, 0x0 } },
+ { MALTESE, { 0x00000409, 0x0000043a, 0x0, 0x0, 0x0 } },
+ { MAORI, { 0x00000409, 0x00000481, 0x0, 0x0, 0x0 } },
+ { MARATHI, { 0x00000409, 0x0000044e, 0x00000439, 0x0, 0x0 } },
+ { MONGOLIAN, { 0x00000450, 0x00000409, 0x0, 0x0, 0x0 } },
+ { NORWEGIAN_BOKMAL, { 0x00000414, 0x00000409, 0x0, 0x0, 0x0 } },
+ { NORWEGIAN_NYNORSK, { 0x00000414, 0x00000409, 0x0, 0x0, 0x0 } },
+ { POLISH, { 0x00010415, 0x00000415, 0x00000409, 0x0, 0x0 } },
+ { PORTUGUESE_BRAZILIAN, { 0x00000416, 0x00000409, 0x0, 0x0, 0x0 } },
+ { PORTUGUESE_STANDARD, { 0x00000816, 0x00000409, 0x0, 0x0, 0x0 } },
+ { PUNJABI, { 0x00000409, 0x00000446, 0x00010439, 0x0, 0x0 } },
+ { QUECHUA_BOLIVIA, { 0x00000409, 0x0000080A, 0x0, 0x0, 0x0 } },
+ { QUECHUA_ECUADOR, { 0x00000409, 0x0000080A, 0x0, 0x0, 0x0 } },
+ { QUECHUA_PERU, { 0x00000409, 0x0000080A, 0x0, 0x0, 0x0 } },
+ { ROMANIAN, { 0x00000418, 0x00000409, 0x0, 0x0, 0x0 } },
+ { RUSSIAN, { 0x00000419, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SAMI_INARI, { 0x0001083b, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SAMI_LULE_NORWAY, { 0x0000043b, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SAMI_LULE_SWEDEN, { 0x0000083b, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SAMI_NORTHERN_FINLAND, { 0x0001083b, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SAMI_NORTHERN_NORWAY, { 0x0000043b, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SAMI_NORTHERN_SWEDEN, { 0x0000083b, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SAMI_SKOLT, { 0x0001083b, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SAMI_SOUTHERN_NORWAY, { 0x0000043b, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SAMI_SOUTHERN_SWEDEN, { 0x0000083b, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SANSKRIT, { 0x00000409, 0x00000439, 0x0, 0x0, 0x0 } },
+ { SERBIAN_LATIN, { 0x0000081a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SERBIAN_LATIN_BOSNIA_HERZEGOVINA, { 0x0000081a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SERBIAN_CYRILLIC, { 0x00000c1a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA, { 0x00000c1a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SLOVAK, { 0x0000041b, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SLOVENIAN, { 0x00000424, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_TRADITIONAL_SORT, { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_MEXICAN, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_MODERN_SORT, { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_GUATEMALA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_COSTA_RICA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_PANAMA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_DOMINICAN_REPUBLIC, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_VENEZUELA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_COLOMBIA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_PERU, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_ARGENTINA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_ECUADOR, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_CHILE, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_URUGUAY, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_PARAGUAY, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_BOLIVIA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_EL_SALVADOR, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_HONDURAS, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_NICARAGUA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SPANISH_PUERTO_RICO, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SWAHILI, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
+ { SWEDISH, { 0x0000041d, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SWEDISH_FINLAND, { 0x0000041d, 0x00000409, 0x0, 0x0, 0x0 } },
+ { SYRIAC, { 0x00000409, 0x0000045a, 0x0, 0x0, 0x0 } },
+ { TAMIL, { 0x00000409, 0x00000449, 0x0, 0x0, 0x0 } },
+ { TATAR, { 0x00000444, 0x00000409, 0x00000419, 0x0, 0x0 } },
+ { TELUGU, { 0x00000409, 0x0000044a, 0x00010439, 0x0, 0x0 } },
+ { THAI, { 0x00000409, 0x0000041e, 0x0, 0x0, 0x0 } },
+ { TSWANA, { 0x00000409, 0x0000041f, 0x0, 0x0, 0x0 } },
+ { UKRAINIAN, { 0x00000422, 0x00000409, 0x0, 0x0, 0x0 } },
+ { TURKISH, { 0x0000041f, 0x0000041f, 0x0, 0x0, 0x0 } },
+ { UKRAINIAN, { 0x00000422, 0x00000409, 0x0, 0x0, 0x0 } },
+ { URDU, { 0x00000401, 0x00000409, 0x0, 0x0, 0x0 } },
+ { UZBEK_LATIN, { 0x00000409, 0x00000843, 0x00000419, 0x0, 0x0 } },
+ { UZBEK_CYRILLIC, { 0x00000843, 0x00000409, 0x00000419, 0x0, 0x0 } },
+ { VIETNAMESE, { 0x00000409, 0x0000042a, 0x0, 0x0, 0x0 } },
+ { WELSH, { 0x00000452, 0x00000809, 0x0, 0x0, 0x0 } },
+ { XHOSA, { 0x00000409, 0x00000409, 0x0, 0x0, 0x0 } },
+};
+
+static BOOL freerdp_get_system_language_and_country_codes(char* language, size_t languageLen,
+ char* country, size_t countryLen)
+{
+ WINPR_ASSERT(language);
+ WINPR_ASSERT(languageLen > 0);
+ WINPR_ASSERT(country);
+ WINPR_ASSERT(countryLen);
+
+#if defined(__APPLE__)
+ {
+ CFIndex strSize;
+ CFStringRef langRef, countryRef;
+ CFLocaleRef localeRef = CFLocaleCopyCurrent();
+ if (!localeRef)
+ return FALSE;
+
+ langRef = (CFStringRef)CFLocaleGetValue(localeRef, kCFLocaleLanguageCode);
+ countryRef = (CFStringRef)CFLocaleGetValue(localeRef, kCFLocaleCountryCode);
+ if (!langRef || !countryRef)
+ {
+ CFRelease(localeRef);
+ return FALSE;
+ }
+
+ if (!CFStringGetCString(langRef, language, languageLen, kCFStringEncodingUTF8) ||
+ !CFStringGetCString(countryRef, country, countryLen, kCFStringEncodingUTF8))
+ {
+ CFRelease(localeRef);
+ return FALSE;
+ }
+
+ CFRelease(localeRef);
+ return TRUE;
+ }
+#else
+ {
+ size_t dot = 0;
+ DWORD nSize = 0;
+ size_t underscore = 0;
+ char* env_lang = NULL;
+ LPCSTR lang = "LANG";
+ /* LANG = <language>_<country>.<encoding> */
+ nSize = GetEnvironmentVariableA(lang, NULL, 0);
+
+ if (!nSize)
+ return FALSE; /* LANG environment variable was not set */
+
+ env_lang = (char*)malloc(nSize);
+
+ if (!env_lang)
+ return FALSE;
+
+ if (GetEnvironmentVariableA(lang, env_lang, nSize) !=
+ nSize - 1) /* Get locale from environment variable LANG */
+ {
+ free(env_lang);
+ return FALSE;
+ }
+
+ underscore = strcspn(env_lang, "_");
+
+ if (underscore > 3)
+ {
+ free(env_lang);
+ return FALSE; /* The language name should not be more than 3 letters long */
+ }
+ else
+ {
+ /* Get language code */
+ size_t len = MIN(languageLen - 1u, underscore);
+ strncpy(language, env_lang, len);
+ language[len] = '\0';
+ }
+
+ dot = strcspn(env_lang, ".");
+
+ /* Get country code */
+ if (dot > underscore)
+ {
+ size_t len = MIN(countryLen - 1, dot - underscore - 1);
+ strncpy(country, &env_lang[underscore + 1], len);
+ country[len] = '\0';
+ }
+ else
+ {
+ free(env_lang);
+ return FALSE; /* Invalid locale */
+ }
+
+ free(env_lang);
+ return TRUE;
+ }
+#endif
+}
+
+static const SYSTEM_LOCALE* freerdp_detect_system_locale(void)
+{
+ char language[LOCALE_LANGUAGE_LEN] = { 0 };
+ char country[LOCALE_COUNTRY_LEN] = { 0 };
+ const SYSTEM_LOCALE* locale = NULL;
+
+ freerdp_get_system_language_and_country_codes(language, ARRAYSIZE(language), country,
+ ARRAYSIZE(country));
+
+ for (size_t i = 0; i < ARRAYSIZE(SYSTEM_LOCALE_TABLE); i++)
+ {
+ const SYSTEM_LOCALE* current = &SYSTEM_LOCALE_TABLE[i];
+
+ if ((strcmp(language, current->language) == 0) && (strcmp(country, current->country) == 0))
+ {
+ locale = current;
+ break;
+ }
+ }
+
+ return locale;
+}
+
+DWORD freerdp_get_system_locale_id(void)
+{
+ const SYSTEM_LOCALE* locale = NULL;
+ locale = freerdp_detect_system_locale();
+
+ if (locale != NULL)
+ return locale->code;
+
+ return 0;
+}
+
+const char* freerdp_get_system_locale_name_from_id(DWORD localeId)
+{
+ for (size_t index = 0; index < ARRAYSIZE(LOCALE_NAME_TABLE); index++)
+ {
+ const LOCALE_NAME* const current = &LOCALE_NAME_TABLE[index];
+
+ if (localeId == current->localeId)
+ return current->name;
+ }
+
+ return NULL;
+}
+
+int freerdp_detect_keyboard_layout_from_system_locale(DWORD* keyboardLayoutId)
+{
+ char language[LOCALE_LANGUAGE_LEN] = { 0 };
+ char country[LOCALE_COUNTRY_LEN] = { 0 };
+
+ freerdp_get_system_language_and_country_codes(language, ARRAYSIZE(language), country,
+ ARRAYSIZE(country));
+
+ if ((strcmp(language, "C") == 0) || (strcmp(language, "POSIX") == 0))
+ {
+ *keyboardLayoutId = ENGLISH_UNITED_STATES; /* U.S. Keyboard Layout */
+ return 0;
+ }
+
+ const SYSTEM_LOCALE* locale = freerdp_detect_system_locale();
+
+ if (!locale)
+ return -1;
+
+ DEBUG_KBD("Found locale : %s_%s", locale->language, locale->country);
+
+ for (size_t i = 0; i < ARRAYSIZE(LOCALE_KEYBOARD_LAYOUTS_TABLE); i++)
+ {
+ const LOCALE_KEYBOARD_LAYOUTS* const current = &LOCALE_KEYBOARD_LAYOUTS_TABLE[i];
+ WINPR_ASSERT(current);
+
+ if (current->locale == locale->code)
+ {
+ /* Locale found in list of default keyboard layouts */
+ for (size_t j = 0; j < 5; j++)
+ {
+ if (current->keyboardLayouts[j] == ENGLISH_UNITED_STATES)
+ {
+ continue; /* Skip, try to get a more localized keyboard layout */
+ }
+ else if (current->keyboardLayouts[j] == 0)
+ {
+ /*
+ * If we skip the ENGLISH_UNITED_STATES keyboard layout but there are no
+ * other possible keyboard layout for the locale, we end up here with k > 1
+ */
+
+ if (j >= 1)
+ {
+ *keyboardLayoutId = ENGLISH_UNITED_STATES;
+ return 0;
+ }
+
+ /* No more keyboard layouts */
+ break;
+ }
+ else
+ {
+ *keyboardLayoutId = current->keyboardLayouts[j];
+ return 0;
+ }
+ }
+ }
+ }
+
+ return -1; /* Could not detect the current keyboard layout from locale */
+}
diff --git a/libfreerdp/locale/xkb_layout_ids.c b/libfreerdp/locale/xkb_layout_ids.c
new file mode 100644
index 0000000..9150fc6
--- /dev/null
+++ b/libfreerdp/locale/xkb_layout_ids.c
@@ -0,0 +1,864 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * RDP Keyboard layout ID detection from common X11 xkb keyboard layout names
+ *
+ * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <freerdp/config.h>
+
+#include "xkb_layout_ids.h"
+
+#include <string.h>
+
+#include <winpr/crt.h>
+
+#include <freerdp/locale/keyboard.h>
+
+#include "liblocale.h"
+
+typedef struct
+{
+ const char* variant; /* XKB Keyboard layout variant */
+ UINT32 keyboardLayoutID; /* Keyboard Layout ID */
+} XKB_VARIANT;
+
+typedef struct
+{
+ const char* layout; /* XKB Keyboard layout */
+ UINT32 keyboardLayoutID; /* Keyboard Layout ID */
+ const XKB_VARIANT* variants;
+} XKB_LAYOUT;
+
+/* Those have been generated automatically and are waiting to be filled by hand */
+
+/* USA */
+static const XKB_VARIANT us_variants[] = {
+ { "chr", 0 }, /* Cherokee */
+ { "euro", 0 }, /* With EuroSign on 5 */
+ { "intl", KBD_UNITED_STATES_INTERNATIONAL }, /* International (with dead keys) */
+ { "alt-intl",
+ KBD_UNITED_STATES_INTERNATIONAL }, /* Alternative international (former us_intl) */
+ { "colemak", 0 }, /* Colemak */
+ { "dvorak", KBD_UNITED_STATES_DVORAK }, /* Dvorak */
+ { "dvorak-intl", KBD_UNITED_STATES_DVORAK }, /* Dvorak international */
+ { "dvorak-l", KBD_UNITED_STATES_DVORAK_FOR_LEFT_HAND }, /* Left handed Dvorak */
+ { "dvorak-r", KBD_UNITED_STATES_DVORAK_FOR_RIGHT_HAND }, /* Right handed Dvorak */
+ { "dvorak-classic", KBD_UNITED_STATES_DVORAK }, /* Classic Dvorak */
+ { "dvp", KBD_UNITED_STATES_DVORAK_PROGRAMMER }, /* Programmer Dvorak */
+ { "rus", 0 }, /* Russian phonetic */
+ { "mac", KBD_US }, /* Macintosh */
+ { "altgr-intl", KBD_UNITED_STATES_INTERNATIONAL }, /* International (AltGr dead keys) */
+ { "olpc2", KBD_US }, /* Group toggle on multiply/divide key */
+ { "", 0 },
+};
+
+/* Afghanistan */
+static const XKB_VARIANT af_variants[] = {
+ { "ps", KBD_PASHTO }, /* Pashto */
+ { "uz", KBD_UZBEK_CYRILLIC }, /* Southern Uzbek */
+ { "olpc-ps", KBD_PASHTO }, /* OLPC Pashto */
+ { "olpc-fa", 0 }, /* OLPC Dari */
+ { "olpc-uz", KBD_UZBEK_CYRILLIC }, /* OLPC Southern Uzbek */
+ { "", 0 },
+};
+
+/* Arabic */
+static const XKB_VARIANT ara_variants[] = {
+ { "azerty", KBD_ARABIC_102_AZERTY }, /* azerty */
+ { "azerty_digits", KBD_ARABIC_102_AZERTY }, /* azerty/digits */
+ { "digits", KBD_ARABIC_102_AZERTY }, /* digits */
+ { "qwerty", KBD_ARABIC_101 }, /* qwerty */
+ { "qwerty_digits", KBD_ARABIC_101 }, /* qwerty/digits */
+ { "buckwalter", KBD_US_ENGLISH_TABLE_FOR_IBM_ARABIC_238_L }, /* Buckwalter */
+ { "", 0 },
+};
+
+/* Armenia */
+static const XKB_VARIANT am_variants[] = {
+ { "phonetic", 0 }, /* Phonetic */
+ { "phonetic-alt", 0 }, /* Alternative Phonetic */
+ { "eastern", KBD_ARMENIAN_EASTERN }, /* Eastern */
+ { "western", KBD_ARMENIAN_WESTERN }, /* Western */
+ { "eastern-alt", KBD_ARMENIAN_EASTERN }, /* Alternative Eastern */
+ { "", 0 },
+};
+
+/* Azerbaijan */
+static const XKB_VARIANT az_variants[] = {
+ { "cyrillic", KBD_AZERI_CYRILLIC }, /* Cyrillic */
+ { "", 0 },
+};
+
+/* Belarus */
+static const XKB_VARIANT by_variants[] = {
+ { "winkeys", KBD_BELARUSIAN }, /* Winkeys */
+ { "latin", KBD_BELARUSIAN }, /* Latin */
+ { "", 0 },
+};
+
+/* Belgium */
+static const XKB_VARIANT be_variants[] = {
+ { "oss", KBD_BELGIAN_FRENCH }, /* Alternative */
+ { "oss_latin9", KBD_BELGIAN_FRENCH }, /* Alternative, latin-9 only */
+ { "oss_sundeadkeys", KBD_BELGIAN_PERIOD }, /* Alternative, Sun dead keys */
+ { "iso-alternate", KBD_BELGIAN_COMMA }, /* ISO Alternate */
+ { "nodeadkeys", KBD_BELGIAN_COMMA }, /* Eliminate dead keys */
+ { "sundeadkeys", KBD_BELGIAN_PERIOD }, /* Sun dead keys */
+ { "wang", KBD_BELGIAN_FRENCH }, /* Wang model 724 azerty */
+ { "", 0 },
+};
+
+/* Bangladesh */
+static const XKB_VARIANT bd_variants[] = {
+ { "probhat", KBD_BENGALI_INSCRIPT }, /* Probhat */
+ { "", 0 },
+};
+
+/* India */
+static const XKB_VARIANT in_variants[] = {
+ { "ben", KBD_BENGALI }, /* Bengali */
+ { "ben_probhat", KBD_BENGALI_INSCRIPT }, /* Bengali Probhat */
+ { "guj", KBD_GUJARATI }, /* Gujarati */
+ { "guru", 0 }, /* Gurmukhi */
+ { "jhelum", 0 }, /* Gurmukhi Jhelum */
+ { "kan", KBD_KANNADA }, /* Kannada */
+ { "mal", KBD_MALAYALAM }, /* Malayalam */
+ { "mal_lalitha", KBD_MALAYALAM }, /* Malayalam Lalitha */
+ { "ori", 0 }, /* Oriya */
+ { "tam_unicode", KBD_TAMIL }, /* Tamil Unicode */
+ { "tam_TAB", KBD_TAMIL }, /* Tamil TAB Typewriter */
+ { "tam_TSCII", KBD_TAMIL }, /* Tamil TSCII Typewriter */
+ { "tam", KBD_TAMIL }, /* Tamil */
+ { "tel", KBD_TELUGU }, /* Telugu */
+ { "urd-phonetic", KBD_URDU }, /* Urdu, Phonetic */
+ { "urd-phonetic3", KBD_URDU }, /* Urdu, Alternative phonetic */
+ { "urd-winkeys", KBD_URDU }, /* Urdu, Winkeys */
+ { "bolnagri", KBD_HINDI_TRADITIONAL }, /* Hindi Bolnagri */
+ { "hin-wx", KBD_HINDI_TRADITIONAL }, /* Hindi Wx */
+ { "", 0 },
+};
+
+/* Bosnia and Herzegovina */
+static const XKB_VARIANT ba_variants[] = {
+ { "alternatequotes", KBD_BOSNIAN }, /* Use guillemets for quotes */
+ { "unicode", KBD_BOSNIAN }, /* Use Bosnian digraphs */
+ { "unicodeus", KBD_BOSNIAN }, /* US keyboard with Bosnian digraphs */
+ { "us", KBD_BOSNIAN_CYRILLIC }, /* US keyboard with Bosnian letters */
+ { "", 0 },
+};
+
+/* Brazil */
+static const XKB_VARIANT br_variants[] = {
+ { "nodeadkeys", KBD_PORTUGUESE_BRAZILIAN_ABNT2 }, /* Eliminate dead keys */
+ { "dvorak", KBD_UNITED_STATES_DVORAK }, /* Dvorak */
+ { "nativo", KBD_PORTUGUESE_BRAZILIAN_ABNT2 }, /* Nativo */
+ { "nativo-us", KBD_PORTUGUESE_BRAZILIAN_ABNT2 }, /* Nativo for USA keyboards */
+ { "nativo-epo", KBD_PORTUGUESE_BRAZILIAN_ABNT2 }, /* Nativo for Esperanto */
+ { "", 0 },
+};
+
+/* Bulgaria */
+static const XKB_VARIANT bg_variants[] = {
+ { "phonetic", KBD_BULGARIAN_LATIN }, /* Traditional Phonetic */
+ { "bas_phonetic", KBD_BULGARIAN_LATIN }, /* Standard Phonetic */
+ { "", 0 },
+};
+
+/* Morocco */
+static const XKB_VARIANT ma_variants[] = {
+ { "french", KBD_FRENCH }, /* French */
+ { "tifinagh", 0 }, /* Tifinagh */
+ { "tifinagh-alt", 0 }, /* Tifinagh Alternative */
+ { "tifinagh-alt-phonetic", 0 }, /* Tifinagh Alternative Phonetic */
+ { "tifinagh-extended", 0 }, /* Tifinagh Extended */
+ { "tifinagh-phonetic", 0 }, /* Tifinagh Phonetic */
+ { "tifinagh-extended-phonetic", 0 }, /* Tifinagh Extended Phonetic */
+ { "", 0 },
+};
+
+/* Canada */
+static const XKB_VARIANT ca_variants[] = {
+ { "fr", KBD_CANADIAN_FRENCH }, /* French Dvorak */
+ { "fr-dvorak", KBD_UNITED_STATES_DVORAK }, /* French Dvorak */
+ { "fr-legacy", KBD_CANADIAN_FRENCH_LEGACY }, /* French (legacy) */
+ { "multix", KBD_CANADIAN_MULTILINGUAL_STANDARD }, /* Multilingual */
+ { "multi", KBD_CANADIAN_MULTILINGUAL_STANDARD }, /* Multilingual, first part */
+ { "multi-2gr", KBD_CANADIAN_MULTILINGUAL_STANDARD }, /* Multilingual, second part */
+ { "ike", KBD_INUKTITUT_LATIN }, /* Inuktitut */
+ { "shs", 0 }, /* Secwepemctsin */
+ { "kut", 0 }, /* Ktunaxa */
+ { "", 0 },
+};
+
+/* China */
+static const XKB_VARIANT cn_variants[] = {
+ { "tib", 0 }, /* Tibetan */
+ { "tib_asciinum", 0 }, /* Tibetan (with ASCII numerals) */
+ { "", 0 },
+};
+
+/* Croatia */
+static const XKB_VARIANT hr_variants[] = {
+ { "alternatequotes", KBD_CROATIAN }, /* Use guillemets for quotes */
+ { "unicode", KBD_CROATIAN }, /* Use Croatian digraphs */
+ { "unicodeus", KBD_CROATIAN }, /* US keyboard with Croatian digraphs */
+ { "us", KBD_CROATIAN }, /* US keyboard with Croatian letters */
+ { "", 0 },
+};
+
+/* Czechia */
+static const XKB_VARIANT cz_variants[] = {
+ { "bksl", KBD_CZECH_PROGRAMMERS }, /* With &lt;\|&gt; key */
+ { "qwerty", KBD_CZECH_QWERTY }, /* qwerty */
+ { "qwerty_bksl", KBD_CZECH_QWERTY }, /* qwerty, extended Backslash */
+ { "ucw", KBD_CZECH }, /* UCW layout (accented letters only) */
+ { "", 0 },
+};
+
+/* Denmark */
+static const XKB_VARIANT dk_variants[] = {
+ { "nodeadkeys", KBD_DANISH }, /* Eliminate dead keys */
+ { "mac", KBD_DANISH }, /* Macintosh */
+ { "mac_nodeadkeys", KBD_DANISH }, /* Macintosh, eliminate dead keys */
+ { "dvorak", KBD_UNITED_STATES_DVORAK }, /* Dvorak */
+ { "", 0 },
+};
+
+/* Netherlands */
+static const XKB_VARIANT nl_variants[] = {
+ { "sundeadkeys", KBD_SWISS_FRENCH }, /* Sun dead keys */
+ { "mac", KBD_SWISS_FRENCH }, /* Macintosh */
+ { "std", KBD_SWISS_FRENCH }, /* Standard */
+ { "", 0 },
+};
+
+/* Estonia */
+static const XKB_VARIANT ee_variants[] = {
+ { "nodeadkeys", KBD_US }, /* Eliminate dead keys */
+ { "dvorak", KBD_UNITED_STATES_DVORAK }, /* Dvorak */
+ { "us", KBD_UNITED_STATES_INTERNATIONAL }, /* US keyboard with Estonian letters */
+ { "", 0 },
+};
+
+/* Iran */
+static const XKB_VARIANT ir_variants[] = {
+ { "pro", 0 }, /* Pro */
+ { "keypad", 0 }, /* Keypad */
+ { "pro_keypad", 0 }, /* Pro Keypad */
+ { "ku", 0 }, /* Kurdish, Latin Q */
+ { "ku_f", 0 }, /* Kurdish, (F) */
+ { "ku_alt", 0 }, /* Kurdish, Latin Alt-Q */
+ { "ku_ara", 0 }, /* Kurdish, Arabic-Latin */
+ { "", 0 },
+};
+
+/* Iraq */
+static const XKB_VARIANT iq_variants[] = {
+ { "ku", 0 }, /* Kurdish, Latin Q */
+ { "ku_f", 0 }, /* Kurdish, (F) */
+ { "ku_alt", 0 }, /* Kurdish, Latin Alt-Q */
+ { "ku_ara", 0 }, /* Kurdish, Arabic-Latin */
+ { "", 0 },
+};
+
+/* Faroe Islands */
+static const XKB_VARIANT fo_variants[] = {
+ { "nodeadkeys", 0 }, /* Eliminate dead keys */
+ { "", 0 },
+};
+
+/* Finland */
+static const XKB_VARIANT fi_variants[] = {
+ { "nodeadkeys", 0 }, /* Eliminate dead keys */
+ { "smi", 0 }, /* Northern Saami */
+ { "classic", 0 }, /* Classic */
+ { "mac", 0 }, /* Macintosh */
+ { "", 0 },
+};
+
+/* France */
+static const XKB_VARIANT fr_variants[] = {
+ { "nodeadkeys", 0 }, /* Eliminate dead keys */
+ { "sundeadkeys", 0 }, /* Sun dead keys */
+ { "oss", 0 }, /* Alternative */
+ { "oss_latin9", 0 }, /* Alternative, latin-9 only */
+ { "oss_nodeadkeys", 0 }, /* Alternative, eliminate dead keys */
+ { "oss_sundeadkeys", 0 }, /* Alternative, Sun dead keys */
+ { "latin9", 0 }, /* (Legacy) Alternative */
+ { "latin9_nodeadkeys", 0 }, /* (Legacy) Alternative, eliminate dead keys */
+ { "latin9_sundeadkeys", 0 }, /* (Legacy) Alternative, Sun dead keys */
+ { "bepo", KBD_FRENCH_BEPO }, /* Bepo, ergonomic, Dvorak way */
+ { "bepo_latin9", 0 }, /* Bepo, ergonomic, Dvorak way, latin-9 only */
+ { "dvorak", 0 }, /* Dvorak */
+ { "mac", 0 }, /* Macintosh */
+ { "bre", 0 }, /* Breton */
+ { "oci", 0 }, /* Occitan */
+ { "geo", 0 }, /* Georgian AZERTY Tskapo */
+ { "", 0 },
+};
+
+/* Ghana */
+static const XKB_VARIANT gh_variants[] = {
+ { "generic", 0 }, /* Multilingual */
+ { "akan", 0 }, /* Akan */
+ { "ewe", 0 }, /* Ewe */
+ { "fula", 0 }, /* Fula */
+ { "ga", 0 }, /* Ga */
+ { "hausa", 0 }, /* Hausa */
+ { "", 0 },
+};
+
+/* Georgia */
+static const XKB_VARIANT ge_variants[] = {
+ { "ergonomic", 0 }, /* Ergonomic */
+ { "mess", 0 }, /* MESS */
+ { "ru", 0 }, /* Russian */
+ { "os", 0 }, /* Ossetian */
+ { "", 0 },
+};
+
+/* Germany */
+static const XKB_VARIANT de_variants[] = {
+ { "deadacute", KBD_GERMAN }, /* Dead acute */
+ { "deadgraveacute", KBD_GERMAN }, /* Dead grave acute */
+ { "nodeadkeys", KBD_GERMAN }, /* Eliminate dead keys */
+ { "ro", KBD_GERMAN }, /* Romanian keyboard with German letters */
+ { "ro_nodeadkeys",
+ KBD_GERMAN }, /* Romanian keyboard with German letters, eliminate dead keys */
+ { "dvorak", KBD_UNITED_STATES_DVORAK }, /* Dvorak */
+ { "sundeadkeys", KBD_GERMAN }, /* Sun dead keys */
+ { "neo", KBD_GERMAN_NEO }, /* Neo 2 */
+ { "mac", KBD_GERMAN }, /* Macintosh */
+ { "mac_nodeadkeys", KBD_GERMAN }, /* Macintosh, eliminate dead keys */
+ { "dsb", KBD_GERMAN }, /* Lower Sorbian */
+ { "dsb_qwertz", KBD_GERMAN }, /* Lower Sorbian (qwertz) */
+ { "qwerty", KBD_GERMAN_IBM }, /* qwerty */
+ { "", 0 },
+};
+
+/* Greece */
+static const XKB_VARIANT gr_variants[] = {
+ { "simple", KBD_GREEK_220 }, /* Simple */
+ { "extended", KBD_GREEK_319 }, /* Extended */
+ { "nodeadkeys", KBD_GREEK_319 }, /* Eliminate dead keys */
+ { "polytonic", KBD_GREEK_POLYTONIC }, /* Polytonic */
+ { "", 0 },
+};
+
+/* Hungary */
+static const XKB_VARIANT hu_variants[] = {
+ { "standard", KBD_HUNGARIAN_101_KEY }, /* Standard */
+ { "nodeadkeys", KBD_HUNGARIAN_101_KEY }, /* Eliminate dead keys */
+ { "qwerty", KBD_HUNGARIAN_101_KEY }, /* qwerty */
+ { "101_qwertz_comma_dead", KBD_HUNGARIAN_101_KEY }, /* 101/qwertz/comma/Dead keys */
+ { "101_qwertz_comma_nodead", KBD_HUNGARIAN_101_KEY }, /* 101/qwertz/comma/Eliminate dead keys */
+ { "101_qwertz_dot_dead", KBD_HUNGARIAN_101_KEY }, /* 101/qwertz/dot/Dead keys */
+ { "101_qwertz_dot_nodead", KBD_HUNGARIAN_101_KEY }, /* 101/qwertz/dot/Eliminate dead keys */
+ { "101_qwerty_comma_dead", KBD_HUNGARIAN_101_KEY }, /* 101/qwerty/comma/Dead keys */
+ { "101_qwerty_comma_nodead", KBD_HUNGARIAN_101_KEY }, /* 101/qwerty/comma/Eliminate dead keys */
+ { "101_qwerty_dot_dead", KBD_HUNGARIAN_101_KEY }, /* 101/qwerty/dot/Dead keys */
+ { "101_qwerty_dot_nodead", KBD_HUNGARIAN_101_KEY }, /* 101/qwerty/dot/Eliminate dead keys */
+ { "102_qwertz_comma_dead", KBD_HUNGARIAN_101_KEY }, /* 102/qwertz/comma/Dead keys */
+ { "102_qwertz_comma_nodead", KBD_HUNGARIAN_101_KEY }, /* 102/qwertz/comma/Eliminate dead keys */
+ { "102_qwertz_dot_dead", KBD_HUNGARIAN_101_KEY }, /* 102/qwertz/dot/Dead keys */
+ { "102_qwertz_dot_nodead", KBD_HUNGARIAN_101_KEY }, /* 102/qwertz/dot/Eliminate dead keys */
+ { "102_qwerty_comma_dead", KBD_HUNGARIAN_101_KEY }, /* 102/qwerty/comma/Dead keys */
+ { "102_qwerty_comma_nodead", KBD_HUNGARIAN_101_KEY }, /* 102/qwerty/comma/Eliminate dead keys */
+ { "102_qwerty_dot_dead", KBD_HUNGARIAN_101_KEY }, /* 102/qwerty/dot/Dead keys */
+ { "102_qwerty_dot_nodead", KBD_HUNGARIAN_101_KEY }, /* 102/qwerty/dot/Eliminate dead keys */
+ { "", 0 },
+};
+
+/* Iceland */
+static const XKB_VARIANT is_variants[] = {
+ { "Sundeadkeys", KBD_ICELANDIC }, /* Sun dead keys */
+ { "nodeadkeys", KBD_ICELANDIC }, /* Eliminate dead keys */
+ { "mac", KBD_ICELANDIC }, /* Macintosh */
+ { "dvorak", KBD_UNITED_STATES_DVORAK }, /* Dvorak */
+ { "", 0 },
+};
+
+/* Israel */
+static const XKB_VARIANT il_variants[] = {
+ { "lyx", KBD_HEBREW }, /* lyx */
+ { "phonetic", KBD_HEBREW }, /* Phonetic */
+ { "biblical", KBD_HEBREW }, /* Biblical Hebrew (Tiro) */
+ { "", 0 },
+};
+
+/* Italy */
+static const XKB_VARIANT it_variants[] = {
+ { "nodeadkeys", KBD_ITALIAN_142 }, /* Eliminate dead keys */
+ { "mac", KBD_ITALIAN }, /* Macintosh */
+ { "geo", KBD_GEORGIAN }, /* Georgian */
+ { "", 0 },
+};
+
+/* Japan */
+static const XKB_VARIANT jp_variants[] = {
+ { "kana", KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002 }, /* Kana */
+ { "OADG109A", KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002 }, /* OADG 109A */
+ { "", 0 },
+};
+
+/* Kyrgyzstan */
+static const XKB_VARIANT kg_variants[] = {
+ { "phonetic", KBD_KYRGYZ_CYRILLIC }, /* Phonetic */
+ { "", 0 },
+};
+
+/* Kazakhstan */
+static const XKB_VARIANT kz_variants[] = {
+ { "ruskaz", KBD_KAZAKH }, /* Russian with Kazakh */
+ { "kazrus", KBD_KAZAKH }, /* Kazakh with Russian */
+ { "", 0 },
+};
+
+/* Latin America */
+static const XKB_VARIANT latam_variants[] = {
+ { "nodeadkeys", KBD_LATIN_AMERICAN }, /* Eliminate dead keys */
+ { "deadtilde", KBD_LATIN_AMERICAN }, /* Include dead tilde */
+ { "sundeadkeys", KBD_LATIN_AMERICAN }, /* Sun dead keys */
+ { "", 0 },
+};
+
+/* Lithuania */
+static const XKB_VARIANT lt_variants[] = {
+ { "std", KBD_LITHUANIAN }, /* Standard */
+ { "us", KBD_LITHUANIAN_IBM }, /* US keyboard with Lithuanian letters */
+ { "ibm", KBD_LITHUANIAN_IBM }, /* IBM (LST 1205-92) */
+ { "lekp", KBD_LITHUANIAN }, /* LEKP */
+ { "lekpa", KBD_LITHUANIAN }, /* LEKPa */
+ { "balticplus", KBD_LITHUANIAN }, /* Baltic+ */
+ { "", 0 },
+};
+
+/* Latvia */
+static const XKB_VARIANT lv_variants[] = {
+ { "apostrophe", KBD_LATVIAN }, /* Apostrophe (') variant */
+ { "tilde", KBD_LATVIAN }, /* Tilde (~) variant */
+ { "fkey", KBD_LATVIAN }, /* F-letter (F) variant */
+ { "", 0 },
+};
+
+/* Montenegro */
+static const XKB_VARIANT me_variants[] = {
+ { "cyrillic", 0 }, /* Cyrillic */
+ { "cyrillicyz", 0 }, /* Cyrillic, Z and ZHE swapped */
+ { "latinunicode", 0 }, /* Latin unicode */
+ { "latinyz", 0 }, /* Latin qwerty */
+ { "latinunicodeyz", 0 }, /* Latin unicode qwerty */
+ { "cyrillicalternatequotes", 0 }, /* Cyrillic with guillemets */
+ { "latinalternatequotes", 0 }, /* Latin with guillemets */
+ { "", 0 },
+};
+
+/* Macedonia */
+static const XKB_VARIANT mk_variants[] = {
+ { "nodeadkeys", KBD_FYRO_MACEDONIAN }, /* Eliminate dead keys */
+ { "", 0 },
+};
+
+/* Malta */
+static const XKB_VARIANT mt_variants[] = {
+ { "us", KBD_MALTESE_48_KEY }, /* Maltese keyboard with US layout */
+ { "", 0 },
+};
+
+/* Norway */
+static const XKB_VARIANT no_variants[] = {
+ { "nodeadkeys", KBD_NORWEGIAN }, /* Eliminate dead keys */
+ { "dvorak", KBD_UNITED_STATES_DVORAK }, /* Dvorak */
+ { "smi", KBD_NORWEGIAN_WITH_SAMI }, /* Northern Saami */
+ { "smi_nodeadkeys", KBD_SAMI_EXTENDED_NORWAY }, /* Northern Saami, eliminate dead keys */
+ { "mac", KBD_NORWEGIAN }, /* Macintosh */
+ { "mac_nodeadkeys", KBD_SAMI_EXTENDED_NORWAY }, /* Macintosh, eliminate dead keys */
+ { "", 0 },
+};
+
+/* Poland */
+static const XKB_VARIANT pl_variants[] = {
+ { "qwertz", KBD_POLISH_214 }, /* qwertz */
+ { "dvorak", KBD_UNITED_STATES_DVORAK }, /* Dvorak */
+ { "dvorak_quotes", KBD_UNITED_STATES_DVORAK }, /* Dvorak, Polish quotes on quotemark key */
+ { "dvorak_altquotes", KBD_UNITED_STATES_DVORAK }, /* Dvorak, Polish quotes on key 1 */
+ { "csb", 0 }, /* Kashubian */
+ { "ru_phonetic_dvorak", KBD_UNITED_STATES_DVORAK }, /* Russian phonetic Dvorak */
+ { "", 0 },
+};
+
+/* Portugal */
+static const XKB_VARIANT pt_variants[] = {
+ { "nodeadkeys", KBD_PORTUGUESE }, /* Eliminate dead keys */
+ { "sundeadkeys", KBD_PORTUGUESE }, /* Sun dead keys */
+ { "mac", KBD_PORTUGUESE }, /* Macintosh */
+ { "mac_nodeadkeys", KBD_PORTUGUESE }, /* Macintosh, eliminate dead keys */
+ { "mac_sundeadkeys", KBD_PORTUGUESE }, /* Macintosh, Sun dead keys */
+ { "nativo", KBD_PORTUGUESE }, /* Nativo */
+ { "nativo-us", KBD_PORTUGUESE }, /* Nativo for USA keyboards */
+ { "nativo-epo", KBD_PORTUGUESE }, /* Nativo for Esperanto */
+ { "", 0 },
+};
+
+/* Romania */
+static const XKB_VARIANT ro_variants[] = {
+ { "cedilla", KBD_ROMANIAN }, /* Cedilla */
+ { "std", KBD_ROMANIAN }, /* Standard */
+ { "std_cedilla", KBD_ROMANIAN }, /* Standard (Cedilla) */
+ { "winkeys", KBD_ROMANIAN }, /* Winkeys */
+ { "crh_f", KBD_TURKISH_F }, /* Crimean Tatar (Turkish F) */
+ { "crh_alt", KBD_TURKISH_Q }, /* Crimean Tatar (Turkish Alt-Q) */
+ { "crh_dobruca1", KBD_TATAR }, /* Crimean Tatar (Dobruca-1 Q) */
+ { "crh_dobruca2", KBD_TATAR }, /* Crimean Tatar (Dobruca-2 Q) */
+ { "", 0 },
+};
+
+/* Russia */
+static const XKB_VARIANT ru_variants[] = {
+ { "phonetic", KBD_RUSSIAN }, /* Phonetic */
+ { "phonetic_winkeys", KBD_RUSSIAN }, /* Phonetic Winkeys */
+ { "typewriter", KBD_RUSSIAN_TYPEWRITER }, /* Typewriter */
+ { "legacy", KBD_RUSSIAN }, /* Legacy */
+ { "tt", KBD_TATAR }, /* Tatar */
+ { "os_legacy", 0 }, /* Ossetian, legacy */
+ { "os_winkeys", 0 }, /* Ossetian, Winkeys */
+ { "cv", 0 }, /* Chuvash */
+ { "cv_latin", 0 }, /* Chuvash Latin */
+ { "udm", 0 }, /* Udmurt */
+ { "kom", 0 }, /* Komi */
+ { "sah", 0 }, /* Yakut */
+ { "xal", 0 }, /* Kalmyk */
+ { "dos", 0 }, /* DOS */
+ { "", 0 },
+};
+
+/* Serbia */
+static const XKB_VARIANT rs_variants[] = {
+ { "yz", KBD_SERBIAN_CYRILLIC }, /* Z and ZHE swapped */
+ { "latin", KBD_SERBIAN_LATIN }, /* Latin */
+ { "latinunicode", KBD_SERBIAN_LATIN }, /* Latin Unicode */
+ { "latinyz", KBD_SERBIAN_LATIN }, /* Latin qwerty */
+ { "latinunicodeyz", KBD_SERBIAN_LATIN }, /* Latin Unicode qwerty */
+ { "alternatequotes", KBD_SERBIAN_CYRILLIC }, /* With guillemets */
+ { "latinalternatequotes", KBD_SERBIAN_LATIN }, /* Latin with guillemets */
+ { "", 0 },
+};
+
+/* Slovenia */
+static const XKB_VARIANT si_variants[] = {
+ { "alternatequotes", KBD_SLOVENIAN }, /* Use guillemets for quotes */
+ { "us", KBD_UNITED_STATES_INTERNATIONAL }, /* US keyboard with Slovenian letters */
+ { "", 0 },
+};
+
+/* Slovakia */
+static const XKB_VARIANT sk_variants[] = {
+ { "bksl", KBD_SLOVAK }, /* Extended Backslash */
+ { "qwerty", KBD_SLOVAK_QWERTY }, /* qwerty */
+ { "qwerty_bksl", KBD_SLOVAK_QWERTY }, /* qwerty, extended Backslash */
+ { "", 0 },
+};
+
+/* Spain */
+static const XKB_VARIANT es_variants[] = {
+ { "nodeadkeys", KBD_SPANISH_VARIATION }, /* Eliminate dead keys */
+ { "deadtilde", KBD_SPANISH_VARIATION }, /* Include dead tilde */
+ { "sundeadkeys", KBD_SPANISH }, /* Sun dead keys */
+ { "dvorak", KBD_UNITED_STATES_DVORAK }, /* Dvorak */
+ { "ast", KBD_SPANISH_VARIATION }, /* Asturian variant with bottom-dot H and bottom-dot L */
+ { "cat", KBD_SPANISH_VARIATION }, /* Catalan variant with middle-dot L */
+ { "mac", KBD_SPANISH }, /* Macintosh */
+ { "", 0 },
+};
+
+/* Sweden */
+static const XKB_VARIANT se_variants[] = {
+ { "nodeadkeys", KBD_SWEDISH }, /* Eliminate dead keys */
+ { "dvorak", KBD_UNITED_STATES_DVORAK }, /* Dvorak */
+ { "rus", KBD_RUSSIAN }, /* Russian phonetic */
+ { "rus_nodeadkeys", KBD_RUSSIAN }, /* Russian phonetic, eliminate dead keys */
+ { "smi", KBD_SWEDISH_WITH_SAMI }, /* Northern Saami */
+ { "mac", KBD_SWEDISH }, /* Macintosh */
+ { "svdvorak", KBD_UNITED_STATES_DVORAK }, /* Svdvorak */
+ { "", 0 },
+};
+
+/* Switzerland */
+static const XKB_VARIANT ch_variants[] = {
+ { "de_nodeadkeys", KBD_SWISS_GERMAN }, /* German, eliminate dead keys */
+ { "de_sundeadkeys", KBD_SWISS_GERMAN }, /* German, Sun dead keys */
+ { "fr", KBD_SWISS_FRENCH }, /* French */
+ { "fr_nodeadkeys", KBD_SWISS_FRENCH }, /* French, eliminate dead keys */
+ { "fr_sundeadkeys", KBD_SWISS_FRENCH }, /* French, Sun dead keys */
+ { "fr_mac", KBD_SWISS_FRENCH }, /* French (Macintosh) */
+ { "de_mac", KBD_SWISS_GERMAN }, /* German (Macintosh) */
+ { "", 0 },
+};
+
+/* Syria */
+static const XKB_VARIANT sy_variants[] = {
+ { "syc", KBD_SYRIAC }, /* Syriac */
+ { "syc_phonetic", KBD_SYRIAC_PHONETIC }, /* Syriac phonetic */
+ { "ku", 0 }, /* Kurdish, Latin Q */
+ { "ku_f", 0 }, /* Kurdish, (F) */
+ { "ku_alt", 0 }, /* Kurdish, Latin Alt-Q */
+ { "", 0 },
+};
+
+/* Tajikistan */
+static const XKB_VARIANT tj_variants[] = {
+ { "legacy", 0 }, /* Legacy */
+ { "", 0 },
+};
+
+/* Sri Lanka */
+static const XKB_VARIANT lk_variants[] = {
+ { "tam_unicode", KBD_TAMIL }, /* Tamil Unicode */
+ { "tam_TAB", KBD_TAMIL }, /* Tamil TAB Typewriter */
+ { "", 0 },
+};
+
+/* Thailand */
+static const XKB_VARIANT th_variants[] = {
+ { "tis", KBD_THAI_KEDMANEE_NON_SHIFTLOCK }, /* TIS-820.2538 */
+ { "pat", KBD_THAI_PATTACHOTE }, /* Pattachote */
+ { "", 0 },
+};
+
+/* Turkey */
+static const XKB_VARIANT tr_variants[] = {
+ { "f", KBD_TURKISH_F }, /* (F) */
+ { "alt", KBD_TURKISH_Q }, /* Alt-Q */
+ { "sundeadkeys", KBD_TURKISH_F }, /* Sun dead keys */
+ { "ku", 0 }, /* Kurdish, Latin Q */
+ { "ku_f", 0 }, /* Kurdish, (F) */
+ { "ku_alt", 0 }, /* Kurdish, Latin Alt-Q */
+ { "intl", KBD_TURKISH_F }, /* International (with dead keys) */
+ { "crh", KBD_TATAR }, /* Crimean Tatar (Turkish Q) */
+ { "crh_f", KBD_TURKISH_F }, /* Crimean Tatar (Turkish F) */
+ { "crh_alt", KBD_TURKISH_Q }, /* Crimean Tatar (Turkish Alt-Q) */
+ { "", 0 },
+};
+
+/* Ukraine */
+static const XKB_VARIANT ua_variants[] = {
+ { "phonetic", KBD_UKRAINIAN }, /* Phonetic */
+ { "typewriter", KBD_UKRAINIAN }, /* Typewriter */
+ { "winkeys", KBD_UKRAINIAN }, /* Winkeys */
+ { "legacy", KBD_UKRAINIAN }, /* Legacy */
+ { "rstu", KBD_UKRAINIAN }, /* Standard RSTU */
+ { "rstu_ru", KBD_UKRAINIAN }, /* Standard RSTU on Russian layout */
+ { "homophonic", KBD_UKRAINIAN }, /* Homophonic */
+ { "crh", KBD_TATAR }, /* Crimean Tatar (Turkish Q) */
+ { "crh_f", KBD_TURKISH_F }, /* Crimean Tatar (Turkish F) */
+ { "crh_alt", KBD_TURKISH_Q }, /* Crimean Tatar (Turkish Alt-Q) */
+ { "", 0 },
+};
+
+/* United Kingdom */
+static const XKB_VARIANT gb_variants[] = {
+ { "extd", KBD_UNITED_KINGDOM_EXTENDED }, /* Extended - Winkeys */
+ { "intl", KBD_UNITED_KINGDOM_EXTENDED }, /* International (with dead keys) */
+ { "dvorak", KBD_UNITED_STATES_DVORAK }, /* Dvorak */
+ { "dvorakukp", KBD_UNITED_STATES_DVORAK }, /* Dvorak (UK Punctuation) */
+ { "mac", KBD_UNITED_KINGDOM }, /* Macintosh */
+ { "colemak", 0 }, /* Colemak */
+ { "", 0 },
+};
+
+/* Uzbekistan */
+static const XKB_VARIANT uz_variants[] = {
+ { "latin", 0 }, /* Latin */
+ { "crh", KBD_TATAR }, /* Crimean Tatar (Turkish Q) */
+ { "crh_f", KBD_TURKISH_F }, /* Crimean Tatar (Turkish F) */
+ { "crh_alt", KBD_TURKISH_Q }, /* Crimean Tatar (Turkish Alt-Q) */
+ { "", 0 },
+};
+
+/* Korea, Republic of */
+static const XKB_VARIANT kr_variants[] = {
+ { "kr104", KBD_KOREAN_INPUT_SYSTEM_IME_2000 }, /* 101/104 key Compatible */
+ { "", 0 },
+};
+
+/* Ireland */
+static const XKB_VARIANT ie_variants[] = {
+ { "CloGaelach", KBD_GAELIC }, /* CloGaelach */
+ { "UnicodeExpert", KBD_GAELIC }, /* UnicodeExpert */
+ { "ogam", KBD_GAELIC }, /* Ogham */
+ { "ogam_is434", KBD_GAELIC }, /* Ogham IS434 */
+ { "", 0 },
+};
+
+/* Pakistan */
+static const XKB_VARIANT pk_variants[] = {
+ { "urd-crulp", 0 }, /* CRULP */
+ { "urd-nla", 0 }, /* NLA */
+ { "ara", KBD_ARABIC_101 }, /* Arabic */
+ { "", 0 },
+};
+
+/* Esperanto */
+static const XKB_VARIANT epo_variants[] = {
+ { "legacy", 0 }, /* displaced semicolon and quote (obsolete) */
+ { "", 0 },
+};
+
+/* Nigeria */
+static const XKB_VARIANT ng_variants[] = {
+ { "igbo", 0 }, /* Igbo */
+ { "yoruba", 0 }, /* Yoruba */
+ { "hausa", 0 }, /* Hausa */
+ { "", 0 },
+};
+
+/* Braille */
+static const XKB_VARIANT brai_variants[] = {
+ { "left_hand", 0 }, /* Left hand */
+ { "right_hand", 0 }, /* Right hand */
+ { "", 0 },
+};
+
+/* Turkmenistan */
+static const XKB_VARIANT tm_variants[] = {
+ { "alt", KBD_TURKISH_Q }, /* Alt-Q */
+ { "", 0 },
+};
+
+static const XKB_LAYOUT xkbLayouts[] = {
+ { "us", KBD_US, us_variants }, /* USA */
+ { "ad", 0, NULL }, /* Andorra */
+ { "af", KBD_FARSI, af_variants }, /* Afghanistan */
+ { "ara", KBD_ARABIC_101, ara_variants }, /* Arabic */
+ { "al", 0, NULL }, /* Albania */
+ { "am", KBD_ARMENIAN_EASTERN, am_variants }, /* Armenia */
+ { "az", KBD_AZERI_CYRILLIC, az_variants }, /* Azerbaijan */
+ { "by", KBD_BELARUSIAN, by_variants }, /* Belarus */
+ { "be", KBD_BELGIAN_FRENCH, be_variants }, /* Belgium */
+ { "bd", KBD_BENGALI, bd_variants }, /* Bangladesh */
+ { "in", KBD_HINDI_TRADITIONAL, in_variants }, /* India */
+ { "ba", KBD_CROATIAN, ba_variants }, /* Bosnia and Herzegovina */
+ { "br", KBD_PORTUGUESE_BRAZILIAN_ABNT, br_variants }, /* Brazil */
+ { "bg", KBD_BULGARIAN_LATIN, bg_variants }, /* Bulgaria */
+ { "ma", KBD_FRENCH, ma_variants }, /* Morocco */
+ { "mm", 0, NULL }, /* Myanmar */
+ { "ca", KBD_US, ca_variants }, /* Canada */
+ { "cd", 0, NULL }, /* Congo, Democratic Republic of the */
+ { "cn", KBD_CHINESE_TRADITIONAL_PHONETIC, cn_variants }, /* China */
+ { "hr", KBD_CROATIAN, hr_variants }, /* Croatia */
+ { "cz", KBD_CZECH, cz_variants }, /* Czechia */
+ { "dk", KBD_DANISH, dk_variants }, /* Denmark */
+ { "nl", KBD_DUTCH, nl_variants }, /* Netherlands */
+ { "bt", 0, NULL }, /* Bhutan */
+ { "ee", KBD_ESTONIAN, ee_variants }, /* Estonia */
+ { "ir", 0, ir_variants }, /* Iran */
+ { "iq", 0, iq_variants }, /* Iraq */
+ { "fo", 0, fo_variants }, /* Faroe Islands */
+ { "fi", KBD_FINNISH, fi_variants }, /* Finland */
+ { "fr", KBD_FRENCH, fr_variants }, /* France */
+ { "gh", 0, gh_variants }, /* Ghana */
+ { "gn", 0, NULL }, /* Guinea */
+ { "ge", KBD_GEORGIAN, ge_variants }, /* Georgia */
+ { "at", KBD_GERMAN, de_variants }, /* Austria */
+ { "de", KBD_GERMAN, de_variants }, /* Germany */
+ { "gr", KBD_GREEK, gr_variants }, /* Greece */
+ { "hu", KBD_HUNGARIAN, hu_variants }, /* Hungary */
+ { "is", KBD_ICELANDIC, is_variants }, /* Iceland */
+ { "il", KBD_HEBREW, il_variants }, /* Israel */
+ { "it", KBD_ITALIAN, it_variants }, /* Italy */
+ { "jp", KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002, jp_variants }, /* Japan */
+ { "kg", 0, kg_variants }, /* Kyrgyzstan */
+ { "kh", 0, NULL }, /* Cambodia */
+ { "kz", KBD_KAZAKH, kz_variants }, /* Kazakhstan */
+ { "la", 0, NULL }, /* Laos */
+ { "latam", KBD_LATIN_AMERICAN, latam_variants }, /* Latin America */
+ { "lt", KBD_LITHUANIAN, lt_variants }, /* Lithuania */
+ { "lv", KBD_LATVIAN, lv_variants }, /* Latvia */
+ { "mao", KBD_MAORI, NULL }, /* Maori */
+ { "me", KBD_SERBIAN_LATIN, me_variants }, /* Montenegro */
+ { "mk", KBD_FYRO_MACEDONIAN, mk_variants }, /* Macedonia */
+ { "mt", KBD_MALTESE_48_KEY, mt_variants }, /* Malta */
+ { "mn", KBD_MONGOLIAN_CYRILLIC, NULL }, /* Mongolia */
+ { "no", KBD_NORWEGIAN, no_variants }, /* Norway */
+ { "pl", KBD_POLISH_PROGRAMMERS, pl_variants }, /* Poland */
+ { "pt", KBD_PORTUGUESE, pt_variants }, /* Portugal */
+ { "ro", KBD_ROMANIAN, ro_variants }, /* Romania */
+ { "ru", KBD_RUSSIAN, ru_variants }, /* Russia */
+ { "rs", KBD_SERBIAN_LATIN, rs_variants }, /* Serbia */
+ { "si", KBD_SLOVENIAN, si_variants }, /* Slovenia */
+ { "sk", KBD_SLOVAK, sk_variants }, /* Slovakia */
+ { "es", KBD_SPANISH, es_variants }, /* Spain */
+ { "se", KBD_SWEDISH, se_variants }, /* Sweden */
+ { "ch", KBD_SWISS_GERMAN, ch_variants }, /* Switzerland */
+ { "sy", KBD_SYRIAC, sy_variants }, /* Syria */
+ { "tj", 0, tj_variants }, /* Tajikistan */
+ { "lk", 0, lk_variants }, /* Sri Lanka */
+ { "th", KBD_THAI_KEDMANEE, th_variants }, /* Thailand */
+ { "tr", KBD_TURKISH_Q, tr_variants }, /* Turkey */
+ { "ua", KBD_UKRAINIAN, ua_variants }, /* Ukraine */
+ { "gb", KBD_UNITED_KINGDOM, gb_variants }, /* United Kingdom */
+ { "uz", KBD_UZBEK_CYRILLIC, uz_variants }, /* Uzbekistan */
+ { "vn", KBD_VIETNAMESE, NULL }, /* Vietnam */
+ { "kr", KBD_KOREAN_INPUT_SYSTEM_IME_2000, kr_variants }, /* Korea, Republic of */
+ { "ie", KBD_UNITED_KINGDOM, ie_variants }, /* Ireland */
+ { "pk", 0, pk_variants }, /* Pakistan */
+ { "mv", 0, NULL }, /* Maldives */
+ { "za", KBD_US, NULL }, /* South Africa */
+ { "epo", 0, epo_variants }, /* Esperanto */
+ { "np", KBD_NEPALI, NULL }, /* Nepal */
+ { "ng", 0, ng_variants }, /* Nigeria */
+ { "et", 0, NULL }, /* Ethiopia */
+ { "sn", 0, NULL }, /* Senegal */
+ { "brai", 0, brai_variants }, /* Braille */
+ { "tm", KBD_TURKISH_Q, tm_variants }, /* Turkmenistan */
+};
+
+static UINT32 find_keyboard_layout_variant(const XKB_LAYOUT* layout, const char* variant)
+{
+ WINPR_ASSERT(layout);
+ WINPR_ASSERT(variant);
+
+ const XKB_VARIANT* variants = layout->variants;
+ if (variants)
+ {
+ const XKB_VARIANT* var = variants;
+ while (var->variant && (strlen(var->variant) != 0))
+ {
+ if (strcmp(var->variant, variant) == 0)
+ return var->keyboardLayoutID;
+ var++;
+ }
+ }
+
+ return layout->keyboardLayoutID;
+}
+
+UINT32 find_keyboard_layout_in_xorg_rules(const char* layout, const char* variant)
+{
+ if ((layout == NULL) || (variant == NULL))
+ return 0;
+
+ DEBUG_KBD("xkbLayout: %s\txkbVariant: %s", layout, variant);
+
+ for (size_t i = 0; i < ARRAYSIZE(xkbLayouts); i++)
+ {
+ const XKB_LAYOUT* cur = &xkbLayouts[i];
+ if (strcmp(cur->layout, layout) == 0)
+ return find_keyboard_layout_variant(cur, variant);
+ }
+
+ return 0;
+}
diff --git a/libfreerdp/locale/xkb_layout_ids.h b/libfreerdp/locale/xkb_layout_ids.h
new file mode 100644
index 0000000..e9c6b27
--- /dev/null
+++ b/libfreerdp/locale/xkb_layout_ids.h
@@ -0,0 +1,28 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * RDP Keyboard layout ID detection from common X11 xkb keyboard layout names
+ *
+ * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FREERDP_LIB_LOCALE_XKB_LAYOUT_IDS_H
+#define FREERDP_LIB_LOCALE_XKB_LAYOUT_IDS_H
+
+#include <freerdp/types.h>
+#include <freerdp/api.h>
+
+FREERDP_LOCAL UINT32 find_keyboard_layout_in_xorg_rules(const char* layout, const char* variant);
+
+#endif /* FREERDP_LIB_LOCALE_XKB_LAYOUT_IDS_H */