SDL: Replaced SDL_GetJoystickCaps() with joystick properties

From f66fe7e2210ada79ced7d7a5b2195fc6a9d23754 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 27 Jan 2024 14:37:30 -0800
Subject: [PATCH] Replaced SDL_GetJoystickCaps() with joystick properties

Fixes https://github.com/libsdl-org/SDL/issues/8927
---
 docs/README-migration.md                      | 12 ++--
 include/SDL3/SDL_gamepad.h                    | 39 ++++--------
 include/SDL3/SDL_joystick.h                   | 39 ++++--------
 src/dynapi/SDL_dynapi.sym                     |  2 -
 src/dynapi/SDL_dynapi_overrides.h             |  2 -
 src/dynapi/SDL_dynapi_procs.h                 |  2 -
 src/joystick/SDL_gamepad.c                    | 10 ---
 src/joystick/SDL_joystick.c                   | 15 -----
 src/joystick/SDL_sysjoystick.h                |  3 -
 src/joystick/android/SDL_sysjoystick.c        |  6 --
 src/joystick/apple/SDL_mfijoystick.m          | 59 ++++++-----------
 src/joystick/bsd/SDL_bsdjoystick.c            |  6 --
 src/joystick/darwin/SDL_iokitjoystick.c       | 22 ++-----
 src/joystick/dummy/SDL_sysjoystick.c          |  6 --
 src/joystick/emscripten/SDL_sysjoystick.c     |  6 --
 src/joystick/haiku/SDL_haikujoystick.cc       |  6 --
 src/joystick/hidapi/SDL_hidapi_ps4.c          |  2 +
 src/joystick/hidapi/SDL_hidapi_ps5.c          |  2 +
 src/joystick/hidapi/SDL_hidapi_switch.c       |  1 +
 src/joystick/hidapi/SDL_hidapi_xbox360.c      |  1 +
 src/joystick/hidapi/SDL_hidapi_xbox360w.c     |  1 +
 src/joystick/hidapi/SDL_hidapijoystick.c      | 63 +++++++++++++++----
 src/joystick/hidapi/SDL_hidapijoystick_c.h    |  8 +++
 src/joystick/linux/SDL_sysjoystick.c          | 17 +----
 src/joystick/n3ds/SDL_sysjoystick.c           |  6 --
 src/joystick/ps2/SDL_sysjoystick.c            | 17 ++---
 src/joystick/psp/SDL_sysjoystick.c            |  6 --
 src/joystick/virtual/SDL_virtualjoystick.c    | 33 +++-------
 src/joystick/vita/SDL_sysjoystick.c           | 14 +----
 src/joystick/windows/SDL_dinputjoystick.c     | 18 +-----
 src/joystick/windows/SDL_dinputjoystick_c.h   |  1 -
 src/joystick/windows/SDL_rawinputjoystick.c   | 41 +++++-------
 .../windows/SDL_windows_gaming_input.c        | 18 ++----
 src/joystick/windows/SDL_windowsjoystick.c    | 10 ---
 src/joystick/windows/SDL_xinputjoystick.c     | 13 +---
 src/joystick/windows/SDL_xinputjoystick_c.h   |  1 -
 test/testcontroller.c                         |  9 ++-
 37 files changed, 176 insertions(+), 341 deletions(-)

diff --git a/docs/README-migration.md b/docs/README-migration.md
index ab82419fa6f4..1bb0c4ba57f1 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -565,9 +565,9 @@ The following functions have been removed:
 * SDL_GameControllerEventState() - replaced with SDL_SetGamepadEventsEnabled() and SDL_GamepadEventsEnabled()
 * SDL_GameControllerGetBindForAxis() - replaced with SDL_GetGamepadBindings()
 * SDL_GameControllerGetBindForButton() - replaced with SDL_GetGamepadBindings()
