Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Modal Dialog with Embedded Game #102247

Merged

Conversation

Hilderin
Copy link
Contributor

@Hilderin Hilderin commented Jan 31, 2025

The idea to fix the embedded process to go in front of a modal popup is to simply refocus the modal when the embedded process get the focus when it a modal window exists.

I found some code that was not useful anymore. The issue that section was trying to solve was replaced some time ago by _check_focused_process_id:

if (embedded_process_was_focused) {
				embedded_process_was_focused = false;
				// Refocus the embedded process if it was focused when the application lost focus,
				// but do not refocus if the embedded process is currently focused (indicating it just lost focus)
				// or if the current window is a different popup or secondary window.
				if (embedding_completed && current_process_id != focused_process_id && window && window->has_focus()) {
					grab_focus();
					queue_update_embedded_process();
				}
			}

Also, EmbeddedProcess::_check_mouse_over did not work as expected because of the addition of last_updated_embedded_process_focused a while ago. It did not refocused the embedded game like the 2D and 3D views do when the user mouse over. It's now fixed.

Tested on Windows 11 and Linux Ubuntu 24.10

@Hilderin Hilderin requested a review from a team as a code owner January 31, 2025 15:37
@Hilderin Hilderin added this to the 4.4 milestone Jan 31, 2025
@Hilderin Hilderin force-pushed the fix-embedded-game-modal-dialog branch from 149f218 to 93aba07 Compare February 1, 2025 14:06
@Hilderin
Copy link
Contributor Author

Hilderin commented Feb 1, 2025

I just pushed a fix to prevent the game window to keep the focus when hitting a breakpoint in the script editor. This issue happens only when this PR is merged with #102251 from my testing.

@bruvzg bruvzg self-requested a review February 4, 2025 07:01
@bruvzg
Copy link
Member

bruvzg commented Feb 4, 2025

It is still possible to get modal dialog completely under the main window or between main and embedded windows, by quickly and repeatedly clicking on embedded window and other part of the main window in the alternating manner. But modal dialog will get itself back on top after another click, so it's not completely unusable.

@Hilderin Hilderin force-pushed the fix-embedded-game-modal-dialog branch from 93aba07 to f2a42be Compare February 6, 2025 02:05
@Hilderin
Copy link
Contributor Author

Hilderin commented Feb 6, 2025

After a rebase, I was able to take advantage of the new timer that calls _check_focused_process_id less frequently than NOTIFICATION_PROCESS. I also added a check to determine if a modal is open when the editor is not focused, but the game process is.

From my tests, this fixes the issue and makes the code clearer. Also, I fixed an issue when the user minimizes the dialog and focus the game process. Before, the editor was refocused, but the dialog was not restored.

@Hilderin Hilderin force-pushed the fix-embedded-game-modal-dialog branch from f2a42be to a9e06b8 Compare February 6, 2025 02:16
Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be working as expected, dialogs consistently stay on top of embedded window.

@akien-mga akien-mga merged commit bd87c3a into godotengine:master Feb 12, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embed Game focus over modal popups
3 participants