#!/bin/sh -e

#  Set up the Synaptics TouchPad for two-finger scroll
#  and button presses, but not mouse pointer motion.
#  (that's what the IBM TrackPoint is for.)
#
#  This works on a Lenovo ThinkPad T440s.
#
#  Based on discussion on Havoc Pennington's blog:
#    http://blog.ometer.com/2013/12/04/fedora-20-beta-on-thinkpad-t440s-report/
#
#  Run with the argument: install
#  to set this up to run at start of each desktop session.

AUTOSTART=$HOME/.config/autostart/deconfuse-synaptics.desktop
THIS_SCRIPT=$(realpath $0)
ID=$(xinput | perl -ne 'print $1 if m/Synaptics TouchPad.*id=(\d+)/')

if [ "x$ID" == "x" ] ; then
	echo "Synaptics TouchPad not found." 1>&2
	exit 1
fi

xinput set-prop $ID 'Synaptics Soft Button Areas' 3477, 5112, 0, 0, 2659, 3476, 0, 0
xinput set-prop $ID 'Device Accel Constant Deceleration' 9999999
xinput set-prop $ID 'Synaptics Tap Action' 0,0,0,0,0,0,0

if [ "x$1" == "xinstall" ] ; then
	mkdir -p $(dirname $AUTOSTART)
	cat << STUFF > $AUTOSTART
[Desktop Entry]
Type=Application
Name=DeconfuseSynaptics
GenericName=Deconfuse Synaptics
Comment=Button presses and two-finger scroll only
Exec=$THIS_SCRIPT
Terminal=false
X-GNOME-Autostart-enabled=true
NoDisplay=true
STUFF
fi
