Created
August 31, 2012 10:44
-
-
Save gazliddon/3551368 to your computer and use it in GitHub Desktop.
SL Compatible fullscreen code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)toggleFullscreen | |
{ | |
// lol statics - should be in the class | |
// fulll screen status should be saved as well | |
static bool fullScreen = false; | |
static NSRect nonFullScreenRect; | |
static NSInteger oldStyleMask; | |
static NSInteger oldLevel; | |
auto w = [self window]; | |
if (!fullScreen) | |
{ | |
// Bits to mask in / out of window mask for full screen | |
auto maskIn = NSBorderlessWindowMask; | |
auto maskOut = NSTitledWindowMask|NSResizableWindowMask|NSTexturedBackgroundWindowMask; | |
// save the current window size and style | |
nonFullScreenRect = [w frame]; | |
oldStyleMask =[w styleMask]; | |
// Turn off the menu bar / dock | |
[NSMenu setMenuBarVisible:NO]; | |
// Set the new style mask, OR in the bits we want and get rid of the ones we don't | |
[w setStyleMask:(oldStyleMask|maskIn) & ~maskOut]; | |
// Set the window to full screen | |
[w setFrame:[[w screen] visibleFrame] display:YES]; | |
// Make it at the front | |
oldLevel = [w level]; | |
[w setLevel:NSFloatingWindowLevel]; | |
} | |
else | |
{ | |
// Restore everything back to where it should be | |
[w setLevel:oldLevel]; | |
[w setStyleMask:oldStyleMask]; | |
[w setFrame:nonFullScreenRect display:YES animate:NO]; | |
[NSMenu setMenuBarVisible:YES]; | |
} | |
// Toggle the fullscreen status | |
fullScreen = !fullScreen; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really this should be in the window rather than the view
But there you go :)