Window visible on all spaces (including other fullscreen apps)

前端 未结 2 459
梦谈多话
梦谈多话 2021-02-04 14:12

I\'m trying to make a window (NSWindow) visible on all the spaces including other full screen app windows. I\'ve been trying to set a higher window level as well as playing with

2条回答
  •  醉酒成梦
    2021-02-04 14:50

    If you want a window to be visible on top of other fullscreen windows (in spaces), you should make an agent (accessory) application. You can do it by setting LSUIElement key in the application’s Info.plist to 1 (YES)

    If you still need a regular application you can do following:

    1. Create a separate agent (helper) application inside your main application bundle which will show your window. (There are plenty of good examples on how you can create such application)

    2. Play with NSApplicationActivationPolicy. You can try to change application's activation policy during a runtime. Swift 3:

      • NSApp.setActivationPolicy(.accessory) switch to agent(accessory)
      • NSApp.setActivationPolicy(.regular) switch to ordinary application

    Keep in mind that .accessory policy hides the icon from Dock and you still need the code you have already:

    window.collectionBehavior = .canJoinAllSpaces window.level = Int(CGWindowLevelForKey(.floatingWindow))

提交回复
热议问题