forked from Shinonome/dots-hyprland
use the more efficient i2c bus number to control ddcci backlight
This commit is contained in:
@@ -65,12 +65,10 @@ class BrightnessDdcService extends BrightnessServiceBase {
|
|||||||
Service.register(this);
|
Service.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(monitor = 0) {
|
constructor(busNum) {
|
||||||
super();
|
super();
|
||||||
// don't use Hyprland.getMonitor(id), Hyprland monitor id isn't consistent
|
this._busNum = busNum;
|
||||||
// with Gdk, but the Array ordering is (magically)
|
Utils.execAsync(`ddcutil -b ${this._busNum} getvcp 10 --brief`)
|
||||||
this._sn = Hyprland.monitors[monitor].serial;
|
|
||||||
Utils.execAsync(`ddcutil --sn ${this._sn} getvcp 10 --brief`)
|
|
||||||
.then((out) => {
|
.then((out) => {
|
||||||
// only the last line is useful
|
// only the last line is useful
|
||||||
out = out.split('\n');
|
out = out.split('\n');
|
||||||
@@ -85,12 +83,12 @@ class BrightnessDdcService extends BrightnessServiceBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setBrightnessCmd(percent) {
|
setBrightnessCmd(percent) {
|
||||||
return `ddcutil --sn ${this._sn} setvcp 10 ${Math.round(percent * 100)}`;
|
return `ddcutil -b ${this._busNum} setvcp 10 ${Math.round(percent * 100)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function listDdcMonitorsSn() {
|
async function listDdcMonitorsSnBus() {
|
||||||
let ddcSn = [];
|
let ddcSnBus = {};
|
||||||
try {
|
try {
|
||||||
const out = await Utils.execAsync('ddcutil detect --brief');
|
const out = await Utils.execAsync('ddcutil detect --brief');
|
||||||
const displays = out.split('\n\n');
|
const displays = out.split('\n\n');
|
||||||
@@ -100,18 +98,19 @@ async function listDdcMonitorsSn() {
|
|||||||
return;
|
return;
|
||||||
const lines = display.split('\n');
|
const lines = display.split('\n');
|
||||||
const sn = lines[3].split(':')[3];
|
const sn = lines[3].split(':')[3];
|
||||||
ddcSn.push(sn);
|
const busNum = lines[1].split('/dev/i2c-')[1];
|
||||||
|
ddcSnBus[sn] = busNum;
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
print(err);
|
print(err);
|
||||||
}
|
}
|
||||||
return ddcSn;
|
return ddcSnBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Service instance
|
// Service instance
|
||||||
const numMonitors = Hyprland.monitors.length;
|
const numMonitors = Hyprland.monitors.length;
|
||||||
const service = Array(numMonitors);
|
const service = Array(numMonitors);
|
||||||
const ddcSn = await listDdcMonitorsSn();
|
const ddcSnBus = await listDdcMonitorsSnBus();
|
||||||
for (let i = 0; i < service.length; i++) {
|
for (let i = 0; i < service.length; i++) {
|
||||||
const monitorName = Hyprland.monitors[i].name;
|
const monitorName = Hyprland.monitors[i].name;
|
||||||
const monitorSn = Hyprland.monitors[i].serial;
|
const monitorSn = Hyprland.monitors[i].serial;
|
||||||
@@ -123,11 +122,11 @@ for (let i = 0; i < service.length; i++) {
|
|||||||
service[i] = new BrightnessCtlService();
|
service[i] = new BrightnessCtlService();
|
||||||
break;
|
break;
|
||||||
case "ddcutil":
|
case "ddcutil":
|
||||||
service[i] = new BrightnessDdcService(i);
|
service[i] = new BrightnessDdcService(ddcSnBus[monitorSn]);
|
||||||
break;
|
break;
|
||||||
case "auto":
|
case "auto":
|
||||||
if (ddcSn.includes(monitorSn))
|
if (monitorSn in ddcSnBus)
|
||||||
service[i] = new BrightnessDdcService(i);
|
service[i] = new BrightnessDdcService(ddcSnBus[monitorSn]);
|
||||||
else
|
else
|
||||||
service[i] = new BrightnessCtlService();
|
service[i] = new BrightnessCtlService();
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user