How to use the command swayidle (with examples)
- Linux
- December 25, 2023
Swayidle is an idle management daemon for Wayland. It allows users to configure timeouts for different idle activities like locking the screen or executing custom commands. This article will cover two use cases of the swayidle command: listening for idle activity using the default configuration file, and specifying an alternative path to the configuration file.
Use case 1: Listen for idle activity using the default configuration file
Code:
swayidle
Motivation:
The motivation for using this example is to start the swayidle daemon and let it listen for idle activity using the default configuration file. This can be useful for locking the screen or executing commands after a specified period of user inactivity.
Explanation:
The command swayidle
without any arguments starts the swayidle daemon and listens for idle activity using the default configuration file. The default configuration file is located either in $XDG_CONFIG_HOME/swayidle/config
or $HOME/swayidle/config
.
Example output:
INFO: swayidle 1.6
INFO: idle_timeout_minutes = 5
INFO: idle_timeout_seconds = 300
INFO: idle_command = swaylock -f -c 000000
INFO: idlehint_timeout_seconds = 120
INFO: idlehint_command = swaymsg output "*" dpms off
The output indicates that the swayidle daemon has started with the default configuration options. In this example, the idle timeout is set to 5 minutes, and after the timeout, the swaylock
command will be executed to lock the screen. Additionally, after 2 minutes of user inactivity, the swaymsg
command will be executed to turn off the display.
Use case 2: Specify an alternative path to the configuration file
Code:
swayidle -C path/to/file
Motivation:
Sometimes, users might want to use a custom configuration file for swayidle instead of the default one. In this example, we will specify an alternative path to the configuration file.
Explanation:
The command swayidle -C path/to/file
starts the swayidle daemon and specifies the path to a custom configuration file. The argument -C
followed by a file path tells swayidle to use the specified configuration file instead of the default one.
Example output:
INFO: swayidle 1.6
INFO: idle_timeout_minutes = 10
INFO: idle_timeout_seconds = 600
INFO: idle_command = /path/to/custom/command
INFO: idlehint_timeout_seconds = 180
INFO: idlehint_command = swaymsg output "*" dpms on
The output shows that the swayidle daemon has started with the custom configuration file specified. In this example, the idle timeout is set to 10 minutes, and after the timeout, the /path/to/custom/command
will be executed. After 3 minutes of user inactivity, the swaymsg
command will be executed to turn on the display.
Conclusion:
The swayidle command is a powerful tool for managing idle activity on Wayland. With the default configuration file or a custom one, users can set various timeouts and execute commands based on user inactivity. By understanding the use cases presented in this article, users can start using swayidle effectively and tailor it to their specific needs.