Module: wine Branch: master Commit: 22008f7fd99b01e5f63780311825cf4e403d2e65 URL: http://source.winehq.org/git/wine.git/?a=commit;h=22008f7fd99b01e5f637803118...
Author: Huw Davies huw@codeweavers.com Date: Wed Nov 20 15:30:36 2013 +0000
winemac: Update the thread's active_keyboard_layout on keyboard change.
---
dlls/winemac.drv/cocoa_app.m | 34 ++++++++++++++++------------------ dlls/winemac.drv/cocoa_event.m | 1 + dlls/winemac.drv/keyboard.c | 39 +++++++++++++++++++++++++-------------- dlls/winemac.drv/macdrv.h | 1 + dlls/winemac.drv/macdrv_cocoa.h | 4 +++- dlls/winemac.drv/macdrv_main.c | 5 ++++- 6 files changed, 50 insertions(+), 34 deletions(-)
diff --git a/dlls/winemac.drv/cocoa_app.m b/dlls/winemac.drv/cocoa_app.m index 284023b..af56872 100644 --- a/dlls/winemac.drv/cocoa_app.m +++ b/dlls/winemac.drv/cocoa_app.m @@ -374,15 +374,15 @@ int macdrv_err_on;
- (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 @@ int macdrv_err_on; 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 @@ int macdrv_err_on; 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 13f9695..00f6f8e 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 52f97da..cc0df4e 100644 --- a/dlls/winemac.drv/keyboard.c +++ b/dlls/winemac.drv/keyboard.c @@ -555,6 +555,28 @@ static void update_layout_list(void) }
/*********************************************************************** + * 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 */ void macdrv_compute_keyboard_layout(struct macdrv_thread_data *thread_data) @@ -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 d49a3c0..120fa51 100644 --- a/dlls/winemac.drv/macdrv.h +++ b/dlls/winemac.drv/macdrv.h @@ -178,6 +178,7 @@ extern void macdrv_compute_keyboard_layout(struct macdrv_thread_data *thread_dat 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 1c2277f..ca53507 100644 --- a/dlls/winemac.drv/macdrv_cocoa.h +++ b/dlls/winemac.drv/macdrv_cocoa.h @@ -241,6 +241,7 @@ typedef struct macdrv_event { 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 5cdd13c..ba15706 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));