简体   繁体   中英

Add NSWindow in front of fullscreen app

I want to have a window in front of all the others apps. I want this window appear on keyword shortcut like "Alfred" app.

I try a lot of solution but nothing work for having NSWindow in front of fullscreen app on main or second screen.

I tried the classic :

[self.window setLevel:NSMainMenuWindowLevel + 1];
[self.window setCollectionBehavior:NSWindowCollectionBehaviorStationary|NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary];
[self.window setHidesOnDeactivate:NO];

It's work except with Fullscreen app.

It's work with NSPanel with [self.videoWindow setStyleMask:NSBorderlessWindowMask]; but only on main screen.

Anyone have a solution ? Alfred developper around ?

Alfred is implemented as an Agent. Agents can display Windows on spaces of fullscreen Apps. You should also make your App an Agent. This can be achieved by adding the Application is Agent flag to the info.plist file of your App and setting the value to YES.

I managed to disdplay auxiliary window on top of full screen app via the following:

  • self.collectionBehavior = NSWindowCollectionBehaviorMoveToActiveSpace | NSWindowCollectionBehaviorFullScreenAuxiliary;
  • do not call [NSApp activateblabla];
  • make application LSUIElement, and do not display the Dock icon via TransformProcessType

However, don't know yet how to display it correctly for app which has the Dock icon. From the other side I do not know which app can do it while having the Dock icon.

It may depend on exactly how the application in question achieves fullscreen, but you likely just need to use a higher window level than NSMainMenuWindowLevel + 1 such as CGShieldingWindowLevel()+1

You can download Quartz Debug from Apples developer downloads (required free developer account)

Quartz Debug can tell you the level of any window and all you need to do is set your window to be higher than the one you are having problems with (assuming the app in question isnt doing something odd to be fullscreen).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM