writeXrandrScriptBin: config input

This commit is contained in:
Zynh Ludwig 2024-08-17 03:43:22 -07:00
parent 9b279a0b3c
commit c4b536f3cf
2 changed files with 42 additions and 22 deletions

View file

@ -65,18 +65,24 @@ in
systemctl suspend systemctl suspend
'') '')
# (writeShellScriptBin "tv-on" '' (writeXrandrScriptBin "tv-on" {
# xrandr \ DP-0 = {
# --output DP-0 --primary --mode 1920x1080 --pos 1920x1080 --rotate normal \ primary = true;
# --output HDMI-0 --mode 1920x1080 --pos 0x1080 --rotate normal \ mode = "1920x1080";
# --output HDMI-1 --mode 1920x1080 --pos 1920x0 --rotate normal \ pos = "1920x1080";
# --output DP-1 --off \ rotate = "normal";
# --output DP-2 --off \ };
# --output DP-3 --off \ HDMI-0 = {
# --output DP-4 --off \ mode = "1920x1080";
# --output DP-5 --off pos = "0x1080";
# '') rotate = "normal";
(writeXrandrScriptBin "tv-on") };
HDMI-1 = {
mode = "1920x1080";
pos = "1920x0";
rotate = "normal";
};
})
feh feh
imagemagick imagemagick

View file

@ -1,13 +1,27 @@
{ writeShellScriptBin }: { lib, writeShellScriptBin }:
name: let
inherit (builtins) getAttr hasAttr isAttrs concatStringsSep;
inherit (lib) assertMsg lists escapeShellArgs;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.cli) toGNUCommandLine;
in
name: config:
assert assertMsg (isAttrs config)
"config should be an attrs, found ${lib.typeOf config}";
let
isPrimary = config:
(hasAttr "primary" config) && (getAttr "primary" config);
getArgList = output: config:
(escapeShellArgs (lists.flatten [
(toGNUCommandLine { } { "--output" = output; })
(lists.optional (isPrimary config) "--primary")
(toGNUCommandLine { } config)
]));
args = mapAttrsToList getArgList config;
in
writeShellScriptBin name '' writeShellScriptBin name ''
xrandr \ xrandr \
--output DP-0 --primary --mode 1920x1080 --pos 1920x1080 --rotate normal \ ${concatStringsSep " \\\n " args}
--output HDMI-0 --mode 1920x1080 --pos 0x1080 --rotate normal \
--output HDMI-1 --mode 1920x1080 --pos 1920x0 --rotate normal \
--output DP-1 --off \
--output DP-2 --off \
--output DP-3 --off \
--output DP-4 --off \
--output DP-5 --off
'' ''