Skip to content

Commit

Permalink
[Input] Add extra shortcut_input input processing step to process U…
Browse files Browse the repository at this point in the history
…nicode character input with Alt / Ctrl modifiers, after processing of shortcuts.
  • Loading branch information
bruvzg committed Apr 5, 2022
1 parent 479143a commit d1207a0
Show file tree
Hide file tree
Showing 41 changed files with 182 additions and 51 deletions.
25 changes: 25 additions & 0 deletions doc/classes/Node.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@
[b]Note:[/b] [method _ready] may be called only once for each node. After removing a node from the scene tree and adding it again, [code]_ready[/code] will not be called a second time. This can be bypassed by requesting another call with [method request_ready], which may be called anywhere before adding the node again.
</description>
</method>
<method name="_shortcut_input" qualifiers="virtual">
<return type="void" />
<argument index="0" name="event" type="InputEvent" />
<description>
Called when an [InputEventKey] or [InputEventShortcut] hasn't been consumed by [method _input] or any GUI [Control] item. The input event propagates up through the node tree until a node consumes it.
It is only called if shortcut processing is enabled, which is done automatically if this method is overridden, and can be toggled with [method set_process_shortcut_input].
To consume the input event and stop it propagating further to other nodes, [method Viewport.set_input_as_handled] can be called.
This method can be used to handle shortcuts.
[b]Note:[/b] This method is only called if the node is present in the scene tree (i.e. if it's not orphan).
</description>
</method>
<method name="_unhandled_input" qualifiers="virtual">
<return type="void" />
<argument index="0" name="event" type="InputEvent" />
Expand All @@ -102,6 +113,7 @@
Called when an [InputEventKey] or [InputEventShortcut] hasn't been consumed by [method _input] or any GUI [Control] item. The input event propagates up through the node tree until a node consumes it.
It is only called if unhandled key input processing is enabled, which is done automatically if this method is overridden, and can be toggled with [method set_process_unhandled_key_input].
To consume the input event and stop it propagating further to other nodes, [method Viewport.set_input_as_handled] can be called.
This method can be used to handle Unicode character input with [kbd]Alt[/kbd], [kbd]Alt + Ctrl[/kbd], and [kbd]Alt + Shift[/kbd] modifiers, after shortcuts were handled.
For gameplay input, this and [method _unhandled_input] are usually a better fit than [method _input] as they allow the GUI to intercept the events first.
[b]Note:[/b] This method is only called if the node is present in the scene tree (i.e. if it's not an orphan).
</description>
Expand Down Expand Up @@ -462,6 +474,12 @@
Returns [code]true[/code] if internal processing is enabled (see [method set_process_internal]).
</description>
</method>
<method name="is_processing_shortcut_input" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if the node is processing shortcuts (see [method set_process_shortcut_input]).
</description>
</method>
<method name="is_processing_unhandled_input" qualifiers="const">
<return type="bool" />
<description>
Expand Down Expand Up @@ -673,6 +691,13 @@
[b]Warning:[/b] Built-in Nodes rely on the internal processing for their own logic, so changing this value from your code may lead to unexpected behavior. Script access to this internal logic is provided for specific advanced uses, but is unsafe and not supported.
</description>
</method>
<method name="set_process_shortcut_input">
<return type="void" />
<argument index="0" name="enable" type="bool" />
<description>
Enables shortcut processing. Enabled automatically if [method _shortcut_input] is overridden. Any calls to this before [method _ready] will be ignored.
</description>
</method>
<method name="set_process_unhandled_input">
<return type="void" />
<argument index="0" name="enable" type="bool" />
Expand Down
6 changes: 3 additions & 3 deletions editor/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void EditorFileDialog::_notification(int p_what) {

case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible()) {
set_process_unhandled_input(false);
set_process_shortcut_input(false);
}
} break;

Expand All @@ -126,7 +126,7 @@ void EditorFileDialog::_notification(int p_what) {
}
}

