Problem: I have to watch the NSStatusItem application popup right below it.
A general solution for this (for example, proposed here or here ) is to add a custom view to NSStatusItem and get a viewport window (statusItem.view.window.frame) and connect to the event moving through the notification NSWindowDidMoveNotification about the status of Item.view.window.
This solution works 99% if the user does not connect an external display that is higher than the previous one (for example, the Mac Book user connects an external monitor), in this case statusItem.view.window.frame will be incorrect, the X coordinate will be actually correct, but the Y coordinate will be the same as on a small screen!
I checked, and most menu apps that have a popup when you click on a status item are inappropriate, as I described.
My solution was to not use the Y coordinate from this frame, but use the corresponding NSScreen visible frame height as follows:
NSScreen *screenWithMenuBar = [[NSScreen screens] objectAtIndex:0]; if( screenWithMenuBar ) {
As stated in Apple's official documentation, the first screen should always be a screen that contains a menu, so it should work, but it seems too much to me.
Have you guys experienced this error? Did you find the best solution?
source share