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 2073

Summary: Mac: window moves unexpectedly when exiting SDL_WINDOW_FULLSCREEN_DESKTOP mode
Product: SDL Reporter: Alex Szpakowski <amaranth72>
Component: videoAssignee: (disabled) Jørgen Tjernø <jorgen>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: jorgen
Version: HG 2.0   
Hardware: x86   
OS: Mac OS X 10.8   
Attachments: Test case demonstrating the issue when exiting fullscreen
Patch to fix the window movement issue.

Description Alex Szpakowski 2013-08-29 07:32:30 UTC
Created attachment 1313 [details]
Test case demonstrating the issue when exiting fullscreen

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];

Alternatively I replaced the above two lines with this all-in-one function call, and it worked as well (I like this one better):
[nswindow setFrame:rect display:false];


I've attached some test code demonstrating the issue. You can press spacebar to toggle fullscreen-desktop mode.
Comment 1 Alex Szpakowski 2013-10-21 06:30:39 UTC
Update: the one-liner fix causes odd window resizing issues when exiting fullscreen with highdpi enabled. The two-line fix (swapping the two lines) works fine though.

I'll add a patch with the line swap.
Comment 2 Alex Szpakowski 2013-10-21 06:31:44 UTC
Created attachment 1385 [details]
Patch to fix the window movement issue.
Comment 3 Sam Lantinga 2013-10-21 09:37:28 UTC
Fixed, thanks!
http://hg.libsdl.org/SDL/rev/e88af17231bd