调整大小和重新定位 window 以覆盖所有显示器

Resize and reposition window to span all monitors

大家好,我正在开发一个小型跨平台 hobby/educational 项目,该项目截取所有显示器的屏幕截图并用一个宽 window 覆盖所有显示器。现在在 Windows 和 GTK 系统上这没有问题。但我在 OSX:

上遇到问题
  1. 第一个主要问题是 window 没有覆盖扩展坞和顶部菜单栏的非工作区域。
  2. 它不会调整大小以跨越多个显示器。

有什么程序化的方法可以做到这一点吗?用户真的很喜欢截屏,因为它会覆盖所有监视器,然后他们裁剪并单击上传到图像服务等。我只想在 OSX.

上为他们带来相同的体验

谢谢

在 OS X 10.9 中,Apple 引入了一项名为 "Displays have separate Spaces" 的功能。请参阅系统偏好设置的任务控制面板。默认开启。

启用时,没有 window 可以跨越多个监视器。即使它以编程方式设置了一个框架,它也只会出现在包含 window 的大部分区域的屏幕上。 window 将被剪裁到该屏幕的框架。

因此,您必须为每个屏幕创建一个单独的 window。

来自10.9 AppKit release notes

Spaces and Multiple Screens

In 10.9, we have added a feature where each screen gets its own set of spaces, and it is possible to switch between spaces on one screen without perturbing the spaces on the other screens. In this mode, a fullscreen window uses one screen, and leaves the contents of any other screens unchanged. …

When this feature is enabled, windows may not visibly span displays. A window will get assigned to the display containing the majority of its geometry if programmatically positioned in a spanning position. A window will get assigned to the display containing the mouse if the window is moved by the user. A window clips to the edge of the display, whether or not there is another adjacent display.

此外,由于菜单栏出现在所有屏幕上,Apple 更改了 windows 受限于屏幕的方式。另外,来自 10.9 AppKit release notes:

constrainFrameRect:toScreen: now invoked for borderless windows

Prior to 10.9, the NSWindow method -[NSWindow constraintFrameRect:toScreen:] was invoked only for windows with NSTitledWindowMask set in their styleMask. In 10.9, this method is invoked for all windows. The default implementation does a more limited constraining for non-titled windows, as described in “NSWindows constrained to not intersect the menu bar” below.

NSWindows constrained to not intersect the menu bar

In 10.9, in support of the new multi-monitor architecture, windows are now constrained to not intersect the menu bar on their containing space. This restriction was already in place for titled windows, but it has been extended to borderless windows whose level is at least NSNormalWindowLevel but less than NSMainMenuWindowLevel. This behavior is implemented in -[NSWindow constraintFrameRect:toScreen:]. You may override that method in an NSWindow subclass to adjust or prevent this constraining.

因此,您要么必须使用 NSWindow 的自定义子类,它将 -constrainFrameRect:toScreen: 覆盖到 return 不受约束的框架,要么您必须设置 window' s levelNSMainMenuWindowLevel 或更高。