void EditorFileDialog::unhandled_input(const Ref<InputEvent> &p_event) {
void EditorFileDialog::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

Ref<InputEventKey> k = p_event;
Expand Down Expand Up @@ -327,7 +327,7 @@ void EditorFileDialog::_post_popup() {
_update_favorites();
}

set_process_unhandled_input(true);
set_process_shortcut_input(true);
}

void EditorFileDialog::_thumbnail_result(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata) {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_file_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class EditorFileDialog : public ConfirmationDialog {
void _thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
void _request_single_thumbnail(const String &p_path);

virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;

bool _is_open_should_be_disabled();

Expand Down
4 changes: 2 additions & 2 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ void EditorProperty::gui_input(const Ref<InputEvent> &p_event) {
}
}

void EditorProperty::unhandled_key_input(const Ref<InputEvent> &p_event) {
void EditorProperty::shortcut_input(const Ref<InputEvent> &p_event) {
if (!selected || !p_event->is_pressed()) {
return;
}
Expand Down Expand Up @@ -971,7 +971,7 @@ EditorProperty::EditorProperty() {
label_reference = nullptr;
bottom_editor = nullptr;
menu = nullptr;
set_process_unhandled_key_input(true);
set_process_shortcut_input(true);
}

void EditorProperty::_update_popup() {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class EditorProperty : public Container {
virtual void _set_read_only(bool p_read_only);

virtual void gui_input(const Ref<InputEvent> &p_event) override;
virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override;
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
const Color *_get_property_colors();

public:
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ void EditorNode::_update_title() {
DisplayServer::get_singleton()->window_set_title(title);
}

void EditorNode::unhandled_input(const Ref<InputEvent> &p_event) {
void EditorNode::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

Ref<InputEventKey> k = p_event;
Expand Down Expand Up @@ -7168,7 +7168,7 @@ EditorNode::EditorNode() {
_update_recent_scenes();

editor_data.restore_editor_global_states();
set_process_unhandled_input(true);
set_process_shortcut_input(true);

load_errors = memnew(RichTextLabel);
load_error_dialog = memnew(AcceptDialog);
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ class EditorNode : public Node {

void _exit_editor(int p_exit_code);

virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;

bool has_main_screen() const { return true; }

Expand Down
6 changes: 3 additions & 3 deletions editor/editor_settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void EditorSettingsDialog::popup_edit_settings() {
search_box->grab_focus();

_update_shortcuts();
set_process_unhandled_input(true);
set_process_shortcut_input(true);

// Restore valid window bounds or pop up at default size.
Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "editor_settings", Rect2());
Expand All @@ -119,7 +119,7 @@ void EditorSettingsDialog::_notification(int p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible()) {
EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "editor_settings", Rect2(get_position(), get_size()));
set_process_unhandled_input(false);
set_process_shortcut_input(false);
}
} break;

Expand Down Expand Up @@ -148,7 +148,7 @@ void EditorSettingsDialog::_notification(int p_what) {
}
}

void EditorSettingsDialog::unhandled_input(const Ref<InputEvent> &p_event) {
void EditorSettingsDialog::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

const Ref<InputEventKey> k = p_event;
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_settings_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class EditorSettingsDialog : public AcceptDialog {
void _settings_property_edited(const String &p_name);
void _settings_save();

virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
void _notification(int p_what);
void _update_icons();

Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/animation_player_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ void AnimationPlayerEditor::_onion_skinning_menu(int p_option) {
}
}

void AnimationPlayerEditor::unhandled_key_input(const Ref<InputEvent> &p_ev) {
void AnimationPlayerEditor::shortcut_input(const Ref<InputEvent> &p_ev) {
ERR_FAIL_COND(p_ev.is_null());

Ref<InputEventKey> k = p_ev;
Expand Down Expand Up @@ -1750,7 +1750,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plug
last_active = false;
timeline_position = 0;

set_process_unhandled_key_input(true);
set_process_shortcut_input(true);

add_child(track_editor);
track_editor->set_v_size_flags(SIZE_EXPAND_FILL);
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/animation_player_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class AnimationPlayerEditor : public VBoxContainer {
void _animation_key_editor_seek(float p_pos, bool p_drag, bool p_timeline_only = false);
void _animation_key_editor_anim_len_changed(float p_len);

virtual void unhandled_key_input(const Ref<InputEvent> &p_ev) override;
virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
void _animation_tool_menu(int p_option);
void _onion_skinning_menu(int p_option);

Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/asset_library_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ void EditorAssetLibrary::_update_repository_options() {
}
}

void EditorAssetLibrary::unhandled_key_input(const Ref<InputEvent> &p_event) {
void EditorAssetLibrary::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

const Ref<InputEventKey> key = p_event;
Expand Down Expand Up @@ -1541,7 +1541,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) {
description = nullptr;

set_process(true);
set_process_unhandled_key_input(true); // Global shortcuts since there is no main element to be focused.
set_process_shortcut_input(true); // Global shortcuts since there is no main element to be focused.

downloads_scroll = memnew(ScrollContainer);
downloads_scroll->set_vertical_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED);
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/asset_library_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class EditorAssetLibrary : public PanelContainer {
protected:
static void _bind_methods();
void _notification(int p_what);
virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override;
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;

public:
void disable_community_support();
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ real_t CanvasItemEditor::snap_angle(real_t p_target, real_t p_start) const {
}
}

void CanvasItemEditor::unhandled_key_input(const Ref<InputEvent> &p_ev) {
void CanvasItemEditor::shortcut_input(const Ref<InputEvent> &p_ev) {
ERR_FAIL_COND(p_ev.is_null());

Ref<InputEventKey> k = p_ev;
Expand Down Expand Up @@ -5322,7 +5322,7 @@ CanvasItemEditor::CanvasItemEditor() {
ED_SHORTCUT("canvas_item_editor/zoom_800_percent", TTR("Zoom to 800%"), Key::KEY_4);
ED_SHORTCUT("canvas_item_editor/zoom_1600_percent", TTR("Zoom to 1600%"), Key::KEY_5);

set_process_unhandled_key_input(true);
set_process_shortcut_input(true);

// Update the menus' checkboxes
call_deferred(SNAME("set_state"), get_state());
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/canvas_item_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class CanvasItemEditor : public VBoxContainer {

void _keying_changed();

virtual void unhandled_key_input(const Ref<InputEvent> &p_ev) override;
virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;

void _draw_text_at_position(Point2 p_position, String p_string, Side p_side);
void _draw_margin_at_position(int p_value, Point2 p_position, Side p_side);
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6848,7 +6848,7 @@ void Node3DEditor::snap_selected_nodes_to_floor() {
}
}

void Node3DEditor::unhandled_key_input(const Ref<InputEvent> &p_event) {
void Node3DEditor::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

if (!is_visible_in_tree()) {
Expand Down Expand Up @@ -7893,7 +7893,7 @@ Node3DEditor::Node3DEditor() {

selected = nullptr;

set_process_unhandled_key_input(true);
set_process_shortcut_input(true);
add_to_group("_spatial_editor_group");

EDITOR_DEF("editors/3d/manipulator_gizmo_size", 80);
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/node_3d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ class Node3DEditor : public VBoxContainer {
protected:
void _notification(int p_what);
//void _gui_input(InputEvent p_event);
virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override;
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;

static void _bind_methods();

Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3019,7 +3019,7 @@ void ScriptEditor::input(const Ref<InputEvent> &p_event) {
}
}

void ScriptEditor::unhandled_key_input(const Ref<InputEvent> &p_event) {
void ScriptEditor::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

if (!is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo()) {
Expand Down Expand Up @@ -3740,7 +3740,7 @@ ScriptEditor::ScriptEditor() {
ED_SHORTCUT("script_editor/next_script", TTR("Next Script"), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::PERIOD);
ED_SHORTCUT("script_editor/prev_script", TTR("Previous Script"), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::COMMA);
set_process_input(true);
set_process_unhandled_key_input(true);
set_process_shortcut_input(true);

file_menu = memnew(MenuButton);
file_menu->set_text(TTR("File"));
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/script_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class ScriptEditor : public PanelContainer {
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);

virtual void input(const Ref<InputEvent> &p_event) override;
virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override;
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;

void _script_list_gui_input(const Ref<InputEvent> &ev);
void _make_script_list_context_menu();
Expand Down
4 changes: 2 additions & 2 deletions editor/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@ void ProjectManager::_notification(int p_what) {
} break;

case NOTIFICATION_VISIBILITY_CHANGED: {
set_process_unhandled_key_input(is_visible_in_tree());
set_process_shortcut_input(is_visible_in_tree());
} break;

case NOTIFICATION_WM_CLOSE_REQUEST: {
Expand Down Expand Up @@ -1962,7 +1962,7 @@ void ProjectManager::_update_project_buttons() {
erase_missing_btn->set_disabled(!_project_list->is_any_project_missing());
}

void ProjectManager::unhandled_key_input(const Ref<InputEvent> &p_ev) {
void ProjectManager::shortcut_input(const Ref<InputEvent> &p_ev) {
ERR_FAIL_COND(p_ev.is_null());

Ref<InputEventKey> k = p_ev;
Expand Down
2 changes: 1 addition & 1 deletion editor/project_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class ProjectManager : public Control {
void _install_project(const String &p_zip_path, const String &p_title);

void _dim_window();
virtual void unhandled_key_input(const Ref<InputEvent> &p_ev) override;
virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
void _files_dropped(PackedStringArray p_files, int p_screen);

void _version_button_pressed();
Expand Down
4 changes: 2 additions & 2 deletions editor/project_settings_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void ProjectSettingsEditor::popup_project_settings() {

_add_feature_overrides();
general_settings_inspector->update_category_list();
set_process_unhandled_input(true);
set_process_shortcut_input(true);

localization_editor->update_translations();
autoload_settings->update_autoload();
Expand Down Expand Up @@ -202,7 +202,7 @@ void ProjectSettingsEditor::_select_type(Variant::Type p_type) {
type_box->select(type_box->get_item_index(p_type));
}

void ProjectSettingsEditor::unhandled_input(const Ref<InputEvent> &p_event) {
void ProjectSettingsEditor::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

const Ref<InputEventKey> k = p_event;
Expand Down
2 changes: 1 addition & 1 deletion editor/project_settings_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ProjectSettingsEditor : public AcceptDialog {
void _feature_selected(int p_index);
void _select_type(Variant::Type p_type);

virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;

String _get_setting_name() const;
void _setting_edited(const String &p_name);
Expand Down
4 changes: 2 additions & 2 deletions editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void SceneTreeDock::input(const Ref<InputEvent> &p_event) {
}
}

void SceneTreeDock::unhandled_key_input(const Ref<InputEvent> &p_event) {
void SceneTreeDock::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

if (get_viewport()->gui_get_focus_owner() && get_viewport()->gui_get_focus_owner()->is_text_field()) {
Expand Down Expand Up @@ -3476,7 +3476,7 @@ SceneTreeDock::SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selec
add_child(quick_open);
quick_open->connect("quick_open", callable_mp(this, &SceneTreeDock::_quick_open));

set_process_unhandled_key_input(true);
set_process_shortcut_input(true);

delete_dialog = memnew(ConfirmationDialog);
add_child(delete_dialog);
Expand Down
2 changes: 1 addition & 1 deletion editor/scene_tree_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class SceneTreeDock : public VBoxContainer {

void _nodes_drag_begin();
virtual void input(const Ref<InputEvent> &p_event) override;
virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override;
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;

void _import_subscene();

Expand Down
Loading

0 comments on commit d1207a0

Please sign in to comment.