buttslock will lock your screen when your machine goes to sleep

This commit is contained in:
Jerome Petazzoni 2015-09-30 14:55:36 -07:00
parent 63dcbba106
commit 231d232006
4 changed files with 69 additions and 0 deletions

15
buttslock/Dockerfile Normal file
View File

@ -0,0 +1,15 @@
#
# This container will listen to DBus events to be notified when your
# computer goes to sleep. When such events happen, it will lock the
# screen with a fancy lock.
#
# It needs to be started with a few bind-mounts:
# - /etc/passwd, /etc/shadow (read-only)
# - /var/run/dbus, the X11 socket (typically /tmp/.X11-unix)
# And it also requires the USER and DISPLAY environment variables to be set.
#
FROM alpine
RUN apk update
RUN apk add i3lock imagemagick py-dbus py-gobject scrot ttf-liberation xkeyboard-config
ADD buttslock.py buttslock.sh lock.png /
CMD /buttslock.py

28
buttslock/buttslock.py Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env python
# Shamelessly pasted from:
# http://serverfault.com/questions/573379/system-suspend-dbus-upower-signals-are-not-seen
from datetime import datetime
import dbus
import gobject
from dbus.mainloop.glib import DBusGMainLoop
import os
def handle_sleep(*args):
print "%s PrepareForSleep%s" % (datetime.now().ctime(), args)
if len(args)>0 and args[0]:
os.system("/buttslock.sh")
DBusGMainLoop(set_as_default=True) # integrate into gobject main loop
bus = dbus.SystemBus() # connect to system wide dbus
bus.add_signal_receiver( # define the signal to listen to
handle_sleep, # callback function
'PrepareForSleep', # signal name
'org.freedesktop.login1.Manager', # interface
'org.freedesktop.login1' # bus name
)
loop = gobject.MainLoop()
loop.run()

26
buttslock/buttslock.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/sh
# Shamelessly copied from:
# https://github.com/meskarune/i3lock-fancy
# All options are here: http://www.imagemagick.org/Usage/blur/#blur_args
#BLURTYPE="0x5" # 7.52s
#BLURTYPE="0x2" # 4.39s
#BLURTYPE="5x3" # 3.80s
BLURTYPE="2x8" # 2.90s
#BLURTYPE="2x3" # 2.92s
# I still have to figure out how to get imagemagick fonts to work in Alpine
#FONT="-font Liberation-Sans"
FONT=
scrot /tmp/scrot.png
convert /tmp/scrot.png \
-level 0%,100%,0.6 -blur $BLURTYPE $FONT \
-pointsize 26 -fill white -gravity center \
-annotate +0+200 'Type password to unlock' \
/tmp/conv.png
composite -gravity center /lock.png /tmp/conv.png /tmp/lock.png
#i3lock --textcolor=ffffff00 --insidecolor=ffffff1c --ringcolor=ffffff3e --linecolor=ffffff00 --keyhlcolor=00000080 --ringvercolor=00000000 --insidevercolor=0000001c --ringwrongcolor=00000055 --insidewrongcolor=0000001c -i $IMAGE
i3lock -i /tmp/lock.png --ignore-empty-password

BIN
buttslock/lock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB