Replaced SDL_GetJoystickCaps() with joystick properties

Fixes https://github.com/libsdl-org/SDL/issues/8927
This commit is contained in:
Sam Lantinga 2024-01-27 14:37:30 -08:00
parent 019dc53764
commit f66fe7e221
37 changed files with 176 additions and 341 deletions

View file

@ -565,9 +565,9 @@ The following functions have been removed:
* SDL_GameControllerEventState() - replaced with SDL_SetGamepadEventsEnabled() and SDL_GamepadEventsEnabled() * SDL_GameControllerEventState() - replaced with SDL_SetGamepadEventsEnabled() and SDL_GamepadEventsEnabled()
* SDL_GameControllerGetBindForAxis() - replaced with SDL_GetGamepadBindings() * SDL_GameControllerGetBindForAxis() - replaced with SDL_GetGamepadBindings()
* SDL_GameControllerGetBindForButton() - replaced with SDL_GetGamepadBindings() * SDL_GameControllerGetBindForButton() - replaced with SDL_GetGamepadBindings()
* SDL_GameControllerHasLED() - replaced with SDL_GetGamepadCaps() * SDL_GameControllerHasLED() - replaced with SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN
* SDL_GameControllerHasRumble() - replaced with SDL_GetGamepadCaps() * SDL_GameControllerHasRumble() - replaced with SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN
* SDL_GameControllerHasRumbleTriggers() - replaced with SDL_GetGamepadCaps() * SDL_GameControllerHasRumbleTriggers() - replaced with SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN
* SDL_GameControllerMappingForDeviceIndex() - replaced with SDL_GetGamepadInstanceMapping() * SDL_GameControllerMappingForDeviceIndex() - replaced with SDL_GetGamepadInstanceMapping()
* SDL_GameControllerMappingForIndex() - replaced with SDL_GetGamepadMappings() * SDL_GameControllerMappingForIndex() - replaced with SDL_GetGamepadMappings()
* SDL_GameControllerNameForIndex() - replaced with SDL_GetGamepadInstanceName() * SDL_GameControllerNameForIndex() - replaced with SDL_GetGamepadInstanceName()
@ -811,9 +811,9 @@ The following functions have been removed:
* SDL_JoystickGetDeviceProductVersion() - replaced with SDL_GetJoystickInstanceProductVersion() * SDL_JoystickGetDeviceProductVersion() - replaced with SDL_GetJoystickInstanceProductVersion()
* SDL_JoystickGetDeviceType() - replaced with SDL_GetJoystickInstanceType() * SDL_JoystickGetDeviceType() - replaced with SDL_GetJoystickInstanceType()
* SDL_JoystickGetDeviceVendor() - replaced with SDL_GetJoystickInstanceVendor() * SDL_JoystickGetDeviceVendor() - replaced with SDL_GetJoystickInstanceVendor()
* SDL_JoystickHasLED() - replaced with SDL_GetJoystickCaps() * SDL_JoystickHasLED() - replaced with SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN
* SDL_JoystickHasRumble() - replaced with SDL_GetJoystickCaps() * SDL_JoystickHasRumble() - replaced with SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN
* SDL_JoystickHasRumbleTriggers() - replaced with SDL_GetJoystickCaps() * SDL_JoystickHasRumbleTriggers() - replaced with SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN
* SDL_JoystickNameForIndex() - replaced with SDL_GetJoystickInstanceName() * SDL_JoystickNameForIndex() - replaced with SDL_GetJoystickInstanceName()
* SDL_JoystickNumBalls() - API has been removed, see https://github.com/libsdl-org/SDL/issues/6766 * SDL_JoystickNumBalls() - API has been removed, see https://github.com/libsdl-org/SDL/issues/6766
* SDL_JoystickPathForIndex() - replaced with SDL_GetJoystickInstancePath() * SDL_JoystickPathForIndex() - replaced with SDL_GetJoystickInstancePath()

View file

