summaryrefslogtreecommitdiffstats
path: root/scene/main/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main/window.cpp')
-rw-r--r--scene/main/window.cpp82
1 files changed, 58 insertions, 24 deletions
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index a6cb5f4526..70b70b8928 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -520,15 +520,12 @@ void Window::request_attention() {
}
}
+#ifndef DISABLE_DEPRECATED
void Window::move_to_foreground() {
- ERR_MAIN_THREAD_GUARD;
- if (embedder) {
- embedder->_sub_window_grab_focus(this);
-
- } else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
- DisplayServer::get_singleton()->window_move_to_foreground(window_id);
- }
+ WARN_DEPRECATED_MSG(R"*(The "move_to_foreground()" method is deprecated, use "grab_focus()" instead.)*");
+ grab_focus();
}
+#endif // DISABLE_DEPRECATED
bool Window::can_draw() const {
ERR_READ_THREAD_GUARD_V(false);
@@ -573,6 +570,10 @@ bool Window::is_in_edited_scene_root() const {
void Window::_make_window() {
ERR_FAIL_COND(window_id != DisplayServer::INVALID_WINDOW_ID);
+ if (transient && transient_to_focused) {
+ _make_transient();
+ }
+
uint32_t f = 0;
for (int i = 0; i < FLAG_MAX; i++) {
if (flags[i]) {
@@ -665,6 +666,10 @@ void Window::_clear_window() {
_update_viewport_size();
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
+
+ if (transient && transient_to_focused) {
+ _clear_transient();
+ }
}
void Window::_rect_changed_callback(const Rect2i &p_callback) {
@@ -864,18 +869,29 @@ void Window::_make_transient() {
return;
}
//find transient parent
- Viewport *vp = get_parent()->get_viewport();
+
Window *window = nullptr;
- while (vp) {
- window = Object::cast_to<Window>(vp);
- if (window) {
- break;
- }
- if (!vp->get_parent()) {
- break;
+
+ if (!is_embedded() && transient_to_focused) {
+ DisplayServer::WindowID focused_window_id = DisplayServer::get_singleton()->get_focused_window();
+ if (focused_window_id != DisplayServer::INVALID_WINDOW_ID) {
+ window = Object::cast_to<Window>(ObjectDB::get_instance(DisplayServer::get_singleton()->window_get_attached_instance_id(focused_window_id)));
}
+ }
- vp = vp->get_parent()->get_viewport();
+ if (!window) {
+ Viewport *vp = get_parent()->get_viewport();
+ while (vp) {
+ window = Object::cast_to<Window>(vp);
+ if (window) {
+ break;
+ }
+ if (!vp->get_parent()) {
+ break;
+ }
+
+ vp = vp->get_parent()->get_viewport();
+ }
}
if (window) {
@@ -919,17 +935,32 @@ void Window::set_transient(bool p_transient) {
}
if (transient) {
- _make_transient();
+ if (!transient_to_focused) {
+ _make_transient();
+ }
} else {
_clear_transient();
}
}
bool Window::is_transient() const {
- ERR_READ_THREAD_GUARD_V(false);
return transient;
}
+void Window::set_transient_to_focused(bool p_transient_to_focused) {
+ ERR_MAIN_THREAD_GUARD;
+ if (transient_to_focused == p_transient_to_focused) {
+ return;
+ }
+
+ transient_to_focused = p_transient_to_focused;
+}
+
+bool Window::is_transient_to_focused() const {
+ ERR_READ_THREAD_GUARD_V(false);
+ return transient_to_focused;
+}
+
void Window::set_exclusive(bool p_exclusive) {
ERR_MAIN_THREAD_GUARD;
if (exclusive == p_exclusive) {
@@ -1262,7 +1293,7 @@ void Window::_notification(int p_what) {
}
}
- if (transient) {
+ if (transient && !transient_to_focused) {
_make_transient();
}
if (visible) {
@@ -1516,7 +1547,7 @@ void Window::child_controls_changed() {
}
updating_child_controls = true;
- call_deferred(SNAME("_update_child_controls"));
+ callable_mp(this, &Window::_update_child_controls).call_deferred();
}
void Window::_update_child_controls() {
@@ -1997,7 +2028,7 @@ void Window::_update_theme_item_cache() {
// Updating without a delay can cause a lot of lag.
if (!wrap_controls) {
updating_embedded_window = true;
- call_deferred(SNAME("_update_embedded_window"));
+ callable_mp(this, &Window::_update_embedded_window).call_deferred();
} else {
child_controls_changed();
}
@@ -2745,7 +2776,9 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("request_attention"), &Window::request_attention);
+#ifndef DISABLE_DEPRECATED
ClassDB::bind_method(D_METHOD("move_to_foreground"), &Window::move_to_foreground);
+#endif // DISABLE_DEPRECATED
ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Window::set_visible);
ClassDB::bind_method(D_METHOD("is_visible"), &Window::is_visible);
@@ -2756,6 +2789,9 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_transient", "transient"), &Window::set_transient);
ClassDB::bind_method(D_METHOD("is_transient"), &Window::is_transient);
+ ClassDB::bind_method(D_METHOD("set_transient_to_focused", "enable"), &Window::set_transient_to_focused);
+ ClassDB::bind_method(D_METHOD("is_transient_to_focused"), &Window::is_transient_to_focused);
+
ClassDB::bind_method(D_METHOD("set_exclusive", "exclusive"), &Window::set_exclusive);
ClassDB::bind_method(D_METHOD("is_exclusive"), &Window::is_exclusive);
@@ -2800,9 +2836,6 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_wrapping_controls"), &Window::is_wrapping_controls);
ClassDB::bind_method(D_METHOD("child_controls_changed"), &Window::child_controls_changed);
- ClassDB::bind_method(D_METHOD("_update_child_controls"), &Window::_update_child_controls);
- ClassDB::bind_method(D_METHOD("_update_embedded_window"), &Window::_update_embedded_window);
-
ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Window::set_theme);
ClassDB::bind_method(D_METHOD("get_theme"), &Window::get_theme);
@@ -2887,6 +2920,7 @@ void Window::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "wrap_controls"), "set_wrap_controls", "is_wrapping_controls");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transient"), "set_transient", "is_transient");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transient_to_focused"), "set_transient_to_focused", "is_transient_to_focused");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclusive"), "set_exclusive", "is_exclusive");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "unresizable"), "set_flag", "get_flag", FLAG_RESIZE_DISABLED);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "borderless"), "set_flag", "get_flag", FLAG_BORDERLESS);