From 257cef3024831c491eac5038465d33b1f4ea7b92 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 28 Aug 2013 22:09:17 -0400 Subject: [PATCH] Change order we enumerate Windows joysticks. Make it so XInput devices are listed before DirectInput devices, and that the XInput devices are sorted by userid in ascending numeric order (so device 0 comes first). --- src/joystick/windows/SDL_dxjoystick.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index 2648ef3ad8b9f..4165c70114eed 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -766,8 +766,10 @@ static void EnumXInputDevices(JoyStick_DeviceData **pContext) { if (s_bXInputEnabled) { - Uint8 userid; - for (userid = 0; userid < SDL_XINPUT_MAX_DEVICES; userid++) { + int iuserid; + /* iterate in reverse, so these are in the final list in ascending numeric order. */ + for (iuserid = SDL_XINPUT_MAX_DEVICES-1; iuserid >= 0; iuserid--) { + const Uint8 userid = (Uint8) iuserid; XINPUT_CAPABILITIES capabilities; if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) { /* Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. */ @@ -796,9 +798,6 @@ void SDL_SYS_JoystickDetect() pCurList = SYS_Joystick; SYS_Joystick = NULL; - /* Look for XInput devices... */ - EnumXInputDevices(&pCurList); - /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */ IDirectInput8_EnumDevices(dinput, DI8DEVCLASS_GAMECTRL, @@ -809,6 +808,9 @@ void SDL_SYS_JoystickDetect() SDL_RawDevList = NULL; SDL_RawDevListCount = 0; + /* Look for XInput devices. Do this last, so they're first in the final list. */ + EnumXInputDevices(&pCurList); + SDL_UnlockMutex( s_mutexJoyStickEnum ); }