The answer by @Chip Jarred did not work for me on macOS 15.5 Sequoia. None of the Dock windows have a "Fullscreen Backdrop" kCGWindowName
.
What worked for me was the simple check for multiple Dock windows that have a negative (around MIN_INT64) value as kCGWindowLayer
. If there are more than one of those Dock windows, the app is running in fullscreen:
func isFullScreen() -> Bool {
guard let windows = CGWindowListCopyWindowInfo(.optionOnScreenOnly, kCGNullWindowID) else {
return false
}
var dockCount = 0
for window in windows as NSArray
{
guard let winInfo = window as? NSDictionary else { continue }
if winInfo["kCGWindowOwnerName"] as? String == "Dock"
{
let windowLayer = winInfo["kCGWindowLayer"]
if let layerValue = windowLayer as? Int64, layerValue < 0 {
dockCount += 1
if dockCount > 1 {
return true
}
}
}
}
return false
}