SDL: Allow building with older versions of GameInput.h

From 4c3f9159e9507b2e3dd817ec5c47b1ea4fe265bd Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 7 Aug 2024 17:39:15 -0700
Subject: [PATCH] Allow building with older versions of GameInput.h

---
 CMakeLists.txt                           | 2 --
 src/joystick/gdk/SDL_gameinputjoystick.c | 8 ++++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 083cbd696c70f..9ffcd9e620245 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1883,8 +1883,6 @@ elseif(WINDOWS)
     #include <stdbool.h>
     #define COBJMACROS
     #include <GameInput.h>
-    // Requires Windows SDK version 10.0.26100.0 or newer
-    static GameInputSystemButtons s = GameInputSystemButtonNone;
     int main(int argc, char **argv) { return 0; }" HAVE_GAMEINPUT_H
   )
   check_include_file(dxgi1_6.h HAVE_DXGI1_6_H)
diff --git a/src/joystick/gdk/SDL_gameinputjoystick.c b/src/joystick/gdk/SDL_gameinputjoystick.c
index 16e05cc3cff1a..31810b0b9a1f9 100644
--- a/src/joystick/gdk/SDL_gameinputjoystick.c
+++ b/src/joystick/gdk/SDL_gameinputjoystick.c
@@ -398,6 +398,8 @@ static void GAMEINPUT_UpdatePowerInfo(SDL_Joystick *joystick, IGameInputDevice *
     SDL_SendJoystickPowerInfo(joystick, state, percent);
 }
 
+#ifdef IGameInput_RegisterSystemButtonCallback
+
 static void CALLBACK GAMEINPUT_InternalSystemButtonCallback(
     _In_ GameInputCallbackToken callbackToken,
     _In_ void * context,
@@ -423,6 +425,8 @@ static void CALLBACK GAMEINPUT_InternalSystemButtonCallback(
     }
 }
 
+#endif // IGameInput_RegisterSystemButtonCallback
+
 static int GAMEINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
 {
     GAMEINPUT_InternalDevice *elem = GAMEINPUT_InternalFindByIndex(device_index);
@@ -446,6 +450,7 @@ static int GAMEINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
         joystick->nbuttons = 11;
         joystick->nhats = 1;
 
+#ifdef IGameInput_RegisterSystemButtonCallback
         if (info->supportedSystemButtons != GameInputSystemButtonNone) {
             if (info->supportedSystemButtons & GameInputSystemButtonShare) {
                 ++joystick->nbuttons;
@@ -457,6 +462,7 @@ static int GAMEINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
 #endif
             IGameInput_RegisterSystemButtonCallback(g_pGameInput, elem->device, (GameInputSystemButtonGuide | GameInputSystemButtonShare), joystick, GAMEINPUT_InternalSystemButtonCallback, &hwdata->system_button_callback_token);
         }
+#endif // IGameInput_RegisterSystemButtonCallback
     } else {
         joystick->naxes = info->controllerAxisCount;
         joystick->nbuttons = info->controllerButtonCount;
@@ -705,6 +711,7 @@ static SDL_bool GAMEINPUT_JoystickGetGamepadMapping(int device_index, SDL_Gamepa
     out->back.kind = EMappingKind_Button;
     out->back.target = SDL_GAMEPAD_BUTTON_BACK;
 
+#ifdef IGameInput_RegisterSystemButtonCallback
     if (elem->info->supportedSystemButtons & GameInputSystemButtonGuide) {
         out->guide.kind = EMappingKind_Button;
         out->guide.target = SDL_GAMEPAD_BUTTON_GUIDE;
@@ -714,6 +721,7 @@ static SDL_bool GAMEINPUT_JoystickGetGamepadMapping(int device_index, SDL_Gamepa
         out->misc1.kind = EMappingKind_Button;
         out->misc1.target = SDL_GAMEPAD_BUTTON_GAMEINPUT_SHARE;
     }
+#endif
 
     out->start.kind = EMappingKind_Button;
     out->start.target = SDL_GAMEPAD_BUTTON_START;