1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-19 14:31:59 +00:00

Merge pull request #102251 from Hilderin/fix-slow-resize-embedded-game

Fix slow resize Embedded Game Window
This commit is contained in:
Thaddeus Crews
2025-02-03 11:14:41 -06:00
3 changed files with 35 additions and 23 deletions

View File

@@ -40,20 +40,6 @@ void EmbeddedProcess::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: { case NOTIFICATION_ENTER_TREE: {
window = get_window(); window = get_window();
} break; } 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: { case NOTIFICATION_DRAW: {
_draw(); _draw();
} break; } break;
@@ -192,7 +178,7 @@ void EmbeddedProcess::embed_process(OS::ProcessID p_pid) {
current_process_id = p_pid; current_process_id = p_pid;
start_embedding_time = OS::get_singleton()->get_ticks_msec(); start_embedding_time = OS::get_singleton()->get_ticks_msec();
embedding_grab_focus = has_focus(); embedding_grab_focus = has_focus();
set_process(true); timer_update_embedded_process->start();
set_notify_transform(true); set_notify_transform(true);
// Attempt to embed the process, but if it has just started and the window is not ready yet, // 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; start_embedding_time = 0;
embedding_grab_focus = false; embedding_grab_focus = false;
timer_embedding->stop(); timer_embedding->stop();
set_process(false); timer_update_embedded_process->stop();
set_notify_transform(false); set_notify_transform(false);
queue_redraw(); queue_redraw();
} }
@@ -242,18 +228,31 @@ bool EmbeddedProcess::_is_embedded_process_updatable() {
} }
void EmbeddedProcess::queue_update_embedded_process() { void EmbeddedProcess::queue_update_embedded_process() {
if (updated_embedded_process_queued || !_is_embedded_process_updatable()) { updated_embedded_process_queued = true;
return; }
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; if (updated_embedded_process_queued) {
updated_embedded_process_queued = false;
callable_mp(this, &EmbeddedProcess::_update_embedded_process).call_deferred(); _update_embedded_process();
}
} }
void EmbeddedProcess::_update_embedded_process() { void EmbeddedProcess::_update_embedded_process() {
updated_embedded_process_queued = false;
if (!_is_embedded_process_updatable()) { if (!_is_embedded_process_updatable()) {
return; return;
} }
@@ -352,6 +351,12 @@ EmbeddedProcess::EmbeddedProcess() {
timer_embedding->set_one_shot(true); timer_embedding->set_one_shot(true);
add_child(timer_embedding); add_child(timer_embedding);
timer_embedding->connect("timeout", callable_mp(this, &EmbeddedProcess::_timer_embedding_timeout)); 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); set_focus_mode(FOCUS_ALL);
} }

View File

@@ -48,6 +48,7 @@ class EmbeddedProcess : public Control {
Window *window = nullptr; Window *window = nullptr;
Timer *timer_embedding = nullptr; Timer *timer_embedding = nullptr;
Timer *timer_update_embedded_process = nullptr;
const int embedding_timeout = 45000; const int embedding_timeout = 45000;
@@ -61,6 +62,7 @@ class EmbeddedProcess : public Control {
void _try_embed_process(); void _try_embed_process();
void _update_embedded_process(); void _update_embedded_process();
void _timer_embedding_timeout(); void _timer_embedding_timeout();
void _timer_update_embedded_process_timeout();
void _draw(); void _draw();
void _check_mouse_over(); void _check_mouse_over();
void _check_focused_process_id(); void _check_focused_process_id();

View File

@@ -979,6 +979,11 @@ GameView::GameView(Ref<GameViewDebugger> p_debugger, WindowWrapper *p_wrapper) {
game_size_label = memnew(Label()); game_size_label = memnew(Label());
main_menu_hbox->add_child(game_size_label); main_menu_hbox->add_child(game_size_label);
game_size_label->hide(); 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); panel = memnew(Panel);
add_child(panel); add_child(panel);