#!/usr/bin/env bash # originally got the idea from this script: # src:https://github.com/veltall/custom-i3lock # get random image to use # https://stackoverflow.com/questions/61290199/how-do-i-select-a-random-file-from-a-directory random_image=$(ls -1 /home/${USER}/.local/share/img/*.png | shuf | head -1) random_image_filname="$(basename -- $random_image)" # get random gravity to use for the overlay image, take the number of displays into account numberOfDisplays=$(xrandr --query | grep -o " connected " | wc -l) gravity=("center") # "center" "northwest" "northeast" "southwest" "southeast" if [[ numberOfDisplays == 1 ]] || [[ numberOfDisplays == 3 ]] ; then gravity=("center" "northwest" "northeast" "southwest" "southeast") elif [[ numberOfDisplays == 2 ]] || [[ numberOfDisplays == 4 ]] ; then gravity=("northeast" "southeast") else gravity=("northeast" "southeast") fi random_gravity=${gravity[ $RANDOM % ${#gravity[@]} ]} # take a screenshot of the entire screen, blur it, and adjust white balance scrot --overwrite /tmp/currentworkspace.png magick /tmp/currentworkspace.png -blur 0x9 /tmp/currentworkspaceblur.png mogrify -brightness-contrast 50 /tmp/currentworkspaceblur.png # send a notification to the user after the screenshot is taken, to avoid including the notification notify-send "LOCKING SCREEN" "The system is about to be locked.\nPress any key to stop this from happening.\n\n${random_image_filname} @ ${random_gravity}" # https://linuxsimply.com/bash-scripting-tutorial/input-output/input/wait-for-input/ read -t 15 -n 1 key # read a single character within a X-seconds period if [ $? = 0 ]; then notify-send "'${key}' is pressed ➔ the screen will not be locked" exit else # find height of background image, and set the overlay to be 1/3 of this workspaceHeight=$(magick /tmp/currentworkspaceblur.png -print "%h" /dev/null) overlayHeight=$((${workspaceHeight} / 3)) # resize the overlay image cp ${random_image} /tmp/overlayimage.png mogrify -resize x${overlayHeight} /tmp/overlayimage.png # create the final image to be used as the lock screen, and lock the system composite -gravity ${random_gravity} /tmp/overlayimage.png /tmp/currentworkspaceblur.png /tmp/lockbackground.png i3lock --tiling -i /tmp/lockbackground.png fi