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

This commit is contained in:
end-4
2024-05-01 22:32:04 +07:00
parent aa9a38cf5f
commit b598dfac1d
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'], 'warnMessages': ["Plug in the charger", "You there?", 'PLUG THE CHARGER ALREADY'],
}, },
'brightness': { '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': { 'music': {
'preferredPlayer': "plasma-browser-integration", '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 numMonitors = Hyprland.monitors.length;
const service = Array(numMonitors); const service = Array(numMonitors);
switch (userOptions.brightness.controller) { for (let i = 0; i < service.length; i++) {
case "brightnessctl": const monitorName = Hyprland.monitors[i].name;
service.fill(new BrightnessCtlService()); const preferredController = userOptions.brightness.controllers[monitorName]
break; || userOptions.brightness.controllers.default || "auto";
case "ddcutil": if (preferredController) {
for (let i = 0; i < numMonitors; i++) { switch (preferredController) {
service[i] = new BrightnessDdcService(i); 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 // make it global for easy use with cli