Frage

Is it possible to check if an NSStatusItem is visible in the system menu bar? It sometimes isn't due to the user having too many status items and the active application menu bar size.

I can check the location of the of the status item via a "hack" like so:

statusRect = [[_statusItem valueForKey:@"window"] frame];

But I can't do the same for is visible: (it always returns true)

BOOL visible = [[_statusItem valueForKey:@"window"] isVisible];
War es hilfreich?

Lösung

I dont believe it's doable without really bad hacks

My first though:

Have a view in your NSStatusItem and combine the window.isVisible with the view's visibleRect. The status bar can't be obscured by windows anyway.
=> didn't work

2. Try

Have a view in your NSStatusItem and try the hack from Proper way to determine if NSView is drawn
=> didn't work

REALLY evil hack that might work

simulate Mouse Clicks via the accessibility api and see if your view gets the event :


what I tried

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    item = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
    item.title = @"TEST";
    view = [[DDQuickMenuStatusItemView alloc] init];
    view.item = item;
    view.title = item.title;
    item.view = view;
    
    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(checkVisible:) userInfo:nil repeats:YES];
}

- (void)checkVisible:(id)timer {
    NSLog(@"NOT WORKING vis: %d", (view.window.isVisible && !NSEqualRects(view.visibleRect, NSZeroRect)));
    NSLog(@"NOT WORKING isDrawn: %d", (view.isDrawn));
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top