From bcf5472d16e6c8089cbd3a9dc825fa96bb1ff39d Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 21 Oct 2013 02:37:03 -0700 Subject: [PATCH] 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/fdd5cc9e9f90/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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 923cd51c52e4a..5529983069c26 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -1058,8 +1058,8 @@ - (void)resetCursorRects } s_moveHack = 0; - [nswindow setFrameOrigin:rect.origin]; [nswindow setContentSize:rect.size]; + [nswindow setFrameOrigin:rect.origin]; s_moveHack = SDL_GetTicks(); /* When the window style changes the title is cleared */