@@ -306,10 +306,21 @@ String Window::get_title() const {
306306 return title;
307307}
308308
309+ void Window::_settings_changed () {
310+ if (visible && initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE && is_in_edited_scene_root ()) {
311+ Size2 screen_size = Size2 (GLOBAL_GET (" display/window/size/viewport_width" ), GLOBAL_GET (" display/window/size/viewport_height" ));
312+ position = (screen_size - size) / 2 ;
313+ if (embedder) {
314+ embedder->_sub_window_update (this );
315+ }
316+ }
317+ }
318+
309319void Window::set_initial_position (Window::WindowInitialPosition p_initial_position) {
310320 ERR_MAIN_THREAD_GUARD;
311321
312322 initial_position = p_initial_position;
323+ _settings_changed ();
313324 notify_property_list_changed ();
314325}
315326
@@ -829,7 +840,12 @@ void Window::set_visible(bool p_visible) {
829840 if (visible) {
830841 embedder = embedder_vp;
831842 if (initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE) {
832- position = (embedder->get_visible_rect ().size - size) / 2 ;
843+ if (is_in_edited_scene_root ()) {
844+ Size2 screen_size = Size2 (GLOBAL_GET (" display/window/size/viewport_width" ), GLOBAL_GET (" display/window/size/viewport_height" ));
845+ position = (screen_size - size) / 2 ;
846+ } else {
847+ position = (embedder->get_visible_rect ().size - size) / 2 ;
848+ }
833849 }
834850 embedder->_sub_window_register (this );
835851 RS::get_singleton ()->viewport_set_update_mode (get_viewport_rid (), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
@@ -1265,6 +1281,12 @@ void Window::_notification(int p_what) {
12651281 } break ;
12661282
12671283 case NOTIFICATION_ENTER_TREE: {
1284+ if (is_in_edited_scene_root ()) {
1285+ if (!ProjectSettings::get_singleton ()->is_connected (" settings_changed" , callable_mp (this , &Window::_settings_changed))) {
1286+ ProjectSettings::get_singleton ()->connect (" settings_changed" , callable_mp (this , &Window::_settings_changed));
1287+ }
1288+ }
1289+
12681290 bool embedded = false ;
12691291 {
12701292 embedder = get_embedder ();
@@ -1280,7 +1302,12 @@ void Window::_notification(int p_what) {
12801302 // Create as embedded.
12811303 if (embedder) {
12821304 if (initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE) {
1283- position = (embedder->get_visible_rect ().size - size) / 2 ;
1305+ if (is_in_edited_scene_root ()) {
1306+ Size2 screen_size = Size2 (GLOBAL_GET (" display/window/size/viewport_width" ), GLOBAL_GET (" display/window/size/viewport_height" ));
1307+ position = (screen_size - size) / 2 ;
1308+ } else {
1309+ position = (embedder->get_visible_rect ().size - size) / 2 ;
1310+ }
12841311 }
12851312 embedder->_sub_window_register (this );
12861313 RS::get_singleton ()->viewport_set_update_mode (get_viewport_rid (), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
@@ -1377,6 +1404,10 @@ void Window::_notification(int p_what) {
13771404 } break ;
13781405
13791406 case NOTIFICATION_EXIT_TREE: {
1407+ if (ProjectSettings::get_singleton ()->is_connected (" settings_changed" , callable_mp (this , &Window::_settings_changed))) {
1408+ ProjectSettings::get_singleton ()->disconnect (" settings_changed" , callable_mp (this , &Window::_settings_changed));
1409+ }
1410+
13801411 set_theme_context (nullptr , false );
13811412
13821413 if (transient) {
0 commit comments