-* SDL_GameControllerHasLED() - replaced with SDL_GetGamepadCaps()
-* SDL_GameControllerHasRumble() - replaced with SDL_GetGamepadCaps()
-* SDL_GameControllerHasRumbleTriggers() - replaced with SDL_GetGamepadCaps()
+* SDL_GameControllerHasLED() - replaced with SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN
+* SDL_GameControllerHasRumble() - replaced with SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN
+* SDL_GameControllerHasRumbleTriggers() - replaced with SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN
 * SDL_GameControllerMappingForDeviceIndex() - replaced with SDL_GetGamepadInstanceMapping()
 * SDL_GameControllerMappingForIndex() - replaced with SDL_GetGamepadMappings()
 * SDL_GameControllerNameForIndex() - replaced with SDL_GetGamepadInstanceName()
@@ -811,9 +811,9 @@ The following functions have been removed:
 * SDL_JoystickGetDeviceProductVersion() - replaced with SDL_GetJoystickInstanceProductVersion()
 * SDL_JoystickGetDeviceType() - replaced with SDL_GetJoystickInstanceType()
 * SDL_JoystickGetDeviceVendor() - replaced with SDL_GetJoystickInstanceVendor()
-* SDL_JoystickHasLED() - replaced with SDL_GetJoystickCaps()
-* SDL_JoystickHasRumble() - replaced with SDL_GetJoystickCaps()
-* SDL_JoystickHasRumbleTriggers() - replaced with SDL_GetJoystickCaps()
+* SDL_JoystickHasLED() - replaced with SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN
+* SDL_JoystickHasRumble() - replaced with SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN
+* SDL_JoystickHasRumbleTriggers() - replaced with SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN
 * SDL_JoystickNameForIndex() - replaced with SDL_GetJoystickInstanceName()
 * SDL_JoystickNumBalls() - API has been removed, see https://github.com/libsdl-org/SDL/issues/6766
 * SDL_JoystickPathForIndex() - replaced with SDL_GetJoystickInstancePath()
diff --git a/include/SDL3/SDL_gamepad.h b/include/SDL3/SDL_gamepad.h
index 2707feec3012..87fd8ee4901f 100644
--- a/include/SDL3/SDL_gamepad.h
+++ b/include/SDL3/SDL_gamepad.h
@@ -75,15 +75,6 @@ typedef enum
     SDL_GAMEPAD_TYPE_MAX
 } SDL_GamepadType;
 
-typedef enum
-{
-    SDL_GAMEPAD_CAP_MONO_LED       = 0x00000001,   /**< This gamepad has an LED that has adjustable brightness */
-    SDL_GAMEPAD_CAP_RGB_LED        = 0x00000002,   /**< This gamepad has an LED that has adjustable color */
-    SDL_GAMEPAD_CAP_PLAYER_LED     = 0x00000004,   /**< This gamepad has a player LED */
-    SDL_GAMEPAD_CAP_RUMBLE         = 0x00000010,   /**< This gamepad has left/right rumble */
-    SDL_GAMEPAD_CAP_TRIGGER_RUMBLE = 0x00000020,   /**< This gamepad has simple trigger rumble */
-} SDL_GamepadCaps;
-
 /**
  *  The list of buttons available on a gamepad
  *
@@ -603,6 +594,13 @@ extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromPlayerIndex(int player_in
  *
  * These properties are shared with the underlying joystick object.
  *
+ * The following read-only properties are provided by SDL:
+ * - `SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN`: true if this gamepad has an LED that has adjustable brightness
+ * - `SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN`: true if this gamepad has an LED that has adjustable color
+ * - `SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN`: true if this gamepad has a player LED
+ * - `SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN`: true if this gamepad has left/right rumble
+ * - `SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this gamepad has simple trigger rumble
+ *
  * \param gamepad a gamepad identifier previously returned by
  *                SDL_OpenGamepad()
  * \returns a valid property ID on success or 0 on failure; call
@@ -615,6 +613,12 @@ extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromPlayerIndex(int player_in
  */
 extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGamepadProperties(SDL_Gamepad *gamepad);
 
+#define SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN       SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN
+#define SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN        SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN
+#define SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN     SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN
+#define SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN         SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN
+#define SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN
+
 /**
  * Get the instance ID of an opened gamepad.
  *
@@ -1178,17 +1182,6 @@ extern DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad,
  */
 extern DECLSPEC int SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
 
