Search code examples
nswindownsmenunsstatusitem

Make MAAttachedWindow to behave like NSMenu


I've read a post on this site on how to hide an MAAttachedWindow when the user clicks outside of it. As at this post, I use the MAAttachedWindow together with a statusItem. Hide MAAttachedWindow when clicking outside. It says I should hide the Window when it resigns its key-state.

But I wonder if there is any other approach instead of the key-status of the window. Working with the key-status adds another problem: In order to get a notification when the window resigns the key-state, all other applications must have been ignored before (which means that the windows of all other applications become inactive and lose their color when your statusMenu appears. It is done by [NSApp activateIgnoringOtherApps:YES]). When you use the Spotlight- or the Airport-statusItem, this does usually not happen. The user would not expect this.

Has anyone made the MAAttachedWindow to behave like a real NSMenu? Is there still a way to work with the key-state without having this problem? Thank you for any hints.


Solution

  • You can make a NSPanel active without using [NSApp activateIgnoringOtherApps:YES]. Just use the NSNonactivatingPanelMask like so:

    NSPanel *panel = [super initWithContentRect:NSZeroRect 
                                                  styleMask: NSNonactivatingPanelMask  
                                                    backing:NSBackingStoreBuffered 
                                                      defer:NO];