From 67d229c702a7422b5a996730577ebdb8eef1f8c5 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sat, 26 Jul 2025 13:16:18 +1000 Subject: brightness: debounce ddc changes --- services/Brightness.qml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'services') diff --git a/services/Brightness.qml b/services/Brightness.qml index eab5468..4654996 100644 --- a/services/Brightness.qml +++ b/services/Brightness.qml @@ -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 { -- cgit v1.2.3-freya