Automatically lock the screen when Librem Key is removed
Open, NormalPublic

Description

As a nice add-on for the Librem Key in PureOS, we would like to automatically lock the screen for the user when they remove their Librem Key. This is a relatively simple addition and I will leave the implementation details (what package to use, etc.) up to you, but ideally this would be in a package that automatically gets installed in PureOS.

This integration requires two files: /etc/udev/rules.d/85-libremkey.rules:

ACTION=="remove", ENV{ID_VENDOR}=="Nitrokey", RUN+="/usr/local/bin/gnome-screensaver-lock"

and /usr/local/bin/gnome-screensaver-lock:

#!/bin/sh

user=`ps aux | egrep "gdm-(wayland|x)-session" | head -n 1 | awk '{print $1}'`

if [ -n $user ]; then
        su $user -c "/usr/bin/dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock"
fi

I leave it up to you whether we keep the script at /usr/local/bin or not. If its location changes, it will also need to change in the udev rule.

The package will need to trigger udev to reload upon installation so it picks up the new rule.

jeremiah.foster triaged this task as "Normal" priority.
hansolo added a subscriber: hansolo.Fri, Feb 8, 7:24 PM

Add Comment