From 6d490ce8def209682d884ad0d98f317de9b29702 Mon Sep 17 00:00:00 2001
From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com>
Date: Wed, 10 May 2023 21:51:50 +0200
Subject: [PATCH] Deprecate push_unhandled_input
The functionality of `push_unhandled_input` has changed so that it no
longer propagates input events to SubViewports.
This makes it less predictable and it should be deprecated in favor of
`push_input` which provides the same functionality and more.
Also this deprecation simplifies the Viewport-API by reducing the methods
for pushing input events, so that users don't need to worry about when
to use which function in order to insert input events.
---
doc/classes/InputEventShortcut.xml | 2 +-
doc/classes/Viewport.xml | 4 +++-
scene/main/viewport.cpp | 34 +++++++++++++++++++-----------
scene/main/viewport.h | 4 ++++
4 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/doc/classes/InputEventShortcut.xml b/doc/classes/InputEventShortcut.xml
index 120c9d87035d..4141888d2c2e 100644
--- a/doc/classes/InputEventShortcut.xml
+++ b/doc/classes/InputEventShortcut.xml
@@ -4,7 +4,7 @@
Represents a triggered keyboard [Shortcut].
- InputEventShortcut is a special event that can be received in [method Node._unhandled_key_input]. It is typically sent by the editor's Command Palette to trigger actions, but can also be sent manually using [method Viewport.push_unhandled_input].
+ InputEventShortcut is a special event that can be received in [method Node._unhandled_key_input]. It is typically sent by the editor's Command Palette to trigger actions, but can also be sent manually using [method Viewport.push_input].
diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml
index 20a1424f4185..d363a115505a 100644
--- a/doc/classes/Viewport.xml
+++ b/doc/classes/Viewport.xml
@@ -173,7 +173,7 @@
Helper method which calls the [code]set_text()[/code] method on the currently focused [Control], provided that it is defined (e.g. if the focused Control is [Button] or [LineEdit]).
-
+
@@ -187,6 +187,8 @@
- [method Node._unhandled_key_input]
If an earlier method marks the input as handled via [method set_input_as_handled], any later method in this list will not be called.
If none of the methods handle the event and [member physics_object_picking] is [code]true[/code], the event is used for physics object picking.
+ [b]Note:[/b] This method doesn't propagate input events to embedded [Window]s or [SubViewport]s.
+ [b]Note:[/b] This method is deprecated, use [method push_input] instead.
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index e6ebaba79e15..e7970b212ee1 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -2999,16 +2999,19 @@ void Viewport::push_input(const Ref &p_event, bool p_local_coords) {
}
if (!is_input_handled()) {
- push_unhandled_input(ev, true);
+ _push_unhandled_input_internal(ev);
}
event_count++;
}
+#ifndef DISABLE_DEPRECATED
void Viewport::push_unhandled_input(const Ref &p_event, bool p_local_coords) {
ERR_MAIN_THREAD_GUARD;
ERR_FAIL_COND(p_event.is_null());
ERR_FAIL_COND(!is_inside_tree());
+ WARN_DEPRECATED_MSG(R"(The "push_unhandled_input" method is deprecated, use "push_input" instead.)");
+
local_input_handled = false;
if (disable_input || !_can_consume_input_events()) {
@@ -3026,31 +3029,36 @@ void Viewport::push_unhandled_input(const Ref &p_event, bool p_local
ev = p_event;
}
+ _push_unhandled_input_internal(ev);
+}
+#endif // DISABLE_DEPRECATED
+
+void Viewport::_push_unhandled_input_internal(const Ref &p_event) {
// Shortcut Input.
- if (Object::cast_to(*ev) != nullptr || Object::cast_to(*ev) != nullptr || Object::cast_to(*ev) != nullptr) {
- get_tree()->_call_input_pause(shortcut_input_group, SceneTree::CALL_INPUT_TYPE_SHORTCUT_INPUT, ev, this);
+ if (Object::cast_to(*p_event) != nullptr || Object::cast_to(*p_event) != nullptr || Object::cast_to(*p_event) != nullptr) {
+ get_tree()->_call_input_pause(shortcut_input_group, SceneTree::CALL_INPUT_TYPE_SHORTCUT_INPUT, p_event, this);
}
// Unhandled Input.
if (!is_input_handled()) {
- get_tree()->_call_input_pause(unhandled_input_group, SceneTree::CALL_INPUT_TYPE_UNHANDLED_INPUT, ev, this);
+ get_tree()->_call_input_pause(unhandled_input_group, SceneTree::CALL_INPUT_TYPE_UNHANDLED_INPUT, p_event, this);
}
// Unhandled key Input - Used for performance reasons - This is called a lot less than _unhandled_input since it ignores MouseMotion, and to handle Unicode input with Alt / Ctrl modifiers after handling shortcuts.
- if (!is_input_handled() && (Object::cast_to(*ev) != nullptr)) {
- get_tree()->_call_input_pause(unhandled_key_input_group, SceneTree::CALL_INPUT_TYPE_UNHANDLED_KEY_INPUT, ev, this);
+ if (!is_input_handled() && (Object::cast_to(*p_event) != nullptr)) {
+ get_tree()->_call_input_pause(unhandled_key_input_group, SceneTree::CALL_INPUT_TYPE_UNHANDLED_KEY_INPUT, p_event, this);
}
if (physics_object_picking && !is_input_handled()) {
if (Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED &&
- (Object::cast_to(*ev) ||
- Object::cast_to(*ev) ||
- Object::cast_to(*ev) ||
- Object::cast_to(*ev) ||
- Object::cast_to(*ev) // To remember state.
+ (Object::cast_to(*p_event) ||
+ Object::cast_to(*p_event) ||
+ Object::cast_to(*p_event) ||
+ Object::cast_to(*p_event) ||
+ Object::cast_to(*p_event) // To remember state.
)) {
- physics_picking_events.push_back(ev);
+ physics_picking_events.push_back(p_event);
set_input_as_handled();
}
}
@@ -4144,7 +4152,9 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_viewport_rid"), &Viewport::get_viewport_rid);
ClassDB::bind_method(D_METHOD("push_text_input", "text"), &Viewport::push_text_input);
ClassDB::bind_method(D_METHOD("push_input", "event", "in_local_coords"), &Viewport::push_input, DEFVAL(false));
+#ifndef DISABLE_DEPRECATED
ClassDB::bind_method(D_METHOD("push_unhandled_input", "event", "in_local_coords"), &Viewport::push_unhandled_input, DEFVAL(false));
+#endif // DISABLE_DEPRECATED
ClassDB::bind_method(D_METHOD("get_camera_2d"), &Viewport::get_camera_2d);
ClassDB::bind_method(D_METHOD("set_as_audio_listener_2d", "enable"), &Viewport::set_as_audio_listener_2d);
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 8870ed6ecae8..63cddddbcbb3 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -414,6 +414,8 @@ class Viewport : public Node {
void _perform_drop(Control *p_control = nullptr, Point2 p_pos = Point2());
void _gui_cleanup_internal_state(Ref p_event);
+ void _push_unhandled_input_internal(const Ref &p_event);
+
Ref _make_input_local(const Ref &ev);
friend class Control;
@@ -575,7 +577,9 @@ class Viewport : public Node {
void push_text_input(const String &p_text);
void push_input(const Ref &p_event, bool p_local_coords = false);
+#ifndef DISABLE_DEPRECATED
void push_unhandled_input(const Ref &p_event, bool p_local_coords = false);
+#endif // DISABLE_DEPRECATED
void set_disable_input(bool p_disable);
bool is_input_disabled() const;