0

我第一次尝试提出以下问题时显然出了点问题:

我正在尝试编写一个传统的全屏切换功能,该功能应该在当前屏幕(监视器)上将一个窗口置于或退出全屏模式,同时不影响其他屏幕的内容 - 无论空间是如何配置的。

我已经让它适用于“传统”空间模式,其中每个空间跨越所有连接的屏幕。在这种情况下,主屏幕上只有 1 个菜单栏和 Dock,可以使用[[NSScreen screens] firstObject]. 因此,我可以做类似的事情

        if ([nsWin screen] == [[NSScreen screens] firstObject]) {
            m_normalPresOpts = [nsApp presentationOptions];
            [nsApp setPresentationOptions:m_normalPresOpts | NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationAutoHideDock];
        }

仅当全屏窗口位于主屏幕上时,才能使 Dock 和菜单栏自动隐藏。

Apple 无法在不重新启动登录会话的情况下切换 Spaces 设置,所以我什至不知道当屏幕有单独的 Spaces 时上面的代码是如何工作的。我怀疑它[[NSScreen screens] firstObject]仍然会包含左上角位于 (0,0) 的屏幕,因此其他屏幕上的全屏窗口将继续使菜单栏和 Dock 可见。此外,我仍在运行 10.9,并且也希望在以后的版本中立即获得此权利。

有没有办法以编程方式确定Spaces 的配置方式或知道给定屏幕是否包含菜单栏/Dock?谷歌搜索没有给我任何与代码相关的结果。不知何故,我错过[NSScreen +screensHaveSeparateSpaces]了我的磁盘文档,这是我问题的最终答案吗?

4

2 回答 2

3

NSScreen 有两个属性

框架

这是当前分辨率下的全屏矩形。此矩形包括当前由菜单栏和停靠栏占用的任何空间。

可见帧

This is the rectangle defining the portion of the screen in which it is currently safe to draw your application content.

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. Because it is based on the current user-interface settings, the returned rectangle can change between calls and should not be cached.

Even when dock hiding is enabled, the rectangle returned by this method may be smaller than the full screen. The system uses a small boundary area to determine when it should display the dock.

So, if they are different, than the screen has menubar and/or dock
于 2017-05-18T11:03:25.913 回答
1

有没有办法以编程方式确定 Spaces 的配置方式或知道给定屏幕是否包含菜单栏/Dock?谷歌搜索没有给我任何与代码相关的结果。不知何故,我在磁盘文档中错过了 [NSScreen +screensHaveSeparateSpaces],这是对我问题的最终答案吗?

是的。

顺便说一句,如果您的文档已过时,您可能会在文档中遗漏它,因为此方法是作为新空间模型的一部分引入而没有记录的 - 它仅存在于头文件中。从那时到现在的某个时间点,文档赶上了。

于 2017-04-23T09:26:27.647 回答