When you install an older version of Raspbian, there is no lock screen option. To add it, instead of going to `/etc/xdg/lxpanel/LXDE-pi/panels/panel` and adding any extra lockscreen lines, simply do this instead:
Technique 1: Screen locks but does not go blank
- Click the RPi start menu and select Preferences > Main Menu Editor
- In the editor click New Item and enter the following in the respective fields:
- Name: Lock
Command: /usr/bin/dm-tool lock(don't use dm-tool lock because it is unsafe. The password can be bypassed with Ctrl Alt F7)- Command: swaylock
- Comment: Lock screen
- Click "Ok" and reboot.
You can also press Ctrl Alt L to lock the screen.
Technique 2: Screen goes blank, then locks and stays blank
The script below is meant to put the monitor into power saving mode just before swaylock is used to lock the screen (without swayidle, the monitor remains switched on even after the screen is locked). Make sure screen blanking is switched on before using this script by going to Raspberry Pi Preferences > Raspberry Pi Configuration > Display > Screen Blanking.
This script assumes that the screen gets locked only when the User manually selects lock.To make this script runnable on lock, go to Preferences > Main Menu Editor and create a new item with the path and name of this script's file as the "command". For example: /home/<your username>/lock_screen.sh
The default swayidle command would be preconfigured in /home/<your username>/.config/labwc/autostart as swayidle -w timeout 600 'wlopm --off \*' resume 'wlopm --on \*' . The script below would override the default swayidle by killing the swayidle process.
![]() |
Create the following script in your Raspberry Pi home directory with the name lock_screen.sh (or whatever name you prefer).
#!/bin/bash
# Kill existing swayidle processes
pkill -f swayidle
# Run swayidle with timeout 1. Screen blanking will happen after 1 second
# wlopm is Wayland output power management. See its man page
swayidle -w timeout 1 'wlopm --off \* ; swaylock &' resume 'wlopm --on \* ; pkill -f swayidle'
# Set screen blanking to 5 minutes (300 seconds)
swayidle -w timeout 300 'wlopm --off \*' resume 'wlopm --on \*' &
To detect if the screen is blanked
You can run `wlopm -j`, and the power mode being on or off will tell you if the screen is blanked or not.
To detect if the screen is locked
#!/bin/bash
#PROCESS_PATH="/usr/sbin/pi-greeter"
PROCESS_PATH="swaylock"
while sleep 2
do
if pgrep -f "$PROCESS_PATH" > /dev/null
then
echo "$PROCESS_PATH is running. Screen is locked"
else
echo "$PROCESS_PATH is not running. Screen is not locked"
fi
done
#PROCESS_PATH="/usr/sbin/pi-greeter"
PROCESS_PATH="swaylock"
while sleep 2
do
if pgrep -f "$PROCESS_PATH" > /dev/null
then
echo "$PROCESS_PATH is running. Screen is locked"
else
echo "$PROCESS_PATH is not running. Screen is not locked"
fi
done
Some bonus info: If you don't like the bright white wallpaper of the login screen, you can change it in /etc/lightdm/pi-greeter.conf.
There really needs to be a better, standardized way to detect screen locks across operating systems.
No comments:
Post a Comment