From 03290f61e790b34fde93926cf48fe146a4310924 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 31 Jan 2024 13:23:26 -0500 Subject: [PATCH] Wallpaper script supports color, no longer sources conf file --- session/src/xmd-load-wallpaper | 52 ++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/session/src/xmd-load-wallpaper b/session/src/xmd-load-wallpaper index 9f7e027..05f1d43 100755 --- a/session/src/xmd-load-wallpaper +++ b/session/src/xmd-load-wallpaper @@ -1,9 +1,51 @@ #!/bin/sh -if type "$XMD_USERDIR/wallpaper" > /dev/null; then - . "$XMD_USERDIR/wallpaper" - - if type xwallpaper > /dev/null; then - xwallpaper "--${mode}" "$file" +name=`basename "$0"` +configFilePath="$XMD_USERDIR/wallpaper" + +isInstalled() { + type "$1" > /dev/null +} + +shouldHaveInstalled() { + if ! isInstalled "$1"; then + echo "$name: $1 is not installed" >&2 + return 1 fi +} + +usage() { + echo "Usage: $name" >&2 + exit 2 +} + +[ "$#" -gt 0 ] && usage + +if type "$configFilePath" > /dev/null; then + color="black" + + while read -r line; do + IFS="=" read key value << EOF +$line +EOF + case "$key" in + "mode") mode="$value";; + "file") file="$value";; + "color") color="$color";; + *) echo "$name: bad key $key in $configFilePath" >&2;; + esac + done < "$configFilePath" + + case "$mode" in + "" | center | focus | maximize | stretch | tile | zoom) ;; + *) + echo "$name: bad mode $mode" >&2 + exit 1 + ;; + esac + + [ -n color ] && shouldHaveInstalled xsetroot && \ + xsetroot -solid "$color" + [ -n mode ] && shouldHaveInstalled xwallpaper && \ + xwallpaper "--${mode}" "$file" fi