#!/bin/bash
#
-# Lock the screen using xscreensaver
+# Lock the screen of a X11 session
#
+# Get current focused window
+# Some screen lockers such as i3lock loose the window focus
+WINDOW="`xdotool getwindowfocus`"
+
# Using xscreensaver
#xscreensaver-command --lock
# https://askubuntu.com/questions/62858/turn-off-monitor-using-command-line#62861
sleep 1
xset dpms force off
+
+# Restore focus
+xdotool windowfocus $WINDOW