Swayidle
What is it?
It is an idle management daemon for Wayland. It is compatible with any Wayland compositor which implements the ext-idle-notify protocol.
It listens for idle activity on your Wayland compositor and executes tasks on various idle-related events. You can specify any number of events at the command line and in the config file.
How to install?
Install it with yay swayidle
Where should the config file be placed?
- XDG_CONFIG_HOME/swayidle/config
- $HOME/swayidle/config
How to use?
Using it in Hyprland config method (my preferred one):
Check the manual page for the available commands to use with swayidle. Then create the entry in the hyprland config file. These are the lines that I use on my config file:
# Start swayidle lockscreen script - 30 seconds for dim and 120 seconds for display off
exec-once = swayidle -w timeout 30 'brightnessctl set 0%' resume 'brightnessctl set 30%'
exec-once = swayidle -w timeout 120 'hyprctl dispatch dpms off' resume 'hyprctl dispatch dpms on'
Check this link for more information about what it does.
Using it with a script that executes in Hyprland config method:
You have to create a config file with the entries that you see in the swayidle manual page. You can also create a script for swayidle which executes different commands when the set times are reached. An example of swayidle script which I am planning to use:
#!/bin/bash
if [ -f "/usr/bin/swayidle" ]; then
echo "swayidle is installed."
swayidle -w timeout 300 'swaylock -f' timeout 360 'hyprctl dispatch dpms off' resume 'hyprctl dispatch dpms on'
else
echo "swayidle is not installed."
fi;
Explanation of the above command:
- It checks if swayidle is installed and it gives messages according to the result.
- If for 300 seconds, the computer was idle, then it will run Swaylock with parameter -f.******
- After 360 seconds of idle, the script will switch OFF the monitor.
- If you touch the mouse or the keyboard, it will switch ON the monitor.
You should make this script executable and run it on startup on your Hyprland config file for this to work.
An other example from the manual page:
config file:
swayidle -w \\
timeout 300 'swaylock -f -c 000000' \\
timeout 600 'swaymsg "output * power off"' \\
resume 'swaymsg "output * power on"' \\
before-sleep 'swaylock -f -c 000000'
Commands to use with this command:
-C : You can choose a different config file to use, to keep your $HOME folder clean
-w : Wait for command to finish executing, before continueing. Helpful for ensuring that a before-sleep command has finished before the system goes to sleep.
Using this option causes swayidle to block until the command finishes.
Manual Page:
For more detailed info on the useage of swayidle, check the man page