Skip to content

Commit

Permalink
More robust LG UltraFine detection
Browse files Browse the repository at this point in the history
  • Loading branch information
OCJvanDijk committed Jul 3, 2019
1 parent 99f3b28 commit 79999ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 12 additions & 6 deletions Brightness Sync/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
os_log("Starting display refresh...")

let allDisplays = AppDelegate.getAllDisplays()
let lgDisplaySerialNumbers = AppDelegate.getConnectedUltraFineDisplaySerialNumbers()
let lgDisplayIdentifiers = AppDelegate.getConnectedUltraFineDisplayIdentifiers()

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

syncTimer?.invalidate()

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

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

for displayInfo in getDisplayInfoDictionaries() {
if
Expand All @@ -125,10 +125,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
{
if
displayName.contains("LG UltraFine"),
let serialNumber = displayInfo[kDisplaySerialNumber] as? UInt32
let vendorNumber = displayInfo[kDisplayVendorID] as? UInt32,
let modelNumber = displayInfo[kDisplayProductID] as? UInt32
{
os_log("Found compatible display: %{public}@", displayName)
ultraFineDisplays.insert(serialNumber)
ultraFineDisplays.insert(DisplayIdentifier(vendorNumber: vendorNumber, modelNumber: modelNumber))
}
else {
os_log("Found incompatible display: %{public}@", displayName)
Expand Down Expand Up @@ -190,4 +191,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@objc func checkForUpdates() {
NSWorkspace.shared.open(URL(string: "https://github.com/OCJvanDijk/Brightness-Sync/releases")!)
}

struct DisplayIdentifier: Hashable {
let vendorNumber: UInt32
let modelNumber: UInt32
}
}
8 changes: 4 additions & 4 deletions Brightness Sync/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSUIElement</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand All @@ -19,11 +17,13 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.5</string>
<string>1.0.6</string>
<key>CFBundleVersion</key>
<string>1.0.5</string>
<string>1.0.6</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2019 Onne van Dijk.</string>
<key>NSPrincipalClass</key>
Expand Down

0 comments on commit 79999ed

Please sign in to comment.