src/joystick/windows/SDL_dxjoystick.c
changeset 7712 66b5b8446275
parent 7711 db9e27a52d77
child 7719 31b5f9ff36ca
equal deleted inserted replaced
7711:db9e27a52d77 7712:66b5b8446275
   764 
   764 
   765 static void
   765 static void
   766 EnumXInputDevices(JoyStick_DeviceData **pContext)
   766 EnumXInputDevices(JoyStick_DeviceData **pContext)
   767 {
   767 {
   768     if (s_bXInputEnabled) {
   768     if (s_bXInputEnabled) {
   769         Uint8 userid;
   769         int iuserid;
   770         for (userid = 0; userid < SDL_XINPUT_MAX_DEVICES; userid++) {
   770         /* iterate in reverse, so these are in the final list in ascending numeric order. */
       
   771         for (iuserid = SDL_XINPUT_MAX_DEVICES-1; iuserid >= 0; iuserid--) {
       
   772             const Uint8 userid = (Uint8) iuserid;
   771             XINPUT_CAPABILITIES capabilities;
   773             XINPUT_CAPABILITIES capabilities;
   772             if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
   774             if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
   773                 /* Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. */
   775                 /* Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. */
   774                 /* !!! FIXME: we might want to support steering wheels or guitars or whatever laster. */
   776                 /* !!! FIXME: we might want to support steering wheels or guitars or whatever laster. */
   775                 if (capabilities.SubType == XINPUT_DEVSUBTYPE_GAMEPAD) {
   777                 if (capabilities.SubType == XINPUT_DEVSUBTYPE_GAMEPAD) {
   794         s_bDeviceRemoved = SDL_FALSE;
   796         s_bDeviceRemoved = SDL_FALSE;
   795 
   797 
   796         pCurList = SYS_Joystick;
   798         pCurList = SYS_Joystick;
   797         SYS_Joystick = NULL;
   799         SYS_Joystick = NULL;
   798 
   800 
   799         /* Look for XInput devices... */
       
   800         EnumXInputDevices(&pCurList);
       
   801 
       
   802         /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
   801         /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
   803         IDirectInput8_EnumDevices(dinput,
   802         IDirectInput8_EnumDevices(dinput,
   804             DI8DEVCLASS_GAMECTRL,
   803             DI8DEVCLASS_GAMECTRL,
   805             EnumJoysticksCallback,
   804             EnumJoysticksCallback,
   806             &pCurList, DIEDFL_ATTACHEDONLY);
   805             &pCurList, DIEDFL_ATTACHEDONLY);
   807 
   806 
   808         SDL_free(SDL_RawDevList);  /* in case we used this in DirectInput enumerator. */
   807         SDL_free(SDL_RawDevList);  /* in case we used this in DirectInput enumerator. */
   809         SDL_RawDevList = NULL;
   808         SDL_RawDevList = NULL;
   810         SDL_RawDevListCount = 0;
   809         SDL_RawDevListCount = 0;
       
   810 
       
   811         /* Look for XInput devices. Do this last, so they're first in the final list. */
       
   812         EnumXInputDevices(&pCurList);
   811 
   813 
   812         SDL_UnlockMutex( s_mutexJoyStickEnum );
   814         SDL_UnlockMutex( s_mutexJoyStickEnum );
   813     }
   815     }
   814 
   816 
   815     if ( pCurList )
   817     if ( pCurList )