允许NSWindow(NSPanel)浮动在全屏应用程序上方 [英] Allow an NSWindow (NSPanel) to float above full screen apps

查看:159
本文介绍了允许NSWindow(NSPanel)浮动在全屏应用程序上方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加一个小窗口,以从系统中的任何位置向主应用程序提供快速输入".

I'm trying to add a little window that provides "quick input" from any place in the system to the main app.

用户可以按下热键,然后弹出窗口,并在所有其他窗口上方浮动.

The user could hit a hotkey, the window pops up, and floats above all other windows.

在大多数情况下,这并不是什么大问题.我可以将NSWindow配置为:

For the most part, this isn't much of a problem. I can configure an NSWindow to be:

level = Int(CGWindowLevelKey.TornOffMenuWindowLevelKey.rawValue)
collectionBehavior = .CanJoinAllSpaces

我还可以将其设置为具有 NSNonactivatingPanelMask 选项的NSPanel.

I can also make it an NSPanel with NSNonactivatingPanelMask option set.

唯一的问题是:即使用户位于包含全屏应用程序的空间中,如何才能使窗口在屏幕上弹出?

我知道当应用程序为 LSUIElement = true (Dock中没有位置的应用程序)时,这是可能的,但我的不是.

I know this is possible when the app is LSUIElement=true (an app without a position in the Dock), but mine isn't.

推荐答案

好吧,我有一个正确的主意,棘手的部分是所有选项之间如何交互.这是有效的方法:

Okay, I had the right idea, the tricky part is how all the options interact with each other. Here's what works:

  • NSPanel,不是 NSWindow
  • 样式遮罩: [.borderless,.nonactivatingPanel]
  • NSPanel, not NSWindow
  • style mask: [.borderless, .nonactivatingPanel]

这些属性:

panel.level = .mainMenu
panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]

Swift 4.2代码

使用这些设置创建并显示面板.然后,您可以将面板拖到全屏应用程序(双显示器设置)上.

Create and show a panel using these settings. Then you can drag the panel onto a fullscreen app (dual monitor setup).

let panel2 = NSPanel(contentRect: NSRect(x: 0, y: 0, width: 200, height: 200), styleMask: [.titled, .nonactivatingPanel], backing: .buffered, defer: true)
panel2.level = .mainMenu
panel2.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
panel2.orderFrontRegardless()

切换为无边界将阻止用户移动窗口.

Switching to borderless will prevent the user from moving your window.

let panel2 = NSPanel(contentRect: NSRect(x: 0, y: 0, width: 200, height: 200), styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: true)
panel2.level = .mainMenu
panel2.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
panel2.orderFrontRegardless()

这篇关于允许NSWindow(NSPanel)浮动在全屏应用程序上方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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