diff options
Diffstat (limited to 'infra/libkookie/modules/workstation/ui/i3/core/tools/i3-locker.nix')
-rw-r--r-- | infra/libkookie/modules/workstation/ui/i3/core/tools/i3-locker.nix | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/infra/libkookie/modules/workstation/ui/i3/core/tools/i3-locker.nix b/infra/libkookie/modules/workstation/ui/i3/core/tools/i3-locker.nix new file mode 100644 index 000000000000..749d41e4eb39 --- /dev/null +++ b/infra/libkookie/modules/workstation/ui/i3/core/tools/i3-locker.nix @@ -0,0 +1,47 @@ +/** A utility script to lock the screen + * + * This tool relies on i3lock, ./lock.png, fortune, and imagemagic to + * create a picture to fill all available screens + */ + +{ pkgs, ... }: +with pkgs; +let + lockIcon = "${i3lock-fancy}/share/i3lock-fancy/icons/lock.png"; + i3lock = "${i3lock}/bin/i3lock"; + mktemp = "${coreutils}/bin/mktemp"; + rm = "${coreutils}/bin/rm"; + fortune = "${fortune}/bin/fortune"; + xrandr = "${xrandr}/bin/xrandr"; + convert = "${imagemagick}/bin/convert"; +in +writeShellScript "libkookie-i3locker" '' + + # Create a temp directory to work in + TMPDIR=$(${mktemp} -d) + BGIMAGE=$TMPDIR/lockbg.png + FORTUNE=$(${fortune} | sed -e 's/\t/ /g') + TMPRES=$(${xrandr} | grep \* | cut -d' ' -f4 | sed ':a;N;$!ba;s/\n/ /g') + RESOLUTION=$(`echo $TMP_RES | sed 's/ /\n/g'`) + + # Create a base image + ${convert} -size 0x0 canvas:black $BGIMAGE + + for mon in "${RESOLUTION[@]}" + do + echo "Running for monitor $mon" + TMPLOCK="$TMPDIR/tmplock.png" + ${convert} -size "$mon" canvas:black -font Inconsolata -pointsize 18 \ + -fill white -gravity center -annotate +0+250 "$FORTUNE" \ + "${lockIcon}" -gravity center -composite "$TMPLOCK" + + ${convert} "$IMAGE" "$TMPLOCK" +append "$IMAGE" + ${rm} "TMPLOCK" + done + + # Lock the screen + ${i3lock} -i "$IMAGE" + + # Remove all the temp images + ${rm} -rf $TMPDIR +'' |