diff --git a/users/guanranwang/home-manager/applications/swayidle/default.nix b/users/guanranwang/home-manager/applications/swayidle/default.nix index a905288..1b53cd9 100644 --- a/users/guanranwang/home-manager/applications/swayidle/default.nix +++ b/users/guanranwang/home-manager/applications/swayidle/default.nix @@ -1,40 +1,47 @@ { pkgs, lib, + config, ... }: { imports = [ ../swaylock ]; - services = { - swayidle = { - enable = true; - timeouts = [ - { - timeout = 900; - command = lib.getExe pkgs.swaylock-effects; - } # lock screen - { - timeout = 905; - command = "${pkgs.sway}/bin/swaymsg \"output * dpms off\""; - resumeCommand = "${pkgs.sway}/bin/swaymsg \"output * dpms on\""; - } # turn off screen - { - timeout = 1200; - command = ''systemctl suspend''; - } # suspend - ]; - events = [ - { - event = "lock"; - command = lib.getExe pkgs.swaylock-effects; - } # loginctl lock-session - { - event = "before-sleep"; - command = lib.getExe pkgs.swaylock-effects; - } # systemctl syspend - ]; - }; + services.swayidle = let + lock = lib.getExe config.programs.swaylock.package; + displayOn = ''${pkgs.sway}/bin/swaymsg "output * power on"''; + displayOff = ''${pkgs.sway}/bin/swaymsg "output * power off"''; + in { + enable = true; + timeouts = [ + { + timeout = 60 * 9; + command = ''${pkgs.libnotify}/bin/notify-send -u critical --expire-time 60000 "60 seconds until lock!"''; + } + { + timeout = 60 * 10; + command = lock; + } # lock screen + { + timeout = 60 * 20; + command = displayOff; + resumeCommand = displayOn; + } # turn off screen + { + timeout = 60 * 30; + command = "systemctl suspend"; + } # suspend + ]; + events = [ + { + event = "lock"; + command = lock; + } # loginctl lock-session + { + event = "before-sleep"; + command = lock; + } # systemctl suspend + ]; }; }