mirror of
https://github.com/MonitorControl/MonitorControl.git
synced 2026-06-03 06:02:21 -06:00
Improved software dimming
This commit is contained in:
parent
f598ff6982
commit
2dd284370b
6 changed files with 45 additions and 14 deletions
|
|
@ -19,6 +19,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
var accessibilityObserver: NSObjectProtocol!
|
||||
var reconfigureID: Int = 0 // dispatched reconfigure command ID
|
||||
var sleepID: Int = 0 // Don't reconfigure display as the system or display is sleeping or wake just recently.
|
||||
let debugSw: Bool = false
|
||||
lazy var preferencesWindowController: PreferencesWindowController = {
|
||||
let storyboard = NSStoryboard(name: "Main", bundle: Bundle.main)
|
||||
let mainPrefsVc = storyboard.instantiateController(withIdentifier: "MainPrefsVC") as? MainPrefsViewController
|
||||
|
|
@ -114,7 +115,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
// externalDisplay.arm64ddc = true
|
||||
// }
|
||||
if !serviceMatch.isDiscouraged {
|
||||
externalDisplay.arm64ddc = true // MARK: (point of interest when testing)
|
||||
externalDisplay.arm64ddc = !debugSw ? true : false // MARK: (point of interest when testing)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -182,7 +183,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
}
|
||||
}
|
||||
}
|
||||
if CGDisplayIsBuiltin(onlineDisplayID) != 0 { // MARK: (point of interest for testing)
|
||||
if !debugSw, 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)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2077</string>
|
||||
<string>2156</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class Display {
|
|||
internal var modelNumber: UInt32?
|
||||
internal var isEnabled: Bool {
|
||||
get {
|
||||
return self.prefs.object(forKey: "\(self.identifier)-state") as? Bool ?? true
|
||||
self.prefs.object(forKey: "\(self.identifier)-state") as? Bool ?? true
|
||||
}
|
||||
set {
|
||||
self.prefs.set(newValue, forKey: "\(self.identifier)-state")
|
||||
|
|
@ -69,11 +69,40 @@ class Display {
|
|||
return self.identifier
|
||||
}
|
||||
|
||||
func setSwBrightness(value: UInt8) -> Bool {
|
||||
func swBrightnessTransform(value: Float, reverse: Bool = false) -> Float {
|
||||
let lowTreshold: Float = 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 !reverse {
|
||||
return value * (1 - lowTreshold) + lowTreshold
|
||||
} else {
|
||||
return (value - lowTreshold) / (1 - lowTreshold)
|
||||
}
|
||||
}
|
||||
|
||||
func setSwBrightness(value: UInt8, fast: Bool = false) -> Bool {
|
||||
var redMin: CGGammaValue = 0
|
||||
var redMax: CGGammaValue = 0
|
||||
var redGamma: CGGammaValue = 0
|
||||
var greenMin: CGGammaValue = 0
|
||||
var greenMax: CGGammaValue = 0
|
||||
var greenGamma: CGGammaValue = 0
|
||||
var blueMin: CGGammaValue = 0
|
||||
var blueMax: CGGammaValue = 0
|
||||
var blueGamma: CGGammaValue = 0
|
||||
let brightnessValue: UInt8 = min(getSwMaxBrightness(), value)
|
||||
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 {
|
||||
floatValue = self.swBrightnessTransform(value: floatValue)
|
||||
os_log("setting software brightness to: %{public}@", type: .debug, String(floatValue))
|
||||
if CGGetDisplayTransferByFormula(self.identifier, &redMin, &redMax, &redGamma, &greenMin, &greenMax, &greenGamma, &blueMin, &blueMax, &blueGamma) == CGError.success {
|
||||
if !fast {
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
for value in stride(from: redMax, to: floatValue, by: 0.0025 * (redMax > floatValue ? -1 : 1)) {
|
||||
CGSetDisplayTransferByFormula(self.identifier, 0, value, redGamma, 0, value, greenGamma, 0, value, blueGamma)
|
||||
Thread.sleep(forTimeInterval: 0.001)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
CGSetDisplayTransferByFormula(self.identifier, 0, floatValue, redGamma, 0, floatValue, greenGamma, 0, floatValue, blueGamma)
|
||||
}
|
||||
self.saveSwBirghtnessPrefValue(Int(brightnessValue))
|
||||
return true
|
||||
}
|
||||
|
|
@ -91,7 +120,8 @@ class Display {
|
|||
var blueMax: CGGammaValue = 0
|
||||
var blueGamma: CGGammaValue = 0
|
||||
if CGGetDisplayTransferByFormula(self.identifier, &redMin, &redMax, &redGamma, &greenMin, &greenMax, &greenGamma, &blueMin, &blueMax, &blueGamma) == CGError.success {
|
||||
let brightnessValue = UInt8(min(max(redMax, greenMax, blueMax), 1) * Float(self.getSwMaxBrightness()))
|
||||
let brightnessValue = UInt8(round(swBrightnessTransform(value: max(redMax, greenMax, blueMax), reverse: true) * Float(self.getSwMaxBrightness())))
|
||||
os_log("Current read software brightness is: %{public}@", type: .debug, String(brightnessValue))
|
||||
return brightnessValue
|
||||
}
|
||||
return self.getSwMaxBrightness()
|
||||
|
|
|
|||
|
|
@ -186,13 +186,13 @@ class ExternalDisplay: Display {
|
|||
}
|
||||
|
||||
if swAfterBirghtnessMode {
|
||||
let currentSwBrightness: UInt8 = self.getSwBrightness()
|
||||
let currentSwBrightness = UInt8(self.getSwBrightnessPrefValue())
|
||||
var swBirghtnessValue = self.calcNewValue(currentValue: Int(currentSwBrightness), maxValue: Int(getSwMaxBrightness()), isUp: isUp, isSmallIncrement: isSmallIncrement)
|
||||
if swBirghtnessValue >= Int(getSwMaxBrightness()) {
|
||||
swBirghtnessValue = Int(getSwMaxBrightness())
|
||||
swAfterBirghtnessMode = false
|
||||
}
|
||||
if self.setSwBrightness(value: UInt8(swBirghtnessValue)) {
|
||||
if self.setSwBrightness(value: UInt8(swBirghtnessValue), fast: true) {
|
||||
self.showOsd(command: .brightness, value: self.getValue(for: .brightness), roundChiclet: !isSmallIncrement)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -308,8 +308,8 @@
|
|||
<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" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="COE-Oc-gZs">
|
||||
<rect key="frame" x="0.0" y="0.0" width="691" height="502"/>
|
||||
<view key="view" horizontalHuggingPriority="1" translatesAutoresizingMaskIntoConstraints="NO" id="COE-Oc-gZs">
|
||||
<rect key="frame" x="0.0" y="0.0" width="691" height="500"/>
|
||||
<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="460"/>
|
||||
|
|
@ -589,7 +589,7 @@
|
|||
</viewController>
|
||||
<customObject id="JDw-du-OST" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="300.5" y="-59"/>
|
||||
<point key="canvasLocation" x="300.5" y="-60"/>
|
||||
</scene>
|
||||
<!--Advanced Prefs View Controller-->
|
||||
<scene sceneID="tdo-vT-sVy">
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2077</string>
|
||||
<string>2156</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSBackgroundOnly</key>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue