如何找出特定 NSScreen 上是否有全屏应用程序运行 [英] How do find out if there is a full-screen app running on a specific NSScreen
问题描述
在 Cocoa/AppKit 中,给定来自 [NSScreen 屏幕]
的屏幕,我如何才能确定在该特定屏幕上是否有全屏应用程序正在运行?我最感兴趣的是使用 Cocoa API 进行全屏的应用程序,但如果有一个解决方案也包含其他类型的全屏应用程序,那就更好了.该解决方案需要能够通过 Mac App Store 的审批.
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.
我的具体用例涉及一个菜单栏应用程序 (NSStatusItem
) 并确定菜单栏是否在 [NSScreen mainScreen]
上显示,以便允许一个全局键盘快捷键,用于在状态项(如果它可见)或浮动窗口(如果没有可见状态项)上显示弹出窗口定位.
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
本身似乎没有公开任何关于 windows/apps 的信息,NSRunningApplication
也没有公开这些信息.
NSScreens
themselves don't seem to expose any information about windows/apps, and NSRunningApplication
doesn't expose this information either.
是否有碳 API 可以找到这一点?例如,如果我有一个窗口列表,我可以遍历它们并查看是否有任何窗口框架与屏幕的框架完全匹配.另一方面,可能有些应用程序具有类似的框架但在其他应用程序下运行(例如 Backdrop 应用程序,https://itunes.apple.com/us/app/backdrop/id411461952?mt=12),因此这样的方法需要查看窗口级别.
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.
推荐答案
可以试试CGWindowList API,比如CGWindowListCopyWindowInfo()
.
You can try the CGWindowList API, such as CGWindowListCopyWindowInfo()
.
如果您只想知道菜单栏是否显示,您应该能够检查 -[NSApplication currentSystemPresentationOptions]
的 NSApplicationPresentationAutoHideMenuBar
或 NSApplicationPresentationHideMenuBar
代码>.该方法还可以告诉您活动应用程序是否处于 Cocoa 全屏模式 (NSApplicationPresentationFullScreen
).
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
).
这篇关于如何找出特定 NSScreen 上是否有全屏应用程序运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!