Hi,
I want to detect if there is a fullscreen window on each screen.
_AXUIElementGetWindow and kAXFullscreenAttribute methods work, but I have to be in a non-sandbox environment to use them.
Is there any other way that also works? I don't think it's enough to judge if it's fullscreen by comparing the window size to the screen size, since it doesn't work on MacBook with notch, or the menu bar is set to 'auto-hide'.
Thanks.
@Frameworks Engineer is correct.
There doesn't appear to be a way to get a handle to another process' NSWindow to check its styleMask.
You can obtain a lot of other information about all windows in the user session such as kCGWindowOwnerPID, kCGWindowOwnerName, kCGWindowNumber, kCGWindowIsOnscreen, kCGWindowBounds etc., however you there isn't API for getting an NSWindow handle using an kCGWindowNumber (or some other value).
All that said, you can likely get a reasonable approximation using a combination of kCGWindowIsOnscreen and kCGWindowBounds.
We also encourage you send us an enhancement request to improve existing API.
Here is the code I used for reference:
func applicationDidFinishLaunching(_ aNotification: Notification) {
let windowList = CGWindowListCopyWindowInfo(.optionAll, kCGNullWindowID)
for (index, windowInfo) in (windowList as! [[String: Any]]).enumerated() {
print("Window \(index): \(windowInfo)")
}
}
For windows that belong to your app you can check the styleMask on the window list:
NSApplication.shared.windows