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 - Mac: window moves unexpectedly when exiting SDL_WINDOW_FULLSCREEN_DESKTOP mode
Summary: Mac: window moves unexpectedly when exiting SDL_WINDOW_FULLSCREEN_DESKTOP mode
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: x86 Mac OS X 10.8
: P2 normal
Assignee: (disabled) Jørgen Tjernø
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-29 07:32 UTC by Alex Szpakowski
Modified: 2013-10-21 09:37 UTC (History)
1 user (show)

See Also:


Attachments
Test case demonstrating the issue when exiting fullscreen (839 bytes, text/x-csrc)
2013-08-29 07:32 UTC, Alex Szpakowski
Details
Patch to fix the window movement issue. (441 bytes, patch)
2013-10-21 06:31 UTC, Alex Szpakowski
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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