Skip to content

Conversation

@LanzaSchneider
Copy link
Contributor

Fixes focus grab warning on macOS when running game in embedded mode.

Issue

图片

When running a game with "Embed Game on Next Play" enabled on macOS, the following warning is printed:
"This control can't grab focus. Use set_focus_mode() and set_focus_behavior_recursive()
to allow a control to get focus."

Root Cause

EmbeddedProcessMacOS is explicitly configured with set_focus_mode(FOCUS_NONE) in its constructor,
while GameView unconditionally calls grab_focus() on it when starting the game instance.

The focus is intentionally delegated to the child layer_host which uses FOCUS_ALL.
However, grab_focus() on the parent process still triggers the warning even though this
is the intended design on macOS.

Solution

Add a focus mode check before calling grab_focus() in GameView::_play_pressed() and
GameView::_instance_starting(). This prevents the warning when the control is explicitly
set to not accept focus, matching the macOS-specific implementation's design.

Changes Made

  • Added if (embedded_process->get_focus_mode_with_override() != FOCUS_NONE) guard
    before embedded_process->grab_focus() calls in game_view.cpp

Testing

  • Tested on macOS: warning no longer appears when launching game in embedded mode
  • Verified other platforms (Windows/Linux) remain unaffected
  • Confirmed focus behavior still works correctly in embedded game window

@LanzaSchneider LanzaSchneider requested a review from a team as a code owner November 29, 2025 01:16
@LanzaSchneider LanzaSchneider force-pushed the fix-focus-grab-warning-macos branch from 8e32d4f to fc79b3c Compare November 29, 2025 01:19
@bruvzg bruvzg self-requested a review November 30, 2025 14:34
@bruvzg bruvzg added this to the 4.6 milestone Nov 30, 2025
@akien-mga akien-mga merged commit c7ae694 into godotengine:master Dec 1, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@LanzaSchneider LanzaSchneider deleted the fix-focus-grab-warning-macos branch December 1, 2025 10:58
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.

3 participants