We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3719

Summary: Cocoa - Incorrect window size when leaving fullscreen
Product: SDL Reporter: bastien.bouclet
Component: videoAssignee: Sam Lantinga <slouken>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: dll, sezeroz
Version: 2.0.5   
Hardware: x86_64   
OS: Mac OS X 10.10   
Attachments: Minimal test case

Description bastien.bouclet 2017-07-29 15:04:08 UTC
Created attachment 2812 [details]
Minimal test case

When exiting a "fullscreen space" on OS X, windows don't go to their defined "windowed mode size", but go back to their previous size.

Steps to reproduce:
1. Create a windowed mode SDL window
2. Toggle it to fullscreen with the SDL_WINDOW_FULLSCREEN_DESKTOP flag
3. While in fullscreen, change the windowed mode size using SDL_SetWindowSize
4. Toggle the window back to windowed mode

Expected result:
- The window has the size specified during step 3.

Actual result:
- The window has the size specified when creating the window in step 1.

Attached is a minimal reproduction test case.
The attached test case works as expected on X11 and Windows.
Comment 1 bastien.bouclet 2017-07-29 15:04:49 UTC
Downstream bug report:
https://bugs.scummvm.org/ticket/9971
Comment 2 Ryan C. Gordon 2017-08-09 05:25:36 UTC
(Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.)

Tagging a bunch of bugs as target-2.0.6.

This means we're in the final stretch for an official SDL 2.0.6 release! These are the bugs we really want to fix before shipping if humanly possible.

That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.6 release, and generally be organized about what we're aiming to ship. After some debate, we might just remove this tag again and deal with it for a later release.

Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment.

Thanks!
--ryan.
Comment 3 Sam Lantinga 2017-08-30 04:42:55 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/f9d5845f2311
Comment 4 bastien.bouclet 2017-08-30 18:50:00 UTC
Thanks.

The window is now resized to its specified size, but it moves to the top left corner of the screen. That is unexpected because neither the user nor the program moved it there. Test program attached (the same one as before).
Comment 5 Sam Lantinga 2017-09-04 18:31:48 UTC
This should be fixed by David Ludwig's patch:
https://hg.libsdl.org/SDL/rev/f76299105635
Comment 6 bastien.bouclet 2017-09-04 19:24:51 UTC
Unfortunately the window still moves to the top left corner of the screen after resizing: https://www.youtube.com/watch?v=T1s0nEvWzrE
Comment 7 David Ludwig 2017-09-04 20:31:06 UTC
Odd.  I had the window-move bug reproduce for me at one point.  I am no longer able to, even when I revert the patch that I applied, and when I revert to just-before the initial patch.
Comment 8 David Ludwig 2017-09-04 20:37:49 UTC
Correction: I am unable to reproduce the window-move bug when using SDL just-after the initial patch was applied, in addition to just-before and just-after my followup patch (which targeted a separate bug).

This is on macOS 10.12.6, Xcode 8.3.3, and the macOS 10.12 SDK, compiling both the attached code, as well as one of my own test apps.

Might the window-move bug be system specific?
Comment 9 Sam Lantinga 2017-09-04 21:53:01 UTC
I'm not seeing this either, using the minimal test case you provided. Can you check the window origin here and make sure it's not 0?
        /* Restore windowed size and position in case it changed while fullscreen */
        {
            NSRect rect;
            rect.origin.x = window->windowed.x;
            rect.origin.y = window->windowed.y;
            rect.size.width = window->windowed.w;
            rect.size.height = window->windowed.h;
            ConvertNSRect([nswindow screen], NO, &rect);

            s_moveHack = 0;
            [nswindow setContentSize:rect.size];
            [nswindow setFrameOrigin:rect.origin];
            s_moveHack = SDL_GetTicks();
        }
Comment 10 bastien.bouclet 2017-09-05 04:57:53 UTC
Using the attached test case :
window->windowed.x: 0
window->windowed.y: 22

Those values come from a "windowDidMove" callback that is received while leaving fullscreen (before trying to resize the window).

This is using OSX 10.10.5.
Comment 11 Sam Lantinga 2017-09-05 10:12:55 UTC
Thanks, I can reproduce this in a VM running OSX 10.10.
Comment 12 Sam Lantinga 2017-09-09 17:32:44 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/05aa6d232dca
Comment 13 Sam Lantinga 2017-09-09 17:58:54 UTC
The fix for this bug introduced bug 3809, so I'm backing it out for SDL 2.0.6 release, until we have a chance to properly handle maximize/restore transitions.