mirror of
https://github.com/MonitorControl/MonitorControl.git
synced 2026-05-15 14:15:55 -06:00
Fixed contrast slider for brightness change (#132)
- FIXED: Issue where changing brightness back from 0 wouldn’t restore previous contrast value - FIXED: Restoring saved contrast value across app restarts - FIXED: Issue where using the brightness slider wouldn’t adjust contrast - FIXED: Issue where setting brightness to 0 after it was already 0 wouldn’t restore the previous contrast setting
This commit is contained in:
parent
da91d767cf
commit
39f76e5058
2 changed files with 47 additions and 17 deletions
|
|
@ -159,23 +159,8 @@ class Display {
|
|||
func setBrightness(to osdValue: Int) {
|
||||
let ddcValue = UInt16(osdValue)
|
||||
|
||||
if self.prefs.bool(forKey: Utils.PrefKeys.lowerContrast.rawValue) {
|
||||
if ddcValue == 0 {
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
_ = self.ddc?.write(command: .contrast, value: ddcValue)
|
||||
}
|
||||
|
||||
if let slider = contrastSliderHandler?.slider {
|
||||
slider.intValue = Int32(ddcValue)
|
||||
}
|
||||
} else if self.getValue(for: DDC.Command.brightness) == 0 {
|
||||
let contrastValue = self.getValue(for: DDC.Command.contrast)
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
_ = self.ddc?.write(command: .contrast, value: UInt16(contrastValue))
|
||||
}
|
||||
}
|
||||
}
|
||||
// Set the contrast value according to the brightness, if necessary
|
||||
self.setContrastValueForBrightness(osdValue)
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
guard self.ddc?.write(command: .brightness, value: ddcValue) == true else {
|
||||
|
|
@ -192,6 +177,33 @@ class Display {
|
|||
self.saveValue(osdValue, for: .brightness)
|
||||
}
|
||||
|
||||
func setContrastValueForBrightness(_ brightness: Int) {
|
||||
var contrastValue: Int?
|
||||
|
||||
if brightness == 0 {
|
||||
contrastValue = 0
|
||||
|
||||
// Save the current DDC value for contrast so it can be restored, even across app restarts
|
||||
if self.getRestoreValue(for: .contrast) == 0 {
|
||||
self.setRestoreValue(self.getValue(for: .contrast), for: .contrast)
|
||||
}
|
||||
} else if self.getValue(for: .brightness) == 0, brightness > 0 {
|
||||
contrastValue = self.getRestoreValue(for: .contrast)
|
||||
}
|
||||
|
||||
// Only write the new contrast value if lowering contrast after brightness is enabled
|
||||
if contrastValue != nil, self.prefs.bool(forKey: Utils.PrefKeys.lowerContrast.rawValue) {
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
_ = self.ddc?.write(command: .contrast, value: UInt16(contrastValue!))
|
||||
self.saveValue(contrastValue!, for: .contrast)
|
||||
}
|
||||
|
||||
if let slider = contrastSliderHandler?.slider {
|
||||
slider.intValue = Int32(contrastValue!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func readDDCValues(for command: DDC.Command, tries: UInt, minReplyDelay delay: UInt64?) -> (current: UInt16, max: UInt16)? {
|
||||
var values: (UInt16, UInt16)?
|
||||
|
||||
|
|
@ -259,6 +271,14 @@ class Display {
|
|||
return max == 0 ? 100 : max
|
||||
}
|
||||
|
||||
func getRestoreValue(for command: DDC.Command) -> Int {
|
||||
return self.prefs.integer(forKey: "restore-\(command.rawValue)-\(self.identifier)")
|
||||
}
|
||||
|
||||
func setRestoreValue(_ value: Int?, for command: DDC.Command) {
|
||||
self.prefs.set(value, forKey: "restore-\(command.rawValue)-\(self.identifier)")
|
||||
}
|
||||
|
||||
func setFriendlyName(_ value: String) {
|
||||
self.prefs.set(value, forKey: "friendlyName-\(self.identifier)")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,16 @@ class SliderHandler {
|
|||
self.display.toggleMute(fromVolumeSlider: true)
|
||||
}
|
||||
|
||||
// If the command is to adjust brightness, also instruct the display to set the contrast value, if necessary
|
||||
if self.cmd == .brightness {
|
||||
self.display.setContrastValueForBrightness(value)
|
||||
}
|
||||
|
||||
// If the command is to adjust contrast, erase the previous value for the contrast to restore after brightness is increased
|
||||
if self.cmd == .contrast {
|
||||
self.display.setRestoreValue(nil, for: .contrast)
|
||||
}
|
||||
|
||||
_ = self.display.ddc?.write(command: self.cmd, value: UInt16(value))
|
||||
self.display.saveValue(value, for: self.cmd)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue