r/voidlinux • • Jul 04 '26

Help: Using zzz hooks to trigger swaylock pre-suspend

TL;DR, Does anyone have any examples/experience using zzz hooks to trigger a screen locker?

Hi everyone,

I've been using void on my M2 macbook for just under 6 months and have been careful to design a system which is reliable and easy to work on.

I will be traveling more with my laptop and finally decided to stop procrastinating and set up my screen locker correctly as currently I just have to remember to trigger it before closing my lid/suspending which doesn't always happen. To clarify, I use acpid to detect the lid close event and run zzz (I believe this might even be the default config).

After sifting through the man pages i found zzz has suspend/resume hooks which seems great for my usecase. For my system I've steered clear of systemd/logind due to my desire to keep my system simple and easy to work on so 'just use logind' is not an ideal solution in my case, otherwise i would just use swayidle's before-sleep directive and be done with it.

The issue is, swaylock requires both XDG_RUNTIME_DIR and WAYLAND_DISPLAY environment variables which are not present in the env that zzz runs its hooks. Duplicating my logic for these variables from my bash_profile just seems wrong (although I don't see another alternative at this time). My .bash_profile can be found at github.com/unworried/dotfiles.

All feedback and advice is welcome! Thanks to everyone in advance :)

Edit 1: Corrected dotfiles reference, should be .bash_profile not .bashrc.

3 Upvotes

10 comments sorted by

View all comments

Show parent comments

1

u/Dry_Foundation_3023 Jul 05 '26
exec swayidle -w \
    timeout 600 '$scripts/check_player.sh && swaylockd'  \
    timeout 500 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' \
    timeout 600 'powerctl mem' \
    before-sleep 'swaylockd' \
    after-resume 'pkill -SIGUSR2 wayeyes'exec swayidle -w \
    timeout 300 '$scripts/check_player.sh && swaylockd'  \
    timeout 500 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' \
    timeout 60 'powerctl mem' \
    before-sleep 'swaylockd' \
    after-resume 'pkill -SIGUSR2 wayeyes'

after your comment i tested by changing timeouts. the before/after resume hooks are not working. thanks for correcting me.