install the required packages/tools
sudo apt-get install xautolock scrot i3lock imagemagick yad
sudo nano ~/.config/yad.conf
show_remain=false (before change)
show_remain=true (after change)
(save and exit --> Ctrl-O, enter, Ctrl-X, enter)
copy the lockscreen transparent lock images to /usr/local/bin/pngs/
sudo nano /usr/local/bin/lock
(add the following text)
#!/bin/bash
# this part of the script has been adopted from the follwoing article
# https://github.com/SvenPM/bits-and-pieces/blob/master/screensaver/locker.sh
# inhibit screen saver when media players are running
# add missing players to regex
if [ `ps -u $USER | grep -Ec "(totem|kodi|mpv|vlc|*mplayer)"` -gt 0 ]; then
exit 0
fi
# timeout prompt before locking the screen
# press ESC to cancel
yad \
--center \
--title "Auto-lock activation" \
--on-top \
--width=230 \
--height=10 \
--timeout=30 \
--timeout-indicator=bottom \
--text "\n \t Press Esc to cancel auto-lock \t" \
--buttons-layout=center \
--button="Lock Screen":0 \
case $? in
0) ;;
*) exit 0;;
esac
#take screenshot
scrot /tmp/screenshot.png
#blur image using convert
convert /tmp/screenshot.png -blur 0x6 /tmp/screenshotblur.png
#overlay the center lock icon on the above blurred image
composite -gravity center /usr/local/bin/pngs/lock-02.png /tmp/screenshotblur.png /tmp/lockscreen.png
#force turn of the screen
xset dpms force off
#activate the lock with the above blurred image with image overlay
i3lock -n -e -i /tmp/lockscreen.png
#remove the generated screenshots and images
rm /tmp/*.png
#exit
exit 0
(save and exit --> Ctrl-O, enter, Ctrl-X, enter)
make the script executable
sudo chmod +x /usr/local/bin/lock
add the following to the ~/.config/openbox/autostart.sh
xautolock -time 10 -locker /usr/local/bin/lock &
The above script doesn't lock the screen even if initiated manually from a keyboard shortcut, so a copy of the same above script is created (/usr/local/bin/lockmanual) and first part of code which checks for active media players has been removed and mapped to the keyboard shortcuts. That way, when a user wants to lock the screen manually even if the media player applications are running the screen lock could be initiated.