Fixed bug 2073 - Mac: window moves unexpectedly when exiting SDL_WINDOW_FULLSCREEN_DESKTOP mode
authorSam Lantinga <slouken@libsdl.org>
Mon, 21 Oct 2013 02:37:03 -0700
changeset 7873 e88af17231bd
parent 7872 ca36ab2a8179
child 7874 446846276cb0
Fixed bug 2073 - Mac: window moves unexpectedly when exiting SDL_WINDOW_FULLSCREEN_DESKTOP mode Alex Szpakowski In Mac OS X, when SDL_SetWindowFullscreen(window, 0) is called on a window which was in SDL_WINDOW_FULLSCREEN_DESKTOP mode, its original size is restored but its position is moved to the bottom of the screen. I tracked down the issue to these two lines: http://hg.libsdl.org/SDL/file/66b5b8446275/src/video/cocoa/SDL_cocoawindow.m#l1034 I believe [nswindow setFrameOrigin:rect.origin] implicitly calls [nswindow constrainFrameRect:rect toScreen:screen], which will attempt to constrain the window to the screen, but at that point the window size is still full-screen rather than the restored window size, so the constrainFrameRect function operates on the wrong window size. https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSWindow_Class/Reference/Reference.html#//apple_ref/occ/instm/NSWindow/constrainFrameRect:toScreen: I resolved the issue by swapping the order of the function calls, like so: [nswindow setContentSize:rect.size]; [nswindow setFrameOrigin:rect.origin];
src/video/cocoa/SDL_cocoawindow.m
--- a/src/video/cocoa/SDL_cocoawindow.m	Mon Oct 21 02:32:34 2013 -0700
+++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Oct 21 02:37:03 2013 -0700
@@ -1058,8 +1058,8 @@
     }
 
     s_moveHack = 0;
+    [nswindow setContentSize:rect.size];
     [nswindow setFrameOrigin:rect.origin];
-    [nswindow setContentSize:rect.size];
     s_moveHack = SDL_GetTicks();
 
     /* When the window style changes the title is cleared */