brightness: debounce ddc changes

This commit is contained in:
2 * r + 2 * t 2025-07-26 13:16:18 +10:00
parent f2464fd414
commit 67d229c702

View file

@ -86,6 +86,7 @@ Singleton {
readonly property string busNum: root.ddcMonitors.find(m => m.model === modelData.model)?.busNum ?? ""
readonly property bool isAppleDisplay: root.appleDisplayPresent && modelData.model.startsWith("StudioDisplay")
property real brightness
property real queuedBrightness
readonly property Process initProc: Process {
stdout: StdioCollector {
@ -101,11 +102,22 @@ Singleton {
}
}
readonly property Timer timer: Timer {
interval: 500
onTriggered: monitor.setBrightness(monitor.queuedBrightness)
}
function setBrightness(value: real): void {
value = Math.max(0, Math.min(1, value));
const rounded = Math.round(value * 100);
if (Math.round(brightness * 100) === rounded)
return;
if (isDdc && timer.running) {
queuedBrightness = value;
return;
}
brightness = value;
if (isAppleDisplay)
@ -114,6 +126,8 @@ Singleton {
Quickshell.execDetached(["ddcutil", "-b", busNum, "setvcp", "10", rounded]);
else
Quickshell.execDetached(["brightnessctl", "s", `${rounded}%`]);
timer.restart();
}
function initBrightness(): void {