Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_MinimizeWindow() fails to minimize fullscreen window on macOS #2907

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed

SDL_MinimizeWindow() fails to minimize fullscreen window on macOS #2907

SDLBugzilla opened this issue Feb 11, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

SDLBugzilla commented Feb 11, 2021

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.8
Reported for operating system, platform: macOS 10.13, x86_64

Comments on the original bug report:

On 2018-05-27 00:53:37 +0000, Joshua Bodine wrote:

Created attachment 3251
Test program that demonstrates issue.

I’ve been running into an issue with the SDL_MinimizeWindow() on macOS 10.13 High Sierra. When I have a fullscreen window open and call SDL_MinimizeWindow() on High Sierra, the window remains visible but goes behind the menu bar and dock. Non-fullscreen windows are unaffected. This issue does not occur on macOS 10.12 Sierra, and in fact it doesn’t occur on High Sierra either if you compile it on an earlier OS (I tried Yosemite with Xcode 7.2.1) and then bring it over to High Sierra to run it.

Here’s a video demonstrating the issue with a test application I wrote, and then with the game I help maintain where I first heard a report of this issue: https://youtu.be/RO1WeW-St3E

I've attached the test code I used to demonstrate the issue.

I experienced this issue with every version of SDL 2 from 2.0.3 to 2.0.8, and even in the latest code in mercurial. I only tested it on Xcode 7 (where the issue doesn’t appear) and Xcode 9 (where the issue appears). I’m not sure exactly which macOS SDK version introduced the problem.

On 2018-10-03 22:13:53 +0000, Joshua Bodine wrote:

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.

On 2019-05-19 09:27:14 +0000, Joshua Bodine wrote:

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.

On 2019-07-30 17:49:34 +0000, Ryan C. Gordon wrote:

(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.

On 2019-07-30 23:28:24 +0000, Joshua Bodine wrote:

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
}

On 2019-09-20 20:47:37 +0000, Ryan C. Gordon wrote:

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.

On 2019-09-20 20:48:44 +0000, Ryan C. Gordon wrote:

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.

On 2019-10-25 05:11:46 +0000, Ryan C. Gordon wrote:

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.

On 2019-10-25 05:16:02 +0000, Ryan C. Gordon wrote:

(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.

On 2020-02-21 20:12:36 +0000, Ryan C. Gordon wrote:

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.

On 2020-02-21 20:22:25 +0000, Joshua Bodine wrote:

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant