From 0dcf28104dde015d277f965b39cd8a34c67be700 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Tue, 23 Sep 2025 17:12:56 +0200 Subject: [PATCH] Allow all gamepad devices for built-in `ui_*` input actions This allows all controllers to navigate the UI, which enhances compatibility with PC handhelds when external controllers are connected. Previously, only the first device was allowed to use `ui_*` actions out of the box, which means that on a PC handheld, external controllers couldn't navigate the UI (since the first ID is always the built-in controller). --- core/input/input_event.cpp | 6 ++++-- core/input/input_event.h | 6 ++++-- editor/settings/input_event_configuration_dialog.cpp | 4 +--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index b3ccda0e191..73a4c4d0823 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -1188,11 +1188,12 @@ String InputEventJoypadMotion::to_string() { return vformat("InputEventJoypadMotion: axis=%d, axis_value=%.2f", axis, axis_value); } -Ref InputEventJoypadMotion::create_reference(JoyAxis p_axis, float p_value) { +Ref InputEventJoypadMotion::create_reference(JoyAxis p_axis, float p_value, int p_device) { Ref ie; ie.instantiate(); ie->set_axis(p_axis); ie->set_axis_value(p_value); + ie->set_device(p_device); return ie; } @@ -1307,10 +1308,11 @@ String InputEventJoypadButton::to_string() { return vformat("InputEventJoypadButton: button_index=%d, pressed=%s, pressure=%.2f", button_index, p, pressure); } -Ref InputEventJoypadButton::create_reference(JoyButton p_btn_index) { +Ref InputEventJoypadButton::create_reference(JoyButton p_btn_index, int p_device) { Ref ie; ie.instantiate(); ie->set_button_index(p_btn_index); + ie->set_device(p_device); return ie; } diff --git a/core/input/input_event.h b/core/input/input_event.h index 62b89bf0fdf..dad73d8b68f 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -339,7 +339,8 @@ public: virtual String as_text() const override; virtual String to_string() override; - static Ref create_reference(JoyAxis p_axis, float p_value); + // The default device ID is `InputMap::ALL_DEVICES`. + static Ref create_reference(JoyAxis p_axis, float p_value, int p_device = -1); InputEventType get_type() const final override { return InputEventType::JOY_MOTION; } @@ -371,7 +372,8 @@ public: virtual String as_text() const override; virtual String to_string() override; - static Ref create_reference(JoyButton p_btn_index); + // The default device ID is `InputMap::ALL_DEVICES`. + static Ref create_reference(JoyButton p_btn_index, int p_device = -1); InputEventType get_type() const final override { return InputEventType::JOY_BUTTON; } diff --git a/editor/settings/input_event_configuration_dialog.cpp b/editor/settings/input_event_configuration_dialog.cpp index 6d37ddcae09..739c0766a32 100644 --- a/editor/settings/input_event_configuration_dialog.cpp +++ b/editor/settings/input_event_configuration_dialog.cpp @@ -527,10 +527,8 @@ void InputEventConfigurationDialog::_input_list_item_selected() { } break; case INPUT_JOY_BUTTON: { JoyButton idx = (JoyButton)(int)selected->get_meta("__index"); - Ref jb = InputEventJoypadButton::create_reference(idx); - // Maintain selected device - jb->set_device(_get_current_device()); + Ref jb = InputEventJoypadButton::create_reference(idx, _get_current_device()); _set_event(jb, jb, false); } break;