#!/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 programatically # blurs and desaturates the image, using that for the lock screen background. A # mighty neat effect. # # Requirements: i3-lock imagemagick [scrot] [xbacklight] # # # 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. # # @param out_file Path to save the lockscreen wallpaper to # function gen_wallpaper_cmd { # Return early if argument 1 not specified [[ -z ${1} ]] && return out_file=${1} tmp_file="/tmp/i3lock$(date '+%s')screen.jpg" screenshot_cmd="" if [[ $(which import 2>/dev/null) ]]; then screenshot_cmd="$(which import) -window root ${tmp_file}" elif [[ $(which scrot 2>/dev/null) ]]; then screenshot_cmd="$(which scrot) -d0 ${tmp_file}" fi # Generate the wallpaper gen command if [[ ${screenshot_cmd} != "" ]]; then # Generate the lockscreen background/screenshot (blurred and slightly less # saturated) out=${screenshot_cmd} # Add the image blur command out=${out}' && ' out=${out}"convert ${tmp_file} -blur 0x4 -modulate 110,50 ${out_file}" # Add command to clean up the original screenshot file out="${out} && " out="${out} rm ${tmp_file}" echo "${out}" fi # Else we echo nothing, indicating no screenshotter was found } # # Locks the screen using i3lock command. Sets # # @param bg Path to image to be used for the lockscreen wallpaper # function lock_screen { # Return early if argument 1 not specified [[ -z ${1} ]] && return bg=${1} dim=0 [[ $(which xbacklight) ]] && dim=1 if [[ ${dim} == 1 ]]; then # Get the previous brightness so we can return to it. prev_bright=$(xbacklight | cut -d '.' -f 1) # Dim the screen, backgrounded so it continues fading after lock xbacklight -set 3% -time 2000 -steps 150& fi # Lock, but remain in foreground so the unlock processes aren't executed yet i3lock -i "${bg}" -n # Resume original brightness [[ ${dim} == 1 ]] && xbacklight -set ${prev_bright}% -time 2000 -steps 150 } # # La fonction primaire # function main { blurry_wallpaper='/tmp/i3lockwall.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 (scrot or import). Exiting." exit 1 fi # Execute in a subshell, or the double amperstands (&&) will fail. Seems I've # discovered a querk of bash. 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 "${bg}" } # Enter the script here main ${ARGV}