@ -75,15 +75,6 @@ typedef enum
SDL_GAMEPAD_TYPE_MAX SDL_GAMEPAD_TYPE_MAX
} SDL_GamepadType; } 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 * 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. * 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 * \param gamepad a gamepad identifier previously returned by
* SDL_OpenGamepad() * SDL_OpenGamepad()
* \returns a valid property ID on success or 0 on failure; call * \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); 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. * 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); 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. * 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 * \returns 0, or -1 if rumble isn't supported on this gamepad
* *
* \since This function is available since SDL 3.0.0. * \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); 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. * SDL_GetError() for more information.
* *
* \since This function is available since SDL 3.0.0. * \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); 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. * SDL_GetError() for more information.
* *
* \since This function is available since SDL 3.0.0. * \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); extern DECLSPEC int SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);

View file

@ -97,15 +97,6 @@ typedef enum
SDL_JOYSTICK_TYPE_THROTTLE SDL_JOYSTICK_TYPE_THROTTLE
} SDL_JoystickType; } 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 typedef enum
{ {
SDL_JOYSTICK_POWER_UNKNOWN = -1, 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. * 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() * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
* \returns a valid property ID on success or 0 on failure; call * \returns a valid property ID on success or 0 on failure; call
* SDL_GetError() for more information. * 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); 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. * 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, extern DECLSPEC Uint8 SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick,
int button); 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. * 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 * \returns 0, or -1 if rumble isn't supported on this joystick
* *
* \since This function is available since SDL 3.0.0. * \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); 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. * SDL_GetError() for more information.
* *
* \since This function is available since SDL 3.0.0. * \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); 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. * SDL_GetError() for more information.
* *
* \since This function is available since SDL 3.0.0. * \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); extern DECLSPEC int SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);

View file

@ -959,8 +959,6 @@ SDL3_0.0.0 {
SDL_GetHapticName; SDL_GetHapticName;
SDL_ReadSurfacePixel; SDL_ReadSurfacePixel;
SDL_FlipSurface; SDL_FlipSurface;
SDL_GetGamepadCaps;
SDL_GetJoystickCaps;
# extra symbols go here (don't modify this line) # extra symbols go here (don't modify this line)
local: *; local: *;
}; };

View file

@ -984,5 +984,3 @@
#define SDL_GetHapticName SDL_GetHapticName_REAL #define SDL_GetHapticName SDL_GetHapticName_REAL
#define SDL_ReadSurfacePixel SDL_ReadSurfacePixel_REAL #define SDL_ReadSurfacePixel SDL_ReadSurfacePixel_REAL
#define SDL_FlipSurface SDL_FlipSurface_REAL #define SDL_FlipSurface SDL_FlipSurface_REAL
#define SDL_GetGamepadCaps SDL_GetGamepadCaps_REAL
#define SDL_GetJoystickCaps SDL_GetJoystickCaps_REAL

View file

