Ubuntu – Disable touchpad while the lid is down


Kubuntu 11.10 (netbook edition)

My wife's netbook has the following problem: when the lid is closed, it activates the touchpad every now and then – it makes small movements and taps. The notebook is set not to go to sleep while the AC adapter is plugged in, so whenever the lid closes, it keeps doing things on its own.

Especially annoying when pausing a film and going to sleep, as after a while it will tap on the player window and resume the film, scaring the crap out of everyone around.

I didn't find any option to disable the touchpad while the lid is down, but maybe there's some kind of an event I could hook into and disable/re-enable it manually?

Best Answer

Since nobody could tell me how to do exactly what I wanted, here's the solution I came up with:

Disabling the touchpad/mouse

$ xinput --list
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ FSPPS/2 Sentelic FingerSensingPad         id=12   [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)]
    ↳ Power Button                              id=9    [slave  keyboard (3)]
    ↳ USB2.0 UVC PC Camera                      id=10   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=11   [slave  keyboard (3)]
    ↳ MSI Laptop hotkeys                        id=13   [slave  keyboard (3)]

As we can see, my touchpad is the one with id=12. To disable it, I need to run:

$ xinput set-int-prop 12 "Device Enabled" 8 0

and to enable it again:

$ xinput set-int-prop 12 "Device Enabled" 8 1

Getting the lid state

First of all, I can get the state of the lid on my system from this file:

$ cat /proc/acpi/button/lid/LID0/state 
state:      open

When I close the lid, the state becomes closed.

Now to get the state as a variable, I can check the exit status of a nifty grep command:

$ grep -q closed /proc/acpi/button/lid/*/state
$ echo $?

So to enable or disable the touchpad depending on the lid state, all I need to do is:

$ grep -q closed /proc/acpi/button/lid/*/state
$ xinput set-int-prop 12 "Device Enabled" 8 $?

Hooking the ACPI lid event

To execute the above commands every time the lid closes or opens, I created the file /etc/acpi/local/lid.sh.post with the following content:

export XAUTHORITY=`ls -1 /home/*/.Xauthority | head -n 1`
export DISPLAY=":`ls -1 /tmp/.X11-unix/ | sed -e s/^X//g | head -n 1`"

grep -q closed /proc/acpi/button/lid/*/state
xinput set-int-prop 12 "Device Enabled" 8 $?

XAUHTORITY and DISPLAY need to be set in order to allow root (who runs the acpid process) to access the user's X session.