在所有空间(包括其他全屏应用程序)上可见的窗口 [英] Window visible on all spaces (including other fullscreen apps)

查看:109
本文介绍了在所有空间(包括其他全屏应用程序)上可见的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在所有空间(包括其他全屏应用程序窗口)上显示一个窗口(NSWindow).我一直在尝试设置更高的窗口级别以及在检查器中使用暴露和空间设置.我在这里找到了一些解决方案,但是它们不起作用.至少在El Capitan上.

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 expose and spaces settings in the inspector. I found some solutions here, but they do not work. At least on El Capitan.

这是要测试的示例代码:

Here is a sample code to test:

let window = NSWindow(contentRect: NSRect(x: 300, y: 300, width: 200, height: 200), styleMask: NSBorderlessWindowMask, backing: .Buffered, `defer`: true)
window.backgroundColor = NSColor.greenColor()
window.level = Int(CGWindowLevelForKey(.FloatingWindowLevelKey))
window.collectionBehavior = [.CanJoinAllSpaces, .Transient]
window.makeKeyAndOrderFront(nil)

现在,它会在所有桌面空间上显示该窗口,但不会在其他应用程序的全屏窗口上显示该窗口.

Now it displays the window on all the desktop spaces but it does not display it over the full screen windows of other apps.

推荐答案

如果您希望一个窗口在其他全屏窗口(在空格中)之上可见,则应制作一个代理(附件)应用程序. 您可以通过将应用程序Info.plist中的LSUIElement键设置为1 (YES)

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. 在主应用程序包中创建一个单独的代理(帮助程序)应用程序,该应用程序将显示您的窗口. (关于如何创建这样的应用程序,有很多很好的例子)

  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)

NSApplicationActivationPolicy.您可以尝试在运行时期间更改应用程序的激活策略. 斯威夫特3:

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

  • NSApp.setActivationPolicy(.accessory)切换到代理(附件)
  • NSApp.setActivationPolicy(.regular)切换到普通应用程序
  • NSApp.setActivationPolicy(.accessory) switch to agent(accessory)
  • NSApp.setActivationPolicy(.regular) switch to ordinary application

请记住,.accessory策略会隐藏Dock中的图标,您仍然需要已有的代码:

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))

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

这篇关于在所有空间(包括其他全屏应用程序)上可见的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