https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0b35adc27414fd45e974f3a495ba775bc9a2c1e5

commit 0b35adc27414fd45e974f3a495ba775bc9a2c1e5
Author:     Amine Khaldi <[email protected]>
AuthorDate: Sun Jan 21 22:26:41 2018 +0100
Commit:     Amine Khaldi <[email protected]>
CommitDate: Sun Jan 21 22:26:41 2018 +0100

    [DINPUT] Sync with Wine 3.0. CORE-14225
---
 dll/directx/wine/dinput/device.c         |  8 ++++----
 dll/directx/wine/dinput/dinput_main.c    | 35 ++++++++++++++------------------
 dll/directx/wine/dinput/dinput_private.h |  2 +-
 dll/directx/wine/dinput/joystick_osx.c   |  8 +++++++-
 media/doc/README.WINE                    |  2 +-
 5 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/dll/directx/wine/dinput/device.c b/dll/directx/wine/dinput/device.c
index a67e24403c..d9f95b913b 100644
--- a/dll/directx/wine/dinput/device.c
+++ b/dll/directx/wine/dinput/device.c
@@ -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;
 }
diff --git a/dll/directx/wine/dinput/dinput_main.c 
b/dll/directx/wine/dinput/dinput_main.c
index e480af77ea..8b106808c5 100644
--- a/dll/directx/wine/dinput/dinput_main.c
+++ b/dll/directx/wine/dinput/dinput_main.c
@@ -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);
diff --git a/dll/directx/wine/dinput/dinput_private.h 
b/dll/directx/wine/dinput/dinput_private.h
index 7a35be2c11..fb8c32ef17 100644
--- a/dll/directx/wine/dinput/dinput_private.h
+++ b/dll/directx/wine/dinput/dinput_private.h
@@ -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);
 
diff --git a/dll/directx/wine/dinput/joystick_osx.c 
b/dll/directx/wine/dinput/joystick_osx.c
index e1358493cb..67b1d63320 100644
--- a/dll/directx/wine/dinput/joystick_osx.c
+++ b/dll/directx/wine/dinput/joystick_osx.c
@@ -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)
                     {
diff --git a/media/doc/README.WINE b/media/doc/README.WINE
index 5e73bf3471..20b10fbddb 100644
--- a/media/doc/README.WINE
+++ b/media/doc/README.WINE
@@ -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

Reply via email to