summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2024-02-28 11:21:23 -0700
committerAaron Ball <nullspoon@oper.io>2024-02-28 11:21:23 -0700
commit0a0feb7fc55339ecc28c7b70432977880dc4a414 (patch)
tree7d4e64c040e1df5c3148b4f1c38fc9280aa81aa5
parent257229282a7b1b78818f6df96dcee3f0b86e2f0b (diff)
downloadbin-master.tar.gz
bin-master.tar.xz
Add swaylock-wrapperHEADmaster
This makes a pretty lockscreen for sway, using grim to take a screenshot, and imagemagick to blur and desaturate.
-rwxr-xr-xswaylock-wrapper66
1 files changed, 66 insertions, 0 deletions
diff --git a/swaylock-wrapper b/swaylock-wrapper
new file mode 100755
index 0000000..2c1fae1
--- /dev/null
+++ b/swaylock-wrapper
@@ -0,0 +1,66 @@
+#!/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 ${@}

Generated by cgit