#!/bin/sh
#
#
#              Companion shell script for xpsitouch.
#
# When xpsitouch executes a program, it calls this script with
# two arguments, for example: 
#
#   /etc/xpsitouchrc.sh 1 2
#
# Where the first argument is the number of the toolbar, and the
# second argument is the button number.
#
# Toolbar 1 is the horizontal bottom toolbar, and 2 is the vertical
# left toolbar. The button numbers are from left to right, and from
# top to bottom.
#

#echo "Args: '$1' '$2'"

# Check for user's .xpsitouchrc.sh
if [ -f ~/.xpsitouchrc.sh ]; then
  echo "Found user script"
  ~/.xpsitouchrc.sh $1 $2
  exit
fi

horiz_toolbar() {
  local button="$1"
  #echo "Launching horizontal toolbar button $1"
  case "$1" in
    1)
      rxvt -geometry 50x10 -e echo "Modify the menu by editing $0"
      ;;
    2)
      rxvt -geometry 50x10 -T "Vi" -e vi
      ;;
    3)
      rxvt -geometry 50x10 -e echo "Modify the menu by editing $0"
      ;;
    4)
      rxvt -geometry 50x10 -e echo "Modify the menu by editing $0"
      ;;
    5)
      rxvt -geometry 50x10 -T "Cal" -e cal
      ;;
    6)
      rxvt -geometry 50x10 -T "Mutt" -e mutt
      ;;
    7)
      /usr/X11R6/bin/xcalc -geometry 250x200
      ;;
    8)
      rxvt  -geometry 50x10 -T "Todo" -e vi ~/todo
      ;;
    9)
      /usr/X11R6/bin/xman
      ;;
    *)
      echo "Must specify the button value between 1 and 9"
      exit 1
  esac
}

vert_toolbar() {
  local $button="$1"
  #echo "Launching vertical toolbar button $1"
  case "$1" in
    1)
      rxvt -geometry 50x10 -e echo "Modify the menu by editing $0"
      ;;
    2)
      rxvt -geometry 50x10 -e echo "Modify the menu by editing $0"
      ;;
    3)
      rxvt -geometry 50x10 -e echo "Modify the menu by editing $0"
      ;;
    4)
      # Reserved for controlling the pointer buttons
      ;;
    5)
      # Reserved for controlling the pointer buttons
      ;;
    *)
      echo "Must specify the button value between 1 and 5"
      exit 1
  esac
}

# The first argument is the toolbar number
case "$1" in
  1)
    horiz_toolbar $2
    ;;
  2)
    vert_toolbar $2
    ;;
  *)
    echo "Usage: $0 toolbarnum buttonnum"
    exit 1
esac

exit 0
