简体   繁体   English

NSStatusItem应用程序焦点

[英]NSStatusItem app focus

How can my menubar application achieve the same behaviours as 1Password or Dropbox: 我的菜单栏应用程序如何实现与1Password或Dropbox相同的行为:

  • clicking their menu bar icons or popovers does not steal focus, eg while I am in for example TextEdit and open 1Password/Dropbox, the blinking cursor disappears but the window itself does not go into the background, yet I can type into 1Password's text field. 点击他们的菜单栏图标或弹出窗口不会窃取焦点,例如当我在例如TextEdit并打开1Password / Dropbox时,闪烁的光标消失但窗口本身不会进入背景,但我可以键入1Password的文本字段。
  • even though they didn't take focus in the first place, they disappear when I click back into another application 即使他们没有首先关注焦点,当我点击回到另一个应用程序时它们也会消失

I figured out how mouse over works in the Dropbox popover table view by using an NSTrackingArea with the options MouseEnteredAndExited, AssumeInside, and ActiveAlways. 我通过使用带有选项MouseEnteredAndExited,AssumeInside和ActiveAlways的NSTrackingArea来了解鼠标在Dropbox弹出窗口视图中是如何工作的。

I am trying to get the same behaviour to work in an NSPopover that opens from an NSStatusItem. 我试图在从NSStatusItem打开的NSPopover中使用相同的行为。

I found a workaround for now. 我现在找到了解决方法。 I am able to get the same behaviour by using non-activating NSPanel with a window level kCGPopUpMenuWindowLevelKey and I had to override canBecomeKeyWindow to return true. 通过使用具有窗口级别kCGPopUpMenuWindowLevelKey非激活NSPanel,我能够获得相同的行为,并且我必须覆盖canBecomeKeyWindow以返回true。

Unfortunately I haven't found a way yet to get a NSPopover to behave this way since it's not a subclass of NSWindow. 不幸的是,我还没有找到一种方法让NSPopover以这种方式运行,因为它不是NSWindow的子类。

要设置您所描述的行为类型,请使用:

yourPopover.behavior = .transient

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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