14

I guess I should check if [NSApplication presentationOptions] contains NSFullScreenModeApplicationPresentationOptions, but how do I achieve that?

EDIT: using [NSApplication presentationOptions] doesn't work as in my document-based app there might be some documents in fullscreen and others not. I'm now looking for another solution. I'm wondering why there isn't a property called [NSWindow isFullscreen] or something like that.

4 Answers 4

32

I was just looking for a solution myself and based on Matthieu's answer I created a category on NSWindow that works fine for me.

@interface NSWindow (FullScreen)

- (BOOL)mn_isFullScreen;

@end

@implementation NSWindow (FullScreen)

- (BOOL)mn_isFullScreen
{
    return (([self styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask);
}

@end
1
  • 1
    NSFullScreenWindowMask is deprecated now. Use NSWindowStyleMaskFullScreen i.e. return (([self styleMask] & NSWindowStyleMaskFullScreen) != 0);
    – w0mbat
    Aug 11, 2020 at 20:08
11

You need to use an & bitwise operator to test that that option is being used. Not tested but probably something like this:

- (BOOL) inFullScreenMode {
    NSApplicationPresentationOptions opts = [[NSApplication sharedApplication ] presentationOptions];
    if ( opts & NSApplicationPresentationFullScreen) {
       return YES;
    }
    return NO;
}

To see if any of your windows are in full screen mode simply check the style mask of the window.

NSUInteger masks = [someNSWindow styleMask]
if ( masks & NSFullScreenWindowMask) {
 // Do something
}
3
  • Thank you, this is exactly what I needed. Just one correction: use NSApp instead of NSApplication, otherwise you will get a warning. Oh... and of course - (BOOL) inFullScreenMode() should be written as - (BOOL) inFullScreenMode.
    – Nickkk
    Jul 27, 2011 at 10:07
  • Unfortunately, now there is another problem: in my document-based app, using the above solution won't work as some of the documents might be fullscreen and others not. Any other solution?
    – Nickkk
    Jul 29, 2011 at 19:54
  • Simply check the style masks of all your windows. I've added some sample code. Jul 31, 2011 at 12:55
4

For Swift 3.0

if let window = NSApp.mainWindow {
    let isWindowFullscreen = window.styleMask.contains(NSFullScreenWindowMask)
}

Obviously, for the original question, you'd replace NSApp.mainWindow with whichever document window you're wanting to check.

2
  • 4
    swift 4.1 = let isWindowFullscreen = window.styleMask.contains(.fullScreen) Apr 20, 2018 at 17:48
  • it's check mask of the window, but not window state that it is fullscreened. So in most cases it does not work Jan 7, 2022 at 6:51
1

The way I handled it in pre-10.7 (where neither NSApplicationPresentationFullScreen nor NSFullScreenWindowMask was available) was to check

if ([mainWindow frame].size.height == [[mainWindow screen] frame].size.height)
{
    // window is fullscreen
}

And this piece of really old code seem to still work not only on "Lion" but also on today's - at the time of writing 10.14.x - OS.

5
  • screen.frame is nil in case of fullscreen :) So it will not work Jan 7, 2022 at 6:59
  • Except that the dcoumentation says "it is nil when the window is offscreen", not when it is fullscreen. And yes - as I mentioned - this old piece of code still works today. developer.apple.com/documentation/appkit/nswindow/…
    – silverdr
    Jan 7, 2022 at 19:06
  • I don't know what is "offscreen" means. But just run the code and check what is placed in this frame when your app is fullscreened. Jan 7, 2022 at 22:23
  • steps to reproduce: 1: place button that print's to console "is fullscreened: (value)" in to the safe area of window. 2. run app and fullscreen it; 3. place mouse to the top of screen (menu line did not appear) and press the button. It will write to console that app is not fullscreened even if it is. Resolution: this code does not work properly. Jan 9, 2022 at 1:40
  • Which is unfortunately again not true. To make it easier here is a ready xcode project you can verify your resolution with: cld.silverdr.com/s/oLcWeLXw3kjcSXW
    – silverdr
    Apr 17, 2022 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.