Use XINPUT_STATE instead of XINPUT_STATE_EX (thanks Andrew!)

XINPUT_STATE_EX isn't actually a thing, we can just use the normal XINPUT_STATE

Fixes https://github.com/libsdl-org/SDL/issues/2797

(cherry picked from commit e8f4045d0bccacbf8f4b716d0dde17140e9f2cc4)
main
Sam Lantinga 2023-11-04 22:24:55 -07:00
parent 3a482ebae0
commit d3f2eb2aba
5 changed files with 12 additions and 39 deletions

View File

@ -1806,16 +1806,6 @@ elseif(WINDOWS)
#include <windows.h>
#include <xinput.h>
int main(int argc, char **argv) { return 0; }" HAVE_XINPUT_H)
check_c_source_compiles("
#include <windows.h>
#include <xinput.h>
XINPUT_GAMEPAD_EX x1;
int main(int argc, char **argv) { return 0; }" HAVE_XINPUT_GAMEPAD_EX)
check_c_source_compiles("
#include <windows.h>
#include <xinput.h>
XINPUT_STATE_EX s1;
int main(int argc, char **argv) { return 0; }" HAVE_XINPUT_STATE_EX)
check_c_source_compiles("
#define COBJMACROS
#include <windows.gaming.input.h>

View File

@ -242,9 +242,6 @@
#cmakedefine HAVE_ROAPI_H @HAVE_ROAPI_H@
#cmakedefine HAVE_SHELLSCALINGAPI_H @HAVE_SHELLSCALINGAPI_H@
#cmakedefine HAVE_XINPUT_GAMEPAD_EX @HAVE_XINPUT_GAMEPAD_EX@
#cmakedefine HAVE_XINPUT_STATE_EX @HAVE_XINPUT_STATE_EX@
#cmakedefine USE_POSIX_SPAWN @USE_POSIX_SPAWN@
/* SDL internal assertion support */

View File

@ -163,28 +163,8 @@ extern "C" {
/* typedef's for XInput structs we use */
#ifndef HAVE_XINPUT_GAMEPAD_EX
typedef struct
{
WORD wButtons;
BYTE bLeftTrigger;
BYTE bRightTrigger;
SHORT sThumbLX;
SHORT sThumbLY;
SHORT sThumbRX;
SHORT sThumbRY;
DWORD dwPaddingReserved;
} XINPUT_GAMEPAD_EX;
#endif
#ifndef HAVE_XINPUT_STATE_EX
typedef struct
{
DWORD dwPacketNumber;
XINPUT_GAMEPAD_EX Gamepad;
} XINPUT_STATE_EX;
#endif
/* This is the same as XINPUT_BATTERY_INFORMATION, but always defined instead of just if WIN32_WINNT >= _WIN32_WINNT_WIN8 */
typedef struct
{
BYTE BatteryType;
@ -204,6 +184,12 @@ typedef struct
SHORT sThumbRY;
} XINPUT_GAMEPAD;
typedef struct
{
DWORD dwPacketNumber;
XINPUT_GAMEPAD Gamepad;
} XINPUT_STATE;
typedef struct
{
WORD wLeftMotorSpeed;
@ -224,7 +210,7 @@ typedef struct
/* Forward decl's for XInput API's we load dynamically and use if available */
typedef DWORD(WINAPI *XInputGetState_t)(
DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */
XINPUT_STATE_EX *pState /* [out] Receives the current state */
XINPUT_STATE *pState /* [out] Receives the current state */
);
typedef DWORD(WINAPI *XInputSetState_t)(

View File

@ -316,7 +316,7 @@ static void RAWINPUT_FillMatchState(WindowsMatchState *state, Uint64 match_state
static struct
{
XINPUT_STATE_EX state;
XINPUT_STATE state;
XINPUT_BATTERY_INFORMATION_EX battery;
SDL_bool connected; /* Currently has an active XInput device */
SDL_bool used; /* Is currently mapped to an SDL device */

View File

@ -421,7 +421,7 @@ static void UpdateXInputJoystickBatteryInformation(SDL_Joystick *joystick, XINPU
}
}
static void UpdateXInputJoystickState_OLD(SDL_Joystick *joystick, XINPUT_STATE_EX *pXInputState, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
static void UpdateXInputJoystickState_OLD(SDL_Joystick *joystick, XINPUT_STATE *pXInputState, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
{
static WORD s_XInputButtons[] = {
XINPUT_GAMEPAD_DPAD_UP, XINPUT_GAMEPAD_DPAD_DOWN, XINPUT_GAMEPAD_DPAD_LEFT, XINPUT_GAMEPAD_DPAD_RIGHT,
@ -448,7 +448,7 @@ static void UpdateXInputJoystickState_OLD(SDL_Joystick *joystick, XINPUT_STATE_E
UpdateXInputJoystickBatteryInformation(joystick, pBatteryInformation);
}
static void UpdateXInputJoystickState(SDL_Joystick *joystick, XINPUT_STATE_EX *pXInputState, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
static void UpdateXInputJoystickState(SDL_Joystick *joystick, XINPUT_STATE *pXInputState, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
{
static WORD s_XInputButtons[] = {
XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y,
@ -513,7 +513,7 @@ Uint32 SDL_XINPUT_JoystickGetCapabilities(SDL_Joystick *joystick)
void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick)
{
HRESULT result;
XINPUT_STATE_EX XInputState;
XINPUT_STATE XInputState;
XINPUT_BATTERY_INFORMATION_EX XBatteryInformation;
if (!XINPUTGETSTATE) {