How to prevent the menu bar from moving when opening my popover?

I have an application with popover that appears in a status element. The fact is that when you click on the icon, when you are in a full-screen application, then push the mouse away from the menu bar to click something in the pop-up window, the menu bar moves up, and the pop-up window also appears. This is annoying.

Does anyone know how to solve this? I tried to connect an invisible menu to a popup, but I cannot make the menu invisible.

A screenshot for clarity, the annoying part is where I wave my hand:

enter image description here

+6
source share
3 answers

The popover window moves because its parent window is a status window, and when the parent window moves, the child moves with it. (Before I explored this, I didn’t even know that Cocoa has parent and child windows.) I solved the problem with this code right 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 remains in one place.

+1
source

Use Carbon Events or watch what happens with the menu bar (window of type NSStatusBarWindow ):

Type Notifications

  • NSWindowDidChangeOcclusionStateNotification
  • NSWindowDidMoveNotification
  • NSWindowWillCloseNotification
  • NSWindowDidCloseNotification

with an object of class NSStatusBarWindow should provide you enough information about the menu bar to show or hide to add the correct processing.

+1
source

Super hacker approach:

A custom window with some super-high level window so that it appears in the menu bar, then add a transparent user view to a new window that catches and processes / blocks mouse clicks according to your needs.

Or:

Get the instance of the window that popover uses to display and track / handle NSWindowWillMoveNotification / NSWindowDidMoveNotification .

0
source

All Articles