Popup not hiding when opening another NSView-popup from status bar

454 views Asked by At

I found this project which works almost perfectly as a base for what I'm trying to do https://github.com/shpakovski/Popup. It places an icon at the menu bar which when clicked displays a popup. The popup internal NSWindow is controlled by its delegate which is called PanelController. It's delegate methods are executed most of the time as it is expected, for example, the (void)windowDidResignKey:(NSNotification *)notification is executed when I click almost anywhere. Though, it is not executed the first time I click another item of the menu bar, for example the skype item. This is what I get:

enter image description here

Any ideas on which NSWindow delegate method am I missing to intercept that first click on another menu bar item?

1

There are 1 answers

5
Rychu On

Just opening menu doesn't make window resign key/main, and opening menu from status item works similar as opening own menu.

I could find only one case where menu can make window resign key, which is when application is not the active one (I find it a bit weird, that it's even possible). So, if your application doesn't need to have own windows, except the popup, you could make it give up focus at start using for example (or maybe even with small delay to make sure the app was deactivated and focus was given to other application):

-(void)applicationDidBecomeActive:(NSNotification *)notification
{
    [[NSApplication sharedApplication] hide:nil]; 
}