8

I have an app which uses an NSStatusItem. On small screens there's not much space in the status bar. When a user switches to an application with a lot of menu items, my status item gets hidden. Is there a way to get notified about this?

What I tried so far:

  • I checked if any NSNotification is fired: No
  • I checked if the statusView is removed from the view hierarchy: No
  • I checked isHiddenOrHasHiddenAncestor: No

Here's the code I use to create the status item.

self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
MyStatusView *maView = [[[MyStatusView alloc] initWithFrame:CGRectMake(0, 0, 50, 22)] autorelease];
[statusItem setTitle:@"Ma Status Item"];
[statusItem setView:maView];
jscs
  • 63,694
  • 13
  • 151
  • 195
stigi
  • 6,661
  • 3
  • 40
  • 50
  • can you test whether its view.center property changes as it moves off the screen? You might be able to add KVO notification to the center property to establish a sort of callback, but I don't know if that would work for a statusItem. – Suz Oct 12 '11 at 20:47
  • I also have a timer running that logs the bounds relative to the window. Not changing... It looks like maView is in it's own window (NSWindow > NSNextStepFrame > maView). Will try and see if this is moved off screen. – stigi Oct 12 '11 at 21:34
  • Window bounds are also still on screen. The window might be overlaid by something else. Don't know how to check for this though.. – stigi Oct 12 '11 at 21:40
  • I figured that the status item is hidden by moving it's window into the background. I ran a timer that checks the windows on top of maView.window like this https://gist.github.com/1282781. Now someone tell me if there's a notification when a Window is moved to the background. – stigi Oct 12 '11 at 22:01
  • @stigi did you end up getting this to work? I can't seem to get the notifications dragoncharmer listed to fire. – Vervious Jul 28 '12 at 19:16

1 Answers1

0

It's pretty smart of you to realize that when a status item is hidden, its window will be moved into the background.

Now the notification you're looking for is: NSWindowDidResignKeyNotification (or NSWindowDidResignMainNotification depending on the context of your application)

For a clear explanation about the difference between a key window and a main window, see this.

hollow7
  • 1,506
  • 1
  • 12
  • 20