Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 933
tbodt Avatar asked Jan 21 '16 00:01

tbodt


People also ask

What are the different menu bar that can be opened?

While menu bar items vary between applications, most menu bars include the standard File, Edit, and View menus. The File menu includes common file options such as New, Open…, Save, and Print. The Edit menu contains commands such as Undo, Select All, Copy, and Paste.

What is the use of menu bar?

The menu bar is the part of a browser or application window, typically at the top left side, that houses drop-down menus that allow the user to interact with the content or application in various ways.

How many menu bar menus are there?

Answer. A XUL document can contain exactly one menu bar, specified using the menubar tag.


2 Answers

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.

like image 158
tbodt Avatar answered Jan 11 '23 03:01

tbodt


Either use Carbon events or watch for things happening to the menu bar (window of type NSStatusBarWindow):

Notifications of type

  • NSWindowDidChangeOcclusionStateNotification
  • NSWindowDidMoveNotification
  • NSWindowWillCloseNotification
  • NSWindowDidCloseNotification

with an object of class NSStatusBarWindow should give you enough information about the menu bar showing or hiding to add proper handling.

like image 33
Jay Avatar answered Jan 11 '23 05:01

Jay