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.cpp77
1 files changed, 53 insertions, 24 deletions
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 6632dd9033..addbd6078a 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -37,7 +37,6 @@
#include "core/string/translation.h"
#include "core/variant/variant_parser.h"
#include "scene/gui/control.h"
-#include "scene/scene_string_names.h"
#include "scene/theme/theme_db.h"
#include "scene/theme/theme_owner.h"
@@ -307,10 +306,21 @@ String Window::get_title() const {
return title;
}
+void Window::_settings_changed() {
+ if (visible && initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE && is_in_edited_scene_root()) {
+ Size2 screen_size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
+ position = (screen_size - size) / 2;
+ if (embedder) {
+ embedder->_sub_window_update(this);
+ }
+ }
+}
+
void Window::set_initial_position(Window::WindowInitialPosition p_initial_position) {
ERR_MAIN_THREAD_GUARD;
initial_position = p_initial_position;
+ _settings_changed();
notify_property_list_changed();
}
@@ -415,7 +425,7 @@ Size2i Window::_clamp_limit_size(const Size2i &p_limit_size) {
if (max_window_size != Size2i()) {
return p_limit_size.clamp(Vector2i(), max_window_size);
} else {
- return p_limit_size.max(Vector2i());
+ return p_limit_size.maxi(0);
}
}
@@ -724,6 +734,9 @@ void Window::_event_callback(DisplayServer::WindowEvent p_event) {
if (!is_inside_tree()) {
return;
}
+ // Ensure keeping the order of input events and window events when input events are buffered or accumulated.
+ Input::get_singleton()->flush_buffered_events();
+
Window *root = get_tree()->get_root();
if (!root->gui.windowmanager_window_over) {
#ifdef DEV_ENABLED
@@ -739,13 +752,13 @@ void Window::_event_callback(DisplayServer::WindowEvent p_event) {
case DisplayServer::WINDOW_EVENT_FOCUS_IN: {
focused = true;
_propagate_window_notification(this, NOTIFICATION_WM_WINDOW_FOCUS_IN);
- emit_signal(SNAME("focus_entered"));
+ emit_signal(SceneStringName(focus_entered));
} break;
case DisplayServer::WINDOW_EVENT_FOCUS_OUT: {
focused = false;
_propagate_window_notification(this, NOTIFICATION_WM_WINDOW_FOCUS_OUT);
- emit_signal(SNAME("focus_exited"));
+ emit_signal(SceneStringName(focus_exited));
} break;
case DisplayServer::WINDOW_EVENT_CLOSE_REQUEST: {
if (exclusive_child != nullptr) {
@@ -827,7 +840,12 @@ void Window::set_visible(bool p_visible) {
if (visible) {
embedder = embedder_vp;
if (initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE) {
- position = (embedder->get_visible_rect().size - size) / 2;
+ if (is_in_edited_scene_root()) {
+ Size2 screen_size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
+ position = (screen_size - size) / 2;
+ } else {
+ position = (embedder->get_visible_rect().size - size) / 2;
+ }
}
embedder->_sub_window_register(this);
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
@@ -843,7 +861,7 @@ void Window::set_visible(bool p_visible) {
focused = false;
}
notification(NOTIFICATION_VISIBILITY_CHANGED);
- emit_signal(SceneStringNames::get_singleton()->visibility_changed);
+ emit_signal(SceneStringName(visibility_changed));
RS::get_singleton()->viewport_set_active(get_viewport_rid(), visible);
@@ -1033,8 +1051,7 @@ void Window::_update_window_size() {
}
if (embedder) {
- size.x = MAX(size.x, 1);
- size.y = MAX(size.y, 1);
+ size = size.maxi(1);
embedder->_sub_window_update(this);
} else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
@@ -1213,10 +1230,10 @@ void Window::set_force_native(bool p_force_native) {
if (force_native == p_force_native) {
return;
}
- force_native = p_force_native;
- if (is_visible()) {
- WARN_PRINT("Can't change \"force_native\" while a window is displayed. Consider hiding window before changing this value.");
+ if (is_visible() && !is_in_edited_scene_root()) {
+ ERR_FAIL_MSG("Can't change \"force_native\" while a window is displayed. Consider hiding window before changing this value.");
}
+ force_native = p_force_native;
}
bool Window::get_force_native() const {
@@ -1225,7 +1242,7 @@ bool Window::get_force_native() const {
Viewport *Window::get_embedder() const {
ERR_READ_THREAD_GUARD_V(nullptr);
- if (force_native && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SUBWINDOWS)) {
+ if (force_native && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SUBWINDOWS) && !is_in_edited_scene_root()) {
return nullptr;
}
@@ -1264,6 +1281,12 @@ void Window::_notification(int p_what) {
} break;
case NOTIFICATION_ENTER_TREE: {
+ if (is_in_edited_scene_root()) {
+ if (!ProjectSettings::get_singleton()->is_connected("settings_changed", callable_mp(this, &Window::_settings_changed))) {
+ ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &Window::_settings_changed));
+ }
+ }
+
bool embedded = false;
{
embedder = get_embedder();
@@ -1279,7 +1302,12 @@ void Window::_notification(int p_what) {
// Create as embedded.
if (embedder) {
if (initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE) {
- position = (embedder->get_visible_rect().size - size) / 2;
+ if (is_in_edited_scene_root()) {
+ Size2 screen_size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
+ position = (screen_size - size) / 2;
+ } else {
+ position = (embedder->get_visible_rect().size - size) / 2;
+ }
}
embedder->_sub_window_register(this);
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
@@ -1319,7 +1347,7 @@ void Window::_notification(int p_what) {
}
if (visible) {
notification(NOTIFICATION_VISIBILITY_CHANGED);
- emit_signal(SceneStringNames::get_singleton()->visibility_changed);
+ emit_signal(SceneStringName(visibility_changed));
RS::get_singleton()->viewport_set_active(get_viewport_rid(), true);
}
@@ -1335,7 +1363,7 @@ void Window::_notification(int p_what) {
} break;
case NOTIFICATION_THEME_CHANGED: {
- emit_signal(SceneStringNames::get_singleton()->theme_changed);
+ emit_signal(SceneStringName(theme_changed));
_invalidate_theme_cache();
_update_theme_item_cache();
} break;
@@ -1376,6 +1404,10 @@ void Window::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
+ if (ProjectSettings::get_singleton()->is_connected("settings_changed", callable_mp(this, &Window::_settings_changed))) {
+ ProjectSettings::get_singleton()->disconnect("settings_changed", callable_mp(this, &Window::_settings_changed));
+ }
+
set_theme_context(nullptr, false);
if (transient) {
@@ -1402,11 +1434,11 @@ void Window::_notification(int p_what) {
} break;
case NOTIFICATION_VP_MOUSE_ENTER: {
- emit_signal(SceneStringNames::get_singleton()->mouse_entered);
+ emit_signal(SceneStringName(mouse_entered));
} break;
case NOTIFICATION_VP_MOUSE_EXIT: {
- emit_signal(SceneStringNames::get_singleton()->mouse_exited);
+ emit_signal(SceneStringName(mouse_exited));
} break;
}
}
@@ -1545,8 +1577,7 @@ Size2 Window::_get_contents_minimum_size() const {
Point2i pos = c->get_position();
Size2i min = c->get_combined_minimum_size();
- max.x = MAX(pos.x + min.x, max.x);
- max.y = MAX(pos.y + min.y, max.y);
+ max = max.max(pos + min);
}
}
@@ -1578,6 +1609,7 @@ bool Window::_can_consume_input_events() const {
}
void Window::_window_input(const Ref<InputEvent> &p_ev) {
+ ERR_MAIN_THREAD_GUARD;
if (EngineDebugger::is_active()) {
// Quit from game window using the stop shortcut (F8 by default).
// The custom shortcut is provided via environment variable when running from the editor.
@@ -1620,7 +1652,7 @@ void Window::_window_input(const Ref<InputEvent> &p_ev) {
_input_from_window(p_ev);
if (p_ev->get_device() != InputEvent::DEVICE_ID_INTERNAL && is_inside_tree()) {
- emit_signal(SceneStringNames::get_singleton()->window_input, p_ev);
+ emit_signal(SceneStringName(window_input), p_ev);
}
if (is_inside_tree()) {
@@ -1703,7 +1735,7 @@ void Window::popup_centered_clamped(const Size2i &p_size, float p_fallback_ratio
Vector2i size_ratio = parent_rect.size * p_fallback_ratio;
Rect2i popup_rect;
- popup_rect.size = Vector2i(MIN(size_ratio.x, expected_size.x), MIN(size_ratio.y, expected_size.y));
+ popup_rect.size = size_ratio.min(expected_size);
popup_rect.size = _clamp_window_size(popup_rect.size);
if (parent_rect != Rect2()) {
@@ -2719,9 +2751,6 @@ void Window::_update_mouse_over(Vector2 p_pos) {
if (is_embedded()) {
mouse_in_window = true;
_propagate_window_notification(this, NOTIFICATION_WM_MOUSE_ENTER);
- } else {
- // Prevent update based on delayed InputEvents from DisplayServer.
- return;
}
}