Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, e.g. 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.

like image 751
iMaddin Avatar asked Oct 20 '22 00:10

iMaddin


2 Answers

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.

like image 54
iMaddin Avatar answered Oct 23 '22 03:10

iMaddin


To set the kind of behavior you are describing you use:

yourPopover.behavior = .transient

like image 42
Pier Avatar answered Oct 23 '22 02:10

Pier