diff --git a/home/wm/default.nix b/home/wm/default.nix index f4f0ad2..508fe76 100644 --- a/home/wm/default.nix +++ b/home/wm/default.nix @@ -61,7 +61,26 @@ in }; }; - notify = my.mkDisableOption "Notify when about to lock the screen"; + notify = { + enable = my.mkDisableOption "Notify when about to lock the screen"; + + delay = mkOption { + type = with types; + addCheck int (x: + let + cfg = config.my.home.wm.screen-lock.notify; + cornerCfg = config.my.home.wm.screen-lock.cornerLock; + in + (cfg.enable && cornerCfg.enable) -> cornerCfg.delay >= x); + default = 5; + example = 15; + description = '' + How many seconds in advance should there be a notification. + This value must be at lesser than or equal to `cornerLock.delay` + when both options are enabled. + ''; + }; + }; timeout = mkOption { type = types.ints.between 1 60; diff --git a/home/wm/screen-lock.nix b/home/wm/screen-lock.nix index 1632be7..720e73a 100644 --- a/home/wm/screen-lock.nix +++ b/home/wm/screen-lock.nix @@ -1,6 +1,14 @@ { config, lib, pkgs, ... }: let cfg = config.my.home.wm.screen-lock; + + notficationCmd = + let + duration = toString (cfg.notify.delay * 1000); + notifyCmd = "${pkgs.libnotify}/bin/notify-send -u critical -t ${duration}"; + in + # Needs to be surrounded by quotes for systemd to launch it correctly + ''"${notifyCmd} -- 'Locking in ${toString cfg.notify.delay} seconds'"''; in { config = lib.mkIf cfg.enable { @@ -19,11 +27,11 @@ in "${toString cfg.cornerLock.delay}" "-corners" "+00-" - ] ++ lib.optionals cfg.notify [ + ] ++ lib.optionals cfg.notify.enable [ "-notify" - "5" + "${toString cfg.notify.delay}" "-notifier" - ''"${pkgs.libnotify}/bin/notify-send -u critical -t 5000 -- 'Locking in 5 seconds'"'' + notficationCmd ]; }; };