#! /bin/bash
FILTER=/usr/share/rotation/winidfilter
if [ ! -f $FILTER ]; then
mkdir -p /usr/share/rotation
cat >> $FILTER << EOF
has no name
window
child
\/
applet
ROX
rox
Panel
panel
Active tasks
Battery Monitor
SD Monitor
Screen Blanker
Volume Control
Wireless Monitor
Clock
X Virtual Keyboard
App Launcher
SCIM
scim
32x32
EOF
fi

# See how we were called.
  
closed() {
    /usr/X11R6/bin/xset s activate
    return 0
}

landscape() {
    /usr/X11R6/bin/xrandr -o normal

    for APP in `xwininfo -root -tree|grep -v -f $FILTER|cut -d\" -f2|grep [a-z]|sed -e "s/ /#/g"`
    do
      APP=`echo $APP|sed -e "s/#/ /g"`
      if [ "`echo $APP|grep 0x`" = "" ]; then
        sleep 1
        #echo "processing $APP..." >> /home/root/rotate.landscape
        xresizewindow "$APP" "638x420+0+0"
      fi
    done
    
    if pidof xvkbd >/dev/null; then xvkbdlauncher; fi

    return 0
}	

portrait() {
    /usr/X11R6/bin/xrandr -o left

    for APP in `xwininfo -root -tree|grep -v -f $FILTER|cut -d\" -f2|grep [a-z]|sed -e "s/ /#/g"`
    do
      APP=`echo $APP|sed -e "s/#/ /g"`
      if [ "`echo $APP|grep 0x`" = "" ]; then
        sleep 1
        #echo "processing $APP..." >> /home/root/rotate.portrait
        xresizewindow "$APP" "478x586+0+0"
      fi 
    done

    if pidof xvkbd >/dev/null; then xvkbdlauncher; fi
    
    return 0
}  


case "$1" in
  closed)
  	closed
	;;
  landscape)
  	landscape
	;;
  portrait)
  	portrait
  	;;	
  *)
	echo "Usage: $0 {closed|landscape|portrait}"
	exit 1
esac

exit $?
