Reputation: 721
Is there a way in Cocoa to receive a notification (or something similar) when the menu bar becomes hidden or visible? I tried looking around and have not found any information on this topic.
Thanks
Upvotes: 6
Views: 2003
Reputation: 90521
I believe the correct approach to this is to use Key-Value Observing (KVO) to observe the presentationOptions
or currentSystemPresentationOptions
property of the application object (NSApp
or [NSApplication sharedApplication]
). When that changes, check its value to see if it includes NSApplicationPresentationHideMenuBar
or NSApplicationPresentationAutoHideMenuBar
. If it does, then the menu is hidden (or hides when the cursor is not near the top of the main screen.
The difference between presentationOptions
and currentSystemPresentationOptions
is whether you're interested in whether the calling app has hidden its menu bar or whether the active app (which may be another app) has hidden its menu bar. The latter indicates whether the user can see any menu bar.
Upvotes: -1
Reputation: 7710
If you only need the current state of the menu bar, another approach is to use the visibleFrame
property of NSScreen
:
The returned rectangle is always based on the current user-interface settings and does not include the area currently occupied by the dock and menu bar.
However, this won't be sufficient by itself if you need to be notified of menu bar visibility changes.
Upvotes: 2
Reputation: 6638
Optionally watch out for (Cocoa) notifications for an object of class NSStatusBarWindow
and notifications like
to get notified when the menu bar showing or hiding.
Upvotes: 2
Reputation: 721
I solved this by using Carbon's menu event handlers.
I registered for events kEventMenuBarHidden
and kEventMenuBarShown
under the class kEventClassMenu
.
Upvotes: 3