SDL: Use XINPUT_STATE instead of XINPUT_STATE_EX (thanks Andrew!) (d3f2e)

From d3f2eb2aba7d7a072e3ef475f2da864f1ee1c0c7 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 4 Nov 2023 22:24:55 -0700
Subject: [PATCH] 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)
---
 CMakeLists.txt                                | 10 -------
 include/build_config/SDL_build_config.h.cmake |  3 --
 src/core/windows/SDL_xinput.h                 | 30 +++++--------------
 src/joystick/windows/SDL_rawinputjoystick.c   |  2 +-
 src/joystick/windows/SDL_xinputjoystick.c     |  6 ++--
 5 files changed, 12 insertions(+), 39 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2962ed177dd3..6d07d9ade658 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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>
diff --git a/include/build_config/SDL_build_config.h.cmake b/include/build_config/SDL_build_config.h.cmake
index 35b5e58579f4..32f6486af295 100644
--- a/include/build_config/SDL_build_config.h.cmake
+++ b/include/build_config/SDL_build_config.h.cmake
@@ -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 */
diff --git a/src/core/windows/SDL_xinput.h b/src/core/windows/SDL_xinput.h
index 1d59a8796d05..a92cb8b8cb8f 100644
--- a/src/core/windows/SDL_xinput.h
+++ b/src/core/windows/SDL_xinput.h
@@ -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)(
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 4cc274d8ac3c..2d8d1aa860c8 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -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 */
diff --git a/src/joystick/windows/SDL_xinputjoystick.c b/src/joystick/windows/SDL_xinputjoystick.c
index 91ad48590b08..b5369bb616cd 100644
--- a/src/joystick/windows/SDL_xinputjoystick.c
+++ b/src/joystick/windows/SDL_xinputjoystick.c
@@ -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) {