From 231d232006958029a636ee5d04f991b868989b54 Mon Sep 17 00:00:00 2001 From: Jerome Petazzoni Date: Wed, 30 Sep 2015 14:55:36 -0700 Subject: [PATCH] buttslock will lock your screen when your machine goes to sleep --- buttslock/Dockerfile | 15 +++++++++++++++ buttslock/buttslock.py | 28 ++++++++++++++++++++++++++++ buttslock/buttslock.sh | 26 ++++++++++++++++++++++++++ buttslock/lock.png | Bin 0 -> 1387 bytes 4 files changed, 69 insertions(+) create mode 100644 buttslock/Dockerfile create mode 100755 buttslock/buttslock.py create mode 100755 buttslock/buttslock.sh create mode 100644 buttslock/lock.png 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 0000000000000000000000000000000000000000..e268624ffb83252bd0838b2861ae9dd30da8f6d6 GIT binary patch literal 1387 zcmV-x1(f=UP)!1A2fvfvbTl{O3P`-+*CY0Qkmh<03LcNwipDF{o;b zh*bUioxnZ74ZvlYf?@u}nH~W8MdWzsA}*GO8BQvvs+)n=fnK1)6k7<>z)9d~5qU*b z0UBn!VuidU6#`mRbvtkfxRzpO0a}3#z+P2-4QTTh(iAJkq75_KOP&PYpfTT>@Br|E zs;*fQE$q8-RaKt_o&hefWg5V3z~|t`2ouXq;V($tvwgtZK)WrI;uLTK_z@Vyjm{f@ z>w#^+r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