4

The problem: I have to follow the app's NSStatusItem popup/window right beneath it.

The general solution for this (like it's suggested here or here) is to add a custom view to the NSStatusItem and get the view's window's frame (statusItem.view.window.frame), and connect to move event through NSWindowDidMoveNotification notification of the statusItem.view.window.

This solution works 99% unless the user connects an external display which is taller than the previous display (for example a Mac Book user connects an external monitor), in this case the statusItem.view.window.frame will be incorrect, X coordinate will be actually correct but the Y coordinate will be the same as it was in the smaller screen!

I've checked and most of the menubar apps which have a popup window when you click the status item are misplaced just like I've described.

My solution was to don't use the Y coordinate from this frame but use the corresponding NSScreen's visibleFrame's height like this:

NSScreen *screenWithMenuBar = [[NSScreen screens] objectAtIndex:0];
    if( screenWithMenuBar ) {
        // correct the top position by the 'screen with the MenuBar's height
        //  workaround: without this the window will be off-placed when the user plugs in an external display,
        //      a display with more height
        NSRect visibleRect = [screenWithMenuBar visibleFrame];
        originPoint.y = visibleRect.size.height + visibleRect.origin.y;
    }

As stated in the official Apple documentation the first screen should be always the screen which contains the menubar so it should work, but it seems too much of a hack for me.

Have you guys experienced this bug? Have you found a better solution?

Community
  • 1
  • 1
Viktor Benei
  • 3,447
  • 2
  • 28
  • 37
  • Does getting the new value of `[[NSStatusBar systemStatusBar] thickness]` work? – Keith Smiley Jul 26 '13 at 21:56
  • @KeithSmiley it's always the same (the menubar's thickness doesn't change when switching to an external monitor) - sorry, maybe I don't understand what you suggest - how should this help? – Viktor Benei Jul 28 '13 at 17:19

0 Answers0