[英]OSX Window Capture
I've been spending some time looking at the window system in OSX. 我一直在花时间看OSX中的窗口系统。 I'm trying to understand all the information around it for some capture code that I'm working on. 我正在尝试了解它周围的所有信息,以获取我正在研究的捕获代码。
I would like to be able to filter my window query such that I only grab windows that are visible in any of the spaces or are minimized in any of the spaces. 我希望能够过滤我的窗口查询,以便我只抓取在任何空格中可见的窗口或在任何空格中最小化。
Right now, using the SonOfGrab test code, and the documentation, I have created a program that can query the window server and give me a listing like this: 现在,使用SonOfGrab测试代码和文档,我创建了一个程序,可以查询窗口服务器并给我一个这样的列表:
{
"name": "Xcode",
"id": 25314,
"width": 16,
"height": 194,
"visible": "NO",
"desktop": -1,
"owner pid": 37319,
"layer": 0
}
I filter out all desktop elements and I only grab shareable windows. 我过滤掉所有桌面元素,我只抓住可共享的窗口。
So as far as I can tell from the documentation, which is sort of limited, and the my example programs are these things 据我所知,从文档中可以看出,这是有限的,我的示例程序就是这些东西
Here are the issues I'm facing with my code and with the SonOfGrab example. 以下是我使用我的代码和SonOfGrab示例所面临的问题。
{
"name": "Activity Monitor",
"id": 94,
"width": 703,
"height": 728,
"visible": "NO",
"desktop": -1,
"owner pid": 2353,
"layer": 0
},
{
"name": "Activity Monitor",
"id": 94,
"width": 703,
"height": 728,
"visible": "NO",
"desktop": -1,
"owner pid": 2353,
"layer": 0
},
I'd like to be able to only list windows that are viewable in any space or are minimized and could potentially be viewed. 我希望能够只列出可在任何空间中查看或最小化并且可能被查看的窗口。 It seems like the visibility and layer kind of help, but maybe I need more window details to figure this out. 它似乎是可见性和层次的帮助,但也许我需要更多的窗口细节来解决这个问题。 Any ideas :-)? 有任何想法吗 :-)?
I don't think you'll be able to achieve what you want. 我认为你不能达到你想要的效果。
You may be interested in windows which are not in layer 0. The layer corresponds to what's called the "window level" elsewhere in the docs. 您可能对不在第0层的窗口感兴趣。该层对应于文档中其他位置的“窗口级别”。 See -[NSWindow setLevel:]
and CGWindowLevelForKey()
. 请参阅-[NSWindow setLevel:]
和CGWindowLevelForKey()
。 For example, in my testing, a floating panel is in layer 3. 例如,在我的测试中,浮动面板位于第3层。
Since you're using the CGWindowList
API, you can use kCGWindowListExcludeDesktopElements
to exclude the menu bar, Dock, etc. You seem to be aware of this, so I'm not sure why you were looking to the layer property. 由于您正在使用CGWindowList
API,您可以使用kCGWindowListExcludeDesktopElements
来排除菜单栏,Dock等。您似乎意识到这一点,所以我不确定您为什么要查看图层属性。
Second, I doubt you can distinguish between minimized and "hidden" windows. 其次,我怀疑你可以区分最小化和“隐藏”的窗口。 The presence of a window in the list only means that it has an associated "window device". 列表中存在窗口仅意味着它具有关联的“窗口设备”。 (See the deferCreation
parameter of the -[NSWindow initWithContentRect:...]
methods and the description of the -[NSWindow windowNumber]
method.) But a window won't be visible if it's on another space, if it's minimized, or if it has been ordered out of the window list by its app (ie hidden). (请参阅-[NSWindow initWithContentRect:...]
方法的deferCreation
参数和-[NSWindow windowNumber]
方法的说明。)但是如果窗口位于另一个空间,如果它被最小化,或者如果窗口被最小化,则该窗口将不可见它已被其应用程序(即隐藏)从窗口列表中排序。 In fact, if the window is a one-shot window (see -setOneShot:
), the window device may be deallocated when it's minimized or hidden. 实际上,如果窗口是一次性窗口(请参阅-setOneShot:
,则窗口设备可以在最小化或隐藏时解除分配。
In other words, there's very little difference between a minimized window and a window that's been hidden, even in the internals of the window server. 换句话说,即使在窗口服务器的内部,最小化窗口和隐藏窗口之间的差别也很小。
Finally, you can't capture the contents of windows that aren't on the current space or that are minimized. 最后,您无法捕获不在当前空间或最小化的窗口内容。 You can see this with the Son of Grab sample code. 您可以使用Son of Grab示例代码查看此内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.