@ -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(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_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(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)

View file

@ -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); 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) int SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue)
{ {
SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad);

View file

@ -1655,21 +1655,6 @@ int SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint1
return retval; 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 SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
int retval; int retval;

View file

@ -190,9 +190,6 @@ typedef struct SDL_JoystickDriver
int (*Rumble)(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); int (*Rumble)(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
int (*RumbleTriggers)(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble); int (*RumbleTriggers)(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble);
/* Capability detection */
Uint32 (*GetCapabilities)(SDL_Joystick *joystick);
/* LED functionality */ /* LED functionality */
int (*SetLED)(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); int (*SetLED)(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);

View file

@ -597,11 +597,6 @@ static int ANDROID_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_ru
return SDL_Unsupported(); 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) static int ANDROID_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
return SDL_Unsupported(); return SDL_Unsupported();
@ -694,7 +689,6 @@ SDL_JoystickDriver SDL_ANDROID_JoystickDriver = {
ANDROID_JoystickOpen, ANDROID_JoystickOpen,
ANDROID_JoystickRumble, ANDROID_JoystickRumble,
ANDROID_JoystickRumbleTriggers, ANDROID_JoystickRumbleTriggers,
ANDROID_JoystickGetCapabilities,
ANDROID_JoystickSetLED, ANDROID_JoystickSetLED,
ANDROID_JoystickSendEffect, ANDROID_JoystickSendEffect,
ANDROID_JoystickSetSensorsEnabled, ANDROID_JoystickSetSensorsEnabled,

View file

@ -1012,6 +1012,26 @@ static int IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
} }
#endif /* ENABLE_MFI_SYSTEM_GESTURE_STATE */ #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 */ #endif /* SDL_JOYSTICK_MFI */
} }
} }
@ -1625,44 +1645,6 @@ static int IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble
#endif #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) static int IOS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
#ifdef ENABLE_MFI_LIGHT #ifdef ENABLE_MFI_LIGHT
@ -2184,7 +2166,6 @@ SDL_JoystickDriver SDL_IOS_JoystickDriver = {
IOS_JoystickOpen, IOS_JoystickOpen,
IOS_JoystickRumble, IOS_JoystickRumble,
IOS_JoystickRumbleTriggers, IOS_JoystickRumbleTriggers,
IOS_JoystickGetCapabilities,
IOS_JoystickSetLED, IOS_JoystickSetLED,
IOS_JoystickSendEffect, IOS_JoystickSendEffect,
IOS_JoystickSetSensorsEnabled, IOS_JoystickSetSensorsEnabled,

View file

@ -829,11 +829,6 @@ static SDL_bool BSD_JoystickGetGamepadMapping(int device_index, SDL_GamepadMappi
return SDL_FALSE; 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) static int BSD_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
return SDL_Unsupported(); return SDL_Unsupported();
@ -863,7 +858,6 @@ SDL_JoystickDriver SDL_BSD_JoystickDriver = {
BSD_JoystickOpen, BSD_JoystickOpen,
BSD_JoystickRumble, BSD_JoystickRumble,
BSD_JoystickRumbleTriggers, BSD_JoystickRumbleTriggers,
BSD_JoystickGetCapabilities,
BSD_JoystickSetLED, BSD_JoystickSetLED,
BSD_JoystickSendEffect, BSD_JoystickSendEffect,
BSD_JoystickSetSensorsEnabled, BSD_JoystickSetSensorsEnabled,

View file

@ -770,6 +770,11 @@ static int DARWIN_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->naxes = device->axes; joystick->naxes = device->axes;
joystick->nhats = device->hats; joystick->nhats = device->hats;
joystick->nbuttons = device->buttons; joystick->nbuttons = device->buttons;
if (device->ffservice) {
SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE);
}
return 0; return 0;
} }
@ -908,22 +913,6 @@ static int DARWIN_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rum
return SDL_Unsupported(); 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) static int DARWIN_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
return SDL_Unsupported(); return SDL_Unsupported();
@ -1084,7 +1073,6 @@ SDL_JoystickDriver SDL_DARWIN_JoystickDriver = {
DARWIN_JoystickOpen, DARWIN_JoystickOpen,
DARWIN_JoystickRumble, DARWIN_JoystickRumble,
DARWIN_JoystickRumbleTriggers, DARWIN_JoystickRumbleTriggers,
DARWIN_JoystickGetCapabilities,
DARWIN_JoystickSetLED, DARWIN_JoystickSetLED,
DARWIN_JoystickSendEffect, DARWIN_JoystickSendEffect,
DARWIN_JoystickSetSensorsEnabled, DARWIN_JoystickSetSensorsEnabled,

View file

@ -92,11 +92,6 @@ static int DUMMY_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumb
return SDL_Unsupported(); 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) static int DUMMY_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
return SDL_Unsupported(); return SDL_Unsupported();
@ -143,7 +138,6 @@ SDL_JoystickDriver SDL_DUMMY_JoystickDriver = {
DUMMY_JoystickOpen, DUMMY_JoystickOpen,
DUMMY_JoystickRumble, DUMMY_JoystickRumble,
DUMMY_JoystickRumbleTriggers, DUMMY_JoystickRumbleTriggers,
DUMMY_JoystickGetCapabilities,
DUMMY_JoystickSetLED, DUMMY_JoystickSetLED,
DUMMY_JoystickSendEffect, DUMMY_JoystickSendEffect,
DUMMY_JoystickSetSensorsEnabled, DUMMY_JoystickSetSensorsEnabled,

View file

@ -395,11 +395,6 @@ static SDL_bool EMSCRIPTEN_JoystickGetGamepadMapping(int device_index, SDL_Gamep
return SDL_FALSE; 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) static int EMSCRIPTEN_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
return SDL_Unsupported(); return SDL_Unsupported();
@ -429,7 +424,6 @@ SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver = {
EMSCRIPTEN_JoystickOpen, EMSCRIPTEN_JoystickOpen,
EMSCRIPTEN_JoystickRumble, EMSCRIPTEN_JoystickRumble,
EMSCRIPTEN_JoystickRumbleTriggers, EMSCRIPTEN_JoystickRumbleTriggers,
EMSCRIPTEN_JoystickGetCapabilities,
EMSCRIPTEN_JoystickSetLED, EMSCRIPTEN_JoystickSetLED,
EMSCRIPTEN_JoystickSendEffect, EMSCRIPTEN_JoystickSendEffect,
EMSCRIPTEN_JoystickSetSensorsEnabled, EMSCRIPTEN_JoystickSetSensorsEnabled,

View file

@ -272,11 +272,6 @@ extern "C"
return SDL_FALSE; 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) static int HAIKU_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
return SDL_Unsupported(); return SDL_Unsupported();
@ -308,7 +303,6 @@ extern "C"
HAIKU_JoystickOpen, HAIKU_JoystickOpen,
HAIKU_JoystickRumble, HAIKU_JoystickRumble,
HAIKU_JoystickRumbleTriggers, HAIKU_JoystickRumbleTriggers,
HAIKU_JoystickGetCapabilities,
HAIKU_JoystickSetLED, HAIKU_JoystickSetLED,
HAIKU_JoystickSendEffect, HAIKU_JoystickSendEffect,
HAIKU_JoystickSetSensorsEnabled, HAIKU_JoystickSetSensorsEnabled,

View file

@ -723,6 +723,8 @@ static void HIDAPI_DriverPS4_SetEnhancedModeAvailable(SDL_DriverPS4_Context *ctx
if (ctx->device->is_bluetooth && ctx->official_controller) { if (ctx->device->is_bluetooth && ctx->official_controller) {
ctx->report_battery = SDL_TRUE; ctx->report_battery = SDL_TRUE;
} }
HIDAPI_UpdateDeviceProperties(ctx->device);
} }
static void HIDAPI_DriverPS4_SetEnhancedMode(SDL_DriverPS4_Context *ctx) static void HIDAPI_DriverPS4_SetEnhancedMode(SDL_DriverPS4_Context *ctx)

