Huw Davies : winemac: Actually set the system's keyboard layout.

Alexandre Julliard julliard at winehq.org
Wed Nov 20 13:38:58 CST 2013


Module: wine
Branch: master
Commit: c4761d800256bb487b6e9e5a53b09af938ca7183
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=c4761d800256bb487b6e9e5a53b09af938ca7183

Author: Huw Davies <huw at codeweavers.com>
Date:   Wed Nov 20 15:30:38 2013 +0000

winemac: Actually set the system's keyboard layout.

---

 dlls/winemac.drv/cocoa_app.m    |   11 +++++
 dlls/winemac.drv/keyboard.c     |   80 ++++++++------------------------------
 dlls/winemac.drv/macdrv_cocoa.h |    1 +
 3 files changed, 29 insertions(+), 63 deletions(-)

diff --git a/dlls/winemac.drv/cocoa_app.m b/dlls/winemac.drv/cocoa_app.m
index af56872..8ab8954 100644
--- a/dlls/winemac.drv/cocoa_app.m
+++ b/dlls/winemac.drv/cocoa_app.m
@@ -2503,3 +2503,14 @@ CFArrayRef macdrv_create_input_source_list(void)
 
     return ret;
 }
+
+int macdrv_select_input_source(TISInputSourceRef input_source)
+{
+    __block int ret = FALSE;
+
+    OnMainThread(^{
+        ret = (TISSelectInputSource(input_source) == noErr);
+    });
+
+    return ret;
+}
diff --git a/dlls/winemac.drv/keyboard.c b/dlls/winemac.drv/keyboard.c
index 15a4c1b..a46d324 100644
--- a/dlls/winemac.drv/keyboard.c
+++ b/dlls/winemac.drv/keyboard.c
@@ -1115,48 +1115,6 @@ void macdrv_hotkey_press(const macdrv_event *event)
 
 
 /***********************************************************************
- *              get_locale_keyboard_layout
- */
-static HKL get_locale_keyboard_layout(void)
-{
-    ULONG_PTR layout;
-    LANGID langid;
-
-    layout = GetUserDefaultLCID();
-
-    /*
-     * Microsoft Office expects this value to be something specific
-     * for Japanese and Korean Windows with an IME the value is 0xe001
-     * We should probably check to see if an IME exists and if so then
-     * set this word properly.
-     */
-    langid = PRIMARYLANGID(LANGIDFROMLCID(layout));
-    if (langid == LANG_CHINESE || langid == LANG_JAPANESE || langid == LANG_KOREAN)
-        layout |= 0xe001 << 16; /* IME */
-    else
-        layout |= layout << 16;
-
-    return (HKL)layout;
-}
-
-
-/***********************************************************************
- *              match_keyboard_layout
- */
-static BOOL match_keyboard_layout(HKL hkl)
-{
-    const DWORD isIME = 0xE0000000;
-    HKL current_hkl = get_locale_keyboard_layout();
-
-    /* if the layout is an IME, only match the low word (LCID) */
-    if (((ULONG_PTR)hkl & isIME) == isIME)
-        return (LOWORD(hkl) == LOWORD(current_hkl));
-    else
-        return (hkl == current_hkl);
-}
-
-
-/***********************************************************************
  *              macdrv_process_text_input
  */
 BOOL macdrv_process_text_input(UINT vkey, UINT scan, UINT repeat, const BYTE *key_state, void *himc)
@@ -1210,20 +1168,11 @@ HKL CDECL macdrv_ActivateKeyboardLayout(HKL hkl, UINT flags)
 {
     HKL oldHkl = 0;
     struct macdrv_thread_data *thread_data = macdrv_init_thread_data();
+    struct layout *layout;
 
-    /* FIXME: Use Text Input Services or NSTextInputContext to actually
-              change the Mac keyboard input source. */
-
-    FIXME("hkl %p flags %04x: semi-stub!\n", hkl, flags);
-    if (flags & KLF_SETFORPROCESS)
-    {
-        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-        FIXME("KLF_SETFORPROCESS not supported\n");
-        return 0;
-    }
+    TRACE("hkl %p flags %04x\n", hkl, flags);
 
-    if (flags)
-        FIXME("flags %x not supported\n",flags);
+    if (flags) FIXME("flags %x not supported\n",flags);
 
     if (hkl == (HKL)HKL_NEXT || hkl == (HKL)HKL_PREV)
     {
@@ -1232,17 +1181,22 @@ HKL CDECL macdrv_ActivateKeyboardLayout(HKL hkl, UINT flags)
         return 0;
     }
 
-    if (!match_keyboard_layout(hkl))
+    EnterCriticalSection(&layout_list_section);
+    update_layout_list();
+
+    LIST_FOR_EACH_ENTRY(layout, &layout_list, struct layout, entry)
     {
-        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-        FIXME("setting keyboard of different locales not supported\n");
-        return 0;
+        if (layout->hkl == hkl)
+        {
+            if (macdrv_select_input_source(layout->input_source))
+            {
+                oldHkl = thread_data->active_keyboard_layout;
+                thread_data->active_keyboard_layout = hkl;
+            }
+            break;
+        }
     }
-
-    oldHkl = thread_data->active_keyboard_layout;
-    if (!oldHkl) oldHkl = macdrv_GetKeyboardLayout(0);
-
-    thread_data->active_keyboard_layout = hkl;
+    LeaveCriticalSection(&layout_list_section);
 
     return oldHkl;
 }
diff --git a/dlls/winemac.drv/macdrv_cocoa.h b/dlls/winemac.drv/macdrv_cocoa.h
index ca53507..f7ffc50 100644
--- a/dlls/winemac.drv/macdrv_cocoa.h
+++ b/dlls/winemac.drv/macdrv_cocoa.h
@@ -415,6 +415,7 @@ extern int macdrv_send_text_input_event(int pressed, unsigned int flags, int rep
 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 int macdrv_select_input_source(TISInputSourceRef input_source) 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_lang_key DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list