If you call CGWindowListCopyWindowInfo () , the CFDictionaryRef that you return contains a series of keys and values . One of them is kCGWindowSharingState , which has three possible values:
Window Sharing Constants Specifies whether and how windows are shared between applications. enum { kCGWindowSharingNone = 0, kCGWindowSharingReadOnly = 1, kCGWindowSharingReadWrite = 2 };
Almost all the windows on my system are kCGWindowSharingReadOnly , and the ScreenShot SonOfGrab screen trial program avoids capturing kCGWindowSharingNone windows, but I could not find a good description of what these conditions are for.
A simple test seems to show that some applications shipped with OS X have windows that are set to kCGWindowSharingNone , in particular Notes and iBooks. As far as I can tell from a quick test, the presence of the kCGWindowSharingNone window actually does not allow CGWindowListCreateImage () to capture the image of this window. There are no windows that I could find to set kCGWindowSharingReadWrite as the sharing mode.
Is this all explained somewhere in the documentation, and did I just skip this, or is it just more or less documented Core Graphics functionality? Is there any good reason not to try to capture the windows of kCGWindowSharingNone , and will I be setting myself up for trouble in the future if I try to do this?
Further research showed that when a Cocoa application calls
[NSWindow setSharingType:]
This sets kCGWindowSharingStateNone in the window and prevents it from being captured using CGWindowListCreateImage () . There are also some other windows that have kCGWindowSharingStateNone , but which can be successfully captured - in particular, iBooks creates such a window.
This is supposedly a bug in iBooks or in any API that it calls (since it does not call the NSWindow API).
objective-c cocoa core-graphics quartz-graphics macos
Mark bessey
source share