Hotkey to toggle touchpad on Thinkpad X220

2012-05-31
tech , linux , thinkpad

My thinkpad x220 is my third thinkpad and the first one with a touchpad. While I find it useful specifically for scrolling documents and for zooming in and out for images, it can also come in the way the rest of the time hen I am primarily using the keyboard and trackpoint. So I wanted to be able to toggle the touchpad on and off using a key.

xinput gave me the following output, so I know the id for my touchpad is 11.

⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ TPPS/2 IBM TrackPoint                     id=13   [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=11   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Sleep Button                              id=8    [slave  keyboard (3)]
    ↳ Integrated Camera                         id=9    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=10   [slave  keyboard (3)]
    ↳ ThinkPad Extra Buttons                    id=12   [slave  keyboard (3)]

Then starting from here, I wrote the following simple script.

 #!/bin/sh

 # I know my trackpad device id is 11
 tp_enabled=`xinput list-props 11 | grep "Device Enabled" | awk '{print $4}'`

 # if enabled, disable it
 if [ $tp_enabled = 1 ]
 then
     xinput set-prop 11 "Device Enabled" 0 && notify-send 'Trackpad disabled'

 # if disabled, enable it
 elif [ $tp_enabled = 0 ]
 then
     xinput set-prop 11 "Device Enabled" 1 && notify-send 'Trackpad enabled'

 else
 notify-send 'Could not get trackpad status'
 fi

Depending on whether the touchpad is enabled or not (getting it from 'xinput list-props 11'), the script accordingly turns it on or off, by using 'xinput set-prop'. In addition a notification appears through notify-osd. I put this script in my path, made it executable and then bound it to F5 (System Settings -> Keyboard -> Shortcuts -> Custom shortcuts). It works perfectly, with the only issue being that the norification bubble stays for 10 seconds and although the man page for notify-send lists the argument --expire-time, this does not work. This apparently is a long-standing bug/feature(?) and I didn't want to go to some lengths at present to work around this.