Search code examples
cocoafullscreenmenubarnspopover

How do I prevent the menu bar from moving down when my popover is open?


I have an app with a popover that appears on a status bar item. The thing is, when you click on the icon while you're in a full screen app, then move the mouse away from the menu bar to click on something in the popup, the menu bar moves up, and so does the popup. It's annoying.

Anyone know of any way to solve this? I've tried attaching an invisible menu to the popup, but I can't get the menu to be invisible.

Screenshot for clarity, the annoying part is where I wave my mouse around:

enter image description here


Solution

  • The popover window is moving because its parent window is the status item window, and when the parent window moves, the child moves with it. (Before I investigated this, I didn't even know Cocoa had parent and child windows.) I solved the problem with this code immediately after showing the popover:

    NSWindow *popoverWindow = self.popup.contentViewController.view.window;
    [popoverWindow.parentWindow removeChildWindow:popoverWindow];
    

    Now, the menu bar still moves up, but at least the popup stays in the same place.