Commit 7ebfaa0ea26bb0f9b3a01e742cccc4e5418c6452

Sam Lantinga 2023-11-02T08:33:15

Check to make sure the Windows joystick device has buttons and axes This reverts commit e5a15f94e2f1a8fbbffb25ea9932cda9679a68fd. It turns out removing this check allows mice like the ROG PUGIO II to show up as game controllers. We need to find a different way to differentiate between gaming mice and pedals. Since these mice show up as controllers, and potentially causing games to use them instead of real controllers, we'll go ahead revert this change for now. Reopens https://github.com/libsdl-org/SDL/issues/8227 (cherry picked from commit ad0af488837e44cbea0f0eab3b2f73b50a74bff4) (cherry picked from commit 20ecd2afcb6a4ef6acb39505d307d42390e6a345)

diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c
index 777fca4..9299619 100644
--- a/src/joystick/windows/SDL_dinputjoystick.c
+++ b/src/joystick/windows/SDL_dinputjoystick.c
@@ -453,6 +453,7 @@ static BOOL CALLBACK EnumJoystickDetectCallback(LPCDIDEVICEINSTANCE pDeviceInsta
     char *hidPath = NULL;
     char *name = NULL;
     LPDIRECTINPUTDEVICE8 device = NULL;
+    DIDEVCAPS caps;
 
     /* We are only supporting HID devices. */
     CHECK(pDeviceInstance->dwDevType & DIDEVTYPE_HID);
@@ -462,6 +463,13 @@ static BOOL CALLBACK EnumJoystickDetectCallback(LPCDIDEVICEINSTANCE pDeviceInsta
     CHECK(QueryDevicePath(device, &hidPath));
     CHECK(QueryDeviceInfo(device, &vendor, &product));
 
+    /* Check to make sure the device has buttons and axes.
+     * This fixes incorrectly detecting the ROG CHAKRAM X mouse as a game controller on Windows 10
+     */
+    caps.dwSize = sizeof(caps);
+    CHECK(SUCCEEDED(IDirectInputDevice8_GetCapabilities(device, &caps)));
+    CHECK(caps.dwAxes > 0 && caps.dwButtons > 0);
+
     CHECK(!SDL_IsXInputDevice(vendor, product, hidPath));
 
     pNewJoystick = *(JoyStick_DeviceData **)pContext;