sdl2-compat: Updated for SDL_GetJoystickCaps() and SDL_GetGamepadCaps()

From 9866f86ce718230ff81ee20ba7c00f57f30f2420 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 22 Jan 2024 19:30:28 -0800
Subject: [PATCH] Updated for SDL_GetJoystickCaps() and SDL_GetGamepadCaps()

---
 src/sdl2_compat.c          | 54 ++++++++++++++++++++++++++++++++++++++
 src/sdl3_include_wrapper.h | 25 +++++++-----------
 src/sdl3_syms.h            |  8 ++----
 3 files changed, 66 insertions(+), 21 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index e594450..3c563f8 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -6802,6 +6802,33 @@ SDL_JoystickPathForIndex(int idx)
     return jid ? SDL3_GetJoystickInstancePath(jid) : NULL;
 }
 
+DECLSPEC SDL_bool SDLCALL
+SDL_JoystickHasLED(SDL_Joystick *joystick)
+{
+    if (SDL3_GetJoystickCaps(joystick) & SDL_JOYSTICK_CAP_RGB_LED) {
+        return SDL_TRUE;
+    }
+    return SDL_FALSE;
+}
+
+DECLSPEC SDL_bool SDLCALL
+SDL_JoystickHasRumble(SDL_Joystick *joystick)
+{
+    if (SDL3_GetJoystickCaps(joystick) & SDL_JOYSTICK_CAP_RUMBLE) {
+        return SDL_TRUE;
+    }
+    return SDL_FALSE;
+}
+
+DECLSPEC SDL_bool SDLCALL
+SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick)
+{
+    if (SDL3_GetJoystickCaps(joystick) & SDL_JOYSTICK_CAP_TRIGGER_RUMBLE) {
+        return SDL_TRUE;
+    }
+    return SDL_FALSE;
+}
+
 DECLSPEC char* SDLCALL
 SDL_GameControllerMappingForDeviceIndex(int idx)
 {
@@ -6997,6 +7024,33 @@ SDL_GameControllerGetBindForButton(SDL_GameController *controller,
     return bind;
 }
 
+DECLSPEC SDL_bool SDLCALL
+SDL_GameControllerHasLED(SDL_Gamepad *gamepad)
+{
+    if (SDL3_GetGamepadCaps(gamepad) & SDL_GAMEPAD_CAP_RGB_LED) {
+        return SDL_TRUE;
+    }
+    return SDL_FALSE;
+}
+
+DECLSPEC SDL_bool SDLCALL
+SDL_GameControllerHasRumble(SDL_Gamepad *gamepad)
+{
+    if (SDL3_GetGamepadCaps(gamepad) & SDL_GAMEPAD_CAP_RUMBLE) {
+        return SDL_TRUE;
+    }
+    return SDL_FALSE;
+}
+
+DECLSPEC SDL_bool SDLCALL
+SDL_GameControllerHasRumbleTriggers(SDL_Gamepad *gamepad)
+{
+    if (SDL3_GetGamepadCaps(gamepad) & SDL_GAMEPAD_CAP_TRIGGER_RUMBLE) {
+        return SDL_TRUE;
+    }
+    return SDL_FALSE;
+}
+
 DECLSPEC int SDLCALL
 SDL_JoystickAttachVirtual(SDL_JoystickType type, int naxes, int nbuttons, int nhats)
 {
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index c37633b..b234268 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -163,9 +163,6 @@
 #define SDL_GamepadEventsEnabled IGNORE_THIS_VERSION_OF_SDL_GamepadEventsEnabled
 #define SDL_GamepadHasAxis IGNORE_THIS_VERSION_OF_SDL_GamepadHasAxis
 #define SDL_GamepadHasButton IGNORE_THIS_VERSION_OF_SDL_GamepadHasButton
-#define SDL_GamepadHasLED IGNORE_THIS_VERSION_OF_SDL_GamepadHasLED
-#define SDL_GamepadHasRumble IGNORE_THIS_VERSION_OF_SDL_GamepadHasRumble
-#define SDL_GamepadHasRumbleTriggers IGNORE_THIS_VERSION_OF_SDL_GamepadHasRumbleTriggers
 #define SDL_GamepadHasSensor IGNORE_THIS_VERSION_OF_SDL_GamepadHasSensor
 #define SDL_GamepadSensorEnabled IGNORE_THIS_VERSION_OF_SDL_GamepadSensorEnabled
 #define SDL_GetAndroidSDKVersion IGNORE_THIS_VERSION_OF_SDL_GetAndroidSDKVersion
@@ -996,6 +993,8 @@
 #define SDL_GetHapticName IGNORE_THIS_VERSION_OF_SDL_GetHapticName
 #define SDL_ReadSurfacePixel IGNORE_THIS_VERSION_OF_SDL_ReadSurfacePixel
 #define SDL_FlipSurface IGNORE_THIS_VERSION_OF_SDL_FlipSurface
+#define SDL_GetJoystickCaps IGNORE_THIS_VERSION_OF_SDL_GetJoystickCaps
+#define SDL_GetGamepadCaps IGNORE_THIS_VERSION_OF_SDL_GetGamepadCaps
 
 
 #define SDL_FUNCTION_POINTER_IS_VOID_POINTER 1
@@ -1540,18 +1539,6 @@
 #undef SDL_GamepadHasButton
 #endif
 
-#ifdef SDL_GamepadHasLED
-#undef SDL_GamepadHasLED
-#endif
-
-#ifdef SDL_GamepadHasRumble
-#undef SDL_GamepadHasRumble
-#endif
-
-#ifdef SDL_GamepadHasRumbleTriggers
-#undef SDL_GamepadHasRumbleTriggers
-#endif
-
 #ifdef SDL_GamepadHasSensor
 #undef SDL_GamepadHasSensor
 #endif
@@ -4872,6 +4859,14 @@
 #undef SDL_FlipSurface
 #endif
 
+#ifdef SDL_GetJoystickCaps
+#undef SDL_GetJoystickCaps
+#endif
+
+#ifdef SDL_GetGamepadCaps
+#undef SDL_GetGamepadCaps
+#endif
+
 #undef SDL_ThreadID /* see at top. */
 
 /* undefine these macros, too: redefine as SDL3_xxx, if needed. */
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index f21c189..2dde4e4 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -664,9 +664,7 @@ SDL3_SYM_PASSTHROUGH(float,truncf,(float a),(a),return)
 SDL3_SYM_PASSTHROUGH(SDL_Locale *,GetPreferredLocales,(void),(),return)
 SDL3_SYM_PASSTHROUGH(int,OpenURL,(const char *a),(a),return)
 SDL3_SYM_RENAMED(SDL_bool,HasSurfaceRLE,SurfaceHasRLE,(SDL_Surface *a),(a),return)
-SDL3_SYM_RENAMED(SDL_bool,GameControllerHasLED,GamepadHasLED,(SDL_GameController *a),(a),return)
 SDL3_SYM_RENAMED(int,GameControllerSetLED,SetGamepadLED,(SDL_GameController *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return)
-SDL3_SYM_PASSTHROUGH(SDL_bool,JoystickHasLED,(SDL_Joystick *a),(a),return)
 SDL3_SYM_RENAMED(int,JoystickSetLED,SetJoystickLED,(SDL_Joystick *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return)
 SDL3_SYM_RENAMED(int,GameControllerRumbleTriggers,RumbleGamepadTriggers,(SDL_GameController *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return)
 SDL3_SYM_RENAMED(int,JoystickRumbleTriggers,RumbleJoystickTriggers,(SDL_Joystick *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return)
@@ -737,10 +735,6 @@ SDL3_SYM_PASSTHROUGH(int,SetWindowMouseRect,(SDL_Window *a, const SDL_Rect *b),(
 SDL3_SYM_PASSTHROUGH(const SDL_Rect*,GetWindowMouseRect,(SDL_Window *a),(a),return)
 SDL3_SYM(int,RenderCoordinatesFromWindow,(SDL_Renderer *a, float b, float c, float *d, float *e),(a,b,c,d,e),return)
 SDL3_SYM(int,RenderCoordinatesToWindow,(SDL_Renderer *a, float b, float c, float *d, float *e),(a,b,c,d,e),return)
-SDL3_SYM_PASSTHROUGH(SDL_bool,JoystickHasRumble,(SDL_Joystick *a),(a),return)
-SDL3_SYM_PASSTHROUGH(SDL_bool,JoystickHasRumbleTriggers,(SDL_Joystick *a),(a),return)
-SDL3_SYM_RENAMED(SDL_bool,GameControllerHasRumble,GamepadHasRumble,(SDL_GameController *a),(a),return)
-SDL3_SYM_RENAMED(SDL_bool,GameControllerHasRumbleTriggers,GamepadHasRumbleTriggers,(SDL_GameController *a),(a),return)
 SDL3_SYM_PASSTHROUGH(void,hid_ble_scan,(SDL_bool a),(a),)
 SDL3_SYM_PASSTHROUGH(int,PremultiplyAlpha,(int a, int b, Uint32 c, const void *d, int e, Uint32 f, void *g, int h),(a,b,c,d,e,f,g,h),return)
 SDL3_SYM(const char*,GetTouchDeviceName,(SDL_TouchID a),(a),return)
@@ -867,6 +861,8 @@ SDL3_SYM(SDL_HapticID *,GetHaptics,(int *a),(a),return)
 SDL3_SYM(const char *,GetHapticInstanceName,(SDL_HapticID a),(a),return)
 SDL3_SYM(SDL_Haptic *,GetHapticFromInstanceID,(SDL_HapticID a),(a),return)
 SDL3_SYM(SDL_HapticID,GetHapticInstanceID,(SDL_Haptic *a),(a),return)
+SDL3_SYM(Uint32,GetJoystickCaps,(SDL_Joystick *a),(a),return)
+SDL3_SYM(Uint32,GetGamepadCaps,(SDL_GameController *a),(a),return)
 
 #undef SDL3_SYM
 #undef SDL3_SYM_PASSTHROUGH