#Qole's setback script, for setting the root window
#wallpaper, and making hildon desktop background transparent.
#Set the hildon desktop to plain black before using.
#Thanks to qwerty12 for compiling the necessary apps!

#Pull in the config, if possible...
[ -f /home/user/.wallpaper ] && . /home/user/.wallpaper

#These come from the config file... If not, fall back on defaults
#See the config file for explanation of the settings.

[ "x$IMGPLACE" != x ] || IMGPLACE="center"

[ "x$IMGADJTYPE1" != x ] || IMGADJTYPE="brightness"
[ "x$IMGADJAMT1" != x ] || IMGADJAMT=".1"
[ "x$IMGADJTYPE2" != x ] || IMGADJTYPE="contrast"
[ "x$IMGADJAMT2" != x ] || IMGADJAMT=".1"

[ "x$TRANSTOP" != x ] || TRANSTOP=".6"
[ "x$TRANSLFT" != x ] || TRANSLFT=".5"
[ "x$TRANSBCK" != x ] || TRANSBCK=".3"

#Start xcompmgr (enables transparency) if it isn't running yet.

if [ "x`pidof /usr/bin/xcompmgr`" = x ] ; then
  xcompmgr &
fi

#Put the background image on the root X window.

hsetroot -$IMGPLACE $1 -$IMGADJTYPE1 $IMGADJAMT1 -$IMGADJTYPE2 $IMGADJAMT2

#Use this instead of hsetroot to overlay the image name
#on the backgound, at the expense of being able to increase
#the background image's brightness.

#habak -mC -hi $1 -mp 85,400 -mh 14 -mf /usr/share/fonts/SwaBI4nh.ttf -ht "$1"

#Use geometry (width) to sort .. background, top, side
WINLIST=`wmctrl -l -G | grep hildon-desktop | awk '{print $5"x"$6" "$1}' | sort -nr | awk '{print $2}'`

COUNT=1 

for WINID in $WINLIST
 do
  #echo "$WINID is id $COUNT"
  case $COUNT in
   1)
     # Background
     transset-df -i $WINID -m $TRANSBCK --dec 1;
     ;;
   2)
     # Top panel
     transset-df -i $WINID -m $TRANSTOP --dec 1;
     ;;
   3)
     # Side panel
     transset-df -i $WINID -m $TRANSLFT --dec 1;
     ;;
  esac
  COUNT=$((++COUNT))
done;
