Change order we enumerate Windows joysticks.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 28 Aug 2013 22:09:17 -0400
changeset 771266b5b8446275
parent 7711 db9e27a52d77
child 7713 6074c53b0cda
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
     1.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Wed Aug 28 22:07:54 2013 -0400
     1.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Wed Aug 28 22:09:17 2013 -0400
     1.3 @@ -766,8 +766,10 @@
     1.4  EnumXInputDevices(JoyStick_DeviceData **pContext)
     1.5  {
     1.6      if (s_bXInputEnabled) {
     1.7 -        Uint8 userid;
     1.8 -        for (userid = 0; userid < SDL_XINPUT_MAX_DEVICES; userid++) {
     1.9 +        int iuserid;
    1.10 +        /* iterate in reverse, so these are in the final list in ascending numeric order. */
    1.11 +        for (iuserid = SDL_XINPUT_MAX_DEVICES-1; iuserid >= 0; iuserid--) {
    1.12 +            const Uint8 userid = (Uint8) iuserid;
    1.13              XINPUT_CAPABILITIES capabilities;
    1.14              if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
    1.15                  /* Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. */
    1.16 @@ -796,9 +798,6 @@
    1.17          pCurList = SYS_Joystick;
    1.18          SYS_Joystick = NULL;
    1.19  
    1.20 -        /* Look for XInput devices... */
    1.21 -        EnumXInputDevices(&pCurList);
    1.22 -
    1.23          /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
    1.24          IDirectInput8_EnumDevices(dinput,
    1.25              DI8DEVCLASS_GAMECTRL,
    1.26 @@ -809,6 +808,9 @@
    1.27          SDL_RawDevList = NULL;
    1.28          SDL_RawDevListCount = 0;
    1.29  
    1.30 +        /* Look for XInput devices. Do this last, so they're first in the final list. */
    1.31 +        EnumXInputDevices(&pCurList);
    1.32 +
    1.33          SDL_UnlockMutex( s_mutexJoyStickEnum );
    1.34      }
    1.35