View file

@ -818,6 +818,8 @@ static void HIDAPI_DriverPS5_SetEnhancedModeAvailable(SDL_DriverPS5_Context *ctx
if (ctx->device->is_bluetooth) { if (ctx->device->is_bluetooth) {
ctx->report_battery = SDL_TRUE; ctx->report_battery = SDL_TRUE;
} }
HIDAPI_UpdateDeviceProperties(ctx->device);
} }
static void HIDAPI_DriverPS5_SetEnhancedMode(SDL_DriverPS5_Context *ctx) static void HIDAPI_DriverPS5_SetEnhancedMode(SDL_DriverPS5_Context *ctx)

View file

@ -727,6 +727,7 @@ static void SDLCALL SDL_PlayerLEDHintChanged(void *userdata, const char *name, c
ctx->m_bPlayerLights = bPlayerLights; ctx->m_bPlayerLights = bPlayerLights;
UpdateSlotLED(ctx); UpdateSlotLED(ctx);
HIDAPI_UpdateDeviceProperties(ctx->device);
} }
} }

View file

@ -131,6 +131,7 @@ static void SDLCALL SDL_PlayerLEDHintChanged(void *userdata, const char *name, c
ctx->player_lights = player_lights; ctx->player_lights = player_lights;
UpdateSlotLED(ctx); UpdateSlotLED(ctx);
HIDAPI_UpdateDeviceProperties(ctx->device);
} }
} }

