Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a Cocoa window which appears on top of fullscreen windows?

I need to make a "full screen overlay window" in a program for OS X. Precisely, the window must at all times be on top of all other windows, including on top of the menu bar in non-maximized-window spaces, and on top of maximized windows in their own spaces, and on top during Exposé. It must not participate in "change space" animations; i.e., its position must be fixed relative to the physical screen at all times. (The window will be semi-transparent and will ignore mouse events, but I know how to do this already.)

How do I achieve this "overlay window" behavior? I have got this far:

  • I should set the window.level to CGWindowLevelKey(kCGMaximumWindowLevelKey) so that it is always on top of other windows in the same space.
  • I should set NSWindowCollectionBehaviorStationary so that the window stays in place during Exposé.

What I don't know is how to keep this behavior when switching spaces. I thought I should set NSWindowCollectionBehaviorCanJoinAllSpaces, but its behavior has two problems:

  • The window does not appear on top of other fullscreen windows.
  • The window is duplicated on every space, rather than staying in the same place on top of all spaces. This is important because of the space-switch animation.

I have heard that an NSPanel would help me, but I have not been able to make this work, either.

In short, Can a window appear on top of a fullscreen window in OS X? Can you provide a short, full example?

like image 929
jameshfisher Avatar asked Jan 05 '16 18:01

jameshfisher


1 Answers

You should be using window.level = CGWindowLevelForKey(.MaximumWindowLevelKey).

I can't help you with the spaces part.

like image 172
rob mayoff Avatar answered Sep 30 '22 21:09

rob mayoff