diff --git a/dlls/winemac.drv/cocoa_app.m b/dlls/winemac.drv/cocoa_app.m index 284023b755f..af5687279c1 100644 --- a/dlls/winemac.drv/cocoa_app.m +++ b/dlls/winemac.drv/cocoa_app.m @@ -374,15 +374,15 @@ - (void) windowRejectedFocusEvent:(const macdrv_event*)event - (void) keyboardSelectionDidChange { - TISInputSourceRef inputSource; + TISInputSourceRef inputSourceLayout; inputSourceIsInputMethodValid = FALSE; - inputSource = TISCopyCurrentKeyboardLayoutInputSource(); - if (inputSource) + inputSourceLayout = TISCopyCurrentKeyboardLayoutInputSource(); + if (inputSourceLayout) { CFDataRef uchr; - uchr = TISGetInputSourceProperty(inputSource, + uchr = TISGetInputSourceProperty(inputSourceLayout, kTISPropertyUnicodeKeyLayoutData); if (uchr) { @@ -393,6 +393,7 @@ - (void) keyboardSelectionDidChange event->keyboard_changed.keyboard_type = self.keyboardType; event->keyboard_changed.iso_keyboard = (KBGetLayoutType(self.keyboardType) == kKeyboardISO); event->keyboard_changed.uchr = CFDataCreateCopy(NULL, uchr); + event->keyboard_changed.input_source = TISCopyCurrentKeyboardInputSource(); if (event->keyboard_changed.uchr) { @@ -407,7 +408,7 @@ - (void) keyboardSelectionDidChange macdrv_release_event(event); } - CFRelease(inputSource); + CFRelease(inputSourceLayout); } } @@ -2218,31 +2219,28 @@ void macdrv_window_rejected_focus(const macdrv_event *event) } /*********************************************************************** - * macdrv_get_keyboard_layout + * macdrv_get_input_source_info * - * Returns the keyboard layout uchr data. + * Returns the keyboard layout uchr data, keyboard type and input source. */ -CFDataRef macdrv_copy_keyboard_layout(CGEventSourceKeyboardType* keyboard_type, int* is_iso) +void macdrv_get_input_source_info(CFDataRef* uchr, CGEventSourceKeyboardType* keyboard_type, int* is_iso, TISInputSourceRef* input_source) { - __block CFDataRef result = NULL; - OnMainThread(^{ - TISInputSourceRef inputSource; + TISInputSourceRef inputSourceLayout; - inputSource = TISCopyCurrentKeyboardLayoutInputSource(); - if (inputSource) + inputSourceLayout = TISCopyCurrentKeyboardLayoutInputSource(); + if (inputSourceLayout) { - CFDataRef uchr = TISGetInputSourceProperty(inputSource, + CFDataRef data = TISGetInputSourceProperty(inputSourceLayout, kTISPropertyUnicodeKeyLayoutData); - result = CFDataCreateCopy(NULL, uchr); - CFRelease(inputSource); + *uchr = CFDataCreateCopy(NULL, data); + CFRelease(inputSourceLayout); *keyboard_type = [WineApplicationController sharedController].keyboardType; *is_iso = (KBGetLayoutType(*keyboard_type) == kKeyboardISO); + *input_source = TISCopyCurrentKeyboardInputSource(); } }); - - return result; } /*********************************************************************** diff --git a/dlls/winemac.drv/cocoa_event.m b/dlls/winemac.drv/cocoa_event.m index 13f96953fdb..00f6f8e6fb3 100644 --- a/dlls/winemac.drv/cocoa_event.m +++ b/dlls/winemac.drv/cocoa_event.m @@ -641,6 +641,7 @@ void macdrv_release_event(macdrv_event *event) break; case KEYBOARD_CHANGED: CFRelease(event->keyboard_changed.uchr); + CFRelease(event->keyboard_changed.input_source); break; case QUERY_EVENT: macdrv_release_query(event->query_event.query); diff --git a/dlls/winemac.drv/keyboard.c b/dlls/winemac.drv/keyboard.c index 52f97da376c..cc0df4e8f7d 100644 --- a/dlls/winemac.drv/keyboard.c +++ b/dlls/winemac.drv/keyboard.c @@ -554,6 +554,28 @@ static void update_layout_list(void) CFRelease(sources); } +/*********************************************************************** + * macdrv_get_hkl_from_source + * + * Find the HKL associated with a given input source. + */ +HKL macdrv_get_hkl_from_source(TISInputSourceRef input) +{ + struct layout *layout; + HKL ret = 0; + + EnterCriticalSection(&layout_list_section); + + update_layout_list(); + layout = get_layout_from_source(input); + if (layout) ret = layout->hkl; + + LeaveCriticalSection(&layout_list_section); + + return ret; +} + + /*********************************************************************** * macdrv_compute_keyboard_layout */ @@ -1027,6 +1049,7 @@ void macdrv_keyboard_changed(const macdrv_event *event) thread_data->keyboard_layout_uchr = CFDataCreateCopy(NULL, event->keyboard_changed.uchr); thread_data->keyboard_type = event->keyboard_changed.keyboard_type; thread_data->iso_keyboard = event->keyboard_changed.iso_keyboard; + thread_data->active_keyboard_layout = macdrv_get_hkl_from_source(event->keyboard_changed.input_source); thread_data->dead_key_state = 0; macdrv_compute_keyboard_layout(thread_data); @@ -1327,22 +1350,10 @@ INT CDECL macdrv_GetKeyNameText(LONG lparam, LPWSTR buffer, INT size) */ HKL CDECL macdrv_GetKeyboardLayout(DWORD thread_id) { - if (!thread_id || thread_id == GetCurrentThreadId()) - { - struct macdrv_thread_data *thread_data = macdrv_thread_data(); - if (thread_data && thread_data->active_keyboard_layout) - return thread_data->active_keyboard_layout; - } - else + if (thread_id && thread_id != GetCurrentThreadId()) FIXME("couldn't return keyboard layout for thread %04x\n", thread_id); - /* FIXME: Use TISGetInputSourceProperty() and kTISPropertyInputSourceLanguages - * to get input source language ID string. Use - * CFLocaleGetWindowsLocaleCodeFromLocaleIdentifier() to convert that - * to a Windows locale ID and from there to a layout handle. - */ - - return get_locale_keyboard_layout(); + return macdrv_init_thread_data()->active_keyboard_layout; } diff --git a/dlls/winemac.drv/macdrv.h b/dlls/winemac.drv/macdrv.h index d49a3c0eeb0..120fa511050 100644 --- a/dlls/winemac.drv/macdrv.h +++ b/dlls/winemac.drv/macdrv.h @@ -178,6 +178,7 @@ static inline RECT rect_from_cgrect(CGRect cgrect) extern void macdrv_keyboard_changed(const macdrv_event *event) DECLSPEC_HIDDEN; extern void macdrv_key_event(HWND hwnd, const macdrv_event *event) DECLSPEC_HIDDEN; extern void macdrv_hotkey_press(const macdrv_event *event) DECLSPEC_HIDDEN; +extern HKL macdrv_get_hkl_from_source(TISInputSourceRef input_source) DECLSPEC_HIDDEN; extern void macdrv_displays_changed(const macdrv_event *event) DECLSPEC_HIDDEN; diff --git a/dlls/winemac.drv/macdrv_cocoa.h b/dlls/winemac.drv/macdrv_cocoa.h index 1c2277f2ba8..ca53507e1b7 100644 --- a/dlls/winemac.drv/macdrv_cocoa.h +++ b/dlls/winemac.drv/macdrv_cocoa.h @@ -241,6 +241,7 @@ extern int macdrv_set_display_mode(const struct macdrv_display* display, CFDataRef uchr; CGEventSourceKeyboardType keyboard_type; int iso_keyboard; + TISInputSourceRef input_source; } keyboard_changed; struct { int button; @@ -411,7 +412,8 @@ extern int macdrv_send_text_input_event(int pressed, unsigned int flags, int rep /* keyboard */ -extern CFDataRef macdrv_copy_keyboard_layout(CGEventSourceKeyboardType* keyboard_type, int* is_iso) DECLSPEC_HIDDEN; +extern void macdrv_get_input_source_info(CFDataRef* uchr,CGEventSourceKeyboardType* keyboard_type, int* is_iso, + TISInputSourceRef* input_source) DECLSPEC_HIDDEN; extern CFArrayRef macdrv_create_input_source_list(void) DECLSPEC_HIDDEN; extern const CFStringRef macdrv_input_source_input_key DECLSPEC_HIDDEN; extern const CFStringRef macdrv_input_source_type_key DECLSPEC_HIDDEN; diff --git a/dlls/winemac.drv/macdrv_main.c b/dlls/winemac.drv/macdrv_main.c index 5cdd13ce074..ba15706fde3 100644 --- a/dlls/winemac.drv/macdrv_main.c +++ b/dlls/winemac.drv/macdrv_main.c @@ -255,6 +255,7 @@ static void set_queue_display_fd(int fd) struct macdrv_thread_data *macdrv_init_thread_data(void) { struct macdrv_thread_data *data = macdrv_thread_data(); + TISInputSourceRef input_source; if (data) return data; @@ -270,7 +271,9 @@ struct macdrv_thread_data *macdrv_init_thread_data(void) ExitProcess(1); } - data->keyboard_layout_uchr = macdrv_copy_keyboard_layout(&data->keyboard_type, &data->iso_keyboard); + macdrv_get_input_source_info(&data->keyboard_layout_uchr, &data->keyboard_type, &data->iso_keyboard, &input_source); + data->active_keyboard_layout = macdrv_get_hkl_from_source(input_source); + CFRelease(input_source); macdrv_compute_keyboard_layout(data); set_queue_display_fd(macdrv_get_event_queue_fd(data->queue));