View file

@ -103,6 +103,7 @@ static void SDLCALL SDL_PlayerLEDHintChanged(void *userdata, const char *name, c
ctx->player_lights = player_lights; ctx->player_lights = player_lights;
UpdateSlotLED(ctx); UpdateSlotLED(ctx);
HIDAPI_UpdateDeviceProperties(ctx->device);
} }
} }

View file

@ -859,6 +859,54 @@ void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joyst
SDL_UnlockJoysticks(); 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) static int HIDAPI_JoystickGetCount(void)
{ {
return SDL_HIDAPI_numjoysticks; return SDL_HIDAPI_numjoysticks;
@ -1471,6 +1519,8 @@ static int HIDAPI_JoystickOpen(SDL_Joystick *joystick, int device_index)
return -1; return -1;
} }
HIDAPI_UpdateJoystickProperties(device, joystick);
if (device->serial) { if (device->serial) {
joystick->serial = SDL_strdup(device->serial); joystick->serial = SDL_strdup(device->serial);
} }
@ -1520,18 +1570,6 @@ static int HIDAPI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rum
return result; 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) static int HIDAPI_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
int result; int result;
@ -1671,7 +1709,6 @@ SDL_JoystickDriver SDL_HIDAPI_JoystickDriver = {
HIDAPI_JoystickOpen, HIDAPI_JoystickOpen,
HIDAPI_JoystickRumble, HIDAPI_JoystickRumble,
HIDAPI_JoystickRumbleTriggers, HIDAPI_JoystickRumbleTriggers,
HIDAPI_JoystickGetCapabilities,
HIDAPI_JoystickSetLED, HIDAPI_JoystickSetLED,
HIDAPI_JoystickSendEffect, HIDAPI_JoystickSendEffect,
HIDAPI_JoystickSetSensorsEnabled, HIDAPI_JoystickSetSensorsEnabled,

View file

@ -40,6 +40,13 @@
#define SDL_JOYSTICK_HIDAPI_XBOXONE #define SDL_JOYSTICK_HIDAPI_XBOXONE
#define SDL_JOYSTICK_HIDAPI_SHIELD #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 */ /* Whether HIDAPI is enabled by default */
#define SDL_HIDAPI_DEFAULT SDL_TRUE #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 void HIDAPI_DisconnectBluetoothDevice(const char *serial);
extern SDL_bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID); 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_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); extern void HIDAPI_DumpPacket(const char *prefix, const Uint8 *data, int size);

View file

