Search code examples
objective-cmacoscocoansstatusitem

NSStatusItem only responds after clicking twice


I have an OSX app with its own window in addition to an icon shown in NSStatusBar. The reason for the NSStatusBar is to enable the app to run in the background when main window closes. When trying to click the statusbar icon, I have to click twice before I get a response (a popover is shown). I would like to click once and get immediate response. The NStatusBar is setup like this:

NSStatusItem *statusItem = [[NSStatusBar systemStatusBar]statusItemWithLength:32];
        statusItemView = [[SDStatusItemView alloc] initWithStatusItem:statusItem];
        statusItemView.image = [NSImage imageNamed:@"myLogo"];
        statusItemView.alternateImage = [NSImage imageNamed:@"myLogo"];
        statusItemView.target=self;
        statusItemView.action = @selector(togglePanel:);

        [self.statusItemView.window setIgnoresMouseEvents:NO];
        [self.statusItemView.window setAcceptsMouseMovedEvents:YES];

My statusItemView (subclass of NSView) is setup with:

-(BOOL) acceptsFirstResponder{
    return YES;
}

- (BOOL)canBecomeKeyWindow
{
    return YES;
}

Everything works okay except that I have to click my statusbar icon twice before I get a response. I have googled this and found similar questions like this one, but nothing that solved my problem. Any help would be greatly appreciated. Thanks. T

Update: I ended up creating my StatusItem using the excellent library CCNStatusItem


Solution

  • You can't really influence the window of the menubar. Use a custom NSView for your status item.

    see the down voted answer here: NSStatusItem releases icon