Skip to content

Add support for the Home LED on NS Controllers#115114

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
ThiLelito:ns_controller_led
Jan 27, 2026
Merged

Add support for the Home LED on NS Controllers#115114
Repiteo merged 1 commit intogodotengine:masterfrom
ThiLelito:ns_controller_led

Conversation

@ThiLelito
Copy link
Contributor

With the addition of Input.set_joy_light() from #111681, I wondered if the LED around the Home Button in some Nintendo Switch controllers could be adjusted. I discovered they could not, because its implementation uses the SDL_SetJoystickLED function while the Home LED uses the SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED hint.

This PR aims to add support for this LED mentioned.

I only changed the drivers/sdl/joypad_sdl.cpp file:

  • Added an if condition on close_joypad to check if it's a NS controller and turn the LED off if true:
    • Sets the SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED hint to "0.0";
  • Added an if condition on has_joy_light to make NS controllers return true;
  • Added logic to set up the brightness of the NS controller LED:
    • It gets the max rgb value of the Color provided;
    • Sets the SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED hint with the char * of the maximum value.

I've tested on Windows and it seems to work. I don't know if there are other controllers that use the same hint and are not mentioned in the if statements. If so, feel free to change or improve it.

@Nintorch
Copy link
Contributor

Hello, thank you for your work! I feel like we can also change the behaviour of SDL to make the existing code work with Switch controllers, it doesn't look too hard to fix, see also:

// Set the LED state
if (HasHomeLED(ctx)) {
if (ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConLeft ||
ctx->m_eControllerType == k_eSwitchDeviceInfoControllerType_JoyConRight) {
SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED,
SDL_HomeLEDHintChanged, ctx);
} else {
SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED,
SDL_HomeLEDHintChanged, ctx);
}
}
}

static void SDLCALL SDL_HomeLEDHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)userdata;
if (hint && *hint) {
int value;
if (SDL_strchr(hint, '.') != NULL) {
value = (int)(100.0f * SDL_atof(hint));
if (value > 255) {
value = 255;
}
} else if (SDL_GetStringBoolean(hint, true)) {
value = 100;
} else {
value = 0;
}
SetHomeLED(ctx, (Uint8)value);
}
}

Maybe we can make the Switch driver report having a SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN capability, similarly to how PS4 controllers work:
static Uint32 HIDAPI_DriverPS4_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;
Uint32 result = 0;
if (ctx->enhanced_mode_available) {
if (ctx->lightbar_supported) {
result |= SDL_JOYSTICK_CAP_RGB_LED;
}
if (ctx->vibration_supported) {
result |= SDL_JOYSTICK_CAP_RUMBLE;
}
}
return result;
}

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, true);
} else {
SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN, false);
}
if (caps & SDL_JOYSTICK_CAP_RGB_LED) {
SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, true);
} else {
SDL_SetBooleanProperty(props, SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, false);
}

What do you think? :)
Should we also ask the SDL developers what they think about it?

Another reason I suggest doing this inside SDL is because the current approach of changing the hint will (probably) modify the home LED of all connected Switch controllers, not just one that was used for set_joy_light, so it might feel like a bug.

@AThousandShips AThousandShips changed the title Added support for the Home LED on NS Controllers Add support for the Home LED on NS Controllers Jan 19, 2026
@ThiLelito
Copy link
Contributor Author

Hey, thanks for your response!

Maybe we can make the Switch driver report having a SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN capability, similarly to how PS4 controllers work.
Should we also ask the SDL developers what they think about it?

I think that we could, it seems to be the best option now that you mentioned it.
I guess we should ask the developers aswell, as they are the ones mostly responsible for the SDL. They may have a better idea of how we can overcome this :)

Another reason I suggest doing this inside SDL is because the current approach of changing the hint will (probably) modify the home LED of all connected Switch controllers, not just one that was used for set_joy_light, so it might feel like a bug.