@ -1609,6 +1609,9 @@ static int LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->hwdata->fd_sensor = -1; 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; return 0;
} }
@ -1660,19 +1663,6 @@ static int LINUX_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumb
return SDL_Unsupported(); 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) static int LINUX_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
return SDL_Unsupported(); return SDL_Unsupported();
@ -2706,7 +2696,6 @@ SDL_JoystickDriver SDL_LINUX_JoystickDriver = {
LINUX_JoystickOpen, LINUX_JoystickOpen,
LINUX_JoystickRumble, LINUX_JoystickRumble,
LINUX_JoystickRumbleTriggers, LINUX_JoystickRumbleTriggers,
LINUX_JoystickGetCapabilities,
LINUX_JoystickSetLED, LINUX_JoystickSetLED,
LINUX_JoystickSendEffect, LINUX_JoystickSendEffect,
LINUX_JoystickSetSensorsEnabled, LINUX_JoystickSetSensorsEnabled,

View file

@ -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) static int N3DS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{ {
return SDL_Unsupported(); return SDL_Unsupported();
@ -284,7 +279,6 @@ SDL_JoystickDriver SDL_N3DS_JoystickDriver = {
.Open = N3DS_JoystickOpen, .Open = N3DS_JoystickOpen,
.Rumble = N3DS_JoystickRumble, .Rumble = N3DS_JoystickRumble,
.RumbleTriggers = N3DS_JoystickRumbleTriggers, .RumbleTriggers = N3DS_JoystickRumbleTriggers,
.GetCapabilities = N3DS_JoystickGetCapabilities,
.SetLED = N3DS_JoystickSetLED, .SetLED = N3DS_JoystickSetLED,
.SendEffect = N3DS_JoystickSendEffect, .SendEffect = N3DS_JoystickSendEffect,
.SetSensorsEnabled = N3DS_JoystickSetSensorsEnabled, .SetSensorsEnabled = N3DS_JoystickSetSensorsEnabled,

View file

@ -210,6 +210,8 @@ static int PS2_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->nhats = 0; joystick->nhats = 0;
joystick->instance_id = device_index; joystick->instance_id = device_index;
SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE);
return 0; return 0;
} }
@ -240,31 +242,25 @@ static int PS2_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl
/* Rumble functionality */ /* Rumble functionality */
static int PS2_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left, Uint16 right) static int PS2_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left, Uint16 right)
{ {
return -1; return SDL_Unsupported();
}
/* Capability detection */
static Uint32 PS2_JoystickGetCapabilities(SDL_Joystick *joystick)
{
return SDL_JOYSTICK_CAP_RUMBLE;
} }
/* LED functionality */ /* LED functionality */
static int PS2_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) static int PS2_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
return -1; return SDL_Unsupported();
} }
/* General effects */ /* General effects */
static int PS2_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) static int PS2_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
{ {
return -1; return SDL_Unsupported();
} }
/* Sensor functionality */ /* Sensor functionality */
static int PS2_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled) 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. /* 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_JoystickOpen,
PS2_JoystickRumble, PS2_JoystickRumble,
PS2_JoystickRumbleTriggers, PS2_JoystickRumbleTriggers,
PS2_JoystickGetCapabilities,
PS2_JoystickSetLED, PS2_JoystickSetLED,
PS2_JoystickSendEffect, PS2_JoystickSendEffect,
PS2_JoystickSetSensorsEnabled, PS2_JoystickSetSensorsEnabled,

View file

@ -173,11 +173,6 @@ static int PSP_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble
return SDL_Unsupported(); 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) static int PSP_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
return SDL_Unsupported(); return SDL_Unsupported();
@ -266,7 +261,6 @@ SDL_JoystickDriver SDL_PSP_JoystickDriver = {
PSP_JoystickOpen, PSP_JoystickOpen,
PSP_JoystickRumble, PSP_JoystickRumble,
PSP_JoystickRumbleTriggers, PSP_JoystickRumbleTriggers,
PSP_JoystickGetCapabilities,
PSP_JoystickSetLED, PSP_JoystickSetLED,
PSP_JoystickSendEffect, PSP_JoystickSendEffect,
PSP_JoystickSetSensorsEnabled, PSP_JoystickSetSensorsEnabled,

View file

@ -422,6 +422,16 @@ static int VIRTUAL_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->nbuttons = hwdata->desc.nbuttons; joystick->nbuttons = hwdata->desc.nbuttons;
joystick->nhats = hwdata->desc.nhats; joystick->nhats = hwdata->desc.nhats;
hwdata->joystick = joystick; 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; return 0;
} }
@ -465,28 +475,6 @@ static int VIRTUAL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_ru
return result; 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) static int VIRTUAL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
int result; int result;
@ -741,7 +729,6 @@ SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver = {
VIRTUAL_JoystickOpen, VIRTUAL_JoystickOpen,
VIRTUAL_JoystickRumble, VIRTUAL_JoystickRumble,
VIRTUAL_JoystickRumbleTriggers, VIRTUAL_JoystickRumbleTriggers,
VIRTUAL_JoystickGetCapabilities,
VIRTUAL_JoystickSetLED, VIRTUAL_JoystickSetLED,
VIRTUAL_JoystickSendEffect, VIRTUAL_JoystickSendEffect,
VIRTUAL_JoystickSetSensorsEnabled, VIRTUAL_JoystickSetSensorsEnabled,

View file

@ -207,6 +207,9 @@ int VITA_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->nhats = 0; joystick->nhats = 0;
joystick->instance_id = device_index; 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; return 0;
} }
@ -344,12 +347,6 @@ static int VITA_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left, Uint
return SDL_Unsupported(); 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) static int VITA_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
int index = (int)SDL_GetJoystickInstanceID(joystick) - 1; int index = (int)SDL_GetJoystickInstanceID(joystick) - 1;
@ -388,17 +385,12 @@ SDL_JoystickDriver SDL_VITA_JoystickDriver = {
VITA_JoystickSetDevicePlayerIndex, VITA_JoystickSetDevicePlayerIndex,
VITA_JoystickGetDeviceGUID, VITA_JoystickGetDeviceGUID,
VITA_JoystickGetDeviceInstanceID, VITA_JoystickGetDeviceInstanceID,
VITA_JoystickOpen, VITA_JoystickOpen,
VITA_JoystickRumble, VITA_JoystickRumble,
VITA_JoystickRumbleTriggers, VITA_JoystickRumbleTriggers,
VITA_JoystickGetCapabilities,
VITA_JoystickSetLED, VITA_JoystickSetLED,
VITA_JoystickSendEffect, VITA_JoystickSendEffect,
VITA_JoystickSetSensorsEnabled, VITA_JoystickSetSensorsEnabled,
VITA_JoystickUpdate, VITA_JoystickUpdate,
VITA_JoystickClose, VITA_JoystickClose,
VITA_JoystickQuit, VITA_JoystickQuit,

View file

@ -826,6 +826,8 @@ int SDL_DINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystic
return SetDIerror("IDirectInputDevice8::SetProperty", result); 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? */ /* What buttons and axes does it have? */
@ -945,17 +947,6 @@ int SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl
return 0; 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) static Uint8 TranslatePOV(DWORD value)
{ {
const Uint8 HAT_VALS[] = { const Uint8 HAT_VALS[] = {
@ -1193,11 +1184,6 @@ int SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl
return SDL_Unsupported(); return SDL_Unsupported();
} }
Uint32 SDL_DINPUT_JoystickGetCapabilities(SDL_Joystick *joystick)
{
return 0;
}
void SDL_DINPUT_JoystickUpdate(SDL_Joystick *joystick) void SDL_DINPUT_JoystickUpdate(SDL_Joystick *joystick)
{ {
} }

View file

@ -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 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_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice);
extern int SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); 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_JoystickUpdate(SDL_Joystick *joystick);
extern void SDL_DINPUT_JoystickClose(SDL_Joystick *joystick); extern void SDL_DINPUT_JoystickClose(SDL_Joystick *joystick);
extern void SDL_DINPUT_JoystickQuit(void); extern void SDL_DINPUT_JoystickQuit(void);

