-
Notifications
You must be signed in to change notification settings - Fork 5
/
PrintScreenIDs.swift
33 lines (26 loc) · 1.21 KB
/
PrintScreenIDs.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Part of Display Menu, Copyright © 2017-2019 Chris Warrick. License: 3-clause BSD.
import Quartz
let maxDisplays: UInt32 = 16
var onlineDisplays = [CGDirectDisplayID](repeating: 0, count: Int(maxDisplays))
var displayCount: UInt32 = 0
CGGetOnlineDisplayList(maxDisplays, &onlineDisplays, &displayCount)
func modeString(_ mode: CGDisplayMode) -> String {
return "\(mode.width) \(mode.height) \(mode.pixelHeight / mode.height)x (\(mode.refreshRate) Hz)"
}
for displayID in onlineDisplays[0..<Int(displayCount)] {
let screenID = "\(CGDisplayVendorNumber(displayID)):\(CGDisplayModelNumber(displayID)):\(CGDisplaySerialNumber(displayID))"
print("--- ScreenID: " + screenID)
let currentMode = CGDisplayCopyDisplayMode(displayID)
if (currentMode == nil) {
print("Current mode unknown")
} else {
print("Current mode:", modeString(currentMode!))
}
let settingsDict: CFDictionary = [kCGDisplayShowDuplicateLowResolutionModes as String: kCFBooleanTrue] as CFDictionary
let modes = CGDisplayCopyAllDisplayModes(displayID, settingsDict as CFDictionary)! as! [CGDisplayMode]
print("Supported modes:")
for mode in modes {
print(" " + modeString(mode))
}
print()
}