-/**
- * Query gamepad capabilities
- *
- * \param gamepad The gamepad to query
- * \returns a mask of SDL_GamepadCaps values indicating the gamepad
- *          capabilities.
- *
- * \since This function is available since SDL 3.0.0.
- */
-extern DECLSPEC Uint32 SDLCALL SDL_GetGamepadCaps(SDL_Gamepad *gamepad);
-
 /**
  * Start a rumble effect on a gamepad.
  *
@@ -1204,8 +1197,6 @@ extern DECLSPEC Uint32 SDLCALL SDL_GetGamepadCaps(SDL_Gamepad *gamepad);
  * \returns 0, or -1 if rumble isn't supported on this gamepad
  *
  * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_GetGamepadCaps
  */
 extern DECLSPEC int SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
 
@@ -1229,8 +1220,6 @@ extern DECLSPEC int SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_f
  *          SDL_GetError() for more information.
  *
  * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_GetGamepadCaps
  */
 extern DECLSPEC int SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
 
@@ -1251,8 +1240,6 @@ extern DECLSPEC int SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint
  *          SDL_GetError() for more information.
  *
  * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_GetGamepadCaps
  */
 extern DECLSPEC int SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
 
diff --git a/include/SDL3/SDL_joystick.h b/include/SDL3/SDL_joystick.h
index c55bc50876de..17833c40892d 100644
--- a/include/SDL3/SDL_joystick.h
+++ b/include/SDL3/SDL_joystick.h
@@ -97,15 +97,6 @@ typedef enum
     SDL_JOYSTICK_TYPE_THROTTLE
 } SDL_JoystickType;
 
