λ

swayaway

a drop-in replacement for swayidle(1)

settings

README.md

4562 bytes raw

swayaway

a drop-in replacement for swayidle(1) for Wayland compositors, written in C99, with no elogind dependency and no libsystemd.

the only dependencies are libwayland-client and libdbus-1.

this exports org.freedesktop.ScreenSaver (plus the org.gnome.ScreenSaver alias) so browsers, media players, and any other app that calls Inhibit()/Uninhibit() can suppress idle timeouts.

it also listens for logind's PrepareForSleep signal to run before-sleep / after-resume commands. if no logind is running, these events simply never fire.

usage

swayaway [options] [events...]

options:

option meaning
-C <path> config file (default: see below)
-d debug output
-w wait for commands to finish (useful with before-sleep + swaylock -f)
-S <seat> pick a specific seat
-h help

events:

timeout <seconds> <command> [resume <command>]
resume <command> # legacy: run on every activity
before-sleep <command>
after-resume <command>

all commands will be executed via /bin/sh -c. this means you can use env vars, pipes, and wildcards in your command. because of this, you should quote the entire command string if it contains spaces, both on the command line and in the config file

example (the classic sway setup):

swayaway -w \
    timeout 300 'swaylock -f -c 000000' \
    timeout 600 'swaymsg "output * power off"' \
    resume 'swaymsg "output * power on"' \
    before-sleep 'swaylock -f -c 000000'

the timeout ... resume ... two-command form is the swayidle 1.8+/1.9 syntax; timeout N resume CMD (old pre-1.8 mode syntax) is also accepted

the top-level resume CMD event (used by the famous sway wiki example) works too.

swayidle's lock, unlock and idlehint events are not supported (they go through the logind Session interface), swayaway rejects them with an error, same as swayidle built without systemd/elogind

config file

without -C, swayaway checks, in order:

  1. $XDG_CONFIG_HOME/swayaway/config
  2. $HOME/.config/swayaway/config
  3. $XDG_CONFIG_HOME/swayidle/config
  4. $HOME/.config/swayidle/config
  5. $HOME/.swayidle/config

so an existing swayidle config works unchanged. Config lines are the same events as the command line; # starts a comment and shell expansion applies (quote commands with spaces: timeout 300 "swaylock -f").

how it works

this basically polls 4 fds, wayland fd, session bus fd, system bus fd, and a signalfd like so:

poll( [ wayland_fd, session_bus_fd, system_bus_fd, signalfd ], timeout )

idle detection via get_idle_notification also respects Wayland-level idle inhibitors (zwp_idle_inhibitor_v1), exactly like swayidle's default.

building

requires libwayland-dev, libdbus-1-dev, wayland-protocols and wayland-scanner

make
doas make install # will install to /usr/local/bin by default, change PREFIX if you want

you can also make the manpages (this requires scdoc):

make man
doas make man-install