Lock screen on lid close and idle

This commit is contained in:
Natsu Kagami 2022-11-08 15:35:13 +01:00
parent a670e5cd7a
commit 5b16bdfc35
Signed by: nki
GPG key ID: 7306B3D3C3AD6E51

View file

@ -74,6 +74,13 @@ in
default = "${pkgs.discord}/bin/discord"; default = "${pkgs.discord}/bin/discord";
}; };
lockCmd = mkOption {
type = types.str;
description = "The screen lock command";
default = "${pkgs.swaylock}/bin/swaylock"
+ (if cfg.wallpaper == "" then "" else " -i ${cfg.wallpaper} -s fill")
+ " -l -k";
};
enableLaptopBars = mkOption { enableLaptopBars = mkOption {
type = types.bool; type = types.bool;
description = "Whether to enable laptop-specific bars (battery)"; description = "Whether to enable laptop-specific bars (battery)";
@ -141,9 +148,7 @@ in
## Screenshot ## Screenshot
"Print" = "exec ${flameshot}/bin/flameshot gui"; "Print" = "exec ${flameshot}/bin/flameshot gui";
## Locking ## Locking
"${mod}+semicolon" = "exec ${pkgs.swaylock}/bin/swaylock" "${mod}+semicolon" = "exec ${cfg.lockCmd}";
+ (if cfg.wallpaper == "" then "" else " -i ${cfg.wallpaper} -s fit")
+ " -l -k";
## Multimedia ## Multimedia
"XF86AudioPrev" = "exec ${playerctl} previous"; "XF86AudioPrev" = "exec ${playerctl} previous";
"XF86AudioPlay" = "exec ${playerctl} play-pause"; "XF86AudioPlay" = "exec ${playerctl} play-pause";
@ -239,13 +244,18 @@ in
wrapperFeatures.base = true; wrapperFeatures.base = true;
wrapperFeatures.gtk = true; wrapperFeatures.gtk = true;
# Fix D-Bus starting up extraConfig =
extraConfig = '' (if cfg.enableLaptopBars then ''
exec systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK && \ # Lock screen on lid close
hash dbus-update-activation-environment 2>/dev/null && \ bindswitch --reload lid:off exec ${cfg.lockCmd}
dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK && \ '' else "") +
systemctl --user start sway-session.target ''
''; # Fix D-Bus starting up
exec systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK && \
hash dbus-update-activation-environment 2>/dev/null && \
dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK && \
systemctl --user start sway-session.target
'';
}; };
config.systemd.user.targets.sway-session = mkIf cfg.enable { config.systemd.user.targets.sway-session = mkIf cfg.enable {
@ -258,6 +268,14 @@ in
}; };
}; };
config.services.swayidle = mkIf cfg.enable {
enable = true;
timeouts = [
# Lock after 15 minutes of idle
{ timeout = 15 * 60; command = cfg.lockCmd; }
];
};
config.programs.waybar = mkIf cfg.enable { config.programs.waybar = mkIf cfg.enable {
enable = true; enable = true;
settings = [ settings = [