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; return;
} }
const ddcciDevices = await readdir('/dev/bus/ddcci'); /** @param {string | null} device
console.log(`Found ddcci devices: ${ddcciDevices}`); * @param {number} externalBrightness
*/
for (const device of ddcciDevices) { const setDdcciBrightness = async function (device, externalBrightness) {
let deviceName = device !== null ? `device ${device}` : 'all devices';
console.log( console.log(
`Setting external monitor brightness to ${externalBrightness} for device ${device}`, `Setting external monitor brightness to ${externalBrightness} for ${deviceName}`,
); );
await execFileP('ddcutil', [ await execFileP('ddcutil', [
`--bus`, ...(device !== null ? [`--bus`, device] : []),
device, ...[`--sleep-multiplier`, '0.20', `setvcp`, `0x10`, `${externalBrightness}`],
`--sleep-multiplier`,
'0.20',
`setvcp`,
`0x10`,
`${externalBrightness}`,
]).catch(err => { ]).catch(err => {
/** @type {string} */ /** @type {string} */
let stdout = err.stdout; let stdout = err.stdout;
// err.stdout contains "No monitor detected on bus" // err.stdout contains "No monitor detected on bus"
if (stdout.includes('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; 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) { if (nextBrightness !== externalBrightness) {