Disable touchpad while the lid is down

Solution 1:

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 $?
1

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.

Solution 2:

What you can do is put your computer to sleep before closing the lid. that way, pressing the power button would resume the sleep, and the lid closed won't affect the touchpad.

Alternativly, you can open your terminal (ctrl+alt+T) and type

sudo rmmod psmouse

It allows a usb mouse, wireless or otherwise, but shuts down the touchpad.

Also, you have the option to install touchpad-indicator, wich provide an easy way to deactivate your touchpad

sudo add-apt-repository ppa:atareao/atareao
sudo apt-get update
sudo apt-get install touchpad-indicator

It will be under Application > Accesory OR, depending on your UI, will be a small "touchpad-like" button next to the volume button