full screen detection breaks on notched macbooks (the window bounds trick doesn't work)
ran into this while working on a small mac utility, figured someone else might hit it too
i wanted to know when the user has something full screen (youtube in chrome, a movie, a game etc) so the app gets out of the way. the usual trick is CGWindowListCopyWindowInfo and checking if a window matches the screen frame. works fine on external monitors, but on a notched macbook full screen windows start below the notch and the strip above it is just painted black. so the window is like 32-38pt shorter than the screen, which is pretty much where a normal zoomed window starts too. can't just loosen the check
what ended up working is asking the window server which space each display is on. full screen apps get their own space and its type is 4
```swift
typealias MainConnection = u/convention(c) () -> Int32
typealias CopyDisplaySpaces = u/convention(c) (Int32) -> Unmanaged<CFArray>?
let cg = dlopen("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics", RTLD_NOW)
let mainConnection = unsafeBitCast(dlsym(cg, "CGSMainConnectionID"), to: MainConnection.self)
let copySpaces = unsafeBitCast(dlsym(cg, "CGSCopyManagedDisplaySpaces"), to: CopyDisplaySpaces.self)
func fullScreenDisplays() -> Set<String> {
let displays = copySpaces(mainConnection())?.takeRetainedValue() as? [[String: Any]] ?? []
var result = Set<String>()
for display in displays {
let current = display["Current Space"] as? [String: Any]
if (current?["type"] as? Int) == 4, let id = display["Display Identifier"] as? String {
result.insert(id)
}
}
return result
}
```
the ids are display uuids (or "Main" if you turned off separate spaces per display), you can map them with CGDisplayCreateUUIDFromDisplayID
it's private api so no app store, but it needs zero permissions. AXFullScreen works too but then you need accessibility. i just run it on activeSpaceDidChangeNotification and once more ~0.4s later since the space animates in
anyone know a public way to do this? would rather not rely on CGS stuff
