Screen locking with awesome wm and lightdm

April 15 2015

There are a few ways of solving the screen locking/screensaver problem if you’re using awesome wm:

  • xautolock and slock
  • xscreensaver
  • lightdm and light-locker

xautolock and slock

xautolock and slock probably come as close (in terms of lightness and philosophy) to awesome, as it gets. They both solve very specific problems:

  • slock: blanking the screen and handling user re-authentication
  • xautolock: controlling and invoking the screen locker on user inactivity

Installing and setting them up is quite simple, as described here:

sudo apt-get install suckless-tools xautolock

Starting xautolock with slock can be easily done using the following script in ~/.config/awesome/scripts/locker.sh:

#!/bin/bash

exec xautolock -detectsleep \
  -time 3 -locker "slock" \
  -notify 30 \
  -notifier "notify-send -u critical -t 10000 -- 'LOCKING screen in 30 seconds'"

and the following line in ~/.config/awesome/rc.lua:

awful.util.spawn_with_shell("~/.config/awesome/scripts/locker.sh&")

To manually lock the screen, the following entry needs to be added to the global key table in your rc.lua file:

      awful.key({ modkey, "Control" }, "l",
	 function ()
	    awful.util.spawn("sync")
	    awful.util.spawn("xautolock -locknow")
      end),

However, there’s a problem with this approach - xautolock does not lock the screen on suspend.

Enter light-locker

light-locker is a simple locker forked from gnome-screensaver, relying on lightdm for locking and unlocking your session. It’s main benefit for my use is that light-locker detects suspends and locks the screen. The downside of light-locker is that it does not monitor keyboard and mouse activity, so it can’t lock your screen responding to inactivity.

This means that we’ll still need to rely on xautolock to lock the screen when it is not being used.

For starters, let’s change the ~/.config/awesome/scripts/locker.sh file we had introduced before:

#!/bin/bash

exec run-one light-locker --lock-on-suspend&

exec xautolock -detectsleep \
  -time 3 -locker "light-locker-command -l" \
  -notify 30 \
  -notifier "notify-send -u critical -t 10000 -- 'LOCKING screen in 30 seconds'"

So, this script starts both light-locker and xautolock to control it. Be sure to install the run-one tool used in the script:

sudo apt-get install run-one

There’s no need to change the keyboard binding defined before and this all works.

My whole awesome wm config can be found here.