home

Void Linux Screenlock

When I first set up the HP Mini with Void Linux I set up i3lock as the screenlocker using xidle to run it. One feature of xidle is that sending it a USR1 signal will cause it to run the locker immediately. I figured I could use that to lock the screen when the laptop goes to sleep (on systemd machines I’ve used slock before) so I looked into acpid and how to use it to lock the screen when the system sleeps.

I got it working but it felt a little janky…

There was no way to force one event handler to run first, so sometimes the machine would only lock the screen after the system had woken up, and the event handler scripts are rather opaque and weird.

Anyway, I had a look through the standard acpid event handler that comes with Void, that handles sleeping when the lid closes, etc. I realised that it just uses the zzz and ZZZ commands to put the machine to sleep and hibernate. One brief check of the man page later I discovered you can just drop scripts into /etc/zzz.d/suspend and /etc/zzz.d/resume to have things happen on, shocking, suspend or resume. And better, they happen before suspend!

So, simply dropping this script into /etc/zzz.d/suspend/00-lock-screen.sh works a treat:

#!/bin/sh

/bin/kill -a -USR1 xidle