16 lines
626 B
Swift
16 lines
626 B
Swift
// ghostty-wincount <pid> — Anzahl sichtbarer Normal-Fenster (Layer 0) des
|
|
// Prozesses, direkt vom Window-Server. Keine Apple-Events, kein TCC-Prompt.
|
|
import CoreGraphics
|
|
import Foundation
|
|
|
|
guard CommandLine.arguments.count == 2, let pid = Int32(CommandLine.arguments[1]) else {
|
|
FileHandle.standardError.write(Data("usage: ghostty-wincount <pid>\n".utf8))
|
|
exit(2)
|
|
}
|
|
let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID) as? [[String: Any]] ?? []
|
|
let n = list.filter {
|
|
($0[kCGWindowOwnerPID as String] as? Int32) == pid &&
|
|
($0[kCGWindowLayer as String] as? Int) == 0
|
|
}.count
|
|
print(n)
|