Search code examples
cocoafullscreennswindowosx-lion

Mac OS X Lion: Detect if another application is running in full screen mode?


In a Cocoa app, is there a way to tell if another application currently is in full screen mode?

My application is configured to show up on all Spaces and listens for mouseEntered events to order itself to the front.

Problem is that when another app is in full screen mode and the user happens to move the mouse across the black area where my app's window is located, it is brought to the front (happens with multiple monitors).

I've only seen the above behavior with [self setCollectionBehavior: NSWindowCollectionBehaviorCanJoinAllSpaces]; enabled.

Here the other relevant code for my app.

- (void) mouseEntered:(NSEvent *)theEvent
{
    // Don't do this when another app is in full screen mode:
    [[self window] orderFront:self];
}

Solution

  • After a great deal of frustration, this worked for me to get a window that floats on all spaces except full-screen ones. I saw the fullScreenNone constant name, and since it described what I wanted, I tried it and found that it worked.

        window.level = .floating
        window.collectionBehavior = [.canJoinAllSpaces, .fullScreenNone]
        window.canHide = false