summaryrefslogtreecommitdiff
path: root/swaylock-wrapper
blob: 2c1fae11b4f99534e37935ca02afdc08b77818eb (plain)
    1 #!/usr/bin/env bash
    2 # Performs a standard screen lock, with an extra bit of style. Before locking
    3 # the screen, takes a screenshot of the current display and blurs and
    4 # desaturates the image, using that for the lock screen background. A mighty
    5 # neat effect. 
    6 #
    7 # Requirements: sway-lock grim imagemagick
    8 #
    9 export IFS=$'\n\t'
   10 set -euo pipefail
   11 
   12 
   13 # Generates the command to execute for taking a screenshot and applying affects
   14 # for use as the lockscreen wallpaper. Note that this does not execute the
   15 # command. It only generates it.
   16 #
   17 # @out_file   Path to save the lockscreen wallpaper to
   18 gen_wallpaper_cmd() {
   19   local out_file="${1:?}"
   20   local cmd=""
   21 
   22   if type -p grim 1>/dev/null 2>/dev/null; then
   23     cmd="$(type -p grim) -c -l 0 -"
   24   else
   25     return 2
   26   fi
   27 
   28   # Generate the wallpaper gen command (with blurring and desaturation)
   29   printf '%s | convert - -scale 50%% -blur 0x3 -modulate 110,50 %s\n' \
   30     "${cmd}" "${out_file}"
   31 }
   32 
   33 
   34 # Locks the screen using i3lock command. Sets 
   35 #
   36 # @bg   Path to image to be used for the lockscreen wallpaper
   37 lock_screen() {
   38   local bg="${1:?}"
   39   # Lock, but remain in foreground so the unlock processes aren't executed yet
   40   swaylock -i "${bg}"
   41 }
   42 
   43 
   44 # La fonction primaire
   45 main() {
   46   blurry_wallpaper='/tmp/swaylockwall.png'
   47   # Get the program path that will screenshot for the background image
   48   lock_wallpaper_cmd="$(gen_wallpaper_cmd ${blurry_wallpaper})"
   49 
   50   if [ "${lock_wallpaper_cmd}" = "" ]; then
   51     echo "Screenshot command not found (grim). Exiting."
   52     return 1
   53   fi
   54 
   55   # Screenshot and post-process
   56   bash -c "${lock_wallpaper_cmd}"
   57 
   58   # Execute the lock screen with the new fancy wallpaper
   59   lock_screen ${blurry_wallpaper}
   60 
   61   # Cleanup the original screenshot and blurred counterpart
   62   rm "${blurry_wallpaper}"
   63 }
   64 
   65 # Enter the script here
   66 main ${@}

Generated by cgit