Fixed bug 5493 - Hint to let the user opt out of having Switch controllers' Home button lit when opened

jibb

New hint to let the user opt out of having Switch controllers' Home button lit when opened.

This is more consistent with the Switch itself (which doesn't light the button normally) and may be preferred by users who may disconnect their controller without letting the application close it.

I think this warrants a Switch-specific hint because the default behaviour is unusual (inconsistent with using a Switch controller on a Switch itself or with some other programs on PC), and because of that it's distinct from other lights (the player number on Switch controllers and the player colour on PlayStation controllers).
This commit is contained in:
Sam Lantinga 2021-01-25 20:38:50 -08:00
parent f23022ef97
commit ac72a2ba8e
2 changed files with 14 additions and 1 deletions

View File

@ -696,6 +696,15 @@ extern "C" {
*/ */
#define SDL_HINT_JOYSTICK_HIDAPI_SWITCH "SDL_JOYSTICK_HIDAPI_SWITCH" #define SDL_HINT_JOYSTICK_HIDAPI_SWITCH "SDL_JOYSTICK_HIDAPI_SWITCH"
/**
* \brief A variable controlling whether the Home button LED should be turned on when a Nintendo Switch controller is opened
*
* This variable can be set to the following values:
* "0" - home button LED is left off
* "1" - home button LED is turned on (the default)
*/
#define SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED "SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED"
/** /**
* \brief A variable controlling whether Switch Joy-Cons should be treated the same as Switch Pro Controllers when using the HIDAPI driver. * \brief A variable controlling whether Switch Joy-Cons should be treated the same as Switch Pro Controllers when using the HIDAPI driver.
* *

View File

@ -876,7 +876,11 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
/* Set the LED state */ /* Set the LED state */
if (ctx->m_bHasHomeLED) { if (ctx->m_bHasHomeLED) {
SetHomeLED(ctx, 100); if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED, SDL_TRUE)) {
SetHomeLED(ctx, 100);
} else {
SetHomeLED(ctx, 0);
}
} }
SetSlotLED(ctx, (joystick->instance_id % 4)); SetSlotLED(ctx, (joystick->instance_id % 4));