From ac72a2ba8e0473257d0e2cc5d3cfb0e9f071399a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 25 Jan 2021 20:38:50 -0800 Subject: [PATCH] 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). --- include/SDL_hints.h | 9 +++++++++ src/joystick/hidapi/SDL_hidapi_switch.c | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/SDL_hints.h b/include/SDL_hints.h index 78173c39a..bacfe1740 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -696,6 +696,15 @@ extern "C" { */ #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. * diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c index 213344f65..8a65853b6 100644 --- a/src/joystick/hidapi/SDL_hidapi_switch.c +++ b/src/joystick/hidapi/SDL_hidapi_switch.c @@ -876,7 +876,11 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti /* Set the LED state */ 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));