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