summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2021-10-15 16:19:26 -0600
committerAaron Ball <nullspoon@oper.io>2021-10-15 16:19:26 -0600
commit257229282a7b1b78818f6df96dcee3f0b86e2f0b (patch)
tree375f75692201b4ac5b4d18f15e1e8e1f0b59c59c
parent051095fc8334dea0cd6d521152f222b454071c84 (diff)
downloadbin-257229282a7b1b78818f6df96dcee3f0b86e2f0b.tar.gz
bin-257229282a7b1b78818f6df96dcee3f0b86e2f0b.tar.xz
random_wallpaper: Support Wayland
-rwxr-xr-xrandom_wallpaper.sh67
1 files changed, 45 insertions, 22 deletions
diff --git a/random_wallpaper.sh b/random_wallpaper.sh
index cd5ffe7..26fd591 100755
--- a/random_wallpaper.sh
+++ b/random_wallpaper.sh
@@ -6,36 +6,59 @@
# Usage:
# random_wallpaper.sh /path/to/wallpapers
#
-# Requirements:
+# Requirements (X11):
# feh
#
+# Requirements (Wayland):
+# swaybg
+#
-# Check for feh
-which feh 2>/dev/null 1>/dev/null
-if [[ $? == 1 ]]; then
- echo "Required program 'feh' not found. Please install and run again."
- exit 1
-fi
+x11_set() {
+ local wallpaper="${1}"
+
+ # Check for feh
+ type -p feh 2>/dev/null 1>/dev/null
+ if [ $? -eq 1 ]; then
+ echo "Required program 'feh' not found. Please install and run again."
+ return 1
+ fi
+
+ # Set the wallpaper
+ feh --bg-fill "${wallpaper}"
+}
+
+wayland_set() {
+ local wallpaper="${1}"
+ local pidfile=/dev/shm/swaybg-$(whoami).pid
+ printf 'Setting wallpaper to %s\n' "${wallpaper}"
+
+ swaybg -o '*' -i "${wallpaper}" -m fill 2>/dev/null 1>/dev/null &
+ echo $! > "${pidfile}.new"
+ sleep .5
+
+ if [ -f "${pidfile}" ] && [ -d /proc/$(cat ${pidfile}) ]; then
+ kill $(cat "${pidfile}")
+ fi
+ mv "${pidfile}.new" "${pidfile}"
+}
# Make sure a wallpaper path was specified
-if [[ -z $1 ]]; then
+if [ -z ${1} ]; then
echo "Please specify a wallpaper path."
exit 1
fi
-# This needs to be set if scheduling in crontab since crontab don't have
-# displays
-# export DISPLAY=:0
-
-search_path=$1
-
-# Randomly select a wallpaper to set
-picture=$(find ${search_path} -type f \
- -name '*.jpg' \
- -o -name '*.JPG' \
- -o -name '*.png' \
- -o -name '*.PNG' \
+search_path=${@}
+randpic=$(find ${search_path} -type f \
+ -iname '*.jpg' \
+ -o -iname '*.png' \
| sort -R | head -n 1)
-# Set the wallpaper
-feh --bg-fill "${picture}"
+if [ -n "${WAYLAND_DISPLAY:-}" ]; then
+ wayland_set "${randpic}"
+elif [ -n "${DISPLAY:-}" ]; then
+ x11_set "${randpic}"
+else
+ printf 'ERROR: Could not detect display manager\n'
+ exit 1
+fi

Generated by cgit