7

Is it possible to make a window to go over the menu bar, without going in fullscreen?

Thanks in Advance!

mxg
  • 20,946
  • 12
  • 59
  • 80

3 Answers3

17

Yes, trivially:

window.level = NSMainMenuWindowLevel + 1;

(Reference: Drawing to the Full Screen, OpenGL Programming Guide for Mac OS X.)

sebastianmarkow is correct in that this is terrible behaviour for a normal document window, but there are several window types for which this is normal: cursors, tool tips, and special utilities like Xscope.

Jens Ayton
  • 14,532
  • 3
  • 33
  • 47
  • 2
    Still doesn't go over Menu Bar. – mxg Jul 21 '11 at 13:45
  • 1
    Please clarify. A window with that window level _does_ order on top of the menu bar, but AppKit won’t let you position a titled window overlapping the menu bar (except in some very odd multiple-screen situations). If you want to do this with a document-style window, well, you’re out of luck as far as I know. – Jens Ayton Jul 21 '11 at 16:33
4

I liked Jens Ayton's answer, but rather than pick an arbitrary number like that, I think it would be preferred that you use one of the defined constants.

Personally, I used NSPopUpMenuWindowLevel as in:

self.window.level = NSPopUpMenuWindowLevel;

Other constants that you might prefer, as of my posting this answer, include:

  • NSNormalWindowLevel
  • NSFloatingWindowLevel
  • NSSubmenuWindowLevel
  • NSNormalWindowLevel
  • NSMainMenuWindowLevel
  • NSStatusWindowLevel
  • NSModalPaneWindowLevel
  • NSPopUpMenuWindowLevel
  • NSScreenSaverWindowLevel

Here's the reference (Apple has a tendency to change how they organize their docs and break these links over the years, but the APIs don't change much, which is why I included that list above. I doubt this link will work in 3 years or so, but these constants probably won't change much in the next 20 years.)

https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSWindow_Class/Reference/Reference.html#//apple_ref/doc/constant_group/Window_Levels

ArtOfWarfare
  • 20,617
  • 19
  • 137
  • 193
  • Surprisingly, it's been nearly 4 years since I posted this answer and the link still works. Maybe Apple changed their ways and stopped rearranging things and breaking links finally... – ArtOfWarfare Apr 14 '17 at 14:15
2

I do not believe that you can go on top of the menu bar, but you can set the menu bar to auto-hide when your application is the frontmost application by calling

[[NSApplication sharedApplication] setPresentationOptions: NSApplicationPresentationAutoHideMenuBar];

Which should let you use the space normally used for the menu bar in your application.

Ashaman
  • 1,065
  • 7
  • 9
  • 1
    From docs: "If you specify `NSApplicationPresentationAutoHideMenuBar`, it must be accompanied by either `NSApplicationPresentationHideDock` or `NSApplicationPresentationAutoHideDock`." Otherwise an exception is raised. – JWWalker Jun 29 '18 at 22:38