From a872682eb877ddef58b46e52153a911c08a9b07e Mon Sep 17 00:00:00 2001 From: ItsLemmy Date: Wed, 17 Sep 2025 00:28:57 -0400 Subject: [PATCH] Brightness: fix #300 --- Services/BrightnessService.qml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Services/BrightnessService.qml b/Services/BrightnessService.qml index 923c20e9..c13221a3 100644 --- a/Services/BrightnessService.qml +++ b/Services/BrightnessService.qml @@ -197,9 +197,12 @@ Singleton { } } + readonly property real stepSize: Settings.data.brightness.brightnessStep / 100.0 + + // Timer for debouncing rapid changes readonly property Timer timer: Timer { - interval: 200 + interval: 100 onTriggered: { if (!isNaN(monitor.queuedBrightness)) { monitor.setBrightness(monitor.queuedBrightness) @@ -208,14 +211,19 @@ Singleton { } } + function setBrightnessDebounced(value: real): void { + monitor.queuedBrightness = value + timer.start() + } + function increaseBrightness(): void { - var stepSize = Settings.data.brightness.brightnessStep / 100.0 - setBrightnessDebounced(monitor.brightness + stepSize) + const value = !isNaN(monitor.queuedBrightness) ? monitor.queuedBrightness : monitor.brightness + setBrightnessDebounced(value + stepSize) } function decreaseBrightness(): void { - var stepSize = Settings.data.brightness.brightnessStep / 100.0 - setBrightnessDebounced(monitor.brightness - stepSize) + const value = !isNaN(monitor.queuedBrightness) ? monitor.queuedBrightness : monitor.brightness + setBrightnessDebounced(value - stepSize) } function setBrightness(value: real): void { @@ -225,7 +233,7 @@ Singleton { if (Math.round(monitor.brightness * 100) === rounded) return - if (isDdc && timer.running) { + if (timer.running) { monitor.queuedBrightness = value return } @@ -247,11 +255,6 @@ Singleton { } } - function setBrightnessDebounced(value: real): void { - monitor.queuedBrightness = value - timer.restart() - } - function initBrightness(): void { if (isAppleDisplay) { initProc.command = ["asdbctl", "get"]