From 22a4f9fd9c5b7f73dac563a361e817a8ae75511c Mon Sep 17 00:00:00 2001 From: Nintorch <92302738+Nintorch@users.noreply.github.com> Date: Sun, 11 Jan 2026 13:07:51 +0500 Subject: [PATCH] Refactor Input.set_joy_light() --- core/input/input.cpp | 9 +++++---- core/input/input.h | 4 ++-- doc/classes/Input.xml | 4 ++-- drivers/sdl/joypad_sdl.cpp | 5 ++--- drivers/sdl/joypad_sdl.h | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/input/input.cpp b/core/input/input.cpp index 416f9f87ee..c75079206c 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -1004,12 +1004,13 @@ void Input::set_joy_features(int p_device, JoypadFeatures *p_features) { _update_joypad_features(p_device); } -bool Input::set_joy_light(int p_device, const Color &p_color) { +void Input::set_joy_light(int p_device, const Color &p_color) { Joypad *joypad = joy_names.getptr(p_device); - if (!joypad || joypad->features == nullptr) { - return false; + if (!joypad || !joypad->has_light || joypad->features == nullptr) { + return; } - return joypad->features->set_joy_light(p_color); + Color linear = p_color.srgb_to_linear(); + joypad->features->set_joy_light(linear); } bool Input::has_joy_light(int p_device) const { diff --git a/core/input/input.h b/core/input/input.h index 200012b340..c912cb34d3 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -84,7 +84,7 @@ public: virtual ~JoypadFeatures() {} virtual bool has_joy_light() const { return false; } - virtual bool set_joy_light(const Color &p_color) { return false; } + virtual void set_joy_light(const Color &p_color) {} }; static constexpr int32_t JOYPADS_MAX = 16; @@ -360,7 +360,7 @@ public: void set_joy_features(int p_device, JoypadFeatures *p_features); - bool set_joy_light(int p_device, const Color &p_color); + void set_joy_light(int p_device, const Color &p_color); bool has_joy_light(int p_device) const; void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0); diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml index 805576f170..8195ad6161 100644 --- a/doc/classes/Input.xml +++ b/doc/classes/Input.xml @@ -398,11 +398,11 @@ - + - Sets the joypad's LED light, if available, to the specified color. Returns [code]true[/code] if the operation was successful. See also [method has_joy_light]. + Sets the joypad's LED light, if available, to the specified color. See also [method has_joy_light]. [b]Note:[/b] There is no way to get the color of the light from a joypad. If you need to know the assigned color, store it separately. [b]Note:[/b] This feature is only supported on Windows, Linux, and macOS. diff --git a/drivers/sdl/joypad_sdl.cpp b/drivers/sdl/joypad_sdl.cpp index 8e808a885a..993847365f 100644 --- a/drivers/sdl/joypad_sdl.cpp +++ b/drivers/sdl/joypad_sdl.cpp @@ -297,9 +297,8 @@ bool JoypadSDL::Joypad::has_joy_light() const { return SDL_GetBooleanProperty(properties_id, SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, false) || SDL_GetBooleanProperty(properties_id, SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN, false); } -bool JoypadSDL::Joypad::set_joy_light(const Color &p_color) { - Color linear = p_color.srgb_to_linear(); - return SDL_SetJoystickLED(get_sdl_joystick(), linear.get_r8(), linear.get_g8(), linear.get_b8()); +void JoypadSDL::Joypad::set_joy_light(const Color &p_color) { + SDL_SetJoystickLED(get_sdl_joystick(), p_color.get_r8(), p_color.get_g8(), p_color.get_b8()); } SDL_Joystick *JoypadSDL::Joypad::get_sdl_joystick() const { diff --git a/drivers/sdl/joypad_sdl.h b/drivers/sdl/joypad_sdl.h index 7010822675..88aa342bf5 100644 --- a/drivers/sdl/joypad_sdl.h +++ b/drivers/sdl/joypad_sdl.h @@ -59,7 +59,7 @@ private: uint64_t ff_effect_timestamp = 0; virtual bool has_joy_light() const override; - virtual bool set_joy_light(const Color &p_color) override; + virtual void set_joy_light(const Color &p_color) override; SDL_Joystick *get_sdl_joystick() const; SDL_Gamepad *get_sdl_gamepad() const;