My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/infra/libkookie/modules/workstation/ui/i3/core/tools/i3-locker.nix

47 lines
1.4 KiB

/** 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";
fortuneBin = "${fortune}/bin/fortune";
xrandrBin = "${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=$(${fortuneBin} | sed -e 's/\t/ /g')
TMPRES=$(${xrandrBin} | 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
''