5

I'd like to perform the following:
when I click on the status bar item (NSStatusItem) I want to highlight it (no menu) indefinitely and when the application loses focus I want to stop highlighting it.

Is there any way of doing this? I can't find it, tbh.

Pedro Vieira
  • 3,330
  • 3
  • 41
  • 76
  • 2
    If I saw an application do this, I would think it was hung, or at least not using the standard event loop, in between highlight and unhighlight. If you want to indicate that your window is visible, you should change your item's icon. – Peter Hosey Jan 12 '13 at 19:56

2 Answers2

2

You can probably do this with a custom view that sends the status item a drawStatusBarBackgroundInRect:withHighlight: message.

I doubt there's any way to do it without a custom view, since, as I mentioned in my comment on the question, keeping the item highlighted when the user doesn't have the mouse down on it looks bad.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • 1
    the thing is: I have a NSWindow (no popover) that will appear right beneath the status bar item (when clicked). So, what I wanna do is to mimic the NSMenu behaviour: I click on status bar, the window is shown and the item is highlighted, when the app loses focus the window disappears and the item goes to normal state. – Pedro Vieira Jan 13 '13 at 04:20
  • @PedroVieira: Sounds reasonable. If I were doing that, I'd make a custom view such as I described in my answer. – Peter Hosey Jan 13 '13 at 04:22
  • Pedro, I am facing exactly the same issue right now. Would you mind sharing how you have implemented Peter's solution ? Cheers. – Laurent Crivello Jan 21 '14 at 21:51
2

Old question, but I think it is worth adding this alternative answer.

This will not automatically un-highlight when the application loses focus, but this allows you to highlight without using a custom view (as the other answer requires):

NSStatusItem *statusItem = [self getStatusItem];
[statusItem.button setHighlighted:YES];

You can unhighlight it manually using the same method:

[statusItem.button setHighlighted:NO];

Note I got this answer from a similar question here.

Community
  • 1
  • 1
lindon fox
  • 3,298
  • 3
  • 33
  • 59