-typedef enum
-{
-    SDL_JOYSTICK_CAP_MONO_LED       = 0x00000001,   /**< This joystick has an LED that has adjustable brightness */
-    SDL_JOYSTICK_CAP_RGB_LED        = 0x00000002,   /**< This joystick has an LED that has adjustable color */
-    SDL_JOYSTICK_CAP_PLAYER_LED     = 0x00000004,   /**< This joystick has a player LED */
-    SDL_JOYSTICK_CAP_RUMBLE         = 0x00000010,   /**< This joystick has left/right rumble */
-    SDL_JOYSTICK_CAP_TRIGGER_RUMBLE = 0x00000020,   /**< This joystick has simple trigger rumble */
-} SDL_JoystickCaps;
-
 typedef enum
 {
     SDL_JOYSTICK_POWER_UNKNOWN = -1,
@@ -469,6 +460,13 @@ extern DECLSPEC int SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, in
 /**
  * Get the properties associated with a joystick.
  *
+ * The following read-only properties are provided by SDL:
+ * - `SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN`: true if this joystick has an LED that has adjustable brightness
+ * - `SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN`: true if this joystick has an LED that has adjustable color
+ * - `SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN`: true if this joystick has a player LED
+ * - `SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN`: true if this joystick has left/right rumble
+ * - `SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this joystick has simple trigger rumble
+ *
  * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  * \returns a valid property ID on success or 0 on failure; call
  *          SDL_GetError() for more information.
@@ -480,6 +478,12 @@ extern DECLSPEC int SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, in
  */
 extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetJoystickProperties(SDL_Joystick *joystick);
 
+#define SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN          "SDL.joystick.cap.mono_led"
+#define SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN           "SDL.joystick.cap.rgb_led"
+#define SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN        "SDL.joystick.cap.player_led"
+#define SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN            "SDL.joystick.cap.rumble"
+#define SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN    "SDL.joystick.cap.trigger_rumble"
+
 /**
  * Get the implementation dependent name of a joystick.
  *
@@ -889,17 +893,6 @@ extern DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick,
 extern DECLSPEC Uint8 SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick,
                                                     int button);
 
-/**
- * Query joystick capabilities
- *
- * \param joystick The joystick to query
- * \returns a mask of SDL_JoystickCaps values indicating the joystick
- *          capabilities.
- *
- * \since This function is available since SDL 3.0.0.
- */
-extern DECLSPEC Uint32 SDLCALL SDL_GetJoystickCaps(SDL_Joystick *joystick);
-
 /**
  * Start a rumble effect.
  *
@@ -915,8 +908,6 @@ extern DECLSPEC Uint32 SDLCALL SDL_GetJoystickCaps(SDL_Joystick *joystick);
  * \returns 0, or -1 if rumble isn't supported on this joystick
  *
  * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_GetJoystickCaps
  */
 extern DECLSPEC int SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
 
@@ -941,8 +932,6 @@ extern DECLSPEC int SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 lo
  *          SDL_GetError() for more information.
  *
  * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_GetJoystickCaps
  */
 extern DECLSPEC int SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
 
@@ -963,8 +952,6 @@ extern DECLSPEC int SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, U
  *          SDL_GetError() for more information.
  *
  * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_GetJoystickCaps
  */
 extern DECLSPEC int SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
 
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index ce3f16210e89..edeca4f1bb69 100644
--- a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -959,8 +959,6 @@ SDL3_0.0.0 {
     SDL_GetHapticName;
     SDL_ReadSurfacePixel;
     SDL_FlipSurface;
-    SDL_GetGamepadCaps;
-    SDL_GetJoystickCaps;
     # extra symbols go here (don't modify this line)
   local: *;
 };
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index adb53d9b6e7b..eefa79983461 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -984,5 +984,3 @@
 #define SDL_GetHapticName SDL_GetHapticName_REAL
 #define SDL_ReadSurfacePixel SDL_ReadSurfacePixel_REAL
 #define SDL_FlipSurface SDL_FlipSurface_REAL
-#define SDL_GetGamepadCaps SDL_GetGamepadCaps_REAL
-#define SDL_GetJoystickCaps SDL_GetJoystickCaps_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 984f8201167d..41b05c74b5dc 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -1009,5 +1009,3 @@ SDL_DYNAPI_PROC(SDL_HapticID,SDL_GetHapticInstanceID,(SDL_Haptic *a),(a),return)
 SDL_DYNAPI_PROC(const char*,SDL_GetHapticName,(SDL_Haptic *a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_ReadSurfacePixel,(SDL_Surface *a, int b, int c, Uint8 *d, Uint8 *e, Uint8 *f, Uint8 *g),(a,b,c,d,e,f,g),return)
 SDL_DYNAPI_PROC(int,SDL_FlipSurface,(SDL_Surface *a, SDL_FlipMode b),(a,b),return)
-SDL_DYNAPI_PROC(Uint32,SDL_GetGamepadCaps,(SDL_Gamepad *a),(a),return)
-SDL_DYNAPI_PROC(Uint32,SDL_GetJoystickCaps,(SDL_Joystick *a),(a),return)
diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c
index ef8a93c0aa91..c699dbc9c243 100644
--- a/src/joystick/SDL_gamepad.c
+++ b/src/joystick/SDL_gamepad.c
@@ -3485,16 +3485,6 @@ int SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 r
     return SDL_RumbleJoystickTriggers(joystick, left_rumble, right_rumble, duration_ms);
 }
 
-Uint32 SDL_GetGamepadCaps(SDL_Gamepad *gamepad)
-{
-    SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
-
-    if (!joystick) {
-        return 0;
-    }
-    return SDL_GetJoystickCaps(joystick);
-}
-
 int SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue)
 {
     SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 63af60e8d5c0..683ec5b82ef2 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -1655,21 +1655,6 @@ int SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint1
     return retval;
 }
 
