From 65e14fd16bec7953356432c336b1d1e573e4921e Mon Sep 17 00:00:00 2001 From: Hilderin <81109165+Hilderin@users.noreply.github.com> Date: Fri, 31 Jan 2025 12:02:06 -0500 Subject: [PATCH] Fix slow resize Embedded Game Window --- editor/plugins/embedded_process.cpp | 51 ++++++++++++++++------------- editor/plugins/embedded_process.h | 2 ++ editor/plugins/game_view_plugin.cpp | 5 +++ 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/editor/plugins/embedded_process.cpp b/editor/plugins/embedded_process.cpp index 10c7188b5c..1638c43712 100644 --- a/editor/plugins/embedded_process.cpp +++ b/editor/plugins/embedded_process.cpp @@ -40,20 +40,6 @@ void EmbeddedProcess::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { window = get_window(); } break; - case NOTIFICATION_PROCESS: { - _check_focused_process_id(); - _check_mouse_over(); - - // We need to detect when the control globally changes location or size on the screen. - // NOTIFICATION_RESIZED and NOTIFICATION_WM_POSITION_CHANGED are not enough to detect - // resized parent to siblings controls that can affect global position. - Rect2i new_global_rect = get_global_rect(); - if (last_global_rect != new_global_rect) { - last_global_rect = new_global_rect; - queue_update_embedded_process(); - } - - } break; case NOTIFICATION_DRAW: { _draw(); } break; @@ -192,7 +178,7 @@ void EmbeddedProcess::embed_process(OS::ProcessID p_pid) { current_process_id = p_pid; start_embedding_time = OS::get_singleton()->get_ticks_msec(); embedding_grab_focus = has_focus(); - set_process(true); + timer_update_embedded_process->start(); set_notify_transform(true); // Attempt to embed the process, but if it has just started and the window is not ready yet, @@ -209,7 +195,7 @@ void EmbeddedProcess::reset() { start_embedding_time = 0; embedding_grab_focus = false; timer_embedding->stop(); - set_process(false); + timer_update_embedded_process->stop(); set_notify_transform(false); queue_redraw(); } @@ -242,18 +228,31 @@ bool EmbeddedProcess::_is_embedded_process_updatable() { } void EmbeddedProcess::queue_update_embedded_process() { - if (updated_embedded_process_queued || !_is_embedded_process_updatable()) { - return; + updated_embedded_process_queued = true; +} + +void EmbeddedProcess::_timer_update_embedded_process_timeout() { + _check_focused_process_id(); + _check_mouse_over(); + + if (!updated_embedded_process_queued) { + // We need to detect when the control globally changes location or size on the screen. + // NOTIFICATION_RESIZED and NOTIFICATION_WM_POSITION_CHANGED are not enough to detect + // resized parent to siblings controls that can affect global position. + Rect2i new_global_rect = get_global_rect(); + if (last_global_rect != new_global_rect) { + last_global_rect = new_global_rect; + queue_update_embedded_process(); + } } - updated_embedded_process_queued = true; - - callable_mp(this, &EmbeddedProcess::_update_embedded_process).call_deferred(); + if (updated_embedded_process_queued) { + updated_embedded_process_queued = false; + _update_embedded_process(); + } } void EmbeddedProcess::_update_embedded_process() { - updated_embedded_process_queued = false; - if (!_is_embedded_process_updatable()) { return; } @@ -352,6 +351,12 @@ EmbeddedProcess::EmbeddedProcess() { timer_embedding->set_one_shot(true); add_child(timer_embedding); timer_embedding->connect("timeout", callable_mp(this, &EmbeddedProcess::_timer_embedding_timeout)); + + timer_update_embedded_process = memnew(Timer); + timer_update_embedded_process->set_wait_time(0.1); + add_child(timer_update_embedded_process); + timer_update_embedded_process->connect("timeout", callable_mp(this, &EmbeddedProcess::_timer_update_embedded_process_timeout)); + set_focus_mode(FOCUS_ALL); } diff --git a/editor/plugins/embedded_process.h b/editor/plugins/embedded_process.h index 14ad44fdae..3e800923a7 100644 --- a/editor/plugins/embedded_process.h +++ b/editor/plugins/embedded_process.h @@ -48,6 +48,7 @@ class EmbeddedProcess : public Control { Window *window = nullptr; Timer *timer_embedding = nullptr; + Timer *timer_update_embedded_process = nullptr; const int embedding_timeout = 45000; @@ -61,6 +62,7 @@ class EmbeddedProcess : public Control { void _try_embed_process(); void _update_embedded_process(); void _timer_embedding_timeout(); + void _timer_update_embedded_process_timeout(); void _draw(); void _check_mouse_over(); void _check_focused_process_id(); diff --git a/editor/plugins/game_view_plugin.cpp b/editor/plugins/game_view_plugin.cpp index d96ee85137..f87f38d5a6 100644 --- a/editor/plugins/game_view_plugin.cpp +++ b/editor/plugins/game_view_plugin.cpp @@ -977,6 +977,11 @@ GameView::GameView(Ref p_debugger, WindowWrapper *p_wrapper) { game_size_label = memnew(Label()); main_menu_hbox->add_child(game_size_label); game_size_label->hide(); + // Setting the minimum size prevents the game workspace from resizing indefinitely + // due to the label size oscillating by a few pixels when the game is in stretch mode + // and the game workspace is at its minimum size. + game_size_label->set_custom_minimum_size(Size2(80 * EDSCALE, 0)); + game_size_label->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_RIGHT); panel = memnew(Panel); add_child(panel);