Skip to content

Commit 08c41c1

Browse files
authored
Fixing software dimming and custom keyboard issues (MonitorControl#671)
* Change icon order * Added option for minimum brightness, fixed text for external display brightness control (+ updated all translations) * Fix cumulative darkening issue upon toggling Disable dimming as fallback when software brightness is not 100% * Further improvement. * New 'Avoid gammatable manipulation' option for coexistence with f.lux in software mode. * Fix some translation errors * Fix signing * Make sure that key repeat speed for custom shortcuts do not go below a certain threshold.
1 parent 6bd775b commit 08c41c1

40 files changed

+406
-118
lines changed

MonitorControl/Enums/PrefKey.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ enum PrefKey: String {
2222
// DDC polling count for display
2323
case pollingCount
2424

25+
// Display should avoid gamma table manipulation and use shades instead (to coexist with other apps doing gamma manipulation)
26+
case avoidGamma
27+
2528
// Command value display
2629
case value
2730

@@ -127,6 +130,9 @@ enum PrefKey: String {
127130
// Change Brightness for all screens
128131
case allScreensBrightness
129132

133+
// Allow zero software brightness
134+
case allowZeroSwBrightness
135+
130136
// Use focus instead of mouse position to determine which display to control for brightness
131137
case useFocusInsteadOfMouse
132138

MonitorControl/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>$(MARKETING_VERSION)</string>
2121
<key>CFBundleVersion</key>
22-
<string>6395</string>
22+
<string>6421</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.utilities</string>
2525
<key>LSMinimumSystemVersion</key>

MonitorControl/Model/Display.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class Display: Equatable {
191191
}
192192

193193
func swBrightnessTransform(value: Float, reverse: Bool = false) -> Float {
194-
let lowTreshold: Float = 0.0 // If we don't want to allow zero brightness for safety reason, this value can be modified (for example to 0.1 for a 10% minimum)
194+
let lowTreshold: Float = prefs.bool(forKey: PrefKey.allowZeroSwBrightness.rawValue) ? 0.0 : 0.15
195195
if !reverse {
196196
return value * (1 - lowTreshold) + lowTreshold
197197
} else {
@@ -214,7 +214,7 @@ class Display: Equatable {
214214
guard app.reconfigureID == 0 else {
215215
return
216216
}
217-
if self.isVirtual {
217+
if self.isVirtual || self.readPrefAsBool(key: .avoidGamma) {
218218
_ = DisplayManager.shared.setShadeAlpha(value: 1 - transientValue, displayID: self.identifier)
219219
} else {
220220
let gammaTableRed = self.defaultGammaTableRed.map { $0 * transientValue }
@@ -227,8 +227,8 @@ class Display: Equatable {
227227
self.swBrightnessSemaphore.signal()
228228
}
229229
} else {
230-
if self.isVirtual {
231-
return DisplayManager.shared.setShadeAlpha(value: 1 - value, displayID: self.identifier)
230+
if self.isVirtual || self.readPrefAsBool(key: .avoidGamma) {
231+
return DisplayManager.shared.setShadeAlpha(value: 1 - newValue, displayID: self.identifier)
232232
} else {
233233
let gammaTableRed = self.defaultGammaTableRed.map { $0 * newValue }
234234
let gammaTableGreen = self.defaultGammaTableGreen.map { $0 * newValue }
@@ -242,8 +242,9 @@ class Display: Equatable {
242242
}
243243

244244
func getSwBrightness() -> Float {
245-
if self.isVirtual {
246-
return 1 - (DisplayManager.shared.getShadeAlpha(displayID: self.identifier) ?? 1)
245+
if self.isVirtual || self.readPrefAsBool(key: .avoidGamma) {
246+
let rawBrightnessValue = 1 - (DisplayManager.shared.getShadeAlpha(displayID: self.identifier) ?? 1)
247+
return self.swBrightnessTransform(value: rawBrightnessValue, reverse: true)
247248
}
248249
var gammaTableRed = [CGGammaValue](repeating: 0, count: 256)
249250
var gammaTableGreen = [CGGammaValue](repeating: 0, count: 256)

MonitorControl/Model/OtherDisplay.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ class OtherDisplay: Display {
7676
func setupCurrentAndMaxValues(command: Command, firstrun: Bool = false) {
7777
var ddcValues: (UInt16, UInt16)?
7878
var maxDDCValue = UInt16(DDC_MAX_DETECT_LIMIT)
79-
var currentDDCValue = UInt16(Float(DDC_MAX_DETECT_LIMIT) * 1)
79+
var currentDDCValue: UInt16
80+
switch command {
81+
case .audioSpeakerVolume: currentDDCValue = UInt16(Float(self.DDC_MAX_DETECT_LIMIT) * 0.125)
82+
case .contrast: currentDDCValue = UInt16(Float(self.DDC_MAX_DETECT_LIMIT) * 0.750)
83+
default: currentDDCValue = UInt16(Float(self.DDC_MAX_DETECT_LIMIT) * 1.000)
84+
}
8085
if command == .audioSpeakerVolume {
8186
currentDDCValue = UInt16(Float(self.DDC_MAX_DETECT_LIMIT) * 0.125) // lower default audio value as high volume might rattle the user.
8287
}
@@ -114,7 +119,7 @@ class OtherDisplay: Display {
114119
_ = self.writeDDCValues(command: command, value: currentDDCValue)
115120
}
116121
} else {
117-
self.savePref(max(0.1, self.prefExists(for: command) ? self.readPrefAsFloat(for: command) : Float(1)), for: command)
122+
self.savePref(self.prefExists(for: command) ? self.readPrefAsFloat(for: command) : Float(1), for: command)
118123
self.savePref(self.readPrefAsFloat(for: command), key: .SwBrightness)
119124
self.brightnessSyncSourceValue = self.readPrefAsFloat(for: command)
120125
self.smoothBrightnessTransient = self.readPrefAsFloat(for: command)

MonitorControl/Support/KeyboardShortcutsManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class KeyboardShortcutsManager {
5656
}
5757

5858
func engage(_ shortcut: KeyboardShortcuts.Name) {
59-
self.initialKeyRepeat = UserDefaults.standard.double(forKey: "InitialKeyRepeat") * 0.014
60-
self.keyRepeat = UserDefaults.standard.double(forKey: "KeyRepeat") * 0.014
59+
self.initialKeyRepeat = max(15, UserDefaults.standard.double(forKey: "InitialKeyRepeat")) * 0.014
60+
self.keyRepeat = max(2, UserDefaults.standard.double(forKey: "KeyRepeat")) * 0.014
6161
self.currentCommand = shortcut
6262
self.isFirstKeypress = true
6363
self.isHold = true

0 commit comments

Comments
 (0)