简体   繁体   English

OSX窗口捕获

[英]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. 我正在尝试了解它周围的所有信息,以获取我正在研究的捕获代码。

WHAT I WANT TO DO 我想做的事

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. 我希望能够过滤我的窗口查询,以便我抓取在任何空格中可见的窗口或在任何空格中最小化。

WORK SO FAR 努力工作

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. 我过滤掉所有桌面元素,我只抓住可共享的窗口。

WHAT I'VE LEARNED 我学到了什么

So as far as I can tell from the documentation, which is sort of limited, and the my example programs are these things 据我所知,从文档中可以看出,这是有限的,我的示例程序就是这些东西

  1. The visibility attribute of a window will tell you if it's visible in the current active space. 窗口的visibility属性将告诉您它是否在当前活动空间中可见。
  2. The layer seems to be important. 该层似乎很重要。 As far as I can tell, the windows that I want to filter are only available in layer 0. It looks like other layers are related to the dock, toolbar, icons, etc. 据我所知,我想要过滤的窗口仅在第0层可用。看起来其他图层与停靠栏,工具栏,图标等相关。
  3. Items that are not visible but in layer 0 are sometimes minimized windows. 不可见但在第0层中的项有时会最小化窗口。

PROBLEMS I'VE ENCOUNTERED 遇到的问题我已经遇到过了

Here are the issues I'm facing with my code and with the SonOfGrab example. 以下是我使用我的代码和SonOfGrab示例所面临的问题。

  1. Minimized windows and closed windows on some applications seem to be identical. 在某些应用程序中,最小化的窗口和关闭的窗口似乎是相同的。 For example with the Activity Monitor. 例如,使用活动监视器。 If I minimize the window or close it, the output is identical. 如果我最小化窗口或关闭它,输出是相同的。 Are there other fields which would help me differentiate this? 还有其他领域可以帮助我区分这个吗? It seems like this happens because the application is always running in the task bar. 这似乎是因为应用程序始终在任务栏中运行。

MINIMIZED ACTIVITY MONITOR 最小化的活动监测

{
    "name": "Activity Monitor",
    "id": 94,
    "width": 703,
    "height": 728,
    "visible": "NO",
    "desktop": -1,
    "owner pid": 2353,
    "layer": 0
},

CLOSED ACTIVITY MONITOR 封闭式活动监测

{
    "name": "Activity Monitor",
    "id": 94,
    "width": 703,
    "height": 728,
    "visible": "NO",
    "desktop": -1,
    "owner pid": 2353,
    "layer": 0
},
  1. Even when I filter out desktop elements and only grab from layer 0. I still see the SystemUIServer floating around. 即使我过滤掉桌面元素并且只从第0层抓取,我仍然看到SystemUIServer浮动。 When I try to grab it's windows with SonOfGrab I don't get anything. 当我试图用SonOfGrab抓住它的窗户时,我什么也得不到。 Is there any meaningful way to filter this other than by name? 有没有什么有意义的方法可以过滤除名字以外的其他方式?
  2. Unviewable windows. 不可见的窗户。 With XCODE I notice that if I have one project opened up and viewable. 使用XCODE,我注意到如果我打开了一个项目并且可以查看。 My program and SonOfGrab will show 5 windows in layer 0. 1 will be visible, the rest are invisible. 我的程序和SonOfGrab将在第0层显示5个窗口.1将是可见的,其余的是不可见的。

SUMMARY 摘要

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM