Skip to content

Commit 2675997

Browse files
committed
Merge pull request #102251 from Hilderin/fix-slow-resize-embedded-game
Fix slow resize Embedded Game Window
2 parents ccc306a + 65e14fd commit 2675997

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

editor/plugins/embedded_process.cpp

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,6 @@ void EmbeddedProcess::_notification(int p_what) {
4040
case NOTIFICATION_ENTER_TREE: {
4141
window = get_window();
4242
} break;
43-
case NOTIFICATION_PROCESS: {
44-
_check_focused_process_id();
45-
_check_mouse_over();
46-
47-
// We need to detect when the control globally changes location or size on the screen.
48-
// NOTIFICATION_RESIZED and NOTIFICATION_WM_POSITION_CHANGED are not enough to detect
49-
// resized parent to siblings controls that can affect global position.
50-
Rect2i new_global_rect = get_global_rect();
51-
if (last_global_rect != new_global_rect) {
52-
last_global_rect = new_global_rect;
53-
queue_update_embedded_process();
54-
}
55-
56-
} break;
5743
case NOTIFICATION_DRAW: {
5844
_draw();
5945
} break;
@@ -192,7 +178,7 @@ void EmbeddedProcess::embed_process(OS::ProcessID p_pid) {
192178
current_process_id = p_pid;
193179
start_embedding_time = OS::get_singleton()->get_ticks_msec();
194180
embedding_grab_focus = has_focus();
195-
set_process(true);
181+
timer_update_embedded_process->start();
196182
set_notify_transform(true);
197183

198184
// 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() {
209195
start_embedding_time = 0;
210196
embedding_grab_focus = false;
211197
timer_embedding->stop();
212-
set_process(false);
198+
timer_update_embedded_process->stop();
213199
set_notify_transform(false);
214200
queue_redraw();
215201
}
@@ -242,18 +228,31 @@ bool EmbeddedProcess::_is_embedded_process_updatable() {
242228
}
243229

244230
void EmbeddedProcess::queue_update_embedded_process() {
245-
if (updated_embedded_process_queued || !_is_embedded_process_updatable()) {
246-
return;
247-
}
248-
249231
updated_embedded_process_queued = true;
232+
}
250233

251-
callable_mp(this, &EmbeddedProcess::_update_embedded_process).call_deferred();
234+
void EmbeddedProcess::_timer_update_embedded_process_timeout() {
235+
_check_focused_process_id();
236+
_check_mouse_over();
237+
238+
if (!updated_embedded_process_queued) {
239+
// We need to detect when the control globally changes location or size on the screen.
240+
// NOTIFICATION_RESIZED and NOTIFICATION_WM_POSITION_CHANGED are not enough to detect
241+
// resized parent to siblings controls that can affect global position.
242+
Rect2i new_global_rect = get_global_rect();
243+
if (last_global_rect != new_global_rect) {
244+
last_global_rect = new_global_rect;
245+
queue_update_embedded_process();
246+
}
247+
}
248+
249+
if (updated_embedded_process_queued) {
250+
updated_embedded_process_queued = false;
251+
_update_embedded_process();
252+
}
252253
}
253254

254255
void EmbeddedProcess::_update_embedded_process() {
255-
updated_embedded_process_queued = false;
256-
257256
if (!_is_embedded_process_updatable()) {
258257
return;
259258
}
@@ -352,6 +351,12 @@ EmbeddedProcess::EmbeddedProcess() {
352351
timer_embedding->set_one_shot(true);
353352
add_child(timer_embedding);
354353
timer_embedding->connect("timeout", callable_mp(this, &EmbeddedProcess::_timer_embedding_timeout));
354+
355+
timer_update_embedded_process = memnew(Timer);
356+
timer_update_embedded_process->set_wait_time(0.1);
357+
add_child(timer_update_embedded_process);
358+
timer_update_embedded_process->connect("timeout", callable_mp(this, &EmbeddedProcess::_timer_update_embedded_process_timeout));
359+
355360
set_focus_mode(FOCUS_ALL);
356361
}
357362

editor/plugins/embedded_process.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class EmbeddedProcess : public Control {
4848

4949
Window *window = nullptr;
5050
Timer *timer_embedding = nullptr;
51+
Timer *timer_update_embedded_process = nullptr;
5152

5253
const int embedding_timeout = 45000;
5354

@@ -61,6 +62,7 @@ class EmbeddedProcess : public Control {
6162
void _try_embed_process();
6263
void _update_embedded_process();
6364
void _timer_embedding_timeout();
65+
void _timer_update_embedded_process_timeout();
6466
void _draw();
6567
void _check_mouse_over();
6668
void _check_focused_process_id();

editor/plugins/game_view_plugin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,11 @@ GameView::GameView(Ref<GameViewDebugger> p_debugger, WindowWrapper *p_wrapper) {
979979
game_size_label = memnew(Label());
980980
main_menu_hbox->add_child(game_size_label);
981981
game_size_label->hide();
982+
// Setting the minimum size prevents the game workspace from resizing indefinitely
983+
// due to the label size oscillating by a few pixels when the game is in stretch mode
984+
// and the game workspace is at its minimum size.
985+
game_size_label->set_custom_minimum_size(Size2(80 * EDSCALE, 0));
986+
game_size_label->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_RIGHT);
982987

983988
panel = memnew(Panel);
984989
add_child(panel);

0 commit comments

Comments
 (0)