如何确定在特定的NSScreen上是否正在运行全屏应用程序 [英] How do find out if there is a full-screen app running on a specific NSScreen

查看:174
本文介绍了如何确定在特定的NSScreen上是否正在运行全屏应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Cocoa/AppKit中,给定[NSScreen screens]中的屏幕,我如何确定在该特定屏幕上是否正在运行全屏应用程序?我对使用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/应用程序的任何信息,并且NSRunningApplication也不公开这些信息.

NSScreens themselves don't seem to expose any information about windows/apps, and NSRunningApplication doesn't expose this information either.

也许有Carbon API可以找到答案吗?例如,如果我有一个窗口列表,则可以遍历它们,查看是否有任何窗口框架与屏幕框架完全匹配.另一方面,可能有一些具有类似框架但在其他应用程序下运行的应用程序(例如Backdrop应用程序

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]中的NSApplicationPresentationAutoHideMenuBarNSApplicationPresentationHideMenuBar.该方法还可以告诉您活动的应用程序是否处于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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