brightness controller: per-name config; add "auto"

This commit is contained in:
end-4
2024-05-01 22:32:04 +07:00
parent 2f3ed21a03
commit f0782d23aa
2 changed files with 32 additions and 12 deletions
@@ -39,7 +39,14 @@ let configOptions = {
'warnMessages': ["Plug in the charger", "You there?", 'PLUG THE CHARGER ALREADY'],
},
'brightness': {
'controller': "brightnessctl", // "brightnessctl" or "ddcutil"
// Object of controller names for each monitor, either "brightnessctl" or "ddcutil" or "auto"
// "default" will be used if unspecified
// Examples
// 'eDP-1': "brightnessctl",
// 'DP-1': "ddcutil",
'controllers': {
'default': "auto",
},
},
'music': {
'preferredPlayer': "plasma-browser-integration",
+24 -11
View File
@@ -89,20 +89,33 @@ class BrightnessDdcService extends BrightnessServiceBase {
}
}
// the singleton instance
// Service instance
const numMonitors = Hyprland.monitors.length;
const service = Array(numMonitors);
switch (userOptions.brightness.controller) {
case "brightnessctl":
service.fill(new BrightnessCtlService());
break;
case "ddcutil":
for (let i = 0; i < numMonitors; i++) {
service[i] = new BrightnessDdcService(i);
for (let i = 0; i < service.length; i++) {
const monitorName = Hyprland.monitors[i].name;
const preferredController = userOptions.brightness.controllers[monitorName]
|| userOptions.brightness.controllers.default || "auto";
if (preferredController) {
switch (preferredController) {
case "brightnessctl":
service[i] = new BrightnessCtlService();
break;
case "ddcutil":
service[i] = new BrightnessDdcService(i);
break;
case "auto":
if (monitorName.startsWith("eDP-"))
service[i] = new BrightnessCtlService();
else if (monitorName.startsWith("DP-"))
service[i] = new BrightnessDdcService(i);
else
service[i] = new BrightnessCtlService();
break;
default:
throw new Error(`Unknown brightness controller ${preferredController}`);
}
break;
default:
throw new Error(`Unknown brightness controller ${userOptions.brightness.controller}`);
}
}
// make it global for easy use with cli