nixos-config/user/sway/swayidle.nix

50 lines
1.2 KiB
Nix

{
config,
pkgs,
lib,
...
}:
let
asScript = filename: text: toString (pkgs.writeShellScript filename text);
isNiri = (config.my.desktop or "") == "niri";
cfg = config.my.swayidle;
in
{
options.my.swayidle.enable = lib.mkEnableOption { };
config.services.swayidle = {
enable = cfg.enable;
timeouts = [
{
timeout = 360;
command = "${pkgs.swaylock}/bin/swaylock -f";
}
]
++ lib.optionals (!isNiri) [
{
timeout = 1800;
command = asScript "swayidle-suspend-monitors" ''
${pkgs.mpc}/bin/mpc status | grep "^[playing]" > /dev/null || ${pkgs.sway}/bin/swaymsg "output * dpms off"
'';
resumeCommand = asScript "swayidle-wakeup-monitors" ''
${pkgs.sway}/bin/swaymsg "output * dpms on"
'';
}
];
events = [
{
event = "before-sleep";
command = "${pkgs.swaylock}/bin/swaylock -f";
}
{
event = "after-resume";
command = asScript "after-resume" ''
${lib.optionalString (!isNiri) "${pkgs.sway}/bin/swaymsg \"output * dpms on\""}
${pkgs.systemd}/bin/systemctl --user restart \
kdeconnect.service kdeconnect-indicator.service
'';
}
];
};
}