View file

@ -1431,6 +1431,21 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN; 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; return 0;
} }
@ -1506,31 +1521,6 @@ static int RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_r
#endif #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) static int RAWINPUT_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
return SDL_Unsupported(); return SDL_Unsupported();
@ -2226,7 +2216,6 @@ SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver = {
RAWINPUT_JoystickOpen, RAWINPUT_JoystickOpen,
RAWINPUT_JoystickRumble, RAWINPUT_JoystickRumble,
RAWINPUT_JoystickRumbleTriggers, RAWINPUT_JoystickRumbleTriggers,
RAWINPUT_JoystickGetCapabilities,
RAWINPUT_JoystickSetLED, RAWINPUT_JoystickSetLED,
RAWINPUT_JoystickSendEffect, RAWINPUT_JoystickSendEffect,
RAWINPUT_JoystickSetSensorsEnabled, RAWINPUT_JoystickSetSensorsEnabled,

View file

@ -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_AxisCount(hwdata->controller, &joystick->naxes);
__x_ABI_CWindows_CGaming_CInput_CIRawGameController_get_SwitchCount(hwdata->controller, &joystick->nhats); __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; 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) static int WGI_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
return SDL_Unsupported(); return SDL_Unsupported();
@ -1026,7 +1019,6 @@ SDL_JoystickDriver SDL_WGI_JoystickDriver = {
WGI_JoystickOpen, WGI_JoystickOpen,
WGI_JoystickRumble, WGI_JoystickRumble,
WGI_JoystickRumbleTriggers, WGI_JoystickRumbleTriggers,
WGI_JoystickGetCapabilities,
WGI_JoystickSetLED, WGI_JoystickSetLED,
WGI_JoystickSendEffect, WGI_JoystickSendEffect,
WGI_JoystickSetSensorsEnabled, WGI_JoystickSetSensorsEnabled,

View file

@ -704,15 +704,6 @@ static int WINDOWS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_ru
return SDL_Unsupported(); 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) static int WINDOWS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{ {
return SDL_Unsupported(); return SDL_Unsupported();
@ -807,7 +798,6 @@ SDL_JoystickDriver SDL_WINDOWS_JoystickDriver = {
WINDOWS_JoystickOpen, WINDOWS_JoystickOpen,
WINDOWS_JoystickRumble, WINDOWS_JoystickRumble,
WINDOWS_JoystickRumbleTriggers, WINDOWS_JoystickRumbleTriggers,
WINDOWS_JoystickGetCapabilities,
WINDOWS_JoystickSetLED, WINDOWS_JoystickSetLED,
WINDOWS_JoystickSendEffect, WINDOWS_JoystickSendEffect,
WINDOWS_JoystickSetSensorsEnabled, WINDOWS_JoystickSetSensorsEnabled,

View file

@ -263,6 +263,9 @@ int SDL_XINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystic
joystick->naxes = 6; joystick->naxes = 6;
joystick->nbuttons = 11; joystick->nbuttons = 11;
joystick->nhats = 1; joystick->nhats = 1;
SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, SDL_TRUE);
return 0; return 0;
} }
@ -351,11 +354,6 @@ int SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl
return 0; return 0;
} }
Uint32 SDL_XINPUT_JoystickGetCapabilities(SDL_Joystick *joystick)
{
return SDL_JOYSTICK_CAP_RUMBLE;
}
void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick) void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick)
{ {
DWORD result; DWORD result;
@ -432,11 +430,6 @@ int SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl
return SDL_Unsupported(); return SDL_Unsupported();
} }
Uint32 SDL_XINPUT_JoystickGetCapabilities(SDL_Joystick *joystick)
{
return 0;
}
void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick) void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick)
{ {
} }

