Commit 8fc1fb08058de734c3aaf541aec7316eb4c53025

Sam Lantinga 2017-08-29T21:42:22

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.

diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 6b6aa57..317862d 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -752,12 +752,21 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
         [NSMenu setMenuBarVisible:YES];
 
         pendingWindowOperation = PENDING_OPERATION_NONE;
-        /* Force the size change event in case it was delivered earlier
-           while the window was still animating into place.
-         */
-        window->w = 0;
-        window->h = 0;
-        [self windowDidResize:aNotification];
+
+        /* 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();
+        }
 
         /* FIXME: Why does the window get hidden? */
         if (window->flags & SDL_WINDOW_SHOWN) {