NSStatusItem app focus - xcode

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.

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.

To set the kind of behavior you are describing you use:
yourPopover.behavior = .transient

Related

Is there a way to get NSPanel “Non activating” style functionality on an NSWindow?

NSPanel has a “Non activating” option for HUD Panels. I’d like to get that same functionality working on an NSWindow, i.e. I want the window to accept clicks but not take focus away from whatever the active app is (by this I mean the app that was active before clicking on the window activated my app—in this case Sketch).
I have tried creating an NSWindow subclass and setting canBecomeMainWindow and canBecomeKeyWindow to NO but that doesn’t seem to be working—I think because those settings only apply to windows within the same app.
What I’m trying to do here is prevent this flickering. I’m pretty sure this is doable as apps like Alfred seem to be doing it.

Pushing a window into focus

I'm developing a small menubar application and I want to display the settings window when the corresponding NSMenuItem is pressed.
I currently have the following IBAction assigned to the menu item:
#IBAction func settingsButtonPressed(sender: NSMenuItem) {
settingsView.makeKeyAndOrderFront(sender)
}
This displays the window, but doesn't push it into focus, so it's displayed behind the currently active window, which is not the behaviour I'm looking for.
I had a suspicion that this might have been due to the fact that the Application is agent target property is set to YES, but this actually has no effect on the outcome.
Could there be anything to be done with the window in the XIB file?
Probably your app is not the active app. It should work to call [NSApp activateIgnoringOtherApps:YES] in addition to making the window key and ordering it front.

All controls disabled in title-less window

In my app I've got a secondary NSWindow that's created from .xib in my NSWindowController in my initWithWindowNibName: method. The window is a plain NSWindow with the title bar switched off.
After creating the window it's shown using makeKeyAndOrderFront: -
and all controls are disabled (text field, combo box).
I have (more than..) triple checked all flags in the window and the view hierarchy of the controls: everything is enabled, allowing editing and not refusing to be first responder.
Totally clueless. Any ideas?
Update #1:
I appears the problem is related to the window not having a title bar. When the title bar is switched on the window - and the controls in the window - behave as expected.
As pointed out by Ken the framework will automatically refuse becoming a key window if the window title is switched off:
Attempts to make the window the key window are abandoned if this
method returns NO. The NSWindow implementation returns YES if the
window has a title bar or a resize bar, or NO otherwise.
A simple subclass did the trick.

Cocoa: NSPopover in statusbar unresponsive

An application has an NSPopover with some user inputs in the status bar and some windows. The windows work fine but when I open the popover in the status bar it opens inactive. I can see everything but it's all greyed out, like it's a background window. I've been trying everything I can find on activate, activateignoringotherapps, makekeyandorderfront, etc but none of these is having an effect. How can I shift the focus to the statusbar popover?
I also made a button in the window that showed the same popup to make sure it is working, when called from the window button it works perfectly from there. Then I click on the status bar, and it opens from there instead, but inactive.
Thanks for the help.
I've run into the same problem and haven't found a solution. Unfortunately, I believe this is a bug: http://www.openradar.me/radar?id=1226415
There's a framework called SFBPopovers which provides similar functionality and works fine with the menu bar.
It might help with your issue.

How do I get a textbox in an NSMenu?

I'm pretty sure i've seen this somewhere (not counting the help menu), and I feel like you could just drag one in under ib in leopard. Not that it matters, but it will either go into a dock menu or a service. Thanks
Try setting an NSTextField as the view of an NSMenuItem.
You can do this in IB by dragging the text field into the nib as a top-level object and setting the menu item's view outlet to point to the field.
Tricky thing you may need to solve in your app: In the IB simulator, at least, pressing return/enter did not dismiss the menu.

Resources