Getting UDEV and Touchpad to play together

One of the downsides of the HP Folio 13 is that the built in touchpad sucks – at least under Linux.  While there are some tweeks that can be done to make it “less bad”, the experience is never better then “OK in a pinch, but only just”.

One of the particularly irritating things is that the sensitivity – quite frequently I brush the touchpad while typing, which moves the cursor.

I have finally found a workable solution – leave the touchpad disabled when a mouse is plugged in, and enable when the mouse is removed.   Although conceptually simple,  the devil proved to be in the details with getting UDEV to “play nice” with my mouse.  I eventually came up with a very simple solution (this is for Ubuntu 12.04, but no doubt will work with other distro’s and versions – provided the file is correctly placed)

I created a file /etc/udev/rules.d/95-mouse.rules with the following content:

ACTION=="add",KERNEL=="mouse[0-9]",SUBSYSTEM=="input" RUN+="/bin/sh -c '/usr/bin/logger TouchpadOff; export DISPLAY=:0;/usr/bin/synclient TouchPadOff=1'"
ACTION=="remove",KERNEL=="mouse[0-9]",SUBSYSTEM=="input" RUN+="/bin/sh -c '/usr/bin/logger TouchpadOn; export DISPLAY=:0;/usr/bin/synclient TouchPadOff=0'"

This worked a treat. It should be practical to remove the usr/bin/logger TouchpadXXX; part – this simply logs the action to Syslog.

Some lessons I learnt along the way:

  1. Beware of ==  vs =   – It took a while to work out that “invalid rule ‘xxxxxx’ was occuring because I used = rather then ==
  2. Ensure the filename has ends “.rules”  – Somewhere along the way I landed up renaming it to “-rules”, and it silently stopped functioning.
  3. While you can identify the mouse using Attributes ATTRS{bInterfaceClass}==”03″,ATTRS{bInterfaceSubClass}==”01″,ATTRS{bInterfaceProtocol}==”02″ you can’t remove a device based on attributes – you need to use environment variables which UDEV sets instead.  (This was not a good solution here as it made the solution mouse specific)