vanadium: minor refactor display config

This commit is contained in:
Primrose 2025-09-02 18:27:58 +08:00
parent a6be9276c0
commit e3c26ec831
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA

View file

@ -41,13 +41,11 @@
allDevices = ["eDP-1"] ++ allExternDevices; allDevices = ["eDP-1"] ++ allExternDevices;
/** # TODO: merge when upstream is merged
TODO: merge when upstream is merged # https://github.com/NixOS/nixpkgs/pull/436434
https://github.com/NixOS/nixpkgs/pull/436434 #
# Generate an attribute set by mapping a function over a list of attribute names.
Generate an attribute set by mapping a function over a list of attribute names. # It allows setting the name of the attribute.
It allows setting the name of the attribute.
*/
genAttrs' = xs: func: builtins.listToAttrs (map func xs); genAttrs' = xs: func: builtins.listToAttrs (map func xs);
mkDpiSwitch = {dpi}: { mkDpiSwitch = {dpi}: {
@ -57,6 +55,7 @@
''}"; ''}";
}; };
# Is scoped to an output device, no need to be called on built-in display
mkBrightnessSwitch = { mkBrightnessSwitch = {
device, device,
brightness, brightness,
@ -69,10 +68,7 @@
# Note: the "position" field corresponds to the "pos" field outputted by autorandr # Note: the "position" field corresponds to the "pos" field outputted by autorandr
# To get the current config, run `xrandr --auto` and then `autorandr --config` # To get the current config, run `xrandr --auto` and then `autorandr --config`
configs = { configs = {
allOff = genAttrs' allDevices (name: { allOff = lib.genAttrs allDevices (_: {enable = false;});
inherit name;
value = {enable = false;};
});
enableBuiltin = { enableBuiltin = {
eDP-1 = { eDP-1 = {
enable = true; enable = true;
@ -96,8 +92,7 @@
frameworkBuiltin = { frameworkBuiltin = {
fingerprint.eDP-1 = built-in; fingerprint.eDP-1 = built-in;
config = with configs; config = with configs; allOff // enableBuiltin;
allOff // enableBuiltin;
hooks.postswitch = mkDpiSwitch {dpi = 150;}; hooks.postswitch = mkDpiSwitch {dpi = 150;};
}; };
@ -106,8 +101,7 @@
${name} = asus-monitor; ${name} = asus-monitor;
eDP-1 = built-in; eDP-1 = built-in;
}; };
config = with configs; config = with configs; allOff // enableDevice name;
allOff // enableDevice name;
hooks.postswitch = hooks.postswitch =
mkDpiSwitch {dpi = 110;} mkDpiSwitch {dpi = 110;}
// mkBrightnessSwitch { // mkBrightnessSwitch {
@ -117,9 +111,6 @@
}; };
in in
{default = frameworkBuiltin;} {default = frameworkBuiltin;}
// genAttrs' allExternDevices (name: { // genAttrs' allExternDevices (name: lib.nameValuePair "asus-${name}" (mkAsusProfile name));
name = "asus-${name}";
value = mkAsusProfile name;
});
}; };
} }