Allow setting the player index to -1, which turns off the player LED for PS5 controllers

This commit is contained in:
Sam Lantinga 2021-01-04 12:24:44 -08:00
parent bf754b52bf
commit b2a0c712cb
4 changed files with 9 additions and 6 deletions

0
Xcode/SDL/SDL.xcodeproj/project.pbxproj Normal file → Executable file
View File

View File

@ -160,9 +160,6 @@ SDL_SetJoystickIDForPlayerIndex(int player_index, SDL_JoystickID instance_id)
int device_index; int device_index;
int existing_player_index; int existing_player_index;
if (player_index < 0) {
return SDL_FALSE;
}
if (player_index >= SDL_joystick_player_count) { if (player_index >= SDL_joystick_player_count) {
SDL_JoystickID *new_players = (SDL_JoystickID *)SDL_realloc(SDL_joystick_players, (player_index + 1)*sizeof(*SDL_joystick_players)); SDL_JoystickID *new_players = (SDL_JoystickID *)SDL_realloc(SDL_joystick_players, (player_index + 1)*sizeof(*SDL_joystick_players));
if (!new_players) { if (!new_players) {
@ -184,7 +181,9 @@ SDL_SetJoystickIDForPlayerIndex(int player_index, SDL_JoystickID instance_id)
SDL_joystick_players[existing_player_index] = -1; SDL_joystick_players[existing_player_index] = -1;
} }
if (player_index >= 0) {
SDL_joystick_players[player_index] = instance_id; SDL_joystick_players[player_index] = instance_id;
}
/* Update the driver with the new index */ /* Update the driver with the new index */
device_index = SDL_JoystickGetDeviceIndexFromInstanceID(instance_id); device_index = SDL_JoystickGetDeviceIndexFromInstanceID(instance_id);

View File

@ -133,8 +133,10 @@ HIDAPI_DriverXbox360_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_Joystic
if (!device->dev) { if (!device->dev) {
return; return;
} }
if (player_index >= 0) {
SetSlotLED(device->dev, (player_index % 4)); SetSlotLED(device->dev, (player_index % 4));
} }
}
static SDL_bool static SDL_bool
HIDAPI_DriverXbox360_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) HIDAPI_DriverXbox360_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)

View File

@ -131,8 +131,10 @@ HIDAPI_DriverXbox360W_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_Joysti
if (!device->dev) { if (!device->dev) {
return; return;
} }
if (player_index >= 0) {
SetSlotLED(device->dev, (player_index % 4)); SetSlotLED(device->dev, (player_index % 4));
} }
}
static SDL_bool static SDL_bool
HIDAPI_DriverXbox360W_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) HIDAPI_DriverXbox360W_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)