Skip to content

Commit f44a987

Browse files
committed
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.
1 parent 3163e0c commit f44a987

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/video/SDL_video.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ static VideoBootStrap *bootstrap[] = {
180180
#if defined(SDL_PLATFORM_MACOS) && defined(SDL_VIDEO_DRIVER_COCOA)
181181
// Support for macOS fullscreen spaces, etc.
182182
extern bool Cocoa_IsWindowInFullscreenSpace(SDL_Window *window);
183+
extern bool Cocoa_IsWindowInFullscreenSpaceTransition(SDL_Window *window);
183184
extern bool Cocoa_SetWindowFullscreenSpace(SDL_Window *window, bool state, bool blocking);
184185
extern bool Cocoa_IsShowingModalDialog(SDL_Window *window);
185186
#endif
@@ -2121,6 +2122,16 @@ bool SDL_SetWindowFullscreenMode(SDL_Window *window, const SDL_DisplayMode *mode
21212122
* is in progress. It will be overwritten if a new request is made.
21222123
*/
21232124
SDL_copyp(&window->current_fullscreen_mode, &window->requested_fullscreen_mode);
2125+
2126+
#if defined(SDL_PLATFORM_MACOS) && defined(SDL_VIDEO_DRIVER_COCOA)
2127+
/* If this is called while in the middle of a Cocoa fullscreen spaces transition,
2128+
* wait until the transition has completed, or the window can wind up in a weird,
2129+
* broken state if a mode switch occurs while in a fullscreen space.
2130+
*/
2131+
if (SDL_strcmp(_this->name, "cocoa") == 0 && Cocoa_IsWindowInFullscreenSpaceTransition(window)) {
2132+
SDL_SyncWindow(window);
2133+
}
2134+
#endif
21242135
if (SDL_WINDOW_FULLSCREEN_VISIBLE(window)) {
21252136
SDL_UpdateFullscreenMode(window, SDL_FULLSCREEN_OP_UPDATE, true);
21262137
SDL_SyncIfRequired(window);

src/video/cocoa/SDL_cocoawindow.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,19 @@ bool Cocoa_IsWindowInFullscreenSpace(SDL_Window *window)
411411
}
412412
}
413413

414+
bool Cocoa_IsWindowInFullscreenSpaceTransition(SDL_Window *window)
415+
{
416+
@autoreleasepool {
417+
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;
418+
419+
if ([data.listener isInFullscreenSpaceTransition]) {
420+
return true;
421+
} else {
422+
return false;
423+
}
424+
}
425+
}
426+
414427
bool Cocoa_IsWindowZoomed(SDL_Window *window)
415428
{
416429
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;

0 commit comments

Comments
 (0)