#!/bin/sh

# a simple script for a one click conversion for touch screen
# friendly settings, JWM only at this stage, others soon
# 01micko 131213
# TODO: pinboard

# get wm
CWM=`cat /etc/windowmanager`
# precaution
ps -A | grep -q $CWM
[ "$?" -eq 0 ] || exit 1

case $CWM in
 jwm)CDIR=/usr/local/jwmconfig2 ;;
 *) exit 0 ;; #TODO, other wm's
esac

touch /tmp/touchscreen$$ 

# passed params are 24, 32, 40, 48
[ "$1" ] || exit 0

change_it(){
	# change the settings
	echo "MENHEIGHT=$1" > $HOME/.jwm/menuheights #enlarges menu
	$CDIR/taskbarPlace top #moves taskbar
	[ "$1" -eq 24 ] && $CDIR/taskbarHeight 28 \
	|| $CDIR/taskbarHeight $1 #makes taskbar taller
	[ "$?" -ne 0 ] && exit 1
	fixmenus
	jwm -restart
	[ "`find /tmp -name 'touchscreen*'`" ] && rm /tmp/touchscreen*
	exit 0
}

revert_it(){
	[ -f $HOME/.jwm/menuheights ] && rm $HOME/.jwm/menuheights
	$CDIR/taskbarPlace bottom
	$CDIR/taskbarHeight 28
	fixmenus
	jwm -restart
	[ "`find /tmp -name 'touchscreen*'`" ] && rm /tmp/touchscreen*
	exit 0
}

case $1 in
 24) change_it 24;;
 32) change_it 32;;
 40) change_it 40;;
 48) change_it 48;;
 revert)revert_it ;;
 *)exit 0 ;;
esac

exit 0
