#!/bin/bash # # Lock the screen of a X11 session # # Get current focused window # Some screen lockers such as i3lock loose the window focus #WINDOW="`xdotool getwindowfocus`" # See https://www.kirsle.net/turn-off-monitor-from-linux-cli # https://askubuntu.com/questions/62858/turn-off-monitor-using-command-line#62861 xset dpms force off sleep 1 # Using xscreensaver #xscreensaver-command --lock # Using i3lock # Ensure it is not forked or we might loose window focus after unlocking #i3lock -c 1c1c1c -n # Using i3lock with forking, so works well with xsuspend i3lock -c 1c1c1c # Restore focus #xdotool windowfocus $WINDOW