Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6814

Raspberry Pi OS • Wayland lock screen how to

$
0
0
Before Wayland was introduced into Raspberry Pi OS I used to use xscreensaver to control screen locking and blanking, with a key combination (<CTRL><ALT>L) that I set up in one of the X config files. This was great because it meant:

(a) if I wanted to manually lock my desktop, I used <CTRL><ALT>L, which caused xscreensaver to start and required me to enter my password to unlock the desktop.
(b) if I stepped away and didn't lock my desktop, xscreensaver would kick after a configurable period of time, and I would have to enter my password to unlock the desktop.
(c) in both cases, xscreensaver would eventually blank the screen (after a configurable period).

I've finally worked out how to implement a similar approach under Wayland. This uses swayidle and swaylock. The first thing to do is go to the Display section in the the Raspberry Pi Control Centre to set the screen to blank automatically. This inserts the following into ~/.config/labwc/autostart:

Code:

swayidle -w timeout 600 'wlopm --off \*' resume 'wlopm --on \*' &
However, all this does is blank the screen after 600 seconds of inactivity and turns off the monitor, and then turns it back on when activity (e.g. mouse move or key press) is detected. It doesn't lock the screen.

With the following change to the autostart file, swayidle will also call swaylock to lock the screen after 300 seconds and then blank it after 600 seconds (and should put the monitor into powersave mode if the monitors supports this - virtually all desktop monitors do):

Code:

swayidle -w timeout 300 'swaylock -f -p' \timeout 600 'wlopm --off \*' resume 'wlopm --on \*' &
The parameters on the swaylock call have the following meaning

-f: swaylock executes in the background (i.e. as a daemon). Without this parameter, there is no return from swaylock to swayidle to allow it to blank the screen, until the screen is unlocked (which would mean swayidle wouldn't call wlopm to blank the screen until it is unlocked, which would then cause the screen to be unblanked anyway).
-p: this is an additional parameter not documented in the swaylock manpage which is to show the Raspberry Pi lock screen. Raspberry Pi OS includes a version of swaylock with a customised lock screen.

Note, if you set the display to not blank it will empty the autostart file. If you then set it to blank again, it will insert the original code shown first.

Another post relating to a Raspberry Pi 5 stated they had to set the autostart file to be executable for the current user. I have not had to do this on my Raspberry Pi 4, but doing so doesn't cause any problems (and may be essential on a Raspberry Pi 5).

Statistics: Posted by tijowa — Fri Oct 24, 2025 4:40 pm — Replies 1 — Views 66



Viewing all articles
Browse latest Browse all 6814

Trending Articles