Now that you've mentioned it, yes, I can't really test it since I don't have two or more controllers with this capability but as the hint is changed without providing the joypad/gamepad, it probably changes every controllers LED lights.

Also thanks @AThousandShips for the suggested change, it really is better.

@ThiLelito ThiLelito requested a review from a team as a code owner January 23, 2026 04:02
@ThiLelito
Copy link
Contributor Author

ThiLelito commented Jan 23, 2026

As discussed and suggested by @Nintorch , I tried changing the Switch SDL file and it seems to work properly, I just can't test it on multiple controllers but it may work as intended now.

  • I've removed the code previously added to joypad.sdl since they are not necessary anymore
  • Done the implementation in SDL_hidapi_switch.c as discussed and it seems to work as intended. The only logical difference is that now it should work for independent controllers as it is now treated as a property instead of a hint.
  • It should work to both the Pro Controller and the Right Joy-Con (I confess I am not sure of how the Joy-con Pair is detected, but as the Pair includes the Right Joy-con I've added it aswell)

I should note that from my tests, the Pro Controller Home LED has different levels of brightness instead of a continuous range. It isn't an issue but I feel like this should be known.

@Nintorch
Copy link
Contributor

Looks good to me! May I ask if the code works if you connect both the Pro Controller and the right Joy Con and call set_joy_light() on one of them?

@ThiLelito
Copy link
Contributor Author

ThiLelito commented Jan 23, 2026

AFAIK it should work as both Pro Controllers and Joy Cons use the same base file (SDL_hidapi_switch) and I've added them to the HIDAPI_DriverSwitch_GetJoystickCapabilities so they should work equally (and separately). Sadly I can't confirm 100% that it works since I can't test it as I only have the NS2 Joy Cons* (and a NS1 Pro Controller)

* The NS2 Joy Cons and NS2 Pro Controllers don't have this LED so they wouldn't work whatsoever.

@Nintorch
Copy link
Contributor

Nintorch commented Jan 23, 2026

Ohh, I see!
@slouken Hello, sorry for bothering you, may I ask if this change would be acceptable as a pull request for SDL repository?

@slouken
Copy link
Contributor

slouken commented Jan 24, 2026

Ohh, I see! @slouken Hello, sorry for bothering you, may I ask if this change would be acceptable as a pull request for SDL repository?

Feel free to make the pull request. I need to think about whether this makes sense, since the home LED is treated differently from a mono LED, but I can think about that later once you've proposed it.

@Nintorch
Copy link
Contributor

@ThiLelito Would you like to make a PR for SDL or would you like me to make it for you, if you want? :)

@ThiLelito
Copy link
Contributor Author

@Nintorch Feel free to make it :)

Copy link
Contributor

@Nintorch Nintorch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected! Great job! :D

(Off-topic, but before you made this PR I didn't even know Switch controllers had home LEDs :D )

Copy link
Member

@Alex2782 Alex2782 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, not tested, but I trust @Nintorch 😃

@Repiteo
Copy link
Contributor

Repiteo commented Jan 26, 2026

Could you squash your commits? See our pull request guidelines for more information

Changed the implementation

Instead of modifying the hint value, now it works like the PS4 ones, but using MONO instead of RGB.

NS Controllers LED Support Added
@ThiLelito
Copy link
Contributor Author

Could you squash your commits? See our pull request guidelines for more information

Done :)

@Gemini04126
Copy link

aww, it's not in 4.6? sad, because i can't get my mom's ps4 controllers to connect, lol

@Repiteo Repiteo modified the milestones: 4.x, 4.7 Jan 27, 2026
@Repiteo Repiteo merged commit 2da55b2 into godotengine:master Jan 27, 2026
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jan 27, 2026

Thanks! Congratulations on your first merged contribution! 🎉

@ThiLelito ThiLelito deleted the ns_controller_led branch January 27, 2026 18:00
rivie13 pushed a commit to rivie13/Phoenix-Agentic-Engine that referenced this pull request Feb 16, 2026
Add support for the Home LED on NS Controllers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

Comments