I am creating a MacOS applet that wants to detect the occlusion state of windows not specific to my current application. Since I cannot get NSWindow objects of other applications, I will need to use the Core Graphics layer to detect and manipulate windows. This means I won't have access to AppKit's NSWindow property "occlusionState" and need to find an alternative way to determine the window's occlusion state.
Right now I'm retrieving a list of CGWindows with the CGWindowListCopyWindowInfo method. I have taken a look at the documentation and see there are a few constants that I could potentially use (kCGWindowLayer, kCGWindowIsOnscreen... which always returns true even if windows are occluded) if I need to find a workaround, but I was curious if you all knew of a better way to do this or if there's some property that I'm not familiar with. If not, is there an example somewhere of an app trying to do this?
let windowList = CGWindowListCopyWindowInfo(type, kCGNullWindowID) as NSArray? as? [[String: AnyObject]]
for entry in windowList!
{
//Get a list of all windows that are visible on the screen ...