Commit f344d7a2 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

winemac: Update the layout list if the enabled input sources change.

parent fecaab9c
...@@ -411,6 +411,11 @@ int macdrv_err_on; ...@@ -411,6 +411,11 @@ int macdrv_err_on;
} }
} }
- (void) enabledKeyboardInputSourcesChanged
{
macdrv_layout_list_needs_update = TRUE;
}
- (CGFloat) primaryScreenHeight - (CGFloat) primaryScreenHeight
{ {
if (!primaryScreenHeightValid) if (!primaryScreenHeightValid)
...@@ -1930,6 +1935,11 @@ int macdrv_err_on; ...@@ -1930,6 +1935,11 @@ int macdrv_err_on;
name:@"com.apple.HIToolbox.beginMenuTrackingNotification" name:@"com.apple.HIToolbox.beginMenuTrackingNotification"
object:nil object:nil
suspensionBehavior:NSNotificationSuspensionBehaviorDrop]; suspensionBehavior:NSNotificationSuspensionBehaviorDrop];
[dnc addObserver:self
selector:@selector(enabledKeyboardInputSourcesChanged)
name:(NSString*)kTISNotifyEnabledKeyboardInputSourcesChanged
object:nil];
} }
- (BOOL) inputSourceIsInputMethod - (BOOL) inputSourceIsInputMethod
......
...@@ -435,6 +435,7 @@ struct layout ...@@ -435,6 +435,7 @@ struct layout
struct list entry; struct list entry;
HKL hkl; HKL hkl;
TISInputSourceRef input_source; TISInputSourceRef input_source;
BOOL enabled; /* is the input source enabled - ie displayed in the input source selector UI */
}; };
static CRITICAL_SECTION layout_list_section; static CRITICAL_SECTION layout_list_section;
...@@ -446,6 +447,8 @@ static CRITICAL_SECTION_DEBUG critsect_debug = ...@@ -446,6 +447,8 @@ static CRITICAL_SECTION_DEBUG critsect_debug =
}; };
static CRITICAL_SECTION layout_list_section = { &critsect_debug, -1, 0, 0, 0, 0 }; static CRITICAL_SECTION layout_list_section = { &critsect_debug, -1, 0, 0, 0, 0 };
int macdrv_layout_list_needs_update = TRUE;
static DWORD get_lcid(CFStringRef lang) static DWORD get_lcid(CFStringRef lang)
{ {
CFRange range; CFRange range;
...@@ -481,10 +484,36 @@ static HKL get_hkl(CFStringRef lang, CFStringRef type) ...@@ -481,10 +484,36 @@ static HKL get_hkl(CFStringRef lang, CFStringRef type)
return (HKL)lcid; return (HKL)lcid;
} }
/******************************************************************
* get_layout_from_source
*
* Must be called while holding the layout_list_section.
* Note, returned layout may not currently be enabled.
*/
static struct layout *get_layout_from_source(TISInputSourceRef input)
{
struct layout *ret = NULL, *layout;
LIST_FOR_EACH_ENTRY(layout, &layout_list, struct layout, entry)
{
if (CFEqual(input, layout->input_source))
{
ret = layout;
break;
}
}
return ret;
}
/*********************************************************************** /***********************************************************************
* update_layout_list * update_layout_list
* *
* Must be called while holding the layout_list_section * Must be called while holding the layout_list_section
*
* If an input source has been disabled (ie. removed from the UI) its
* entry remains in the layout list but is marked as such and is not
* enumerated by GetKeyboardLayoutList. This is to ensure the
* HKL <-> input source mapping is unique.
*/ */
static void update_layout_list(void) static void update_layout_list(void)
{ {
...@@ -492,23 +521,34 @@ static void update_layout_list(void) ...@@ -492,23 +521,34 @@ static void update_layout_list(void)
struct layout *layout; struct layout *layout;
int i; int i;
if (!list_empty(&layout_list)) return; if (!InterlockedExchange(&macdrv_layout_list_needs_update, FALSE)) return;
sources = macdrv_create_input_source_list(); sources = macdrv_create_input_source_list();
LIST_FOR_EACH_ENTRY(layout, &layout_list, struct layout, entry)
layout->enabled = FALSE;
for (i = 0; i < CFArrayGetCount(sources); i++) for (i = 0; i < CFArrayGetCount(sources); i++)
{ {
CFDictionaryRef dict = CFArrayGetValueAtIndex(sources, i); CFDictionaryRef dict = CFArrayGetValueAtIndex(sources, i);
TISInputSourceRef input = (TISInputSourceRef)CFDictionaryGetValue(dict, macdrv_input_source_input_key); TISInputSourceRef input = (TISInputSourceRef)CFDictionaryGetValue(dict, macdrv_input_source_input_key);
CFStringRef type = CFDictionaryGetValue(dict, macdrv_input_source_type_key); layout = get_layout_from_source(input);
CFStringRef lang = CFDictionaryGetValue(dict, macdrv_input_source_lang_key); if (!layout)
{
CFStringRef type = CFDictionaryGetValue(dict, macdrv_input_source_type_key);
CFStringRef lang = CFDictionaryGetValue(dict, macdrv_input_source_lang_key);
layout = HeapAlloc(GetProcessHeap(), 0, sizeof(*layout));
layout->input_source = (TISInputSourceRef)CFRetain(input);
layout->hkl = get_hkl(lang, type);
layout = HeapAlloc(GetProcessHeap(), 0, sizeof(*layout)); list_add_tail(&layout_list, &layout->entry);
layout->input_source = (TISInputSourceRef)CFRetain(input); TRACE("adding new layout %p\n", layout->hkl);
layout->hkl = get_hkl(lang, type); }
else
TRACE("enabling already existing layout %p\n", layout->hkl);
list_add_tail(&layout_list, &layout->entry); layout->enabled = TRUE;
TRACE("adding new layout %p\n", layout->hkl);
} }
CFRelease(sources); CFRelease(sources);
...@@ -1322,6 +1362,7 @@ UINT CDECL macdrv_GetKeyboardLayoutList(INT size, HKL *list) ...@@ -1322,6 +1362,7 @@ UINT CDECL macdrv_GetKeyboardLayoutList(INT size, HKL *list)
LIST_FOR_EACH_ENTRY(layout, &layout_list, struct layout, entry) LIST_FOR_EACH_ENTRY(layout, &layout_list, struct layout, entry)
{ {
if (!layout->enabled) continue;
if (list) if (list)
{ {
if (count >= size) break; if (count >= size) break;
......
...@@ -416,6 +416,7 @@ extern CFArrayRef macdrv_create_input_source_list(void) DECLSPEC_HIDDEN; ...@@ -416,6 +416,7 @@ 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;
extern const CFStringRef macdrv_input_source_lang_key DECLSPEC_HIDDEN; extern const CFStringRef macdrv_input_source_lang_key DECLSPEC_HIDDEN;
extern int macdrv_layout_list_needs_update DECLSPEC_HIDDEN;
/* clipboard */ /* clipboard */
......
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