Skip to content

Commit 79999ed

Browse files
committed
More robust LG UltraFine detection
1 parent 99f3b28 commit 79999ed

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Brightness Sync/AppDelegate.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
5353
os_log("Starting display refresh...")
5454

5555
let allDisplays = AppDelegate.getAllDisplays()
56-
let lgDisplaySerialNumbers = AppDelegate.getConnectedUltraFineDisplaySerialNumbers()
56+
let lgDisplayIdentifiers = AppDelegate.getConnectedUltraFineDisplayIdentifiers()
5757

5858
let builtin = allDisplays.first { CGDisplayIsBuiltin($0) == 1 }
59-
let syncTo = allDisplays.filter { lgDisplaySerialNumbers.contains(CGDisplaySerialNumber($0)) }
59+
let syncTo = allDisplays.filter { lgDisplayIdentifiers.contains(DisplayIdentifier(vendorNumber: CGDisplayVendorNumber($0), modelNumber: CGDisplayModelNumber($0))) }
6060

6161
syncTimer?.invalidate()
6262

@@ -115,8 +115,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
115115
return Array(onlineDisplays[0..<Int(displayCount)])
116116
}
117117

118-
static func getConnectedUltraFineDisplaySerialNumbers() -> Set<uint32> {
119-
var ultraFineDisplays = Set<uint32>()
118+
static func getConnectedUltraFineDisplayIdentifiers() -> Set<DisplayIdentifier> {
119+
var ultraFineDisplays = Set<DisplayIdentifier>()
120120

121121
for displayInfo in getDisplayInfoDictionaries() {
122122
if
@@ -125,10 +125,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
125125
{
126126
if
127127
displayName.contains("LG UltraFine"),
128-
let serialNumber = displayInfo[kDisplaySerialNumber] as? UInt32
128+
let vendorNumber = displayInfo[kDisplayVendorID] as? UInt32,
129+
let modelNumber = displayInfo[kDisplayProductID] as? UInt32
129130
{
130131
os_log("Found compatible display: %{public}@", displayName)
131-
ultraFineDisplays.insert(serialNumber)
132+
ultraFineDisplays.insert(DisplayIdentifier(vendorNumber: vendorNumber, modelNumber: modelNumber))
132133
}
133134
else {
134135
os_log("Found incompatible display: %{public}@", displayName)
@@ -190,4 +191,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
190191
@objc func checkForUpdates() {
191192
NSWorkspace.shared.open(URL(string: "https://github.com/OCJvanDijk/Brightness-Sync/releases")!)
192193
}
194+
195+
struct DisplayIdentifier: Hashable {
196+
let vendorNumber: UInt32
197+
let modelNumber: UInt32
198+
}
193199
}

Brightness Sync/Info.plist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>LSUIElement</key>
6-
<true/>
75
<key>CFBundleDevelopmentRegion</key>
86
<string>$(DEVELOPMENT_LANGUAGE)</string>
97
<key>CFBundleExecutable</key>
@@ -19,11 +17,13 @@
1917
<key>CFBundlePackageType</key>
2018
<string>APPL</string>
2119
<key>CFBundleShortVersionString</key>
22-
<string>1.0.5</string>
20+
<string>1.0.6</string>
2321
<key>CFBundleVersion</key>
24-
<string>1.0.5</string>
22+
<string>1.0.6</string>
2523
<key>LSMinimumSystemVersion</key>
2624
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
25+
<key>LSUIElement</key>
26+
<true/>
2727
<key>NSHumanReadableCopyright</key>
2828
<string>Copyright © 2019 Onne van Dijk.</string>
2929
<key>NSPrincipalClass</key>

0 commit comments

Comments
 (0)