How to know if a NSWindow is fullscreen in Mac OS X Lion?

前端 未结 4 1245
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 05:14

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

相关标签:
4条回答
  • 2021-01-04 05:42

    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
    
    0 讨论(0)
  • 2021-01-04 05:42

    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
    }
    
    0 讨论(0)
  • 2021-01-04 05:49

    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.

    0 讨论(0)
  • 2021-01-04 05:56

    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.

    0 讨论(0)
提交回复
热议问题