Fixed the joystick side of XInput haptic detection on Windows 8
authorSam Lantinga <slouken@libsdl.org>
Mon, 31 Mar 2014 10:38:26 -0700
changeset 8689671977fe0abd
parent 8688 1543a7183f88
child 8690 e55279d94f1e
Fixed the joystick side of XInput haptic detection on Windows 8
src/joystick/windows/SDL_dxjoystick.c
     1.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Sat Mar 29 12:29:38 2014 -0700
     1.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Mon Mar 31 10:38:26 2014 -0700
     1.3 @@ -959,12 +959,13 @@
     1.4      SDL_zerop(joystick->hwdata);
     1.5  
     1.6      if (joystickdevice->bXInputDevice) {
     1.7 -        const SDL_bool bIs14OrLater = (SDL_XInputVersion >= ((1<<16)|4));
     1.8          const Uint8 userId = joystickdevice->XInputUserId;
     1.9          XINPUT_CAPABILITIES capabilities;
    1.10 +        XINPUT_VIBRATION state;
    1.11  
    1.12          SDL_assert(s_bXInputEnabled);
    1.13          SDL_assert(XINPUTGETCAPABILITIES);
    1.14 +        SDL_assert(XINPUTSETSTATE);
    1.15          SDL_assert(userId >= 0);
    1.16          SDL_assert(userId < SDL_XINPUT_MAX_DEVICES);
    1.17  
    1.18 @@ -977,9 +978,8 @@
    1.19          } else {
    1.20              /* Current version of XInput mistakenly returns 0 as the Type. Ignore it and ensure the subtype is a gamepad. */
    1.21              SDL_assert(capabilities.SubType == XINPUT_DEVSUBTYPE_GAMEPAD);
    1.22 -            if ((!bIs14OrLater) || (capabilities.Flags & XINPUT_CAPS_FFB_SUPPORTED)) {
    1.23 -                joystick->hwdata->bXInputHaptic = SDL_TRUE;
    1.24 -            }
    1.25 +            SDL_zero(state);
    1.26 +            joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS);
    1.27              joystick->hwdata->userid = userId;
    1.28  
    1.29              /* The XInput API has a hard coded button/axis mapping, so we just match it */
    1.30 @@ -987,7 +987,7 @@
    1.31              joystick->nbuttons = 15;
    1.32              joystick->nballs = 0;
    1.33              joystick->nhats = 0;
    1.34 -		}
    1.35 +        }
    1.36      } else {  /* use DirectInput, not XInput. */
    1.37          LPDIRECTINPUTDEVICE8 device;
    1.38          DIPROPDWORD dipdw;
    1.39 @@ -1675,7 +1675,7 @@
    1.40  /* return SDL_TRUE if this device was opened with XInput */
    1.41  SDL_bool SDL_SYS_IsXInputJoystick(SDL_Joystick * joystick)
    1.42  {
    1.43 -	return joystick->hwdata->bXInputDevice;
    1.44 +    return joystick->hwdata->bXInputDevice;
    1.45  }
    1.46  
    1.47  #endif /* SDL_JOYSTICK_DINPUT */