Swayidle: Difference between revisions
Appearance
Fix swaymsg package (prior to this change: `swaymsg: command not found`) |
m Added install through config/sway |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
Swayidle is an idle management daemon for Wayland. | [https://github.com/swaywm/swayidle Swayidle] is an idle management daemon for Wayland. | ||
== Installation == | == Installation == | ||
=== Standalone === | |||
{{File|3=environment.systemPackages = with pkgs; [ | |||
swayidle | |||
];|name=/etc/nixos/configuration.nix|lang=nix}} | |||
{{ | === Home Manager - Standalone === | ||
{{File|3=services.swayidle.enable = true;|name=/etc/nixos/home.nix|lang=nix}} | |||
}} | |||
=== Home Manager - Through Sway === | |||
{{File|3=programs.sway.extraPackages = with pkgs; [swayidle];|name=/etc/nixos/home.nix|lang=nix}} | |||
== Configuration == | == Configuration == | ||
| Line 18: | Line 23: | ||
# Suspend the system | # Suspend the system | ||
which could be set using {{ic|services.swayidle.timeouts}}. {{ic|services.swayidle.events}} is useful to make the behavior consistent with the above in case {{ic|systemctl suspend}}, {{ic|loginctl lock-session}} are manually run. | which could be set using {{ic|services.swayidle.timeouts}}. {{ic|services.swayidle.events}} is useful to make the behavior consistent with the above in case {{ic|systemctl suspend}}, {{ic|loginctl lock-session}} are manually run. | ||
Additional options may be found within the Home Manager Appendix under [https://nix-community.github.io/home-manager/options.xhtml#opt-services.swayidle.enable services.swayidle]. | |||
{{file|~/.config/home-manager/home.nix|nix|3= | {{file|~/.config/home-manager/home.nix|nix|3= | ||
| Line 77: | Line 84: | ||
See [https://man.archlinux.org/man/extra/swayidle/swayidle.1.en the man page] for further information. | See [https://man.archlinux.org/man/extra/swayidle/swayidle.1.en the man page] for further information. | ||
[[Category:Wayland]] | |||
Latest revision as of 03:29, 1 January 2026
Swayidle is an idle management daemon for Wayland.
Installation
Standalone
❄︎ /etc/nixos/configuration.nix
environment.systemPackages = with pkgs; [
swayidle
];
Home Manager - Standalone
❄︎ /etc/nixos/home.nix
services.swayidle.enable = true;
Home Manager - Through Sway
❄︎ /etc/nixos/home.nix
programs.sway.extraPackages = with pkgs; [swayidle];
Configuration
Swayidle has a lot of flexibility in its setup, but what is usually done is as follows:
- Send notification before doing the following
- Lock screen (typically Swaylock is used)
- Turn off the screen (Note that the command may differ among window managers)
- Suspend the system
which could be set using services.swayidle.timeouts. services.swayidle.events is useful to make the behavior consistent with the above in case systemctl suspend, loginctl lock-session are manually run.
Additional options may be found within the Home Manager Appendix under services.swayidle.
❄︎ ~/.config/home-manager/home.nix
services.swayidle =
let
# Lock command
lock = "${pkgs.swaylock}/bin/swaylock --daemonize";
# TODO: modify "display" function based on your window manager
# Sway
display = status: "${pkgs.sway}/bin/swaymsg 'output * power ${status}'";
# Hyprland
# display = status: "hyprctl dispatch dpms ${status}";
# Niri
# display = status: "${pkgs.niri}/bin/niri msg action power-${status}-monitors";
in
{
enable = true;
timeouts = [
{
timeout = 15; # in seconds
command = "${pkgs.libnotify}/bin/notify-send 'Locking in 5 seconds' -t 5000";
}
{
timeout = 20;
command = lock;
}
{
timeout = 25;
command = display "off";
resumeCommand = display "on";
}
{
timeout = 30;
command = "${pkgs.systemd}/bin/systemctl suspend";
}
];
events = [
{
event = "before-sleep";
# adding duplicated entries for the same event may not work
command = (display "off") + "; " + lock;
}
{
event = "after-resume";
command = display "on";
}
{
event = "lock";
command = (display "off") + "; " + lock;
}
{
event = "unlock";
command = display "on";
}
];
};
See the man page for further information.