View file

@ -32,7 +32,6 @@ extern int SDL_XINPUT_JoystickInit(void);
extern void SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext); extern void SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext);
extern int SDL_XINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice); 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 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_JoystickUpdate(SDL_Joystick *joystick);
extern void SDL_XINPUT_JoystickClose(SDL_Joystick *joystick); extern void SDL_XINPUT_JoystickClose(SDL_Joystick *joystick);
extern void SDL_XINPUT_JoystickQuit(void); extern void SDL_XINPUT_JoystickQuit(void);

View file

@ -977,6 +977,7 @@ static void HandleGamepadAdded(SDL_JoystickID id, SDL_bool verbose)
gamepad = controllers[i].gamepad; gamepad = controllers[i].gamepad;
if (gamepad) { if (gamepad) {
if (verbose) { if (verbose) {
SDL_PropertiesID props = SDL_GetGamepadProperties(gamepad);
const char *name = SDL_GetGamepadName(gamepad); const char *name = SDL_GetGamepadName(gamepad);
const char *path = SDL_GetGamepadPath(gamepad); const char *path = SDL_GetGamepadPath(gamepad);
SDL_Log("Opened gamepad %s%s%s\n", name, path ? ", " : "", path ? path : ""); 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); 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"); 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"); SDL_Log("Trigger rumble supported");
} }