diff --git a/buttslock/Dockerfile b/buttslock/Dockerfile new file mode 100644 index 0000000..ee14255 --- /dev/null +++ b/buttslock/Dockerfile @@ -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 diff --git a/buttslock/buttslock.py b/buttslock/buttslock.py new file mode 100755 index 0000000..126ed4c --- /dev/null +++ b/buttslock/buttslock.py @@ -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() + diff --git a/buttslock/buttslock.sh b/buttslock/buttslock.sh new file mode 100755 index 0000000..7c780e9 --- /dev/null +++ b/buttslock/buttslock.sh @@ -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 + diff --git a/buttslock/lock.png b/buttslock/lock.png new file mode 100644 index 0000000..e268624 Binary files /dev/null and b/buttslock/lock.png differ