From c7bc322bf610c623db8365f1877adcf78c8173c3 Mon Sep 17 00:00:00 2001 From: Hilderin <81109165+Hilderin@users.noreply.github.com> Date: Wed, 19 Feb 2025 17:49:28 -0500 Subject: [PATCH] Fix Embedded Game does not focus when mouse over on Windows --- editor/plugins/embedded_process.cpp | 13 +++++++++---- platform/windows/display_server_windows.cpp | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/editor/plugins/embedded_process.cpp b/editor/plugins/embedded_process.cpp index 0da2dceb5f4..d11b6425d83 100644 --- a/editor/plugins/embedded_process.cpp +++ b/editor/plugins/embedded_process.cpp @@ -321,10 +321,15 @@ void EmbeddedProcess::_check_mouse_over() { return; } - // When there's a modal window, we don't want to grab the focus to prevent - // the game window to go in front of the modal window. - if (_get_current_modal_window()) { - return; + // Check if there's an exclusive popup, an open menu, or a tooltip. + // We don't want to grab focus to prevent the game window from coming to the front of the modal window + // or the open menu from closing when the mouse cursor moves outside the menu and over the embedded game. + Vector wl = DisplayServer::get_singleton()->get_window_list(); + for (const DisplayServer::WindowID &window_id : wl) { + Window *w = Window::get_from_id(window_id); + if (w && (w->is_exclusive() || w->get_flag(Window::FLAG_POPUP))) { + return; + } } // Force "regrabbing" the game window focus. diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 2a49bb9da57..e2b1876b581 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -3000,6 +3000,7 @@ Error DisplayServerWindows::embed_process(WindowID p_window, OS::ProcessID p_pid } if (p_grab_focus) { + SetForegroundWindow(ep->window_handle); SetFocus(ep->window_handle); }