Commit 22008f7f authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

winemac: Update the thread's active_keyboard_layout on keyboard change.

parent f344d7a2
...@@ -374,15 +374,15 @@ int macdrv_err_on; ...@@ -374,15 +374,15 @@ int macdrv_err_on;
- (void) keyboardSelectionDidChange - (void) keyboardSelectionDidChange
{ {
TISInputSourceRef inputSource; TISInputSourceRef inputSourceLayout;
inputSourceIsInputMethodValid = FALSE; inputSourceIsInputMethodValid = FALSE;
inputSource = TISCopyCurrentKeyboardLayoutInputSource(); inputSourceLayout = TISCopyCurrentKeyboardLayoutInputSource();
if (inputSource) if (inputSourceLayout)
{ {
CFDataRef uchr; CFDataRef uchr;
uchr = TISGetInputSourceProperty(inputSource, uchr = TISGetInputSourceProperty(inputSourceLayout,
kTISPropertyUnicodeKeyLayoutData); kTISPropertyUnicodeKeyLayoutData);
if (uchr) if (uchr)
{ {
...@@ -393,6 +393,7 @@ int macdrv_err_on; ...@@ -393,6 +393,7 @@ int macdrv_err_on;
event->keyboard_changed.keyboard_type = self.keyboardType; event->keyboard_changed.keyboard_type = self.keyboardType;
event->keyboard_changed.iso_keyboard = (KBGetLayoutType(self.keyboardType) == kKeyboardISO); event->keyboard_changed.iso_keyboard = (KBGetLayoutType(self.keyboardType) == kKeyboardISO);
event->keyboard_changed.uchr = CFDataCreateCopy(NULL, uchr); event->keyboard_changed.uchr = CFDataCreateCopy(NULL, uchr);
event->keyboard_changed.input_source = TISCopyCurrentKeyboardInputSource();
if (event->keyboard_changed.uchr) if (event->keyboard_changed.uchr)
{ {
...@@ -407,7 +408,7 @@ int macdrv_err_on; ...@@ -407,7 +408,7 @@ int macdrv_err_on;
macdrv_release_event(event); macdrv_release_event(event);
} }
CFRelease(inputSource); CFRelease(inputSourceLayout);
} }
} }
...@@ -2218,31 +2219,28 @@ void macdrv_window_rejected_focus(const macdrv_event *event) ...@@ -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(^{ OnMainThread(^{
TISInputSourceRef inputSource; TISInputSourceRef inputSourceLayout;
inputSource = TISCopyCurrentKeyboardLayoutInputSource(); inputSourceLayout = TISCopyCurrentKeyboardLayoutInputSource();
if (inputSource) if (inputSourceLayout)
{ {
CFDataRef uchr = TISGetInputSourceProperty(inputSource, CFDataRef data = TISGetInputSourceProperty(inputSourceLayout,
kTISPropertyUnicodeKeyLayoutData); kTISPropertyUnicodeKeyLayoutData);
result = CFDataCreateCopy(NULL, uchr); *uchr = CFDataCreateCopy(NULL, data);
CFRelease(inputSource); CFRelease(inputSourceLayout);
*keyboard_type = [WineApplicationController sharedController].keyboardType; *keyboard_type = [WineApplicationController sharedController].keyboardType;
*is_iso = (KBGetLayoutType(*keyboard_type) == kKeyboardISO); *is_iso = (KBGetLayoutType(*keyboard_type) == kKeyboardISO);
*input_source = TISCopyCurrentKeyboardInputSource();
} }
}); });
return result;
} }
/*********************************************************************** /***********************************************************************
......
...@@ -641,6 +641,7 @@ void macdrv_release_event(macdrv_event *event) ...@@ -641,6 +641,7 @@ void macdrv_release_event(macdrv_event *event)
break; break;
case KEYBOARD_CHANGED: case KEYBOARD_CHANGED:
CFRelease(event->keyboard_changed.uchr); CFRelease(event->keyboard_changed.uchr);
CFRelease(event->keyboard_changed.input_source);
break; break;
case QUERY_EVENT: case QUERY_EVENT:
macdrv_release_query(event->query_event.query); macdrv_release_query(event->query_event.query);
......
...@@ -555,6 +555,28 @@ static void update_layout_list(void) ...@@ -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 * macdrv_compute_keyboard_layout
*/ */
void macdrv_compute_keyboard_layout(struct macdrv_thread_data *thread_data) void macdrv_compute_keyboard_layout(struct macdrv_thread_data *thread_data)
...@@ -1027,6 +1049,7 @@ void macdrv_keyboard_changed(const macdrv_event *event) ...@@ -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_layout_uchr = CFDataCreateCopy(NULL, event->keyboard_changed.uchr);
thread_data->keyboard_type = event->keyboard_changed.keyboard_type; thread_data->keyboard_type = event->keyboard_changed.keyboard_type;
thread_data->iso_keyboard = event->keyboard_changed.iso_keyboard; 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; thread_data->dead_key_state = 0;
macdrv_compute_keyboard_layout(thread_data); macdrv_compute_keyboard_layout(thread_data);
...@@ -1327,22 +1350,10 @@ INT CDECL macdrv_GetKeyNameText(LONG lparam, LPWSTR buffer, INT size) ...@@ -1327,22 +1350,10 @@ INT CDECL macdrv_GetKeyNameText(LONG lparam, LPWSTR buffer, INT size)
*/ */
HKL CDECL macdrv_GetKeyboardLayout(DWORD thread_id) HKL CDECL macdrv_GetKeyboardLayout(DWORD thread_id)
{ {
if (!thread_id || thread_id == GetCurrentThreadId()) 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
FIXME("couldn't return keyboard layout for thread %04x\n", thread_id); FIXME("couldn't return keyboard layout for thread %04x\n", thread_id);
/* FIXME: Use TISGetInputSourceProperty() and kTISPropertyInputSourceLanguages return macdrv_init_thread_data()->active_keyboard_layout;
* 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();
} }
......
...@@ -178,6 +178,7 @@ extern void macdrv_compute_keyboard_layout(struct macdrv_thread_data *thread_dat ...@@ -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_keyboard_changed(const macdrv_event *event) DECLSPEC_HIDDEN;
extern void macdrv_key_event(HWND hwnd, 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 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; extern void macdrv_displays_changed(const macdrv_event *event) DECLSPEC_HIDDEN;
......
...@@ -241,6 +241,7 @@ typedef struct macdrv_event { ...@@ -241,6 +241,7 @@ typedef struct macdrv_event {
CFDataRef uchr; CFDataRef uchr;
CGEventSourceKeyboardType keyboard_type; CGEventSourceKeyboardType keyboard_type;
int iso_keyboard; int iso_keyboard;
TISInputSourceRef input_source;
} keyboard_changed; } keyboard_changed;
struct { struct {
int button; int button;
...@@ -411,7 +412,8 @@ extern int macdrv_send_text_input_event(int pressed, unsigned int flags, int rep ...@@ -411,7 +412,8 @@ extern int macdrv_send_text_input_event(int pressed, unsigned int flags, int rep
/* keyboard */ /* 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 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_input_key DECLSPEC_HIDDEN;
extern const CFStringRef macdrv_input_source_type_key DECLSPEC_HIDDEN; extern const CFStringRef macdrv_input_source_type_key DECLSPEC_HIDDEN;
......
...@@ -255,6 +255,7 @@ static void set_queue_display_fd(int fd) ...@@ -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 *macdrv_init_thread_data(void)
{ {
struct macdrv_thread_data *data = macdrv_thread_data(); struct macdrv_thread_data *data = macdrv_thread_data();
TISInputSourceRef input_source;
if (data) return data; if (data) return data;
...@@ -270,7 +271,9 @@ struct macdrv_thread_data *macdrv_init_thread_data(void) ...@@ -270,7 +271,9 @@ struct macdrv_thread_data *macdrv_init_thread_data(void)
ExitProcess(1); 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); macdrv_compute_keyboard_layout(data);
set_queue_display_fd(macdrv_get_event_queue_fd(data->queue)); set_queue_display_fd(macdrv_get_event_queue_fd(data->queue));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment