| Summary: | SDL_MinimizeWindow() fails to minimize fullscreen window on macOS | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Joshua Bodine <josh> |
| Component: | video | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | blocker | ||
| Priority: | P2 | CC: | amaranth72, icculus, sezeroz |
| Version: | 2.0.8 | Keywords: | target-2.0.12 |
| Hardware: | x86_64 | ||
| OS: | macOS 10.13 | ||
| Attachments: | Test program that demonstrates issue. | ||
|
Description
Joshua Bodine
2018-05-27 00:53:37 UTC
I just wanted to update this with the information that I just tested it and the exact same issue persists on macOS Mojave with Xcode 10. Can someone please at least look at this? SDL_MinimizeWindow() on fullscreen windows has been completely broken on macOS since High Sierra. I reviewed the code to see if I could help come up with a fix, but the function is very simple... it is just a call to [NSWindow minimize]. I tried to see if there was a way to switch the window to windowed mode prior to minimizing, but from what I can tell, SDL doesn't actually seem to track whether the window is fullscreen or not, so it would be hard to know when to make the switch and when not to. Maybe it is a macOS SDK bug? I'm happy to help report it to them, if anyone can tell me that the issue is not in SDL's code. It would be great if this could be addressed before the next stable release. (Sorry if you get several emails like this, we're marking a bunch of bugs.) We're hoping to ship SDL 2.0.11 on a much shorter timeframe than we have historically done releases, so I'm starting to tag bugs we hope to have closed in this release cycle. Note that this tag means we just intend to scrutinize this bug for the 2.0.11 release: we may fix it, reject it, or even push it back to a later release for now, but this helps give us both a goal and a wishlist for the next release. If this bug has been quiet for a few months and you have new information (such as, "this is definitely still broken" or "this got fixed at some point"), please feel free to retest and/or add more notes to the bug. --ryan. For what it's worth, this is how we worked around the issue for now. We track the fullscreen status internally, and if it's fullscreen when we need to minimize, we switch it to windowed mode first, minimize it, and then restore it to fullscreen. Obviously not an ideal solution, but just in case it helps.
diff --git a/src/platform/SDL2Window.cxx b/src/platform/SDL2Window.cxx
index 1301c294d..188e3a691 100644
--- a/src/platform/SDL2Window.cxx
+++ b/src/platform/SDL2Window.cxx
@@ -48,7 +48,26 @@ void SDLWindow::setFullscreen(bool on)
void SDLWindow::iconify(void)
{
+ // workaround for SDL 2 bug on macOS (or just a macOS bug?) where trying to
+ // iconify the window just sends it to the background instead
+ // bug report: https://bugzilla.libsdl.org/show_bug.cgi?id=4177
+ // TODO: Remove this workaround when/if SDL2 includes their own workaround.
+#if defined(__APPLE__) && defined(MAC_OS_X_VERSION_10_13) && \
+ MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_13
+ if (fullScreen)
+ SDL_SetWindowFullscreen(windowId, 0);
+#endif
+
SDL_MinimizeWindow(windowId);
+
+ // continuation of above workaround; so far, it seems sufficient to simply
+ // set the window back to fullscreen after minimizing it; this does seem a
+ // bit precarious...
+#if defined(__APPLE__) && defined(MAC_OS_X_VERSION_10_13) && \
+ MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_13
+ if (fullScreen)
+ SDL_SetWindowFullscreen(windowId, SDL_WINDOW_FULLSCREEN);
+#endif
}
We're changing how we do SDL release versions; now releases will be even numbers (2.0.10, 2.0.12, etc), and as soon as we tag a release, we'll move the internal version number to an odd number (2.0.12 ships, we tag the latest in revision control as 2.0.13 immediately, which will become 2.0.14 on release, etc). As such, I'm moving the bugs tagged with target-2.0.11 to target 2.0.12. Sorry if you get a lot of email from this change! Thanks, --ryan. We're changing how we do SDL release versions; now releases will be even numbers (2.0.10, 2.0.12, etc), and as soon as we tag a release, we'll move the internal version number to an odd number (2.0.12 ships, we tag the latest in revision control as 2.0.13 immediately, which will become 2.0.14 on release, etc). As such, I'm moving the bugs tagged with target-2.0.11 to target 2.0.12. Sorry if you get a lot of email from this change! Thanks, --ryan.
So this appears to be a timing/sequence issue. If I put...
SDL_Delay(1000);
SDL_PumpEvents();
...into SDL_MinimizeWindow() between the call to SDL_UpdateFullscreenMode(window, SDL_FALSE) and the call to _this->MinimizeWindow(), it works correctly (albeit with an extra second delay).
Small delays, like 10ms or even 100ms, aren't enough.
So we just need to figure out what it _actually_ needs to wait on and do so before returning from Cocoa_SetWindowFullscreenSpace().
It's worth noting that we do a bunch of things to the window when returning from a fullscreen space in windowDidExitFullScreen. I suspect one of them takes awhile to happen and make its way through the event queue and until it does, -[NSWindow minimize] doesn't work.
--ryan.
(In reply to Ryan C. Gordon from comment #7) > So we just need to figure out what it _actually_ needs to wait on and do so > before returning from Cocoa_SetWindowFullscreenSpace(). Adding Alex to the CC list for ideas. --ryan. After experimenting with this for way too long, I ended up stepping through -[NSWindow miniaturize:] in the debugger, and discovered it looks for the minimize button on the titlebar to be enabled, and returns without doing anything if it isn't. The added delay+pumpevents gives the system time to reenable that button and adjust other state. So I've added code to windowDidExitFullscreen to wait for exactly that button to reenable, which probably solves other similar problems, but definitely fixes this. Fixed in https://hg.libsdl.org/SDL/rev/6710fbe3b098 ... --ryan. Thank you! |