Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It depends on the conditions it can fail, if it's only false when has_joy_light is fales, bool return is redundant. If not, I would keep it even if other similar methods do not have return value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Theoretically, this method shouldn't fail if a joypad has LED light, otherwise I would consider it a bug

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 {
Expand Down
4 changes: 2 additions & 2 deletions core/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Input : public Object {
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;
Expand Down Expand Up @@ -360,7 +360,7 @@ class Input : public Object {

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);
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/Input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@
</description>
</method>
<method name="set_joy_light">
<return type="bool" />
<return type="void" />
<param index="0" name="device" type="int" />
<param index="1" name="color" type="Color" />
<description>
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.
</description>
Expand Down
5 changes: 2 additions & 3 deletions drivers/sdl/joypad_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion drivers/sdl/joypad_sdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class JoypadSDL {
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;
Expand Down