#!/bin/sh -u # # Change the image menu backdrop image for the running FVWM. # - Cameron Simpson 18oct2002 # : ${TMPDIR:=/tmp} cmd=`basename "$0"` call="$0 $*" domenu= aspect=-t strippfx= pickn=16 desk= usage="Usage: $cmd [options...] [ imagefile | bglist-args... ] - Write FVWM commands to stdout instead of to FVWM. -t Choose tall images. -w Choose wider images. -d n Set the menu backdrop for the specified desktop. Default: the current desktop." badopts= opts= exec 3>&1 1>&2 fvcmd=fvwmcmd [ "x$1" = x- ] && { fvcmd=echo; shift; } while : do case $1 in -d) desk=$2; shift opts="$opts -d $desk" ;; -[tw]) aspect=$1 ;; -?*)echo "$cmd: unrecognised option: $1" >&2; badopts=1 ;; --) shift; break ;; *) break ;; esac shift done [ $badopts ] && { echo "$usage" >&2; exit 2; } ############################################################### # A URL? Fetch and use. case "$#,$1" in 1,http://*) set -x exec withurl "$1" "$0" $opts ;; esac [ -n "$desk" ] || desk=`currentdesk` || exit 1 menucs=`expr 2048 + $desk` ############################################################### # Erase menu backdrop. if [ "x$*" = xnone ] then desktop "$desk" menubg '' exec >&3 3>&- exec $fvcmd "Colorset $menucs RootTransparent" fi ############################################################### # single filename - set image directly if [ $# = 1 ] && [ -f "$1" -a -s "$1" ] then srcimage=$1; shift desktop "$desk" menubg_src "$srcimage" & cachefile=`filecache "$srcimage"` || exit 1 desktop "$desk" menubg "$cachefile" || exit 1 lastvalue menubg "$cachefile" & shade=60 mulshade=0.$shade convname=pngof/sh$shade imagefile=`convof -C "$convname" -discard "$cachefile" \ gm convert "$cachefile" \ -normalize \ -operator red Multiply "$mulshade" \ -operator green Multiply "$mulshade" \ -operator blue Multiply "$mulshade" \ -quality 100 png:-` || exit 1 if [ -n "$DISPLAY" ] then exec >&3 3>&- $fvcmd "Colorset $menucs AspectPixmap $imagefile" fi exit 0 fi ############################################################### # presume search args pickimargs=$* set -- `pickim -P "$strippfx" -n $pickn $aspect ${1+"$@"} | sort -u` || exit 1 [ $# = 0 ] && { echo "$cmd: no image files chosen!" >&2; exit 1; } [ -t 1 ] && ( cd; ls -ld -- "$@" ) tmpf=$TMPDIR/menubg$$ for arg do echo "$arg" done >"$tmpf" ( echo "DestroyMenu MenuBG" echo "AddToMenu MenuBG \"MenuBG $pickimargs\" Title" fvwm-menu-imlist -l "$tmpf" MenuBG menubg; rm "$tmpf" echo "Popup MenuBG" ) | fvwmcmd exit $?