brightness: adjust DDCCI initialize timings

* Delay DDCCI monitor initialization until after `ddcutil detect` to
  ensure `isDdc`, `busNum`, and `ddcMonitors` are properly set.
* Run `ddcutil getvcp` sequentially to avoid failures from concurrent
  executions.
This commit is contained in:
Moeta Yuko
2025-11-24 18:22:36 +00:00
parent 1836a2ff1c
commit 5242373db5
@@ -48,6 +48,16 @@ Singleton {
ddcProc.running = true; ddcProc.running = true;
} }
function initializeMonitor(i: int): void {
if (i >= monitors.length)
return;
monitors[i].initialize();
}
function ddcDetectFinished(): void {
initializeMonitor(0);
}
Process { Process {
id: ddcProc id: ddcProc
@@ -64,7 +74,7 @@ Singleton {
} }
} }
} }
onExited: root.ddcMonitorsChanged() onExited: root.ddcDetectFinished()
} }
Process { Process {
@@ -75,14 +85,8 @@ Singleton {
id: monitor id: monitor
required property ShellScreen screen required property ShellScreen screen
readonly property bool isDdc: { property bool isDdc
const match = root.ddcMonitors.find(m => m.name === screen.name && !root.monitors.slice(0, root.monitors.indexOf(this)).some(mon => mon.busNum === m.busNum)); property string busNum
return !!match;
}
readonly property string busNum: {
const match = root.ddcMonitors.find(m => m.name === screen.name && !root.monitors.slice(0, root.monitors.indexOf(this)).some(mon => mon.busNum === m.busNum));
return match?.busNum ?? "";
}
property int rawMaxBrightness: 100 property int rawMaxBrightness: 100
property real brightness property real brightness
property real brightnessMultiplier: 1.0 property real brightnessMultiplier: 1.0
@@ -110,6 +114,9 @@ Singleton {
function initialize() { function initialize() {
monitor.ready = false; monitor.ready = false;
const match = root.ddcMonitors.find(m => m.name === screen.name && !root.monitors.slice(0, root.monitors.indexOf(this)).some(mon => mon.busNum === m.busNum));
isDdc = !!match;
busNum = match?.busNum ?? "";
initProc.command = isDdc ? ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"] : ["sh", "-c", `echo "a b c $(brightnessctl g) $(brightnessctl m)"`]; initProc.command = isDdc ? ["ddcutil", "-b", busNum, "getvcp", "10", "--brief"] : ["sh", "-c", `echo "a b c $(brightnessctl g) $(brightnessctl m)"`];
initProc.running = true; initProc.running = true;
} }
@@ -123,6 +130,9 @@ Singleton {
monitor.ready = true; monitor.ready = true;
} }
} }
onExited: (exitCode, exitStatus) => {
initializeMonitor(root.monitors.indexOf(monitor) + 1);
}
} }
// We need a delay for DDC monitors because they can be quite slow and might act weird with rapid changes // We need a delay for DDC monitors because they can be quite slow and might act weird with rapid changes
@@ -157,14 +167,6 @@ Singleton {
function setBrightnessMultiplier(value: real): void { function setBrightnessMultiplier(value: real): void {
monitor.brightnessMultiplier = value; monitor.brightnessMultiplier = value;
} }
Component.onCompleted: {
initialize();
}
onBusNumChanged: {
initialize();
}
} }
Component { Component {