fix(users/Profpatsch/alacritty): work around missing /etc/bus/ddcci

For some reason the driver does not mount the bus sometimes, in that
case just call the tool directly without a specific bus, so we get at
least some sort of brightness adjustment (lol).

Change-Id: Ie8fe8c500fb1025609b569715e681e053e6e06ed
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12909
Reviewed-by: Profpatsch <mail@profpatsch.de>
Tested-by: BuildkiteCI
This commit is contained in:
Profpatsch 2024-12-25 17:36:39 +01:00
parent 3bd43e39dd
commit bcaf9c6074

View file

@ -837,32 +837,40 @@ async function onDdcutilBrightnessChange(externalBrightness) {
return;
}
const ddcciDevices = await readdir('/dev/bus/ddcci');
console.log(`Found ddcci devices: ${ddcciDevices}`);
for (const device of ddcciDevices) {
/** @param {string | null} device
* @param {number} externalBrightness
*/
const setDdcciBrightness = async function (device, externalBrightness) {
let deviceName = device !== null ? `device ${device}` : 'all devices';
console.log(
`Setting external monitor brightness to ${externalBrightness} for device ${device}`,
`Setting external monitor brightness to ${externalBrightness} for ${deviceName}`,
);
await execFileP('ddcutil', [
`--bus`,
device,
`--sleep-multiplier`,
'0.20',
`setvcp`,
`0x10`,
`${externalBrightness}`,
...(device !== null ? [`--bus`, device] : []),
...[`--sleep-multiplier`, '0.20', `setvcp`, `0x10`, `${externalBrightness}`],
]).catch(err => {
/** @type {string} */
let stdout = err.stdout;
// err.stdout contains "No monitor detected on bus"
if (stdout.includes('No monitor detected on bus')) {
console.log(`External monitor on bus ${device} is gone, ignoring.`);
console.log(`External monitor on bus ${deviceName} is gone, ignoring.`);
return;
}
console.warn(`Error setting brightness with ddcutil for device ${device}`, err);
console.warn(`Error setting brightness with ddcutil for ${deviceName}`, err);
});
};
const ddcciDevices = await readdir('/dev/bus/ddcci').catch(err => ({ err: err }));
if ('err' in ddcciDevices) {
console.warn('Error reading /dev/bus/ddcci', ddcciDevices.err);
console.log('Trying to set external brightness without knowing the device');
await setDdcciBrightness(null, externalBrightness);
} else {
console.log(`Found ddcci devices: ${ddcciDevices}`);
for (const device of ddcciDevices) {
await setDdcciBrightness(device, externalBrightness);
}
}
if (nextBrightness !== externalBrightness) {