Linux: Disable Elantech or Synaptics Touchpad

The touchpad was driving me crazy when tipping. Just getting near it was enough to accidentally click all over the place.

There is a nifty tool for Synaptics touchpads that supposedly disables the touchpad while typing. I forgot the name, but google knows about it.

But this laptop has an Elantech Touchpad. It might behave like a Synaptics model in Windows (don’t know, saw some driver files/options), but in Linux it’s picked up by evdev as PS/2 mouse.

Solution

So here’s my solution:
Place this script in your users folder (or /usr/local/bin as root) and make it executable. I named it toggle-touchpad. Calling it nicely turns the touchpad on/off.

#!/bin/sh
#
# toggles touchpads on/off
# Supported are both Synaptics and Elantech touchpads

# sanity check
if [ ! -x /usr/bin/xinput ]; then
	echo "Error: /usr/bin/xinput not found"
	exit 1
fi

getTouchDeviceId()
{
# extract the device id for the supplied touch device name
	xinput list | sed -nr "s|.*$1.*id=([0-9]+).*|\1|p"
}

# Get the xinput device number and enabling property for the touchpad
XINPUTNUM=$(getTouchDeviceId "SynPS/2 Synaptics TouchPad")
ENABLEPROP="Synaptics Off"
if [ -z "$XINPUTNUM" ]; then
	XINPUTNUM=$(getTouchDeviceId "PS/2 Elantech Touchpad")
	ENABLEPROP="Device Enabled"
fi

# if we failed to get an input, exit
[ -z "$XINPUTNUM" ] && exit 1

# get the current state of the touchpad
TPSTATUS=$(xinput list-props $XINPUTNUM | awk "/$ENABLEPROP/ { print \$NF }")

# if getting the status failed, exit
[ -z "$TPSTATUS" ] && exit 1

if [ $TPSTATUS = 0 ]; then
	xinput set-prop $XINPUTNUM "$ENABLEPROP" 1
else
	xinput set-prop $XINPUTNUM "$ENABLEPROP" 0
fi

Other solution

synclient TouchpadOff=1 and synclient TouchpadOff=0 should do the same, if that’s on your system.

My story with Elantech touchpad

I played around with all the init settings, read through whatever I could find but it keeps acting as mouse.
And honestly I detest touchpads unless I sit in a train with the laptop on my legs.

So I wrote my own script using “xinput list/set-prop”, feel free to play around with them. Basically you have to get the ID of the device (or use the name) and then set the property “Device Enabled” to “0” or “1”.
Well, as soon as I was done, I found a similar script on some Ubuntu forum which does a little more parsing and thus also recognizes Synaptics touchpads. Merged it with my own and the above is the result.

Note: I would like to link to the Ubuntu-script, but cannot find the link anymore.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: