From: Rémi Bernon <rbernon@codeweavers.com> --- dlls/winemac.drv/keyboard.c | 54 +++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/dlls/winemac.drv/keyboard.c b/dlls/winemac.drv/keyboard.c index 7c49be7849f..281dd555246 100644 --- a/dlls/winemac.drv/keyboard.c +++ b/dlls/winemac.drv/keyboard.c @@ -313,7 +313,9 @@ static struct list layout_list = LIST_INIT( layout_list ); struct layout { struct list entry; - HKL hkl; + LANGID lang; + /* "Layout Id", used by NtUserGetKeyboardLayoutName / LoadKeyboardLayoutW */ + WORD layout_id; TISInputSourceRef input_source; BOOL enabled; /* is the input source enabled - ie displayed in the input source selector UI */ }; @@ -412,27 +414,10 @@ static DWORD get_lcid(CFStringRef lang) return locale->inotneutral ? entry->id : locale->idefaultlanguage; } -static HKL get_hkl(CFStringRef lang, CFStringRef type) +static HKL get_layout_hkl(struct layout *layout, LCID locale) { - ULONG_PTR lcid = get_lcid(lang); - struct layout *layout; - - /* Look for the last occurrence of this lcid in the list and if - present use that value + 0x10000 */ - LIST_FOR_EACH_ENTRY_REV(layout, &layout_list, struct layout, entry) - { - ULONG_PTR hkl = HandleToUlong(layout->hkl); - - if (LOWORD(hkl) == lcid) - { - lcid = (hkl & ~0xe0000000) + 0x10000; - break; - } - } - - if (!CFEqual(type, kTISTypeKeyboardLayout)) lcid |= 0xe0000000; - - return (HKL)lcid; + if (!layout->layout_id) return UlongToHandle(MAKELONG(locale, layout->lang)); + return UlongToHandle(MAKELONG(locale, layout->layout_id)); } /****************************************************************** @@ -468,6 +453,7 @@ static struct layout *get_layout_from_source(TISInputSourceRef input) */ static void update_layout_list(void) { + LCID locale = LOWORD(NtUserGetKeyboardLayout(0)); CFArrayRef sources; struct layout *layout; int i; @@ -486,18 +472,26 @@ static void update_layout_list(void) layout = get_layout_from_source(input); if (!layout) { + static WORD next_layout_id = 1; + CFStringRef type = CFDictionaryGetValue(dict, macdrv_input_source_type_key); - CFStringRef lang = CFDictionaryGetValue(dict, macdrv_input_source_lang_key); + LANGID lang = get_lcid(CFDictionaryGetValue(dict, macdrv_input_source_lang_key)); + UINT index = 0; + + LIST_FOR_EACH_ENTRY_REV(layout, &layout_list, struct layout, entry) + if (layout->lang == lang) index++; - layout = malloc(sizeof(*layout)); + layout = calloc(1, sizeof(*layout)); layout->input_source = (TISInputSourceRef)CFRetain(input); - layout->hkl = get_hkl(lang, type); + layout->lang = lang; + if (!CFEqual(type, kTISTypeKeyboardLayout)) layout->layout_id = 0xe000 | next_layout_id++; + else if (index) layout->layout_id = 0xf000 | next_layout_id++; list_add_tail(&layout_list, &layout->entry); - TRACE("adding new layout %p\n", layout->hkl); + TRACE("adding new layout %p\n", get_layout_hkl(layout, locale)); } else - TRACE("enabling already existing layout %p\n", layout->hkl); + TRACE("enabling already existing layout %p\n", get_layout_hkl(layout, locale)); layout->enabled = TRUE; } @@ -512,6 +506,7 @@ static void update_layout_list(void) */ HKL macdrv_get_hkl_from_source(TISInputSourceRef input) { + LCID locale = LOWORD(NtUserGetKeyboardLayout(0)); struct layout *layout; HKL ret = 0; @@ -519,7 +514,7 @@ HKL macdrv_get_hkl_from_source(TISInputSourceRef input) update_layout_list(); layout = get_layout_from_source(input); - if (layout) ret = layout->hkl; + if (layout) ret = get_layout_hkl(layout, locale); pthread_mutex_unlock(&layout_list_mutex); @@ -1165,7 +1160,7 @@ BOOL macdrv_ActivateKeyboardLayout(HKL hkl, UINT flags) LIST_FOR_EACH_ENTRY(layout, &layout_list, struct layout, entry) { - if (layout->hkl == hkl) + if (HIWORD(hkl) == layout->layout_id ? layout->layout_id : layout->lang) { if (macdrv_select_input_source(layout->input_source)) { @@ -1302,6 +1297,7 @@ INT macdrv_GetKeyNameText(LONG lparam, LPWSTR buffer, INT size) */ UINT macdrv_GetKeyboardLayoutList(INT size, HKL *list) { + LCID locale = LOWORD(NtUserGetKeyboardLayout(0)); int count = 0; struct layout *layout; @@ -1317,7 +1313,7 @@ UINT macdrv_GetKeyboardLayoutList(INT size, HKL *list) if (list) { if (count >= size) break; - list[count] = layout->hkl; + list[count] = get_layout_hkl(layout, locale); TRACE("\t%d: %p\n", count, list[count]); } count++; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10138