Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HOWTO: Is NSWindow In FullScreen Mode (Lion) AND Enabling/Disabling?

I spent a great deal of time figuring out how to determine if my NSWindow is in full screen mode or not and also how to enable/disable it from going in or out of full screen mode. This is useful when I am animating a view to another view or doing something where going into or out of full screen mode will mess stuff up. Sort of like locking down a window from being resized.

The answer to this is posted below.

like image 918
Arvin Avatar asked Apr 10 '12 21:04

Arvin


1 Answers

For anyone interested here are some methods you can categorize or use as is. I spent some time looking for how to do this and thought it can help someone else out:

This one will tell you if you are or are not in full screen mode:

@implementation MyWindow

- (void) setStyleMask:(NSUInteger)styleMask {

    MyWindowController *wndController = (MyWindowController *)self.windowController;
    wndController.fullScreenMode = (styleMask & NSFullScreenWindowMask);
    [super setStyleMask:styleMask];
}

@end

I am setting a property in my window controller.

For completeness here is what the category on NSWindow would look like:

@implementation NSWindow (CategoryNSWindow)

#pragma mark - Full Screen Mode:

- (BOOL) inFullScreenMode {

    return (self.styleMask & NSFullScreenWindowMask);
}

@end

These two methods will enable / disable the ability to go into or out of full screen mode:

- (void) enableFullScreen {

    NSWindowCollectionBehavior behavior = [self.window collectionBehavior];
    behavior |= NSWindowCollectionBehaviorFullScreenPrimary;
    [self.window setCollectionBehavior:behavior];
}

- (void) disableFullScreen {

    NSWindowCollectionBehavior behavior = [self.window collectionBehavior];
    behavior ^= NSWindowCollectionBehaviorFullScreenPrimary;
    [self.window setCollectionBehavior:behavior];
}

Rename methods as you please.

like image 158
Arvin Avatar answered Sep 27 '22 15:09

Arvin