Fix SDL3 focus handling: restore mouse grab and cursor state on alt-tab/Win key#2856
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Investigate issue with regaining focus on SDL3 in Windows
Fix SDL3 focus handling: restore mouse grab and cursor state on alt-tab/Win key
Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows with SDL3, alt-tabbing or pressing the Win key leaves the cursor invisible on the desktop and breaks camera rotation when clicking back into the app.
Root causes in
SdlMouseInput:SDL_HideCursor()is never reversed on focus loss → cursor invisible everywhere outside the appSDL_SetWindowRelativeMouseMode+ mouse grab are released by SDL3 on focus loss but never re-applied on focus regain → mouse delta input stops workingFix: Handle
SDL_EVENT_WINDOW_FOCUS_LOSTandSDL_EVENT_WINDOW_FOCUS_GAINEDinSdlMouseInput.onSDLEvent():SDL_ShowCursor()if cursor was hidden; reset X11 warp state to avoid stale warp eventssetCursorVisible(cursorVisible)to re-apply grab, relative mode, and cursor visibility as they were before focus was lost