diff --git a/docs/README-migration.md b/docs/README-migration.md index ab82419fa6..1bb0c4ba57 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 2707feec30..87fd8ee490 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 c55bc50876..17833c4089 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 ce3f16210e..edeca4f1bb 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 adb53d9b6e..eefa799834 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 984f820116..41b05c74b5 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 ef8a93c0aa..c699dbc9c2 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 63af60e8d5..683ec5b82e 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 d91fc2d8de..95544118da 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 cacb47b9e5..8b064c8898 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 3accd8b300..b65560deb6 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 @@ SDL_JoystickDriver SDL_IOS_JoystickDriver = { 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 ecdc3132a3..647015c470 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 d2e1af3fb0..9900ecf446 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 125e3c03ff..0d6a850d2c 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 3a6cd9d06f..a9be05618f 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 9110b0adca..77961036ec 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 fc996bb836..ebb1936bec 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 b641989b63..0e52bf8244 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 2f96f9f613..15290d1ccc 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 a75c199aa1..819487b014 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 225fa0bb1f..acae253a40 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 90b87cd8b7..e0a9adb598 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, - HIDAPI_JoystickGetCapabilities, HIDAPI_JoystickSetLED, HIDAPI_JoystickSendEffect, HIDAPI_JoystickSetSensorsEnabled, diff --git a/src/joystick/hidapi/SDL_hidapijoystick_c.h b/src/joystick/hidapi/SDL_hidapijoystick_c.h index 9cb1702194..c99073bade 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick_c.h +++ b/src/joystick/hidapi/SDL_hidapijoystick_c.h @@ -40,6 +40,13 @@ #define SDL_JOYSTICK_HIDAPI_XBOXONE #define SDL_JOYSTICK_HIDAPI_SHIELD +/* Joystick capability definitions */ +#define SDL_JOYSTICK_CAP_MONO_LED 0x00000001 +#define SDL_JOYSTICK_CAP_RGB_LED 0x00000002 +#define SDL_JOYSTICK_CAP_PLAYER_LED 0x00000004 +#define SDL_JOYSTICK_CAP_RUMBLE 0x00000010 +#define SDL_JOYSTICK_CAP_TRIGGER_RUMBLE 0x00000020 + /* Whether HIDAPI is enabled by default */ #define SDL_HIDAPI_DEFAULT SDL_TRUE @@ -156,6 +163,7 @@ extern SDL_bool HIDAPI_HasConnectedUSBDevice(const char *serial); extern void HIDAPI_DisconnectBluetoothDevice(const char *serial); extern SDL_bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID); extern void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID); +extern void HIDAPI_UpdateDeviceProperties(SDL_HIDAPI_Device *device); extern void HIDAPI_DumpPacket(const char *prefix, const Uint8 *data, int size); diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 6ac291622b..841e4b026e 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -1609,6 +1609,9 @@ static int LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index) joystick->hwdata->fd_sensor = -1; } + if (joystick->hwdata->ff_rumble || joystick->hwdata->ff_sine) { + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE); + } return 0; } @@ -1660,19 +1663,6 @@ static int LINUX_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumb return SDL_Unsupported(); } -static Uint32 LINUX_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - Uint32 result = 0; - - SDL_AssertJoysticksLocked(); - - if (joystick->hwdata->ff_rumble || joystick->hwdata->ff_sine) { - result |= SDL_JOYSTICK_CAP_RUMBLE; - } - - return result; -} - static int LINUX_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); @@ -2706,7 +2696,6 @@ SDL_JoystickDriver SDL_LINUX_JoystickDriver = { LINUX_JoystickOpen, LINUX_JoystickRumble, LINUX_JoystickRumbleTriggers, - LINUX_JoystickGetCapabilities, LINUX_JoystickSetLED, LINUX_JoystickSendEffect, LINUX_JoystickSetSensorsEnabled, diff --git a/src/joystick/n3ds/SDL_sysjoystick.c b/src/joystick/n3ds/SDL_sysjoystick.c index 79a666f6b7..863a1c1747 100644 --- a/src/joystick/n3ds/SDL_sysjoystick.c +++ b/src/joystick/n3ds/SDL_sysjoystick.c @@ -245,11 +245,6 @@ static void N3DS_JoystickSetDevicePlayerIndex(int device_index, int player_index { } -static Uint32 N3DS_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - return 0; -} - static int N3DS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { return SDL_Unsupported(); @@ -284,7 +279,6 @@ SDL_JoystickDriver SDL_N3DS_JoystickDriver = { .Open = N3DS_JoystickOpen, .Rumble = N3DS_JoystickRumble, .RumbleTriggers = N3DS_JoystickRumbleTriggers, - .GetCapabilities = N3DS_JoystickGetCapabilities, .SetLED = N3DS_JoystickSetLED, .SendEffect = N3DS_JoystickSendEffect, .SetSensorsEnabled = N3DS_JoystickSetSensorsEnabled, diff --git a/src/joystick/ps2/SDL_sysjoystick.c b/src/joystick/ps2/SDL_sysjoystick.c index 44ec63eafd..ad264584e6 100644 --- a/src/joystick/ps2/SDL_sysjoystick.c +++ b/src/joystick/ps2/SDL_sysjoystick.c @@ -210,6 +210,8 @@ static int PS2_JoystickOpen(SDL_Joystick *joystick, int device_index) joystick->nhats = 0; joystick->instance_id = device_index; + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE); + return 0; } @@ -240,31 +242,25 @@ static int PS2_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl /* Rumble functionality */ static int PS2_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left, Uint16 right) { - return -1; -} - -/* Capability detection */ -static Uint32 PS2_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - return SDL_JOYSTICK_CAP_RUMBLE; + return SDL_Unsupported(); } /* LED functionality */ static int PS2_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { - return -1; + return SDL_Unsupported(); } /* General effects */ static int PS2_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { - return -1; + return SDL_Unsupported(); } /* Sensor functionality */ static int PS2_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled) { - return -1; + return SDL_Unsupported(); } /* Function to update the state of a joystick - called as a device poll. @@ -355,7 +351,6 @@ SDL_JoystickDriver SDL_PS2_JoystickDriver = { PS2_JoystickOpen, PS2_JoystickRumble, PS2_JoystickRumbleTriggers, - PS2_JoystickGetCapabilities, PS2_JoystickSetLED, PS2_JoystickSendEffect, PS2_JoystickSetSensorsEnabled, diff --git a/src/joystick/psp/SDL_sysjoystick.c b/src/joystick/psp/SDL_sysjoystick.c index f66abfaa7d..2ae252865b 100644 --- a/src/joystick/psp/SDL_sysjoystick.c +++ b/src/joystick/psp/SDL_sysjoystick.c @@ -173,11 +173,6 @@ static int PSP_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble return SDL_Unsupported(); } -static Uint32 PSP_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - return 0; -} - static int PSP_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); @@ -266,7 +261,6 @@ SDL_JoystickDriver SDL_PSP_JoystickDriver = { PSP_JoystickOpen, PSP_JoystickRumble, PSP_JoystickRumbleTriggers, - PSP_JoystickGetCapabilities, PSP_JoystickSetLED, PSP_JoystickSendEffect, PSP_JoystickSetSensorsEnabled, diff --git a/src/joystick/virtual/SDL_virtualjoystick.c b/src/joystick/virtual/SDL_virtualjoystick.c index e683c654bb..d756f368dc 100644 --- a/src/joystick/virtual/SDL_virtualjoystick.c +++ b/src/joystick/virtual/SDL_virtualjoystick.c @@ -422,6 +422,16 @@ static int VIRTUAL_JoystickOpen(SDL_Joystick *joystick, int device_index) joystick->nbuttons = hwdata->desc.nbuttons; joystick->nhats = hwdata->desc.nhats; hwdata->joystick = joystick; + + if (hwdata->desc.SetLED) { + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, SDL_TRUE); + } + if (hwdata->desc.Rumble) { + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE); + } + if (hwdata->desc.RumbleTriggers) { + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN, SDL_TRUE); + } return 0; } @@ -465,28 +475,6 @@ static int VIRTUAL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_ru return result; } -static Uint32 VIRTUAL_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - joystick_hwdata *hwdata; - Uint32 caps = 0; - - SDL_AssertJoysticksLocked(); - - hwdata = joystick->hwdata; - if (hwdata) { - if (hwdata->desc.Rumble) { - caps |= SDL_JOYSTICK_CAP_RUMBLE; - } - if (hwdata->desc.RumbleTriggers) { - caps |= SDL_JOYSTICK_CAP_TRIGGER_RUMBLE; - } - if (hwdata->desc.SetLED) { - caps |= SDL_JOYSTICK_CAP_RGB_LED; - } - } - return caps; -} - static int VIRTUAL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { int result; @@ -741,7 +729,6 @@ SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver = { VIRTUAL_JoystickOpen, VIRTUAL_JoystickRumble, VIRTUAL_JoystickRumbleTriggers, - VIRTUAL_JoystickGetCapabilities, VIRTUAL_JoystickSetLED, VIRTUAL_JoystickSendEffect, VIRTUAL_JoystickSetSensorsEnabled, diff --git a/src/joystick/vita/SDL_sysjoystick.c b/src/joystick/vita/SDL_sysjoystick.c index b8cdb4d949..35ec7ebdd8 100644 --- a/src/joystick/vita/SDL_sysjoystick.c +++ b/src/joystick/vita/SDL_sysjoystick.c @@ -207,6 +207,9 @@ int VITA_JoystickOpen(SDL_Joystick *joystick, int device_index) joystick->nhats = 0; joystick->instance_id = device_index; + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, SDL_TRUE); + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE); + return 0; } @@ -344,12 +347,6 @@ static int VITA_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left, Uint return SDL_Unsupported(); } -static Uint32 VITA_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - // always return LED and rumble supported for now - return SDL_JOYSTICK_CAP_RGB_LED | SDL_JOYSTICK_CAP_RUMBLE; -} - static int VITA_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { int index = (int)SDL_GetJoystickInstanceID(joystick) - 1; @@ -388,17 +385,12 @@ SDL_JoystickDriver SDL_VITA_JoystickDriver = { VITA_JoystickSetDevicePlayerIndex, VITA_JoystickGetDeviceGUID, VITA_JoystickGetDeviceInstanceID, - VITA_JoystickOpen, - VITA_JoystickRumble, VITA_JoystickRumbleTriggers, - - VITA_JoystickGetCapabilities, VITA_JoystickSetLED, VITA_JoystickSendEffect, VITA_JoystickSetSensorsEnabled, - VITA_JoystickUpdate, VITA_JoystickClose, VITA_JoystickQuit, diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c index 61a17b1d3a..80a8d66eb3 100644 --- a/src/joystick/windows/SDL_dinputjoystick.c +++ b/src/joystick/windows/SDL_dinputjoystick.c @@ -826,6 +826,8 @@ int SDL_DINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystic return SetDIerror("IDirectInputDevice8::SetProperty", result); } */ + + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE); } /* What buttons and axes does it have? */ @@ -945,17 +947,6 @@ int SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl return 0; } -Uint32 SDL_DINPUT_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - Uint32 result = 0; - - if (joystick->hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) { - result |= SDL_JOYSTICK_CAP_RUMBLE; - } - - return result; -} - static Uint8 TranslatePOV(DWORD value) { const Uint8 HAT_VALS[] = { @@ -1193,11 +1184,6 @@ int SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl return SDL_Unsupported(); } -Uint32 SDL_DINPUT_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - return 0; -} - void SDL_DINPUT_JoystickUpdate(SDL_Joystick *joystick) { } diff --git a/src/joystick/windows/SDL_dinputjoystick_c.h b/src/joystick/windows/SDL_dinputjoystick_c.h index d864f737d0..780f6a3634 100644 --- a/src/joystick/windows/SDL_dinputjoystick_c.h +++ b/src/joystick/windows/SDL_dinputjoystick_c.h @@ -30,7 +30,6 @@ extern void SDL_DINPUT_JoystickDetect(JoyStick_DeviceData **pContext); extern SDL_bool SDL_DINPUT_JoystickPresent(Uint16 vendor, Uint16 product, Uint16 version); extern int SDL_DINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice); extern int SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); -extern Uint32 SDL_DINPUT_JoystickGetCapabilities(SDL_Joystick *joystick); extern void SDL_DINPUT_JoystickUpdate(SDL_Joystick *joystick); extern void SDL_DINPUT_JoystickClose(SDL_Joystick *joystick); extern void SDL_DINPUT_JoystickQuit(void); diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c index 60ae2f3da6..671e3a376d 100644 --- a/src/joystick/windows/SDL_rawinputjoystick.c +++ b/src/joystick/windows/SDL_rawinputjoystick.c @@ -1431,6 +1431,21 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN; +#ifdef SDL_JOYSTICK_RAWINPUT_XINPUT + if (ctx->is_xinput) { + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE); + } +#endif +#ifdef SDL_JOYSTICK_RAWINPUT_WGI + if (ctx->is_xinput) { + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE); + + if (ctx->is_xboxone) { + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN, SDL_TRUE); + } + } +#endif + return 0; } @@ -1506,31 +1521,6 @@ static int RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_r #endif } -static Uint32 RAWINPUT_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - Uint32 result = 0; -#if defined(SDL_JOYSTICK_RAWINPUT_XINPUT) || defined(SDL_JOYSTICK_RAWINPUT_WGI) - RAWINPUT_DeviceContext *ctx = joystick->hwdata; - -#ifdef SDL_JOYSTICK_RAWINPUT_XINPUT - if (ctx->is_xinput) { - result |= SDL_JOYSTICK_CAP_RUMBLE; - } -#endif -#ifdef SDL_JOYSTICK_RAWINPUT_WGI - if (ctx->is_xinput) { - result |= SDL_JOYSTICK_CAP_RUMBLE; - - if (ctx->is_xboxone) { - result |= SDL_JOYSTICK_CAP_TRIGGER_RUMBLE; - } - } -#endif -#endif /**/ - - return result; -} - static int RAWINPUT_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); @@ -2226,7 +2216,6 @@ SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver = { RAWINPUT_JoystickOpen, RAWINPUT_JoystickRumble, RAWINPUT_JoystickRumbleTriggers, - RAWINPUT_JoystickGetCapabilities, RAWINPUT_JoystickSetLED, RAWINPUT_JoystickSendEffect, RAWINPUT_JoystickSetSensorsEnabled, diff --git a/src/joystick/windows/SDL_windows_gaming_input.c b/src/joystick/windows/SDL_windows_gaming_input.c index 71a2c3b381..61e8b2c417 100644 --- a/src/joystick/windows/SDL_windows_gaming_input.c +++ b/src/joystick/windows/SDL_windows_gaming_input.c @@ -749,6 +749,11 @@ static int WGI_JoystickOpen(SDL_Joystick *joystick, int device_index) __x_ABI_CWindows_CGaming_CInput_CIRawGameController_get_AxisCount(hwdata->controller, &joystick->naxes); __x_ABI_CWindows_CGaming_CInput_CIRawGameController_get_SwitchCount(hwdata->controller, &joystick->nhats); + if (hwdata->gamepad) { + /* FIXME: Can WGI even tell us if trigger rumble is supported? */ + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE); + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN, SDL_TRUE); + } return 0; } @@ -794,18 +799,6 @@ static int WGI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble } } -static Uint32 WGI_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - struct joystick_hwdata *hwdata = joystick->hwdata; - - if (hwdata->gamepad) { - /* FIXME: Can WGI even tell us if trigger rumble is supported? */ - return (SDL_JOYSTICK_CAP_RUMBLE | SDL_JOYSTICK_CAP_TRIGGER_RUMBLE); - } else { - return 0; - } -} - static int WGI_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); @@ -1026,7 +1019,6 @@ SDL_JoystickDriver SDL_WGI_JoystickDriver = { WGI_JoystickOpen, WGI_JoystickRumble, WGI_JoystickRumbleTriggers, - WGI_JoystickGetCapabilities, WGI_JoystickSetLED, WGI_JoystickSendEffect, WGI_JoystickSetSensorsEnabled, diff --git a/src/joystick/windows/SDL_windowsjoystick.c b/src/joystick/windows/SDL_windowsjoystick.c index 59d851287b..0aa33797ab 100644 --- a/src/joystick/windows/SDL_windowsjoystick.c +++ b/src/joystick/windows/SDL_windowsjoystick.c @@ -704,15 +704,6 @@ static int WINDOWS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_ru return SDL_Unsupported(); } -static Uint32 WINDOWS_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - if (joystick->hwdata->bXInputDevice) { - return SDL_XINPUT_JoystickGetCapabilities(joystick); - } else { - return SDL_DINPUT_JoystickGetCapabilities(joystick); - } -} - static int WINDOWS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); @@ -807,7 +798,6 @@ SDL_JoystickDriver SDL_WINDOWS_JoystickDriver = { WINDOWS_JoystickOpen, WINDOWS_JoystickRumble, WINDOWS_JoystickRumbleTriggers, - WINDOWS_JoystickGetCapabilities, WINDOWS_JoystickSetLED, WINDOWS_JoystickSendEffect, WINDOWS_JoystickSetSensorsEnabled, diff --git a/src/joystick/windows/SDL_xinputjoystick.c b/src/joystick/windows/SDL_xinputjoystick.c index e054ad88bb..44d3457edb 100644 --- a/src/joystick/windows/SDL_xinputjoystick.c +++ b/src/joystick/windows/SDL_xinputjoystick.c @@ -263,6 +263,9 @@ int SDL_XINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystic joystick->naxes = 6; joystick->nbuttons = 11; joystick->nhats = 1; + + SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE); + return 0; } @@ -351,11 +354,6 @@ int SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl return 0; } -Uint32 SDL_XINPUT_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - return SDL_JOYSTICK_CAP_RUMBLE; -} - void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick) { DWORD result; @@ -432,11 +430,6 @@ int SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl return SDL_Unsupported(); } -Uint32 SDL_XINPUT_JoystickGetCapabilities(SDL_Joystick *joystick) -{ - return 0; -} - void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick) { } diff --git a/src/joystick/windows/SDL_xinputjoystick_c.h b/src/joystick/windows/SDL_xinputjoystick_c.h index 180086388d..8973f8b7c3 100644 --- a/src/joystick/windows/SDL_xinputjoystick_c.h +++ b/src/joystick/windows/SDL_xinputjoystick_c.h @@ -32,7 +32,6 @@ extern int SDL_XINPUT_JoystickInit(void); extern void SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext); extern int SDL_XINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice); extern int SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); -extern Uint32 SDL_XINPUT_JoystickGetCapabilities(SDL_Joystick *joystick); extern void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick); extern void SDL_XINPUT_JoystickClose(SDL_Joystick *joystick); extern void SDL_XINPUT_JoystickQuit(void); diff --git a/test/testcontroller.c b/test/testcontroller.c index 60cb83bd8b..16908afbb7 100644 --- a/test/testcontroller.c +++ b/test/testcontroller.c @@ -977,6 +977,7 @@ static void HandleGamepadAdded(SDL_JoystickID id, SDL_bool verbose) gamepad = controllers[i].gamepad; if (gamepad) { if (verbose) { + SDL_PropertiesID props = SDL_GetGamepadProperties(gamepad); const char *name = SDL_GetGamepadName(gamepad); const char *path = SDL_GetGamepadPath(gamepad); SDL_Log("Opened gamepad %s%s%s\n", name, path ? ", " : "", path ? path : ""); @@ -986,11 +987,15 @@ static void HandleGamepadAdded(SDL_JoystickID id, SDL_bool verbose) SDL_Log("Firmware version: 0x%x (%d)\n", firmware_version, firmware_version); } - if (SDL_GetGamepadCaps(gamepad) & SDL_GAMEPAD_CAP_RUMBLE) { + if (SDL_GetBooleanProperty(props, SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN, SDL_FALSE)) { + SDL_Log("Has player LED"); + } + + if (SDL_GetBooleanProperty(props, SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN, SDL_FALSE)) { SDL_Log("Rumble supported"); } - if (SDL_GetGamepadCaps(gamepad) & SDL_GAMEPAD_CAP_TRIGGER_RUMBLE) { + if (SDL_GetBooleanProperty(props, SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN, SDL_FALSE)) { SDL_Log("Trigger rumble supported"); }