Partial fix for incompatibility with Custom ColorSync Profiles.

This commit is contained in:
waydabber 2021-08-13 17:44:27 +02:00
parent 344579ab35
commit ec70bddf53
8 changed files with 62 additions and 39 deletions

View file

@ -60,7 +60,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationWillTerminate(_: Notification) {
os_log("Goodbye!", type: .info)
DisplayManager.shared.resetSwBrightness()
DisplayManager.shared.resetSwBrightnessForAllDisplays()
self.statusItem.isVisible = true
}
@ -114,7 +114,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// externalDisplay.arm64ddc = true
// }
if !serviceMatch.isDiscouraged {
externalDisplay.arm64ddc = true // MARK: (point of interest when testing)
externalDisplay.arm64ddc = false // MARK: (point of interest when testing)
}
}
}
@ -182,7 +182,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}
}
if CGDisplayIsBuiltin(onlineDisplayID) != 0 { // MARK: (point of interest for testing)
if false, CGDisplayIsBuiltin(onlineDisplayID) != 0 { // MARK: (point of interest for testing)
display = InternalDisplay(id, name: name, vendorNumber: vendorNumber, modelNumber: modelNumber, isVirtual: isVirtual)
} else {
display = ExternalDisplay(id, name: name, vendorNumber: vendorNumber, modelNumber: modelNumber, isVirtual: isVirtual)
@ -190,9 +190,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
DisplayManager.shared.addDisplay(display: display)
}
if firstrun {
DisplayManager.shared.resetSwBrightness()
DisplayManager.shared.resetSwBrightnessForAllDisplays(settingsOnly: true)
} else {
DisplayManager.shared.restoreSwBrightness()
if prefs.bool(forKey: Utils.PrefKeys.fallbackSw.rawValue) || prefs.bool(forKey: Utils.PrefKeys.lowerSwAfterBrightness.rawValue) {
DisplayManager.shared.restoreSwBrightnessForAllDisplays()
}
}
self.updateArm64AVServices()
NotificationCenter.default.post(name: Notification.Name(Utils.PrefKeys.displayListUpdate.rawValue), object: nil)
@ -422,7 +424,6 @@ extension AppDelegate: MediaKeyTapDelegate {
}
@objc func handleFallbackSwChanged() {
DisplayManager.shared.resetSwBrightness()
self.updateDisplays()
}
@ -432,10 +433,13 @@ extension AppDelegate: MediaKeyTapDelegate {
@objc func handlePreferenceReset() {
os_log("Resetting all preferences.")
if prefs.bool(forKey: Utils.PrefKeys.fallbackSw.rawValue) || prefs.bool(forKey: Utils.PrefKeys.lowerSwAfterBrightness.rawValue) {
DisplayManager.shared.resetSwBrightnessForAllDisplays()
}
if let bundleID = Bundle.main.bundleIdentifier {
UserDefaults.standard.removePersistentDomain(forName: bundleID)
}
DisplayManager.shared.resetSwBrightness()
app.statusItem.isVisible = true
self.setDefaultPrefs()
self.checkPermissions()
self.updateMediaKeyTap()

View file

@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1980</string>
<string>2075</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
@ -33,4 +33,4 @@
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
</plist>

View file

@ -71,10 +71,12 @@ class DisplayManager {
self.displays = []
}
func resetSwBrightness() {
func resetSwBrightnessForAllDisplays(settingsOnly: Bool = false) {
for externalDisplay in self.getNonVirtualExternalDisplays() {
guard externalDisplay.setSwBrightness(value: externalDisplay.getSwMaxBrightness()) else {
continue
if !settingsOnly {
_ = externalDisplay.setSwBrightness(value: externalDisplay.getSwMaxBrightness())
} else {
externalDisplay.saveSwBirghtnessPrefValue(Int(externalDisplay.getSwMaxBrightness()))
}
if externalDisplay.isSw() {
externalDisplay.saveValue(Int(externalDisplay.getSwMaxBrightness()), for: .brightness)
@ -82,7 +84,7 @@ class DisplayManager {
}
}
func restoreSwBrightness() {
func restoreSwBrightnessForAllDisplays() {
for externalDisplay in self.getExternalDisplays() {
if externalDisplay.getValue(for: .brightness) == 0 || externalDisplay.isSw() {
// Out of caution we won't let it restore to complete darkness, not to interfere with login, etc. This is how Apple devices work as well.

View file

@ -71,7 +71,8 @@ class Display {
func setSwBrightness(value: UInt8) -> Bool {
let brightnessValue: UInt8 = min(getSwMaxBrightness(), value)
let floatValue = Float(Float(brightnessValue) / Float(self.getSwMaxBrightness()))
var floatValue = Float(Float(brightnessValue) / Float(self.getSwMaxBrightness()))
floatValue = floatValue * 0.95 + 0.05 // We don't allow decrease lower than 5% for safety reasons and because some displays blank off after a while on full screen black
if CGSetDisplayTransferByFormula(self.identifier, 0, floatValue, 1, 0, floatValue, 1, 0, floatValue, 1) == CGError.success {
self.saveSwBirghtnessPrefValue(Int(brightnessValue))
return true
@ -96,6 +97,10 @@ class Display {
return self.getSwMaxBrightness()
}
func resetSwBrightness() -> Bool {
return self.setSwBrightness(value: self.getSwMaxBrightness())
}
func saveSwBirghtnessPrefValue(_ value: Int) {
self.prefs.set(value, forKey: "SwBrightness-\(self.identifier)")
}

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="19150" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19150"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@ -301,17 +302,17 @@
</viewController>
<customObject id="34q-0u-YTQ" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="301" y="367"/>
<point key="canvasLocation" x="301" y="529"/>
</scene>
<!--Main Prefs View Controller-->
<scene sceneID="zAg-r8-WQ5">
<objects>
<viewController storyboardIdentifier="MainPrefsVC" id="BGD-tY-Myx" customClass="MainPrefsViewController" customModule="MonitorControl" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" horizontalHuggingPriority="1" translatesAutoresizingMaskIntoConstraints="NO" id="COE-Oc-gZs">
<rect key="frame" x="0.0" y="0.0" width="691" height="452"/>
<view key="view" horizontalHuggingPriority="1" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="COE-Oc-gZs">
<rect key="frame" x="0.0" y="0.0" width="691" height="502"/>
<subviews>
<gridView xPlacement="leading" yPlacement="fill" rowAlignment="none" rowSpacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="noT-gJ-0yS">
<rect key="frame" x="20" y="20" width="651" height="412"/>
<rect key="frame" x="20" y="20" width="651" height="460"/>
<rows>
<gridRow bottomPadding="-5" id="d70-FX-dma"/>
<gridRow bottomPadding="-10" id="QQ6-z4-SQj"/>
@ -324,6 +325,7 @@
<gridRow bottomPadding="-10" id="xlB-05-nd7"/>
<gridRow bottomPadding="-10" id="fnu-hr-lg2"/>
<gridRow bottomPadding="-5" id="fZn-VF-HKh"/>
<gridRow id="hKt-Zi-ARh"/>
<gridRow height="2" bottomPadding="-5" id="gGa-4U-s7D"/>
<gridRow height="16" bottomPadding="-10" id="g3B-cE-vmT"/>
<gridRow bottomPadding="-5" id="Unk-I5-6mY"/>
@ -336,7 +338,7 @@
<gridCells>
<gridCell row="d70-FX-dma" column="eHC-Ur-UsS" xPlacement="trailing" id="ixb-6N-RsC">
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="HkH-iv-GLz">
<rect key="frame" x="152" y="396" width="76" height="16"/>
<rect key="frame" x="152" y="444" width="76" height="16"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" baseWritingDirection="leftToRight" alignment="right" title="Application:" id="okD-DG-pYa">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -346,7 +348,7 @@
</gridCell>
<gridCell row="d70-FX-dma" column="64O-72-10l" xPlacement="leading" id="v0S-4P-60y">
<button key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9Gu-aU-Td2">
<rect key="frame" x="235" y="395" width="108" height="18"/>
<rect key="frame" x="235" y="443" width="108" height="18"/>
<buttonCell key="cell" type="check" title="Start at Login" bezelStyle="regularSquare" imagePosition="left" inset="2" id="j72-NF-zsW">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@ -359,7 +361,7 @@
<gridCell row="QQ6-z4-SQj" column="eHC-Ur-UsS" xPlacement="trailing" id="Kx3-tx-tfm"/>
<gridCell row="QQ6-z4-SQj" column="64O-72-10l" id="okK-xx-Dxu">
<button key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="mvI-eU-qF0">
<rect key="frame" x="235" y="364" width="416" height="18"/>
<rect key="frame" x="235" y="412" width="416" height="18"/>
<buttonCell key="cell" type="check" title="Hide Menu Icon" bezelStyle="regularSquare" imagePosition="left" inset="2" id="aXL-i8-S6R">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@ -372,7 +374,7 @@
<gridCell row="SYZ-Ci-NFT" column="eHC-Ur-UsS" xPlacement="trailing" id="2pd-qA-kLg"/>
<gridCell row="SYZ-Ci-NFT" column="64O-72-10l" id="KSN-i7-5AM">
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9JI-rw-5OZ">
<rect key="frame" x="235" y="342" width="418" height="13"/>
<rect key="frame" x="235" y="390" width="418" height="13"/>
<textFieldCell key="cell" controlSize="small" lineBreakMode="clipping" title="If the menu item is hidden, just relaunch the app to reveal Preferences!" id="PVE-y7-zIk">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
@ -382,13 +384,13 @@
</gridCell>
<gridCell row="kq5-g8-wyx" column="eHC-Ur-UsS" headOfMergedCell="Mt2-uw-XYS" id="Mt2-uw-XYS">
<box key="contentView" autoresizesSubviews="NO" horizontalHuggingPriority="1" verticalHuggingPriority="750" horizontalCompressionResistancePriority="1000" placeholderIntrinsicWidth="651" placeholderIntrinsicHeight="2" verifyAmbiguity="off" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="Hy5-8z-HH1">
<rect key="frame" x="0.0" y="318" width="651" height="6"/>
<rect key="frame" x="0.0" y="366" width="651" height="6"/>
</box>
</gridCell>
<gridCell row="kq5-g8-wyx" column="64O-72-10l" headOfMergedCell="Mt2-uw-XYS" id="G91-kj-yti"/>
<gridCell row="sTd-j8-JBA" column="eHC-Ur-UsS" xPlacement="trailing" id="Lmh-9O-zi6">
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="hSH-na-AhI">
<rect key="frame" x="130" y="289" width="98" height="16"/>
<rect key="frame" x="130" y="337" width="98" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Menu contents:" id="MJx-MK-e7D">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -398,7 +400,7 @@
</gridCell>
<gridCell row="sTd-j8-JBA" column="64O-72-10l" id="DbJ-oq-2oU">
<button key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="jiL-N0-OxS">
<rect key="frame" x="235" y="288" width="416" height="18"/>
<rect key="frame" x="235" y="336" width="416" height="18"/>
<buttonCell key="cell" type="check" title="Show volume slider in menu" bezelStyle="regularSquare" imagePosition="left" inset="2" id="dhP-eB-1L6">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@ -411,7 +413,7 @@
<gridCell row="ndw-Bq-1vH" column="eHC-Ur-UsS" xPlacement="trailing" id="XyP-dx-B3A"/>
<gridCell row="ndw-Bq-1vH" column="64O-72-10l" xPlacement="leading" id="AlB-kz-Uue">
<button key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="xGa-qG-9ut">
<rect key="frame" x="235" y="252" width="202" height="18"/>
<rect key="frame" x="235" y="300" width="202" height="18"/>
<buttonCell key="cell" type="check" title="Show contrast slider in menu" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="xSI-8W-Xd0">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@ -423,13 +425,13 @@
</gridCell>
<gridCell row="CrM-x5-re7" column="eHC-Ur-UsS" headOfMergedCell="UBc-A2-Il4" id="UBc-A2-Il4">
<box key="contentView" autoresizesSubviews="NO" horizontalHuggingPriority="1" verticalHuggingPriority="750" horizontalCompressionResistancePriority="1000" placeholderIntrinsicWidth="651" placeholderIntrinsicHeight="2" verifyAmbiguity="off" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="YEg-U6-LH4">
<rect key="frame" x="0.0" y="234" width="651" height="6"/>
<rect key="frame" x="0.0" y="282" width="651" height="6"/>
</box>
</gridCell>
<gridCell row="CrM-x5-re7" column="64O-72-10l" headOfMergedCell="UBc-A2-Il4" id="s0l-Gz-1c0"/>
<gridCell row="DnA-aR-kcy" column="eHC-Ur-UsS" xPlacement="trailing" id="vO3-t1-Aqs">
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="zi2-7o-qA0">
<rect key="frame" x="109" y="205" width="119" height="16"/>
<rect key="frame" x="109" y="253" width="119" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="right" title="Brightness control:" id="hdd-Zz-buN">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -439,8 +441,8 @@
</gridCell>
<gridCell row="DnA-aR-kcy" column="64O-72-10l" id="Srb-mF-ZHj">
<button key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="IDx-gH-haW">
<rect key="frame" x="235" y="204" width="416" height="18"/>
<buttonCell key="cell" type="check" title="Fallback to software dimming if required" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="kMa-3q-udl">
<rect key="frame" x="235" y="252" width="416" height="18"/>
<buttonCell key="cell" type="check" title="Fallback to software dimming if required" bezelStyle="regularSquare" imagePosition="left" inset="2" id="kMa-3q-udl">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
@ -452,7 +454,7 @@
<gridCell row="xlB-05-nd7" column="eHC-Ur-UsS" id="A6K-rU-q8d"/>
<gridCell row="xlB-05-nd7" column="64O-72-10l" id="3by-qE-2cw">
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Bl8-vV-CVn">
<rect key="frame" x="235" y="167" width="418" height="28"/>
<rect key="frame" x="235" y="215" width="418" height="28"/>
<textFieldCell key="cell" controlSize="small" title="If an external display can't be controlled, software dimming will be used instead." id="n4V-jQ-1Ri">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
@ -463,7 +465,7 @@
<gridCell row="fnu-hr-lg2" column="eHC-Ur-UsS" xPlacement="trailing" id="7Br-bw-2Th"/>
<gridCell row="fnu-hr-lg2" column="64O-72-10l" xPlacement="leading" id="VsI-fh-hJ5">
<button key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="i5K-Cd-wxm">
<rect key="frame" x="235" y="140" width="307" height="18"/>
<rect key="frame" x="235" y="188" width="307" height="18"/>
<buttonCell key="cell" type="check" title="Further lower brightness via software dimming" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="fhy-Er-0aI">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@ -476,7 +478,7 @@
<gridCell row="fZn-VF-HKh" column="eHC-Ur-UsS" xPlacement="trailing" id="4xt-0S-gdo"/>
<gridCell row="fZn-VF-HKh" column="64O-72-10l" xPlacement="leading" id="CMT-YB-Lnh">
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" placeholderIntrinsicWidth="400" placeholderIntrinsicHeight="28" preferredMaxLayoutWidth="400" translatesAutoresizingMaskIntoConstraints="NO" id="XMe-OL-ELb">
<rect key="frame" x="235" y="103" width="404" height="28"/>
<rect key="frame" x="235" y="151" width="404" height="28"/>
<textFieldCell key="cell" controlSize="small" title="This lets you further lower brightness via software dimming even after display has reached zero brightness." id="yeg-GN-SuO">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
@ -484,6 +486,17 @@
</textFieldCell>
</textField>
</gridCell>
<gridCell row="hKt-Zi-ARh" column="eHC-Ur-UsS" id="3OM-jW-1Kg"/>
<gridCell row="hKt-Zi-ARh" column="64O-72-10l" id="0ZZ-ZJ-Sry">
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gpq-uh-XWx">
<rect key="frame" x="235" y="108" width="418" height="28"/>
<textFieldCell key="cell" controlSize="small" title="Please be aware that both of these features are currently incompatible with custom ColorSync Display Calibration Profiles!" id="3BD-NN-46v">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</gridCell>
<gridCell row="gGa-4U-s7D" column="eHC-Ur-UsS" headOfMergedCell="hH2-hj-VXr" id="hH2-hj-VXr">
<box key="contentView" autoresizesSubviews="NO" horizontalHuggingPriority="1" verticalHuggingPriority="750" horizontalCompressionResistancePriority="1000" placeholderIntrinsicWidth="651" placeholderIntrinsicHeight="2" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="zA4-hk-MYo">
<rect key="frame" x="0.0" y="84" width="651" height="6"/>
@ -576,7 +589,7 @@
</viewController>
<customObject id="JDw-du-OST" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="300.5" y="-73"/>
<point key="canvasLocation" x="300.5" y="-59"/>
</scene>
<!--Advanced Prefs View Controller-->
<scene sceneID="tdo-vT-sVy">

View file

@ -51,8 +51,6 @@ class AdvancedPrefsViewController: NSViewController, PreferencePane, NSTableView
if let window = self.view.window {
alert.beginSheetModal(for: window, completionHandler: { modalResponse in
if modalResponse == NSApplication.ModalResponse.alertFirstButtonReturn {
DisplayManager.shared.resetSwBrightness()
app.statusItem.isVisible = true
NotificationCenter.default.post(name: Notification.Name(Utils.PrefKeys.preferenceReset.rawValue), object: nil)
}
})

View file

@ -119,7 +119,7 @@ class MainPrefsViewController: NSViewController, PreferencePane {
self.prefs.set(true, forKey: Utils.PrefKeys.lowerSwAfterBrightness.rawValue)
case .off:
self.prefs.set(false, forKey: Utils.PrefKeys.lowerSwAfterBrightness.rawValue)
DisplayManager.shared.resetSwBrightness()
DisplayManager.shared.resetSwBrightnessForAllDisplays()
default: break
}
#if DEBUG
@ -133,6 +133,7 @@ class MainPrefsViewController: NSViewController, PreferencePane {
self.prefs.set(true, forKey: Utils.PrefKeys.fallbackSw.rawValue)
case .off:
self.prefs.set(false, forKey: Utils.PrefKeys.fallbackSw.rawValue)
DisplayManager.shared.resetSwBrightnessForAllDisplays()
default: break
}
#if DEBUG

View file

@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1980</string>
<string>2075</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSBackgroundOnly</key>
@ -33,4 +33,4 @@
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
</plist>