X11 keycodes are just Linux keycodes + 8 nowadays according to evdev or libinput drivers, and we can avoid innacurate reconstruction in the most common case.
Opening this as a draft for now, to show where I'd like to go with https://gitlab.winehq.org/wine/wine/-/merge_requests/2062.
-- v2: winex11: Use KbdLayerDescriptor for ToUnicodeEx. win32u: Force US layout in ToUnicode when CTRL is pressed. winex11: Use KbdLayerDescriptor for VkKeyScanEx. winex11: Use KbdLayerDescriptor for MAPVK_VK_TO_CHAR. winex11: Fill the Xkb layout KBDTABLES VkToWchar tables. winex11: Use KbdLayerDescriptor for GetKeyNameText. winex11: Fill the Xkb layout KBDTABLES KeyNames tables. winex11: Use KbdLayerDescriptor for MapVirtualKeyEx. winex11: Create KBDTABLES with VSCtoVK tables for Xkb layouts. winex11: Lookup xkb layout in KbdLayerDescriptor. win32u: Introduce KbdLayerDescriptor user driver entry. winex11: Get rid of now unnecessary EVENT_event_to_vkey. server: Convert CTRL + VK_PAUSE to VK_CANCEL. winex11: Drop now unnecessray nonchar_key_vkey table. winex11: Drop now unnecessary keyboard layout detection code. winex11: Use static scan code to vkey mapping tables. winex11: Support fixed X11 keycode to scancode conversion. winex11: Use scancode high bit to set KEYEVENTF_EXTENDEDKEY flag. winex11: Don't update the keyboard layouts on MappingNotify. winex11: Stop sending WM_INPUTLANGCHANGEREQUEST on MappingNotify. winex11: Send WM_INPUTLANGCHANGEREQUEST when Xkb group changes. winex11: Compute Xkb keyboard layout ID and language. winex11: Keep a list of every known Xkb keyboard layout. winex11: Read the _XKB_RULES_NAMES root window property. winex11: Listen to _XKB_RULES_NAMES root window property changes. win32u: Init vsc2char in NtUserMapVirtualKeyEx only if necessary. win32u: Init vsc2vk in NtUserMapVirtualKeyEx only if necessary. win32u: Init vsc2vk in NtUserGetKeyNameText only if necessary.
This merge request has too many patches to be relayed via email. Please visit the URL below to see the contents of the merge request. https://gitlab.winehq.org/wine/wine/-/merge_requests/2122
Rebased and updated with an (hopefully) improved version, which now unconditionally uses fixed keycode to scancode mapping, as well as static scancode to vkey mapping tables.
The Xkb layouts are also all translated into KBDTABLES and exposed to win32u through a new KbdLayerDescriptor driver entry point, instead of all the individual mapping callbacks. The various Win32 keyboard mapping functions are now implemented using KBDTABLES only.
It includes most of https://gitlab.winehq.org/wine/wine/-/merge_requests/2408, except for the registry entries, which are probably not very useful and were subject to race conditions in that MR. This allow us to completely drop the old and bogus keyboard layout detection code, and properly detect the layouts from Xkb rules.
This should also support Win32 keyboard layout activation, when Xkb group changes (which happens when switching to another Linux keyboard layout, within the active group of 4 layout that are mapped together, and pressing a key), as well as when Xkb rules are changed (when more than 4 layouts are used and the active group of 4 layouts is changed).