Rémi Bernon : dinput: Call hid_joystick_enum_device directly in JoyConfig8Impl_GetConfig.

Alexandre Julliard julliard at winehq.org
Tue Oct 26 16:19:19 CDT 2021


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

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Tue Oct 26 09:17:31 2021 +0200

dinput: Call hid_joystick_enum_device directly in JoyConfig8Impl_GetConfig.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dinput/dinput_main.c    | 41 ++++++++++-------------------------------
 dlls/dinput/dinput_private.h | 11 -----------
 dlls/dinput/joystick_hid.c   |  7 -------
 dlls/dinput/keyboard.c       |  6 ------
 dlls/dinput/mouse.c          |  6 ------
 5 files changed, 10 insertions(+), 61 deletions(-)

diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index 745fdafa920..bc033a1baca 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -74,13 +74,6 @@ static inline IDirectInputDeviceImpl *impl_from_IDirectInputDevice8W(IDirectInpu
     return CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface);
 }
 
-static const struct dinput_device *dinput_devices[] =
-{
-    &mouse_device,
-    &keyboard_device,
-    &joystick_hid_device,
-};
-
 HINSTANCE DINPUT_instance;
 
 static HWND di_em_win;
@@ -927,10 +920,11 @@ static HRESULT WINAPI JoyConfig8Impl_DeleteType(IDirectInputJoyConfig8 *iface, L
 
 static HRESULT WINAPI JoyConfig8Impl_GetConfig(IDirectInputJoyConfig8 *iface, UINT id, LPDIJOYCONFIG info, DWORD flags)
 {
+    DIDEVICEINSTANCEW instance = {.dwSize = sizeof(DIDEVICEINSTANCEW)};
     IDirectInputImpl *di = impl_from_IDirectInputJoyConfig8(iface);
+    unsigned int i = 0;
     UINT found = 0;
-    int i, j;
-    HRESULT r;
+    HRESULT hr;
 
     FIXME("(%p)->(%d, %p, 0x%08x): semi-stub!\n", iface, id, info, flags);
 
@@ -941,29 +935,14 @@ static HRESULT WINAPI JoyConfig8Impl_GetConfig(IDirectInputJoyConfig8 *iface, UI
     X(DIJC_CALLOUT)
 #undef X
 
-    /* Enumerate all joysticks in order */
-    for (i = 0; i < ARRAY_SIZE(dinput_devices); i++)
+    do
     {
-        if (!dinput_devices[i]->enum_device) continue;
-
-        for (j = 0, r = S_OK; SUCCEEDED(r); j++)
-        {
-            DIDEVICEINSTANCEW dev;
-            dev.dwSize = sizeof(dev);
-            if ((r = dinput_devices[i]->enum_device(DI8DEVCLASS_GAMECTRL, 0, &dev, di->dwVersion, j)) == S_OK)
-            {
-                /* Only take into account the chosen id */
-                if (found == id)
-                {
-                    if (flags & DIJC_GUIDINSTANCE)
-                        info->guidInstance = dev.guidInstance;
-
-                    return DI_OK;
-                }
-                found += 1;
-            }
-        }
-    }
+        hr = hid_joystick_enum_device( DI8DEVCLASS_GAMECTRL, 0, &instance, di->dwVersion, i++ );
+        if (hr != DI_OK) continue;
+        if (flags & DIJC_GUIDINSTANCE) info->guidInstance = instance.guidInstance;
+        /* Only take into account the chosen id */
+        if (found++ == id) return DI_OK;
+    } while (SUCCEEDED(hr));
 
     return DIERR_NOMOREITEMS;
 }
diff --git a/dlls/dinput/dinput_private.h b/dlls/dinput/dinput_private.h
index e9b40bb95b6..461af021a30 100644
--- a/dlls/dinput/dinput_private.h
+++ b/dlls/dinput/dinput_private.h
@@ -52,13 +52,6 @@ struct IDirectInputImpl
 extern const IDirectInput7AVtbl dinput7_a_vtbl DECLSPEC_HIDDEN;
 extern const IDirectInput8AVtbl dinput8_a_vtbl DECLSPEC_HIDDEN;
 
-/* Function called by all devices that Wine supports */
-struct dinput_device {
-    const char *name;
-    HRESULT (*enum_device)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id);
-    HRESULT (*create_device)(IDirectInputImpl *dinput, REFGUID rguid, IDirectInputDevice8W **out);
-};
-
 extern HRESULT mouse_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version, int index );
 extern HRESULT mouse_create_device( IDirectInputImpl *dinput, const GUID *guid, IDirectInputDevice8W **out );
 extern HRESULT keyboard_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version, int index );
@@ -72,10 +65,6 @@ struct DevicePlayer {
     struct list entry;
 };
 
-extern const struct dinput_device mouse_device DECLSPEC_HIDDEN;
-extern const struct dinput_device keyboard_device DECLSPEC_HIDDEN;
-extern const struct dinput_device joystick_hid_device DECLSPEC_HIDDEN;
-
 extern void dinput_hooks_acquire_device(LPDIRECTINPUTDEVICE8W iface);
 extern void dinput_hooks_unacquire_device(LPDIRECTINPUTDEVICE8W iface);
 extern int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam );
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c
index 3419fed7d79..4632109a35b 100644
--- a/dlls/dinput/joystick_hid.c
+++ b/dlls/dinput/joystick_hid.c
@@ -1867,13 +1867,6 @@ failed:
     return hr;
 }
 
-const struct dinput_device joystick_hid_device =
-{
-    "Wine HID joystick driver",
-    hid_joystick_enum_device,
-    hid_joystick_create_device,
-};
-
 static HRESULT WINAPI hid_joystick_effect_QueryInterface( IDirectInputEffect *iface, REFIID iid, void **out )
 {
     TRACE( "iface %p, iid %s, out %p\n", iface, debugstr_guid( iid ), out );
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index 3b8f52b38f2..a6032cbd0a4 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -204,12 +204,6 @@ HRESULT keyboard_create_device( IDirectInputImpl *dinput, const GUID *guid, IDir
     return DI_OK;
 }
 
-const struct dinput_device keyboard_device = {
-  "Wine keyboard driver",
-  keyboard_enum_device,
-  keyboard_create_device
-};
-
 static HRESULT keyboard_poll( IDirectInputDevice8W *iface )
 {
     check_dinput_events();
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index 325d38c90d3..84b5410bb36 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -153,12 +153,6 @@ HRESULT mouse_create_device( IDirectInputImpl *dinput, const GUID *guid, IDirect
     return DI_OK;
 }
 
-const struct dinput_device mouse_device = {
-    "Wine mouse driver",
-    mouse_enum_device,
-    mouse_create_device
-};
-
 /******************************************************************************
  *	SysMouseA (DInput Mouse support)
  */




More information about the wine-cvs mailing list