Replaced SDL_GetJoystickCaps() with joystick properties
Fixes https://github.com/libsdl-org/SDL/issues/8927
This commit is contained in:
parent
019dc53764
commit
f66fe7e221
37 changed files with 176 additions and 341 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue