summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@iohq.net>2015-04-09 22:25:44 -0600
committerAaron Ball <nullspoon@iohq.net>2015-04-09 22:25:44 -0600
commitb85c040ef738c9a2ca6823e990703c72607ca20f (patch)
tree6435815137dc2060332323b1fc7464df78c1a31a
parent8317b4d08e3d5b2a9e86c6a582799f5429d783fc (diff)
downloadbin-b85c040ef738c9a2ca6823e990703c72607ca20f.tar.gz
bin-b85c040ef738c9a2ca6823e990703c72607ca20f.tar.xz
Refactor of the i3-lock-wrapper
Made it a bit more tolerant of missing binaries. Broke bits into functions. Added more comments.
-rwxr-xr-xi3-lock-wrapper105
1 files changed, 89 insertions, 16 deletions
diff --git a/i3-lock-wrapper b/i3-lock-wrapper
index 556ab5a..f8f2c70 100755
--- a/i3-lock-wrapper
+++ b/i3-lock-wrapper
@@ -3,30 +3,103 @@
# 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.
+# mighty neat effect.
#
# Requirements: i3-lock imagemagick [scrot] [xbacklight]
#
-base=/tmp/i3-lock-wrapper-$(date "+%s")
-file1=base.jpg
-file2=base2.png
-if [[ $(which import) ]]; then
- import -window root "$file1"
-elif [[ $(which scrot) ]]; then
- scrot -d0 "$file1"
-else
- echo "Screenshot command not found (scrot or import). Exiting."
-fi
+#
+# 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})
-convert "$file1" -blur 0x4 -modulate 110,50 "$file2"
+ 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}"
-xbacklight -set 2% -time 3000 -steps 100&
+ # Execute the lock screen with the new fancy wallpaper
+ lock_screen ${blurry_wallpaper}
-i3lock -i "$file2" -n
+ # Cleanup the original screenshot and blurred counterpart
+ rm "${bg}"
+}
-xbacklight -set 10% -time 2000 -steps 100
-rm "$file1" "$file2"
+# Enter the script here
+main ${ARGV}

Generated by cgit