cocoa: Wait for fullscreen spaces transitions to complete if switching to an exclusive mode

If attempting to switch to an exclusive mode while a fullscreen spaces transition is active, wait until the transition is complete before trying to apply the changes, or the window can wind up in a weird, broken state if a mode switch occurs while in a fullscreen space.

(cherry picked from commit f44a98729c)
This commit is contained in:
Frank Praznik
2025-08-04 23:54:40 -04:00
parent 09356c709a
commit 85d1d70ca1
2 changed files with 24 additions and 0 deletions

View File

@@ -173,6 +173,7 @@ static VideoBootStrap *bootstrap[] = {
#if defined(SDL_PLATFORM_MACOS) && defined(SDL_VIDEO_DRIVER_COCOA)
// Support for macOS fullscreen spaces, etc.
extern bool Cocoa_IsWindowInFullscreenSpace(SDL_Window *window);
extern bool Cocoa_IsWindowInFullscreenSpaceTransition(SDL_Window *window);
extern bool Cocoa_SetWindowFullscreenSpace(SDL_Window *window, bool state, bool blocking);
extern bool Cocoa_IsShowingModalDialog(SDL_Window *window);
#endif
@@ -2111,6 +2112,16 @@ bool SDL_SetWindowFullscreenMode(SDL_Window *window, const SDL_DisplayMode *mode
* is in progress. It will be overwritten if a new request is made.
*/
SDL_copyp(&window->current_fullscreen_mode, &window->requested_fullscreen_mode);
#if defined(SDL_PLATFORM_MACOS) && defined(SDL_VIDEO_DRIVER_COCOA)
/* If this is called while in the middle of a Cocoa fullscreen spaces transition,
* wait until the transition has completed, or the window can wind up in a weird,
* broken state if a mode switch occurs while in a fullscreen space.
*/
if (SDL_strcmp(_this->name, "cocoa") == 0 && Cocoa_IsWindowInFullscreenSpaceTransition(window)) {
SDL_SyncWindow(window);
}
#endif
if (SDL_WINDOW_FULLSCREEN_VISIBLE(window)) {
SDL_UpdateFullscreenMode(window, SDL_FULLSCREEN_OP_UPDATE, true);
SDL_SyncIfRequired(window);

View File

@@ -411,6 +411,19 @@ bool Cocoa_IsWindowInFullscreenSpace(SDL_Window *window)
}
}
bool Cocoa_IsWindowInFullscreenSpaceTransition(SDL_Window *window)
{
@autoreleasepool {
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;
if ([data.listener isInFullscreenSpaceTransition]) {
return true;
} else {
return false;
}
}
}
bool Cocoa_IsWindowZoomed(SDL_Window *window)
{
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;