Wake to lock in sway?

I’ve had success with the reform-standby script with putting my machine to sleep and waking it up. Groovy. But, and please forgive the newbie question here because sway is something I’m still adjusting to, I cannot seem to figure out how to get swaylock configured in such a way that the machine wakes up to being locked, which is my preference.

Has anybody else managed to configure sway with swaylock so that waking the machine from the standby brings up a lock screen rather than straight to the desktop? Thanks in advance. I’ll keep trying to figure it out for myself but I thought maybe somebody in the community had already solved this one.


I’d bet that invoking swaylock at the end of the reform-standby script would do it.

1 Like

Modifying the reform-standby script isn’t required: if you have something like the following in your sway config it will behave as you need. This also sets a nice lockscreen image (and automatic brightness reduction), but the specific bit of the command you’re interested in is before-sleep.

exec swayidle -w \
    timeout 60 'brightnessctl -s s 1' resume 'brightnessctl -r' \
    timeout 300 'grim /tmp/pixels.png && convert /tmp/pixels.png -scale 5% -scale 1000% /tmp/pixels.png && swaylock -f -i /tmp/pixels.png' \
    timeout 600 'swaymsg "output * dpms off"' \
    before-sleep 'grim /tmp/pixels.png && convert /tmp/pixels.png -scale 5% -scale 1000% /tmp/pixels.png && swaylock -f -i /tmp/pixels.png'