home: wm: screen-lock: add 'notify.delay' setting

This commit is contained in:
Bruno BELANYI 2021-04-19 16:44:28 +00:00
parent e5b5e73294
commit f8a1480d09
2 changed files with 31 additions and 4 deletions

View File

@ -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;

View File

@ -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
];
};
};