atomikpanda
atomikpanda

Reputation: 1886

NSWindow in front of every app and in front of the menu bar Objective-c Mac

How can I make my NSWindow appear in front of every app and the menubar? I also don't want a title bar on my window. Just a fullscreen app without the dock menubar and not in apple's fullscreen mode. I can get my window above all of the other apps and dock like this:

[window setLevel:kCGPopUpMenuWindowLevel];

but it doesn't cover the mac menubar.

Upvotes: 4

Views: 2837

Answers (4)

mcmohorn
mcmohorn

Reputation: 95

In Swift 5:

window.level = .screenSaver

Upvotes: 0

Sam Soffes
Sam Soffes

Reputation: 14935

In Swift 3:

window.level = Int(CGWindowLevelForKey(.mainMenuWindow)) + 2

Upvotes: 2

Justin
Justin

Reputation: 2142

Set the window level to NSMainMenuWindowLevel + 2.

If you use NSMainMenuWindowLevel + 1 the top menu bar will still appear sometimes but is very unpredictable. NSMainMenuWindowLevel + 2 forces it to stay above the menu bar and keep focus permanently.

[window setLevel:NSMainMenuWindowLevel + 2];

Upvotes: 2

DrummerB
DrummerB

Reputation: 40211

You can't move a default window higher that the menu bar, because it's constrained. You have to subclass NSWindow and override constrainFrameRect:toScreen:

- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen {
    return frameRect;
}

Upvotes: 7

Related Questions