testpattern.swift (1300B)
1 // Fullscreen LEFT (red) / RIGHT (blue) pattern on the headset display (vendor 8718). 2 import AppKit 3 let app = NSApplication.shared 4 app.setActivationPolicy(.regular) 5 guard let screen = NSScreen.screens.first(where: { 6 CGDisplayVendorNumber(($0.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as? NSNumber)?.uint32Value ?? 0) == 8718 7 }) else { print("headset display not found"); exit(1) } 8 final class V: NSView { 9 override func draw(_ r: NSRect) { 10 let h = bounds.width / 2 11 NSColor.red.setFill(); NSRect(x: 0, y: 0, width: h, height: bounds.height).fill() 12 NSColor.blue.setFill(); NSRect(x: h, y: 0, width: h, height: bounds.height).fill() 13 let a: [NSAttributedString.Key: Any] = [.font: NSFont.boldSystemFont(ofSize: 140), .foregroundColor: NSColor.white] 14 for (i, t) in ["LEFT", "RIGHT"].enumerated() { 15 let s = NSAttributedString(string: t, attributes: a), z = s.size() 16 s.draw(at: NSPoint(x: h * CGFloat(i) + (h - z.width) / 2, y: (bounds.height - z.height) / 2)) 17 } 18 } 19 } 20 let w = NSWindow(contentRect: screen.frame, styleMask: .borderless, backing: .buffered, defer: false, screen: screen) 21 w.level = .screenSaver; w.contentView = V(); w.setFrame(screen.frame, display: true); w.orderFrontRegardless() 22 app.run()