#!/bin/sh -u # # Set the root background, update state files to match. # - Cameron Simpson # : ${TMPDIR:=/tmp} : ${RBG_PICKIM:='-w -x "$HALFX" -y "$HALFY"'} tmppfx=$TMPDIR/rbg$$ trap 'rm -f "$tmppfx".*' 0 trap 'rm -f "$tmppfx".*; exit 1' 1 2 13 15 cmd=$0 usage="Usage: $cmd [-1] [-d desk] [-n] [-xpl] [[imagefile [imagefile] | imlist-search-args... | -xpl [xpl-args...]} -1 Choose exactly one image. -d desk Set the background for the specified desk. Default: the current desk backdrop. -: the global default backdrop. -n No action. Just print the chosen image(s). -xpl Xplanet mode. Following arguments are passed to xpl, not imlist-search." [ -n "$DISPLAY" ] || { echo "$cmd: no \$DISPLAY!" >&2; exit 1; } badopts= pickn=20 perdesk= pickopts= strippfx= bgdesk=. doxpl= doit=1 while : do case $1 in -d) bgdesk=$2; shift ;; -n) doit= ;; -1) pickn=1 ;; -xpl) doxpl=1; shift; break ;; *) break ;; esac shift done [ "x$bgdesk" = x. ] && bgdesk=`currentdesk` if [ $doxpl ] then set -x if xplimg=`xpl -png -g screen ${1+"$@"}` then xplimg=`filecache "$xplimg"` || exit 1 deskbg -d "$bgdesk" "$xplimg" fi exit $? fi if [ $# = 0 ] then allfiles= else # try to recast line as a list of cachefiles allfiles=1 first= for file do if [ $first ]; then first=; set --; fi cfile=`filecache "$file" 2>/dev/null` || { allfiles= cfile=$file; } set -- ${1+"$@"} "$cfile" done fi [ $allfiles ] && exec deskbg -d "$bgdesk" -- ${1+"$@"} # presume keyword search tmpf=$tmppfx.txt eval "pickim -P \"\$strippfx\" -n \"\$pickn\" -w -x \"\$HALFX\" -y \"\$HALFY\" $RBG_PICKIM "'${1+"$@"}' | sort -u >"$tmpf" [ -s "$tmpf" ] || { echo "$cmd: no image files chosen!" >&2 exit 1 } [ $doit ] || { cat "$tmpf"; exit $?; } ## no exec so trap may run # pop up menu choice { echo "DestroyMenu RBGMenu" echo "AddToMenu RBGMenu \"Set Root BG: deskbg -d $bgdesk\" Title" fvwm-menu-imlist -l - RBGMenu deskbg -d "$bgdesk" echo "Popup RBGMenu" } \ <"$tmpf" \ | fvwmcmd