-Uint32 SDL_GetJoystickCaps(SDL_Joystick *joystick)
-{
-    Uint32 retval;
-
-    SDL_LockJoysticks();
-    {
-        CHECK_JOYSTICK_MAGIC(joystick, 0);
-
-        retval = joystick->driver->GetCapabilities(joystick);
-    }
-    SDL_UnlockJoysticks();
-
-    return retval;
-}
-
 int SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
 {
     int retval;
diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h
index d91fc2d8de0f..95544118da18 100644
--- a/src/joystick/SDL_sysjoystick.h
+++ b/src/joystick/SDL_sysjoystick.h
@@ -190,9 +190,6 @@ typedef struct SDL_JoystickDriver
     int (*Rumble)(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
     int (*RumbleTriggers)(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble);
 
-    /* Capability detection */
-    Uint32 (*GetCapabilities)(SDL_Joystick *joystick);
-
     /* LED functionality */
     int (*SetLED)(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
 
diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c
index cacb47b9e5d4..8b064c889812 100644
--- a/src/joystick/android/SDL_sysjoystick.c
+++ b/src/joystick/android/SDL_sysjoystick.c
@@ -597,11 +597,6 @@ static int ANDROID_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_ru
     return SDL_Unsupported();
 }
 
-static Uint32 ANDROID_JoystickGetCapabilities(SDL_Joystick *joystick)
-{
-    return 0;
-}
-
 static int ANDROID_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
 {
     return SDL_Unsupported();
@@ -694,7 +689,6 @@ SDL_JoystickDriver SDL_ANDROID_JoystickDriver = {
     ANDROID_JoystickOpen,
     ANDROID_JoystickRumble,
     ANDROID_JoystickRumbleTriggers,
-    ANDROID_JoystickGetCapabilities,
     ANDROID_JoystickSetLED,
     ANDROID_JoystickSendEffect,
     ANDROID_JoystickSetSensorsEnabled,
diff --git a/src/joystick/apple/SDL_mfijoystick.m b/src/joystick/apple/SDL_mfijoystick.m
index 3accd8b300e3..b65560deb6e7 100644
--- a/src/joystick/apple/SDL_mfijoystick.m
+++ b/src/joystick/apple/SDL_mfijoystick.m
@@ -1012,6 +1012,26 @@ static int IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
             }
 #endif /* ENABLE_MFI_SYSTEM_GESTURE_STATE */
 
+            if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
+                GCController *controller = device->controller;
+#ifdef ENABLE_MFI_LIGHT
+                if (controller.light) {
+                    SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, SDL_TRUE);
+                }
+#endif
+
+#ifdef ENABLE_MFI_RUMBLE
+                if (controller.haptics) {
+                    for (GCHapticsLocality locality in controller.haptics.supportedLocalities) {
+                        if ([locality isEqualToString:GCHapticsLocalityHandles]) {
+                            SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE);
+                        } else if ([locality isEqualToString:GCHapticsLocalityTriggers]) {
+                            SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN, SDL_TRUE);
+                        }
+                    }
+                }
+#endif
+            }
 #endif /* SDL_JOYSTICK_MFI */
         }
     }
@@ -1625,44 +1645,6 @@ static int IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble
 #endif
 }
 
