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
'')
# (writeShellScriptBin "tv-on" ''
# xrandr \
# --output DP-0 --primary --mode 1920x1080 --pos 1920x1080 --rotate normal \
# --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
# '')
(writeXrandrScriptBin "tv-on")
(writeXrandrScriptBin "tv-on" {
DP-0 = {
primary = true;
mode = "1920x1080";
pos = "1920x1080";
rotate = "normal";
};
HDMI-0 = {
mode = "1920x1080";
pos = "0x1080";
rotate = "normal";
};
HDMI-1 = {
mode = "1920x1080";
pos = "1920x0";
rotate = "normal";
};
})
feh
imagemagick

View file

@ -1,13 +1,27 @@
{ writeShellScriptBin }:
name:
{ lib, writeShellScriptBin }:
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 ''
xrandr \
--output DP-0 --primary --mode 1920x1080 --pos 1920x1080 --rotate normal \
--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
${concatStringsSep " \\\n " args}
''