Fixed bug 3719 - Cocoa - Incorrect window size when leaving fullscreen
authorSam Lantinga <slouken@libsdl.org>
Tue, 29 Aug 2017 21:42:22 -0700
changeset 11421f9d5845f2311
parent 11420 f1dcaee3479b
child 11422 243b1a53ad89
Fixed bug 3719 - Cocoa - Incorrect window size when leaving fullscreen

bastien.bouclet

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.
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Tue Aug 29 18:25:55 2017 -0400
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Tue Aug 29 21:42:22 2017 -0700
     1.3 @@ -752,12 +752,21 @@
     1.4          [NSMenu setMenuBarVisible:YES];
     1.5  
     1.6          pendingWindowOperation = PENDING_OPERATION_NONE;
     1.7 -        /* Force the size change event in case it was delivered earlier
     1.8 -           while the window was still animating into place.
     1.9 -         */
    1.10 -        window->w = 0;
    1.11 -        window->h = 0;
    1.12 -        [self windowDidResize:aNotification];
    1.13 +
    1.14 +        /* Restore windowed size and position in case it changed while fullscreen */
    1.15 +        {
    1.16 +            NSRect rect;
    1.17 +            rect.origin.x = window->windowed.x;
    1.18 +            rect.origin.y = window->windowed.y;
    1.19 +            rect.size.width = window->windowed.w;
    1.20 +            rect.size.height = window->windowed.h;
    1.21 +            ConvertNSRect([nswindow screen], NO, &rect);
    1.22 +
    1.23 +            s_moveHack = 0;
    1.24 +            [nswindow setContentSize:rect.size];
    1.25 +            [nswindow setFrameOrigin:rect.origin];
    1.26 +            s_moveHack = SDL_GetTicks();
    1.27 +        }
    1.28  
    1.29          /* FIXME: Why does the window get hidden? */
    1.30          if (window->flags & SDL_WINDOW_SHOWN) {