0

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

Community
  • 1
  • 1
Trond Kristiansen
  • 2,379
  • 23
  • 48
  • canBecomeKeyWindow applies to NSWindow objects only, you don't need that. Do you need to always click twice before the popup appears, or it happens only the first time you try? Also, could you add the contents of the togglePanel: method to the question? – Cristik Apr 11 '15 at 09:43

1 Answers1

1

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

Community
  • 1
  • 1
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • I see. I removed my statusItemView.image, but kept the rest. My statusItemView is a subclass of NSView with a mouseDown method, canBecomeKeyWindow, and accepts first responder. This still does not work until second click. Do I need to add tracking etc to have a custom view? Could you help with some more details for how to get this to work? Thanks! – Trond Kristiansen Apr 10 '15 at 17:01