-static Uint32 IOS_JoystickGetCapabilities(SDL_Joystick *joystick)
-{
-    Uint32 result = 0;
-
-#if defined(ENABLE_MFI_LIGHT) || defined(ENABLE_MFI_RUMBLE)
-    @autoreleasepool {
-        SDL_JoystickDeviceItem *device = joystick->hwdata;
-
-        if (device == NULL) {
-            return 0;
-        }
-
-        if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
-            GCController *controller = device->controller;
-#ifdef ENABLE_MFI_LIGHT
-            if (controller.light) {
-                result |= SDL_JOYSTICK_CAP_RGB_LED;
-            }
-#endif
-
-#ifdef ENABLE_MFI_RUMBLE
-            if (controller.haptics) {
-                for (GCHapticsLocality locality in controller.haptics.supportedLocalities) {
-                    if ([locality isEqualToString:GCHapticsLocalityHandles]) {
-                        result |= SDL_JOYSTICK_CAP_RUMBLE;
-                    } else if ([locality isEqualToString:GCHapticsLocalityTriggers]) {
-                        result |= SDL_JOYSTICK_CAP_TRIGGER_RUMBLE;
-                    }
-                }
-            }
-#endif
-        }
-    }
-#endif /* ENABLE_MFI_LIGHT || ENABLE_MFI_RUMBLE */
-
-    return result;
-}
-
 static int IOS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
 {
 #ifdef ENABLE_MFI_LIGHT
@@ -2184,7 +2166,6 @@ static void GetAppleSFSymbolsNameForElement(GCControllerElement *element, char *
     IOS_JoystickOpen,
     IOS_JoystickRumble,
     IOS_JoystickRumbleTriggers,
-    IOS_JoystickGetCapabilities,
     IOS_JoystickSetLED,
     IOS_JoystickSendEffect,
     IOS_JoystickSetSensorsEnabled,
diff --git a/src/joystick/bsd/SDL_bsdjoystick.c b/src/joystick/bsd/SDL_bsdjoystick.c
index ecdc3132a342..647015c470b2 100644
--- a/src/joystick/bsd/SDL_bsdjoystick.c
+++ b/src/joystick/bsd/SDL_bsdjoystick.c
@@ -829,11 +829,6 @@ static SDL_bool BSD_JoystickGetGamepadMapping(int device_index, SDL_GamepadMappi
     return SDL_FALSE;
 }
 
-static Uint32 BSD_JoystickGetCapabilities(SDL_Joystick *joystick)
-{
-    return 0;
-}
-
 static int BSD_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
 {
     return SDL_Unsupported();
@@ -863,7 +858,6 @@ SDL_JoystickDriver SDL_BSD_JoystickDriver = {
     BSD_JoystickOpen,
     BSD_JoystickRumble,
     BSD_JoystickRumbleTriggers,
-    BSD_JoystickGetCapabilities,
     BSD_JoystickSetLED,
     BSD_JoystickSendEffect,
     BSD_JoystickSetSensorsEnabled,
diff --git a/src/joystick/darwin/SDL_iokitjoystick.c b/src/joystick/darwin/SDL_iokitjoystick.c
index d2e1af3fb0f0..9900ecf44680 100644
--- a/src/joystick/darwin/SDL_iokitjoystick.c
+++ b/src/joystick/darwin/SDL_iokitjoystick.c
@@ -770,6 +770,11 @@ static int DARWIN_JoystickOpen(SDL_Joystick *joystick, int device_index)
     joystick->naxes = device->axes;
     joystick->nhats = device->hats;
     joystick->nbuttons = device->buttons;
+
+    if (device->ffservice) {
+        SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE);
+    }
+
     return 0;
 }
 
@@ -908,22 +913,6 @@ static int DARWIN_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rum
     return SDL_Unsupported();
 }
 
-static Uint32 DARWIN_JoystickGetCapabilities(SDL_Joystick *joystick)
-{
-    recDevice *device = joystick->hwdata;
-    Uint32 result = 0;
-
-    if (!device) {
-        return 0;
-    }
-
-    if (device->ffservice) {
-        result |= SDL_JOYSTICK_CAP_RUMBLE;
-    }
-
-    return result;
-}
-
 static int DARWIN_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
 {
     return SDL_Unsupported();
@@ -1084,7 +1073,6 @@ SDL_JoystickDriver SDL_DARWIN_JoystickDriver = {
     DARWIN_JoystickOpen,
     DARWIN_JoystickRumble,
     DARWIN_JoystickRumbleTriggers,
-    DARWIN_JoystickGetCapabilities,
     DARWIN_JoystickSetLED,
     DARWIN_JoystickSendEffect,
     DARWIN_JoystickSetSensorsEnabled,
diff --git a/src/joystick/dummy/SDL_sysjoystick.c b/src/joystick/dummy/SDL_sysjoystick.c
index 125e3c03ffa3..0d6a850d2c09 100644
--- a/src/joystick/dummy/SDL_sysjoystick.c
+++ b/src/joystick/dummy/SDL_sysjoystick.c
@@ -92,11 +92,6 @@ static int DUMMY_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumb
     return SDL_Unsupported();
 }
 
-static Uint32 DUMMY_JoystickGetCapabilities(SDL_Joystick *joystick)
-{
-    return 0;
-}
-
 static int DUMMY_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
 {
     return SDL_Unsupported();
@@ -143,7 +138,6 @@ SDL_JoystickDriver SDL_DUMMY_JoystickDriver = {
     DUMMY_JoystickOpen,
     DUMMY_JoystickRumble,
     DUMMY_JoystickRumbleTriggers,
-    DUMMY_JoystickGetCapabilities,
     DUMMY_JoystickSetLED,
     DUMMY_JoystickSendEffect,
     DUMMY_JoystickSetSensorsEnabled,
diff --git a/src/joystick/emscripten/SDL_sysjoystick.c b/src/joystick/emscripten/SDL_sysjoystick.c
index 3a6cd9d06fe7..a9be05618f96 100644
--- a/src/joystick/emscripten/SDL_sysjoystick.c
+++ b/src/joystick/emscripten/SDL_sysjoystick.c
@@ -395,11 +395,6 @@ static SDL_bool EMSCRIPTEN_JoystickGetGamepadMapping(int device_index, SDL_Gamep
     return SDL_FALSE;
 }
 
-static Uint32 EMSCRIPTEN_JoystickGetCapabilities(SDL_Joystick *joystick)
-{
-    return 0;
-}
-
 static int EMSCRIPTEN_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
 {
     return SDL_Unsupported();
@@ -429,7 +424,6 @@ SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver = {
     EMSCRIPTEN_JoystickOpen,
     EMSCRIPTEN_JoystickRumble,
     EMSCRIPTEN_JoystickRumbleTriggers,
-    EMSCRIPTEN_JoystickGetCapabilities,
     EMSCRIPTEN_JoystickSetLED,
     EMSCRIPTEN_JoystickSendEffect,
     EMSCRIPTEN_JoystickSetSensorsEnabled,
diff --git a/src/joystick/haiku/SDL_haikujoystick.cc b/src/joystick/haiku/SDL_haikujoystick.cc
index 9110b0adca5c..77961036ecb3 100644
--- a/src/joystick/haiku/SDL_haikujoystick.cc
+++ b/src/joystick/haiku/SDL_haikujoystick.cc
@@ -272,11 +272,6 @@ extern "C"
         return SDL_FALSE;
     }
 
-    static Uint32 HAIKU_JoystickGetCapabilities(SDL_Joystick *joystick)
-    {
-        return 0;
-    }
-
     static int HAIKU_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
     {
         return SDL_Unsupported();
@@ -308,7 +303,6 @@ extern "C"
         HAIKU_JoystickOpen,
         HAIKU_JoystickRumble,
         HAIKU_JoystickRumbleTriggers,
-        HAIKU_JoystickGetCapabilities,
         HAIKU_JoystickSetLED,
         HAIKU_JoystickSendEffect,
         HAIKU_JoystickSetSensorsEnabled,
diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c
index fc996bb836ad..ebb1936bec11 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps4.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps4.c
@@ -723,6 +723,8 @@ static void HIDAPI_DriverPS4_SetEnhancedModeAvailable(SDL_DriverPS4_Context *ctx
     if (ctx->device->is_bluetooth && ctx->official_controller) {
         ctx->report_battery = SDL_TRUE;
     }
+
+    HIDAPI_UpdateDeviceProperties(ctx->device);
 }
 
 static void HIDAPI_DriverPS4_SetEnhancedMode(SDL_DriverPS4_Context *ctx)
diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c
index b641989b632b..0e52bf8244eb 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps5.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps5.c
@@ -818,6 +818,8 @@ static void HIDAPI_DriverPS5_SetEnhancedModeAvailable(SDL_DriverPS5_Context *ctx
     if (ctx->device->is_bluetooth) {
         ctx->report_battery = SDL_TRUE;
     }
+
+    HIDAPI_UpdateDeviceProperties(ctx->device);
 }
 
 static void HIDAPI_DriverPS5_SetEnhancedMode(SDL_DriverPS5_Context *ctx)
diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c
index 2f96f9f61303..15290d1ccc70 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch.c
@@ -727,6 +727,7 @@ static void SDLCALL SDL_PlayerLEDHintChanged(void *userdata, const char *name, c
         ctx->m_bPlayerLights = bPlayerLights;
 
         UpdateSlotLED(ctx);
+        HIDAPI_UpdateDeviceProperties(ctx->device);
     }
 }
 
diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360.c b/src/joystick/hidapi/SDL_hidapi_xbox360.c
index a75c199aa111..819487b01423 100644
--- a/src/joystick/hidapi/SDL_hidapi_xbox360.c
+++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c
@@ -131,6 +131,7 @@ static void SDLCALL SDL_PlayerLEDHintChanged(void *userdata, const char *name, c
         ctx->player_lights = player_lights;
 
         UpdateSlotLED(ctx);
+        HIDAPI_UpdateDeviceProperties(ctx->device);
     }
 }
 
diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360w.c b/src/joystick/hidapi/SDL_hidapi_xbox360w.c
index 225fa0bb1f83..acae253a404b 100644
--- a/src/joystick/hidapi/SDL_hidapi_xbox360w.c
+++ b/src/joystick/hidapi/SDL_hidapi_xbox360w.c
@@ -103,6 +103,7 @@ static void SDLCALL SDL_PlayerLEDHintChanged(void *userdata, const char *name, c
         ctx->player_lights = player_lights;
 
         UpdateSlotLED(ctx);
+        HIDAPI_UpdateDeviceProperties(ctx->device);
     }
 }
 
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index 90b87cd8b740..e0a9adb59858 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -859,6 +859,54 @@ void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joyst
     SDL_UnlockJoysticks();
 }
 
+static void HIDAPI_UpdateJoystickProperties(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
+{
+    SDL_PropertiesID props = SDL_GetJoystickProperties(joystick);
+    Uint32 caps = device->driver->GetJoystickCapabilities(device, joystick);
+
+    if (caps & SDL_JOYSTICK_CAP_MONO_LED) {
+        SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN, SDL_TRUE);
+    } else {
+        SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN, SDL_FALSE);
+    }
+    if (caps & SDL_JOYSTICK_CAP_RGB_LED) {
+        SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, SDL_TRUE);
+    } else {
+        SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, SDL_FALSE);
+    }
+    if (caps & SDL_JOYSTICK_CAP_PLAYER_LED) {
+        SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN, SDL_TRUE);
+    } else {
+        SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN, SDL_FALSE);
+    }
+    if (caps & SDL_JOYSTICK_CAP_RUMBLE) {
+        SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE);
+    } else {
+        SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_FALSE);
+    }
+    if (caps & SDL_JOYSTICK_CAP_TRIGGER_RUMBLE) {
+        SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN, SDL_TRUE);
+    } else {
+        SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN, SDL_FALSE);
+    }
+}
+
+void HIDAPI_UpdateDeviceProperties(SDL_HIDAPI_Device *device)
+{
+    int i;
+
+    SDL_LockJoysticks();
+
+    for (i = 0; i < device->num_joysticks; ++i) {
+        SDL_Joystick *joystick = SDL_GetJoystickFromInstanceID(device->joysticks[i]);
+        if (joystick) {
+            HIDAPI_UpdateJoystickProperties(device, joystick);
+        }
+    }
+
+    SDL_UnlockJoysticks();
+}
+
 static int HIDAPI_JoystickGetCount(void)
 {
     return SDL_HIDAPI_numjoysticks;
@@ -1471,6 +1519,8 @@ static int HIDAPI_JoystickOpen(SDL_Joystick *joystick, int device_index)
         return -1;
     }
 
+    HIDAPI_UpdateJoystickProperties(device, joystick);
+
     if (device->serial) {
         joystick->serial = SDL_strdup(device->serial);
     }
@@ -1520,18 +1570,6 @@ static int HIDAPI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rum
     return result;
 }
 
-static Uint32 HIDAPI_JoystickGetCapabilities(SDL_Joystick *joystick)
-{
-    Uint32 result = 0;
-    SDL_HIDAPI_Device *device = NULL;
-
-    if (HIDAPI_GetJoystickDevice(joystick, &device)) {
-        result = device->driver->GetJoystickCapabilities(device, joystick);
-    }
-
-    return result;
-}
-
 static int HIDAPI_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
 {
     int result;
@@ -1671,7 +1709,6 @@ SDL_JoystickDriver SDL_HIDAPI_JoystickDriver = {
     HIDAPI_JoystickOpen,
     HIDAPI_JoystickRumble,
     HIDAPI_JoystickRumbleTriggers,
-    

(Patch may be truncated, please check the link at the top of this post.)