#!/usr/bin/env bash # Performs a standard screen lock, with an extra bit of style. Before locking # the screen, takes a screenshot of the current display and blurs and # desaturates the image, using that for the lock screen background. A mighty # neat effect. # # Requirements: sway-lock grim imagemagick # export IFS=$'\n\t' set -euo pipefail # Generates the command to execute for taking a screenshot and applying affects # for use as the lockscreen wallpaper. Note that this does not execute the # command. It only generates it. # # @out_file Path to save the lockscreen wallpaper to gen_wallpaper_cmd() { local out_file="${1:?}" local cmd="" if type -p grim 1>/dev/null 2>/dev/null; then cmd="$(type -p grim) -c -l 0 -" else return 2 fi # Generate the wallpaper gen command (with blurring and desaturation) printf '%s | convert - -scale 50%% -blur 0x3 -modulate 110,50 %s\n' \ "${cmd}" "${out_file}" } # Locks the screen using i3lock command. Sets # # @bg Path to image to be used for the lockscreen wallpaper lock_screen() { local bg="${1:?}" # Lock, but remain in foreground so the unlock processes aren't executed yet swaylock -i "${bg}" } # La fonction primaire main() { blurry_wallpaper='/tmp/swaylockwall.png' # Get the program path that will screenshot for the background image lock_wallpaper_cmd="$(gen_wallpaper_cmd ${blurry_wallpaper})" if [ "${lock_wallpaper_cmd}" = "" ]; then echo "Screenshot command not found (grim). Exiting." return 1 fi # Screenshot and post-process bash -c "${lock_wallpaper_cmd}" # Execute the lock screen with the new fancy wallpaper lock_screen ${blurry_wallpaper} # Cleanup the original screenshot and blurred counterpart rm "${blurry_wallpaper}" } # Enter the script here main ${@}