In Cocoa/AppKit, given a screen from [NSScreen screens]
, how can I find out if there's a full-screen app running on that specific screen? I'm mostly interested in apps that use the Cocoa APIs for full-screen, but if there's a solution that also encompasses other types of full-screen apps, even better. The solution needs be able to pass Mac App Store approval.
My specific use case involves a menu bar app (NSStatusItem
) and figuring out whether or not a menubar is shown at all on [NSScreen mainScreen]
in order to allow a global keyboard shortcut to show either a popover positioning on the status item (if it's visible) or a floating window if there's no visible status item.
NSScreens
themselves don't seem to expose any information about windows/apps, and NSRunningApplication
doesn't expose this information either.
Are there perhaps Carbon APIs for finding this out? For example, if I have a list of windows, I could iterate through them and see if any window frames match the screens' frame exactly. On the other hand, there might be apps that have a frame like that but run underneath other apps (like the Backdrop app, https://itunes.apple.com/us/app/backdrop/id411461952?mt=12), so an approach like this would need to look at window levels.
You can try the CGWindowList API, such as CGWindowListCopyWindowInfo()
.
If you just want to know if the menu bar is showing, you should be able to check -[NSApplication currentSystemPresentationOptions]
for NSApplicationPresentationAutoHideMenuBar
or NSApplicationPresentationHideMenuBar
. That method can also tell you if the active app is in Cocoa full-screen mode (NSApplicationPresentationFullScreen
).