brightness: debounce ddc changes
This commit is contained in:
parent
f2464fd414
commit
67d229c702
1 changed files with 14 additions and 0 deletions
|
|
@ -86,6 +86,7 @@ Singleton {
|
||||||
readonly property string busNum: root.ddcMonitors.find(m => m.model === modelData.model)?.busNum ?? ""
|
readonly property string busNum: root.ddcMonitors.find(m => m.model === modelData.model)?.busNum ?? ""
|
||||||
readonly property bool isAppleDisplay: root.appleDisplayPresent && modelData.model.startsWith("StudioDisplay")
|
readonly property bool isAppleDisplay: root.appleDisplayPresent && modelData.model.startsWith("StudioDisplay")
|
||||||
property real brightness
|
property real brightness
|
||||||
|
property real queuedBrightness
|
||||||
|
|
||||||
readonly property Process initProc: Process {
|
readonly property Process initProc: Process {
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
|
|
@ -101,11 +102,22 @@ Singleton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readonly property Timer timer: Timer {
|
||||||
|
interval: 500
|
||||||
|
onTriggered: monitor.setBrightness(monitor.queuedBrightness)
|
||||||
|
}
|
||||||
|
|
||||||
function setBrightness(value: real): void {
|
function setBrightness(value: real): void {
|
||||||
value = Math.max(0, Math.min(1, value));
|
value = Math.max(0, Math.min(1, value));
|
||||||
const rounded = Math.round(value * 100);
|
const rounded = Math.round(value * 100);
|
||||||
if (Math.round(brightness * 100) === rounded)
|
if (Math.round(brightness * 100) === rounded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (isDdc && timer.running) {
|
||||||
|
queuedBrightness = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
brightness = value;
|
brightness = value;
|
||||||
|
|
||||||
if (isAppleDisplay)
|
if (isAppleDisplay)
|
||||||
|
|
@ -114,6 +126,8 @@ Singleton {
|
||||||
Quickshell.execDetached(["ddcutil", "-b", busNum, "setvcp", "10", rounded]);
|
Quickshell.execDetached(["ddcutil", "-b", busNum, "setvcp", "10", rounded]);
|
||||||
else
|
else
|
||||||
Quickshell.execDetached(["brightnessctl", "s", `${rounded}%`]);
|
Quickshell.execDetached(["brightnessctl", "s", `${rounded}%`]);
|
||||||
|
|
||||||
|
timer.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
function initBrightness(): void {
|
function initBrightness(): void {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue