We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5508

Summary: [PATCH] Provide default Alt+Tab handling with keyboard grab enabled
Product: SDL Reporter: Cameron Gutman <cameron.gutman>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: x86   
OS: Windows 10   
Attachments: Patch to minimize on Alt+Tab
Patch to minimize on Alt+Tab v2

Description Cameron Gutman 2021-01-28 02:50:46 UTC
Per our previous discussion, this patch adds logic to minimize the window on Alt+Tab if:
- The window has keyboard grab
- The window is full-screen
- SDL_HINT_NO_GRABBED_ALT_TAB_HANDLER is 0 or unset

I'm not sure if there's a different place you'd rather me put this code, but I stuck it in SDL_SendKeyboardKeyInternal().

I went with minimizing the window instead of something like manually releasing the keyboard grab because I figure it will be less disturbing to the app. If we manually released the keyboard grab, the application would have to figure out that the grab disappeared from under it and regrab when it gains focus again. It would also require the user to press Alt+Tab twice to get the desired behavior, since the first would be eaten by the keyboard grab. By using minimize, we can let the focus leaving naturally release the grab and regrab on subsequent focus gain.
Comment 1 Cameron Gutman 2021-01-28 02:51:28 UTC
Created attachment 4724 [details]
Patch to minimize on Alt+Tab
Comment 2 Sam Lantinga 2021-01-29 16:57:03 UTC
Can you change the hint to something like SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, and default it to true?
Comment 3 Cameron Gutman 2021-01-30 03:15:30 UTC
Created attachment 4735 [details]
Patch to minimize on Alt+Tab v2

Sure, how's this?
Comment 4 Sam Lantinga 2021-01-30 20:33:20 UTC
Looks good!
https://hg.libsdl.org/SDL/rev/66802b4fc7fa