Skip to content

Instantly share code, notes, and snippets.

@lukas2511
Created October 5, 2018 19:21
Show Gist options
  • Save lukas2511/45adc7e983e6528a363b73a4e5c2b4a6 to your computer and use it in GitHub Desktop.
Save lukas2511/45adc7e983e6528a363b73a4e5c2b4a6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
if [ "${1}" = "suspend" ]; then
(sleep 2; systemctl suspend) &
fi
FILTER_COMPLEX=""
while read LINE; do
if [[ $LINE =~ ^Screen.+current\ ([0-9]+)\ x\ ([0-9]+),.+$ ]]; then
SCREEN_WIDTH=${BASH_REMATCH[1]}
SCREEN_HEIGHT=${BASH_REMATCH[2]}
fi
if [[ $LINE =~ ([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+) ]]; then
POS_X=$((${BASH_REMATCH[3]}+${BASH_REMATCH[1]}/2-90))
POS_Y=$((${BASH_REMATCH[4]}+${BASH_REMATCH[2]}/2-90))
if [ -z "${FILTER_COMPLEX}" ]; then
FILTER_COMPLEX="${FILTER_COMPLEX} [0:v:0] [2:v:0] overlay=$((${BASH_REMATCH[3]} + 170)):$((${BASH_REMATCH[4]} + 238)) [clear_screen];"
FILTER_COMPLEX="${FILTER_COMPLEX} [clear_screen] boxblur=16:1 [blurred_screen];"
fi
FILTER_COMPLEX="${FILTER_COMPLEX} [blurred_screen] [1:v:0] overlay=${POS_X}:${POS_Y} [blurred_screen];"
fi
done <<< "$(xrandr)"
timeout 1.5 ffmpeg -v error -nostats -nostdin -y \
-video_size ${SCREEN_WIDTH:-1920}x${SCREEN_HEIGHT:-1080} \
-threads 1 \
-f x11grab -r 60 -i "${DISPLAY}+0,0" \
-i /home/lukas2511/Pictures/lock.png \
-i /home/lukas2511/Pictures/cryptolocker.png \
-vframes 1 \
-filter_complex "${FILTER_COMPLEX::-1}" \
-map '[blurred_screen]' \
/tmp/lockshot.png || cp /home/lukas2511/Pictures/lockscreen.png /tmp/lockshot.png
if [ -n "${WAYLAND_DISPLAY:-}" ]; then
swaylock -c 141414 -i /tmp/lockshot.png -f || swaylock -c 141414 -i /home/lukas2511/Pictures/lockscreen.png -f
else
i3lock -c 141414 -i /tmp/lockshot.png -f || i3lock -c 141414 -i /home/lukas2511/.lockscreen.png -f
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment