[DINPUT] Sync with Wine 3.0. CORE-14225
authorAmine Khaldi <amine.khaldi@reactos.org>
Sun, 21 Jan 2018 21:26:41 +0000 (22:26 +0100)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sun, 21 Jan 2018 21:26:41 +0000 (22:26 +0100)
dll/directx/wine/dinput/device.c
dll/directx/wine/dinput/dinput_main.c
dll/directx/wine/dinput/dinput_private.h
dll/directx/wine/dinput/joystick_osx.c
media/doc/README.WINE

index a67e244..d9f95b9 100644 (file)
@@ -976,9 +976,9 @@ HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
     EnterCriticalSection(&This->crit);
     res = This->acquired ? S_FALSE : DI_OK;
     This->acquired = 1;
-    LeaveCriticalSection(&This->crit);
     if (res == DI_OK)
-        check_dinput_hooks(iface, TRUE);
+        check_dinput_hooks(iface);
+    LeaveCriticalSection(&This->crit);
 
     return res;
 }
@@ -1004,9 +1004,9 @@ HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
     EnterCriticalSection(&This->crit);
     res = !This->acquired ? DI_NOEFFECT : DI_OK;
     This->acquired = 0;
-    LeaveCriticalSection(&This->crit);
     if (res == DI_OK)
-        check_dinput_hooks(iface, FALSE);
+        check_dinput_hooks(iface);
+    LeaveCriticalSection(&This->crit);
 
     return res;
 }
index e480af7..8b10680 100644 (file)
@@ -1637,7 +1637,7 @@ static DWORD WINAPI hook_thread_proc(void *param)
 
     /* Force creation of the message queue */
     PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE );
-    SetEvent(param);
+    SetEvent(*(LPHANDLE)param);
 
     while (GetMessageW( &msg, 0, 0, 0 ))
     {
@@ -1705,7 +1705,6 @@ static DWORD WINAPI hook_thread_proc(void *param)
 }
 
 static DWORD hook_thread_id;
-static HANDLE hook_thread_event;
 
 static CRITICAL_SECTION_DEBUG dinput_critsect_debug =
 {
@@ -1724,21 +1723,24 @@ static BOOL check_hook_thread(void)
     TRACE("IDirectInputs left: %d\n", list_count(&direct_input_list));
     if (!list_empty(&direct_input_list) && !hook_thread)
     {
-        hook_thread_event = CreateEventW(NULL, FALSE, FALSE, NULL);
-        hook_thread = CreateThread(NULL, 0, hook_thread_proc, hook_thread_event, 0, &hook_thread_id);
+        HANDLE event;
+
+        event = CreateEventW(NULL, FALSE, FALSE, NULL);
+        hook_thread = CreateThread(NULL, 0, hook_thread_proc, &event, 0, &hook_thread_id);
+        if (event && hook_thread)
+        {
+            HANDLE handles[2];
+            handles[0] = event;
+            handles[1] = hook_thread;
+            WaitForMultipleObjects(2, handles, FALSE, INFINITE);
+        }
         LeaveCriticalSection(&dinput_hook_crit);
+        CloseHandle(event);
     }
     else if (list_empty(&direct_input_list) && hook_thread)
     {
         DWORD tid = hook_thread_id;
 
-        if (hook_thread_event) /* if thread is not started yet */
-        {
-            WaitForSingleObject(hook_thread_event, INFINITE);
-            CloseHandle(hook_thread_event);
-            hook_thread_event = NULL;
-        }
-
         hook_thread_id = 0;
         PostThreadMessageW(tid, WM_USER+0x10, 0, 0);
         LeaveCriticalSection(&dinput_hook_crit);
@@ -1754,7 +1756,7 @@ static BOOL check_hook_thread(void)
     return hook_thread_id != 0;
 }
 
-void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface, BOOL acquired)
+void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface)
 {
     static HHOOK callwndproc_hook;
     static ULONG foreground_cnt;
@@ -1764,7 +1766,7 @@ void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface, BOOL acquired)
 
     if (dev->dwCoopLevel & DISCL_FOREGROUND)
     {
-        if (acquired)
+        if (dev->acquired)
             foreground_cnt++;
         else
             foreground_cnt--;
@@ -1779,13 +1781,6 @@ void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface, BOOL acquired)
         callwndproc_hook = NULL;
     }
 
-    if (hook_thread_event) /* if thread is not started yet */
-    {
-        WaitForSingleObject(hook_thread_event, INFINITE);
-        CloseHandle(hook_thread_event);
-        hook_thread_event = NULL;
-    }
-
     PostThreadMessageW( hook_thread_id, WM_USER+0x10, 1, 0 );
 
     LeaveCriticalSection(&dinput_hook_crit);
index 7a35be2..fb8c32e 100644 (file)
@@ -85,7 +85,7 @@ extern const struct dinput_device joystick_linux_device DECLSPEC_HIDDEN;
 extern const struct dinput_device joystick_linuxinput_device DECLSPEC_HIDDEN;
 extern const struct dinput_device joystick_osx_device DECLSPEC_HIDDEN;
 
-extern void check_dinput_hooks(LPDIRECTINPUTDEVICE8W, BOOL) DECLSPEC_HIDDEN;
+extern void check_dinput_hooks(LPDIRECTINPUTDEVICE8W) DECLSPEC_HIDDEN;
 extern void check_dinput_events(void) DECLSPEC_HIDDEN;
 typedef int (*DI_EVENT_PROC)(LPDIRECTINPUTDEVICE8A, WPARAM, LPARAM);
 
index e135849..67b1d63 100644 (file)
@@ -640,14 +640,20 @@ static void get_osx_device_elements(JoystickImpl *device, int axis_map[8])
         {
             IOHIDElementRef element = ( IOHIDElementRef ) CFArrayGetValueAtIndex( elements, idx );
             int type = IOHIDElementGetType( element );
+            int usage_page = IOHIDElementGetUsagePage( element );
 
             TRACE("element %s\n", debugstr_element(element));
 
+            if (usage_page >= kHIDPage_VendorDefinedStart)
+            {
+                /* vendor pages can repurpose type ids, resulting in incorrect case matches below (e.g. ds4 controllers) */
+                continue;
+            }
+
             switch(type)
             {
                 case kIOHIDElementTypeInput_Button:
                 {
-                    int usage_page = IOHIDElementGetUsagePage( element );
                     TRACE("kIOHIDElementTypeInput_Button usage_page %d\n", usage_page);
                     if (usage_page != kHIDPage_Button)
                     {
index 5e73bf3..20b10fb 100644 (file)
@@ -30,7 +30,7 @@ reactos/dll/directx/wine/d3dx9_24 => 43 # Synced to Wine-3.0
 reactos/dll/directx/wine/d3dxof         # Synced to WineStaging-2.9
 reactos/dll/directx/wine/ddraw          # Synced to Wine-3.0
 reactos/dll/directx/wine/devenum        # Synced to Wine-3.0
-reactos/dll/directx/wine/dinput         # Synced to WineStaging-2.16
+reactos/dll/directx/wine/dinput         # Synced to Wine-3.0
 reactos/dll/directx/wine/dinput8        # Synced to WineStaging-2.9
 reactos/dll/directx/wine/dmusic         # Synced to WineStaging-2.9
 reactos/dll/directx/wine/dplay          # Synced to WineStaging-2.9