Skip to content

Instantly share code, notes, and snippets.

@gazliddon
Created August 31, 2012 10:44
Show Gist options
  • Save gazliddon/3551368 to your computer and use it in GitHub Desktop.
Save gazliddon/3551368 to your computer and use it in GitHub Desktop.
SL Compatible fullscreen code
- (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;
}
@gazliddon
Copy link
Author

Really this should be in the window rather than the view

But there you go :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment