Repository: godotengine/godot (language: cpp)

Issue:
Embedded Game does not focus when mouse over on Windows
### Tested versions

Reproductible in Godot 4.4 beta 4 on Windows
Not reproductible in Godot 4.4 beta 3
Not reproductible on Linux

### System information

Godot v4.4.beta4 - Windows 11 (build 26100) - Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 (NVIDIA; 32.0.15.7216) - 11th Gen Intel(R) Core(TM) i5-11600KF @ 3.90GHz (12 threads)

### Issue description

The the mouse is over the embedded game window it should auto focus. That was the intended behaviour to same a click from the user to interact with the game and to simulate the same behaviour as the 2D and 3D view.

### Steps to reproduce

- Start the game Embedded
- Focus something else in the editor (except a textfield)
- Mouse over the game window
- It should automatically focus the game


Godot 4 beta 3:

https://github.com/user-attachments/assets/21117fe2-8521-4bf2-8728-ae3dcaa5c47f

Godot 4 beta 4:

https://github.com/user-attachments/assets/d99039da-d10d-4e14-9d6c-0f38bb7f5a3a

### Minimal reproduction project (MRP)

Any project


Discussion / hints:

Fix patch:
diff --git a/editor/plugins/embedded_process.cpp b/editor/plugins/embedded_process.cpp
index 0da2dceb5f4d..d11b6425d834 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<DisplayServer::WindowID> 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 2a49bb9da57e..e2b1876b5816 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);
 	}
 


Test patch: