# Description:
# ------------
#
# Monitor the Toshiba keys, and respond appropriately.  All the predefined
# keys function as they are labeled (except for Function-F3: Suspend to RAM,
# and Function-F4: Hibernate).  Function-b activates 
# the screensaver (which in turn will cause the lcd to be powered off), and 
# Function-c toggles the cPad backlight.  Opening and closing the lid of the
# laptop will use the Festival text-to-speech software 
# (http://www.cstr.ed.ac.uk/projects/festival/) to say "Hello" and "Goodbye"
# as appropriate (just for a cuteness factor).
#
# Requisites:
# -----------
#
# In addition to any scripts invoked by the various functions, the following
# utilities are used:
#
# cdcd     - command line CD player, for interfacing the physical CD controls
#            obtained from: http://cdcd.undergrid.net/
# usr_cpad - Interface to the Synaptic cPad
#            obtained from: http://www.janerob.com/rob/ts5100/cPad/index.shtml
# festival - Text-to-speech software
#            obtained from: http://www.cstr.ed.ac.uk/projects/festival/
# expectk  - TCL/Expect with TK GUI support, provided by most distributions
#
# Functions implemented:
# ----------------------
#
# Key or Button:        Action:
# ------------------    --------------------------------------
# Toshiba world button  Run Mozilla
# Toshiba t button      Open a Gnome-Terminal
# Function+Escape       Toggle Mute
# Function+F1           Lock Screen
# Function+F2           Cycle fan: off, low, high
# Function+F5           Switch Video Out
# Function+F6           Dim LCD; beep at minimum setting
# Function+F7           Brighten LCD; beep at maximum setting
# Function+F8           Toggle Wireless/Wired connection
# CD Stop button        Stop CD or Eject CD if stopped
# CD Previous button    Play Previous track
# CD Next button        Play Next track
# CD Play button        Play CD or pause/resume if playing
# Lid open/close        Use Festival for "Hello"/"Goodbye"
# Function+b            Blank Screen
# Function+c            Toggle cPad Backlight
# Function+d            Toggle DMA on/off for /dev/hdc
#
# Usage:
# ------
#
# This script should be run as root.  It can be started in /etc/rc.d/rc.local
# at system initialization (redirect all output to /dev/null if doing that).
# If run interactively, it will display the keys/buttons as they are processed
# and the action taken (useful for debugging).
#
# Notes:
# ------
#
# 1. Because of the way gnome-terminal is started from an su session, make sure
#    to set the XAUTHORITY in the ~/.bash_profile (of the person logged in, not 
#    root!).  For example:
#
#      export XAUTHORITY=/home/myuserid/.Xauthority
#
#    If this isn't done, the /root/.xauth?????? file will be used, causing a
#    20 second delay anytime xauth is invoked (for example, starting an ssh
#    session).
#
# 2. Be careful of the commands in your .bashrc and .bash_profile.  If this
#    script stops when attempting to open a Mozilla window or Gnome-terminal
#    window, those are the first place to check, because they are invoked via
#    an "su" command that starts a login shell.  Beware of commands that work
#    in foreground, but not in background (e.g., stty).

