nixos-config/modules/programs/kanshi/default.nix

113 lines
2.7 KiB
Nix
Raw Normal View History

{
config
, lib
, writeShellScript
, kanshi
, wallpapersPath ? "/home/${config.system.singleUser}/Data/Wallpapers"
}:
let
wallpapersHorizontal = "${wallpapersPath}/horizontal";
wallpapersVertical = "${wallpapersPath}/vertical";
wallpaperScript = writeShellScript "wallpaper.sh" ''
[[ $# -lt 1 ]] && echo "No profile specified" && exit 1
random_file() {
find "$1" -maxdepth 1 -type f | shuf -n 1
}
setbg() {
# Sets the background of $1 to $2
swaymsg "output \"$1\" background $2 fill"
}
case $1 in
homeMultihead)
horiz=$(random_file ${wallpapersHorizontal})
vert=$(random_file ${wallpapersVertical})
setbg "eDP-1" $horiz
setbg "HDMI-A-1" $vert
;;
genericMultihead)
horiz1=$(random_file ${wallpapersHorizontal})
horiz2=$(random_file ${wallpapersHorizontal})
setbg "eDP-1" $horiz1
setbg "HDMI-A-1" $horiz2
;;
laptop)
horiz=$(random_file ${wallpapersHorizontal})
setbg "eDP-1" $horiz
;;
esac
'';
mkProfile = name: outputs: {
outputs = outputs;
exec = "${wallpaperScript} ${name}";
};
in {
environment.systemPackages = [ kanshi ];
systemd.user.services.kanshi = {
description = "Dynamic display configuration tool";
wantedBy = [ "default.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${kanshi}/bin/kanshi";
Restart = "on-failure";
};
};
home-manager.users."${config.system.singleUser}".services.kanshi = {
enable = true;
profiles = let
horizontal = "Samsung Electric Company C27F398 H4ZN200596";
vertical = "Goldstar Company Ltd IPS235 Serial Number";
in {
homeMultihead = mkProfile "homeMultihead" [
{
criteria = vertical;
status = "enable";
mode = "1920x1080";
transform = "270";
position = "1920,-1080";
}
{
criteria = horizontal;
status = "enable";
mode = "1920x1080";
position = "1920,-1080";
}
{
criteria = "eDP-1";
status = "enable";
mode = "1920x1080";
position = "0,0";
}
];
genericMultihead = mkProfile "genericMultihead" [
{
criteria = "eDP-1";
mode = "1920x1080";
status = "enable";
}
{
criteria = "HDMI-A-1";
status = "enable";
}
];
laptop = mkProfile "laptop" [
{
criteria = "eDP-1";
status = "enable";
mode = "1920x1080";
position = "0,0";
}
];
};
};
}