简体   繁体   中英

NSStatusItem app focus

How can my menubar application achieve the same behaviours as 1Password or 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.
  • 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.

I am trying to get the same behaviour to work in an NSPopover that opens from an NSStatusItem.

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.

Unfortunately I haven't found a way yet to get a NSPopover to behave this way since it's not a subclass of NSWindow.

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

yourPopover.behavior = .transient

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