diff --git a/hosts/snowhawk/home.nix b/hosts/snowhawk/home.nix index 87390c1..bb2db25 100644 --- a/hosts/snowhawk/home.nix +++ b/hosts/snowhawk/home.nix @@ -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 diff --git a/pkgs/writeXrandrScriptBin.nix b/pkgs/writeXrandrScriptBin.nix index 64eaaf4..47f04c1 100644 --- a/pkgs/writeXrandrScriptBin.nix +++ b/pkgs/writeXrandrScriptBin.nix @@ -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} ''