brightness: delay setting for ddc monitors (#2022)

This commit is contained in:
end-4
2025-09-20 10:37:24 +02:00
parent ed8e4b8766
commit b9ae5cafa0
+17 -6
View File
@@ -103,16 +103,27 @@ Singleton {
} }
} }
function setBrightness(value: real): void { // We need a delay for DDC monitors because they can be quite slow and might act weird with rapid changes
value = Math.max(0.01, Math.min(1, value)); property var setTimer: Timer {
const rounded = Math.round(value * monitor.rawMaxBrightness); id: setTimer
if (Math.round(brightness * monitor.rawMaxBrightness) === rounded) interval: monitor.isDdc ? 300 : 0
return; onTriggered: {
brightness = value; syncBrightness();
}
}
function syncBrightness() {
const rounded = Math.round(monitor.brightness * monitor.rawMaxBrightness);
setProc.command = isDdc ? ["ddcutil", "-b", busNum, "setvcp", "10", rounded] : ["brightnessctl", "s", rounded, "--quiet"]; setProc.command = isDdc ? ["ddcutil", "-b", busNum, "setvcp", "10", rounded] : ["brightnessctl", "s", rounded, "--quiet"];
setProc.startDetached(); setProc.startDetached();
} }
function setBrightness(value: real): void {
value = Math.max(0.01, Math.min(1, value));
monitor.brightness = value;
setTimer.restart();
}
Component.onCompleted: { Component.onCompleted: {
initialize(); initialize();
} }