diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-01-29 13:15:42 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-01-29 13:15:42 +0100 |
commit | f220d46cdccb15f1aa141cd89c9dacee85b1b6ec (patch) | |
tree | bd02a89eb9942b5e6e6b54335ad750661502bc86 /editor | |
parent | 17e7f85c06366b427e5068c5b3e2940e27ff5f1d (diff) | |
parent | 8406e60522bb8d09649193be43c1c819edc1d059 (diff) | |
download | redot-engine-f220d46cdccb15f1aa141cd89c9dacee85b1b6ec.tar.gz |
Merge pull request #80231 from romlok/input-key-location
Support detecting and mapping ctrl/alt/shift/meta by their left/right physical location
Diffstat (limited to 'editor')
-rw-r--r-- | editor/event_listener_line_edit.cpp | 6 | ||||
-rw-r--r-- | editor/input_event_configuration_dialog.cpp | 46 | ||||
-rw-r--r-- | editor/input_event_configuration_dialog.h | 4 |
3 files changed, 53 insertions, 3 deletions
diff --git a/editor/event_listener_line_edit.cpp b/editor/event_listener_line_edit.cpp index 2c46e1c20a..c29e83d624 100644 --- a/editor/event_listener_line_edit.cpp +++ b/editor/event_listener_line_edit.cpp @@ -79,7 +79,11 @@ String EventListenerLineEdit::get_event_text(const Ref<InputEvent> &p_event, boo if (!text.is_empty()) { text += " " + TTR("or") + " "; } - text += mods_text + keycode_get_string(key->get_physical_keycode()) + " (" + TTR("Physical") + ")"; + text += mods_text + keycode_get_string(key->get_physical_keycode()) + " (" + TTR("Physical"); + if (key->get_location() != KeyLocation::UNSPECIFIED) { + text += " " + key->as_text_location(); + } + text += ")"; } if (key->get_key_label() != Key::NONE) { if (!text.is_empty()) { diff --git a/editor/input_event_configuration_dialog.cpp b/editor/input_event_configuration_dialog.cpp index 0f483fcaef..22673bec64 100644 --- a/editor/input_event_configuration_dialog.cpp +++ b/editor/input_event_configuration_dialog.cpp @@ -64,6 +64,7 @@ void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, c bool show_mods = false; bool show_device = false; bool show_key = false; + bool show_location = false; if (mod.is_valid()) { show_mods = true; @@ -77,12 +78,17 @@ void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, c if (k.is_valid()) { show_key = true; - if (k->get_keycode() == Key::NONE && k->get_physical_keycode() == Key::NONE && k->get_key_label() != Key::NONE) { + Key phys_key = k->get_physical_keycode(); + if (k->get_keycode() == Key::NONE && phys_key == Key::NONE && k->get_key_label() != Key::NONE) { key_mode->select(KEYMODE_UNICODE); } else if (k->get_keycode() != Key::NONE) { key_mode->select(KEYMODE_KEYCODE); - } else if (k->get_physical_keycode() != Key::NONE) { + } else if (phys_key != Key::NONE) { key_mode->select(KEYMODE_PHY_KEYCODE); + if (phys_key == Key::SHIFT || phys_key == Key::CTRL || phys_key == Key::ALT || phys_key == Key::META) { + key_location->select((int)k->get_location()); + show_location = true; + } } else { // Invalid key. event = Ref<InputEvent>(); @@ -103,6 +109,7 @@ void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, c mod_container->set_visible(show_mods); device_container->set_visible(show_device); key_mode->set_visible(show_key); + location_container->set_visible(show_location); additional_options_container->show(); // Update mode selector based on original key event. @@ -240,6 +247,9 @@ void InputEventConfigurationDialog::_on_listen_input_changed(const Ref<InputEven k->set_physical_keycode(Key::NONE); k->set_keycode(Key::NONE); } + if (key_location->get_selected_id() == (int)KeyLocation::UNSPECIFIED) { + k->set_location(KeyLocation::UNSPECIFIED); + } } Ref<InputEventWithModifiers> mod = received_event; @@ -433,6 +443,17 @@ void InputEventConfigurationDialog::_key_mode_selected(int p_mode) { _set_event(k, original_event); } +void InputEventConfigurationDialog::_key_location_selected(int p_location) { + Ref<InputEventKey> k = event; + if (k.is_null()) { + return; + } + + k->set_location((KeyLocation)p_location); + + _set_event(k, original_event); +} + void InputEventConfigurationDialog::_input_list_item_selected() { TreeItem *selected = input_list_tree->get_selected(); @@ -594,6 +615,8 @@ void InputEventConfigurationDialog::popup_and_configure(const Ref<InputEvent> &p // Select "All Devices" by default. device_id_option->select(0); + // Also "all locations". + key_location->select(0); } if (!p_current_action_name.is_empty()) { @@ -726,5 +749,24 @@ InputEventConfigurationDialog::InputEventConfigurationDialog() { key_mode->hide(); additional_options_container->add_child(key_mode); + // Key Location Selection + + location_container = memnew(HBoxContainer); + location_container->hide(); + + Label *location_label = memnew(Label); + location_label->set_text(TTR("Physical location")); + location_container->add_child(location_label); + + key_location = memnew(OptionButton); + key_location->set_h_size_flags(Control::SIZE_EXPAND_FILL); + key_location->add_item(TTR("Any"), (int)KeyLocation::UNSPECIFIED); + key_location->add_item(TTR("Left"), (int)KeyLocation::LEFT); + key_location->add_item(TTR("Right"), (int)KeyLocation::RIGHT); + key_location->connect("item_selected", callable_mp(this, &InputEventConfigurationDialog::_key_location_selected)); + + location_container->add_child(key_location); + additional_options_container->add_child(location_container); + main_vbox->add_child(additional_options_container); } diff --git a/editor/input_event_configuration_dialog.h b/editor/input_event_configuration_dialog.h index bde0b73ade..3ef089be8b 100644 --- a/editor/input_event_configuration_dialog.h +++ b/editor/input_event_configuration_dialog.h @@ -99,6 +99,9 @@ private: OptionButton *key_mode = nullptr; + HBoxContainer *location_container = nullptr; + OptionButton *key_location = nullptr; + void _set_event(const Ref<InputEvent> &p_event, const Ref<InputEvent> &p_original_event, bool p_update_input_list_selection = true); void _on_listen_input_changed(const Ref<InputEvent> &p_event); void _on_listen_focus_changed(); @@ -110,6 +113,7 @@ private: void _mod_toggled(bool p_checked, int p_index); void _autoremap_command_or_control_toggled(bool p_checked); void _key_mode_selected(int p_mode); + void _key_location_selected(int p_location); void _device_selection_changed(int p_option_button_index); void _set_current_device(int p_device); |