From 052a9d3284396e1db8fb26642067c344ef6e1467 Mon Sep 17 00:00:00 2001 From: Rusty Moyher Date: Fri, 2 Jun 2023 11:45:21 -0500 Subject: [PATCH] macOS: Removed the fullscreen blanking window - Removed the blanking window used in SDL_WINDOW_FULLSCREEN. This allows CMD + Tab to work. - Changed the fullscreen NSWindow level so this works properly. Fixes issue #7776 --- src/video/cocoa/SDL_cocoamodes.m | 42 ++++--------------------------- src/video/cocoa/SDL_cocoawindow.m | 4 +-- 2 files changed, 7 insertions(+), 39 deletions(-) diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m index bb872ff602..2daff95b25 100644 --- a/src/video/cocoa/SDL_cocoamodes.m +++ b/src/video/cocoa/SDL_cocoamodes.m @@ -487,7 +487,7 @@ int Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_ SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata; CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken; - CGError result; + CGError result = kCGErrorSuccess; /* Fade to black to hide resolution-switching flicker */ if (CGAcquireDisplayFadeReservation(5, &fade_token) == kCGErrorSuccess) { @@ -497,31 +497,9 @@ int Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_ if (data == display->desktop_mode.driverdata) { /* Restoring desktop mode */ SetDisplayModeForDisplay(displaydata->display, data); - - if (CGDisplayIsMain(displaydata->display)) { - CGReleaseAllDisplays(); - } else { - CGDisplayRelease(displaydata->display); - } } else { - /* Put up the blanking window (a window above all other windows) */ - if (CGDisplayIsMain(displaydata->display)) { - /* If we don't capture all displays, Cocoa tries to rearrange windows... *sigh* */ - result = CGCaptureAllDisplays(); - } else { - result = CGDisplayCapture(displaydata->display); - } - if (result != kCGErrorSuccess) { - CG_SetError("CGDisplayCapture()", result); - goto ERR_NO_CAPTURE; - } - /* Do the physical switch */ result = SetDisplayModeForDisplay(displaydata->display, data); - if (result != kCGErrorSuccess) { - CG_SetError("CGDisplaySwitchToMode()", result); - goto ERR_NO_SWITCH; - } } /* Fade in again (asynchronously) */ @@ -530,21 +508,11 @@ int Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_ CGReleaseDisplayFadeReservation(fade_token); } + if (result != kCGErrorSuccess) { + CG_SetError("CGDisplaySwitchToMode()", result); + return -1; + } return 0; - - /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */ -ERR_NO_SWITCH: - if (CGDisplayIsMain(displaydata->display)) { - CGReleaseAllDisplays(); - } else { - CGDisplayRelease(displaydata->display); - } -ERR_NO_CAPTURE: - if (fade_token != kCGDisplayFadeReservationInvalidToken) { - CGDisplayFade(fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE); - CGReleaseDisplayFadeReservation(fade_token); - } - return -1; } void Cocoa_QuitModes(SDL_VideoDevice *_this) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 92fc803e1e..1813f3ddcc 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -2355,7 +2355,7 @@ void Cocoa_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_V if (SDL_ShouldAllowTopmost() && fullscreen) { /* OpenGL is rendering to the window, so make it visible! */ - [nswindow setLevel:CGShieldingWindowLevel()]; + [nswindow setLevel:kCGMainMenuWindowLevel + 1]; } else if (window->flags & SDL_WINDOW_ALWAYS_ON_TOP) { [nswindow setLevel:NSFloatingWindowLevel]; } else { @@ -2461,7 +2461,7 @@ void Cocoa_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, SDL_bo if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS) && ![data.listener isInFullscreenSpace]) { /* OpenGL is rendering to the window, so make it visible! */ /* Doing this in 10.11 while in a Space breaks things (bug #3152) */ - [data.nswindow setLevel:CGShieldingWindowLevel()]; + [data.nswindow setLevel:kCGMainMenuWindowLevel + 1]; } else if (window->flags & SDL_WINDOW_ALWAYS_ON_TOP) { [data.nswindow setLevel:NSFloatingWindowLevel]; } else {