Make swayidle work for both sway and niri

Tudor Roman 2024-04-01 14:41:11 +02:00
parent 952a7ae023
commit f564446b11
Signed by: tudor
SSH Key Fingerprint: SHA256:3CwS9plgXBecpXImPGxDIaSktUXBejbV/zerZMqzzBk
2 changed files with 39 additions and 40 deletions

View File

@ -95,5 +95,44 @@ in
};
};
};
services.swayidle = let
swaymsg = "${config.wayland.windowManager.sway.package}/bin/swaymsg";
niri = "${config.programs.niri.package}/bin/niri";
# if running nixos: make sure swaylock is enabled system-wide in the system config!
# if not: make sure you either have swaylock installed via the system package manager,
# or you have a valid PAM config for it.
# otherwise, it will not be able to unlock the screen!
swaylock = "/usr/bin/env swaylock";
swaylockCmd = "${swaylock} -c 000000 -fF";
in {
enable = true;
systemdTarget = "wl-session.target";
events = [
# make sure the screen is locked before going to sleep
{
event = "before-sleep";
command = swaylockCmd;
}
{
event = "lock";
command = swaylockCmd;
}
# stop the screen locker if loginctl says it's time to unlock
# (you can test by running loginctl unlock-session).
# regarding the sigusr1 thing, see swaylock(1).
{
event = "unlock";
command = "pkill -USR1 swaylock";
}
];
timeouts = [
{
timeout = 600;
command = "${swaymsg} \"output * power off\" || ${niri} msg action power-off-monitors";
resumeCommand = "${swaymsg} \"output * power on\" || true";
}
];
};
};
}

View File

@ -37,46 +37,6 @@ in
# this key is set here only to make it start when sway starts.
services.kanshi.systemdTarget = "sway-session.target";
# does things if the computer is left untouched for a while
services.swayidle = let
swaymsg = "${config.wayland.windowManager.sway.package}/bin/swaymsg";
# if running nixos: make sure swaylock is enabled system-wide in the system config!
# if not: make sure you either have swaylock installed via the system package manager,
# or you have a valid PAM config for it.
# otherwise, it will not be able to unlock the screen!
swaylock = "/usr/bin/env swaylock";
swaylockCmd = "${swaylock} -c 000000 -fF";
in {
enable = true;
systemdTarget = "sway-session.target";
events = [
# make sure the screen is locked before going to sleep
{
event = "before-sleep";
command = swaylockCmd;
}
{
event = "lock";
command = swaylockCmd;
}
# stop the screen locker if loginctl says it's time to unlock
# (you can test by running loginctl unlock-session).
# regarding the sigusr1 thing, see swaylock(1).
{
event = "unlock";
command = "pkill -USR1 swaylock";
}
];
timeouts = [
{
timeout = 600;
command = "${swaymsg} \"output * power off\"";
resumeCommand = "${swaymsg} \"output * power on\"";
}
# TODO: suspend after a longer while
];
};
# the belly of the beast
wayland.windowManager.sway = {
enable = true;