Rooot.net

  • Increase font size
  • Default font size
  • Decrease font size
The great thing about a computer notebook is that no matter how much you stuff into it, it doesn't get bigger or heavier.
Home Geek stuff Linux Disable a synaptics touchpad when a mouse is plugged in

Disable a synaptics touchpad when a mouse is plugged in

Touchpad may be convenient when you don't have enough space to use a mouse. But it's more often a source of annoyance when you're typing something and you're losing focus each time your hand hits the touchpad. That's why I like to disable the touchpad when I'm using a mouse. Here is a way to automatically disable your touchpad using udev and synclient.

Allow touchpad control

In your /etc/X11/xorg.conf file, go to your InputDevice sections and look for an identifier "Synaptics Touchpad". Add the SHMConfig option:

Option "SHMConfig" "on"

This will allow you to use the commands

~$ synclient TouchPadOff=1

and

~$ synclient TouchPadOff=0

used to disable or enable the synaptics touchpad.

Detect mouse events

When you plug in a mouse, some information is logged into /var/log/syslog:

kernel: usb 3-1: new low speed USB device using uhci_hcd and address 8
kernel: usb 3-1: configuration #1 chosen from 1 choice
kernel: input: Logitech USB Optical Mouse as /class/input/input14
kernel: input: USB HID v1.11 Mouse [Logitech USB Optical Mouse] on usb-0000:00:1d.0-1

We will use this information to create a udev rule. You can get further information with

~$ udevadm monitor --kernel
KERNEL[1284501196.096508] add      /devices/pci0000:00/0000:00:1d.0/usb5/5-1 (usb)
KERNEL[1284501196.099346] add      /devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1:1.0 (usb)
KERNEL[1284501196.099413] add      /devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1:1.0/0003:046D:C01D.0048 (hid)
KERNEL[1284501196.115797] add      /devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1:1.0/input/input86 (input)
KERNEL[1284501196.115929] add      /devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1:1.0/input/input86/mouse2 (input)
KERNEL[1284501196.115974] add      /devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1:1.0/input/input86/event13 (input)
KERNEL[1284501196.116176] add      /devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1:1.0/0003:046D:C01D.0048/hidraw/hidraw2 (hidraw)

Udev rules creation

Since we may be using different makes of mouse, we have to make the script as generic as possible. To do so I'll grab all events from the "input" subsystem and let the script take care of checking the device name to make sure the event comes from a mouse.

~$ cat > 90_synaptics_mouse.rules << EOF
# Run switchSynapticsTouchpad.sh when a mouse is plugged (or unplugged)
SUBSYSTEM=="input", ACTION=="*", RUN+="/usr/local/bin/switchSynapticsTouchpad.sh"
EOF

The last part is to create the switchSynapticsTouchpad.sh script which will do the actual job of switch the touchpad on and off.

~$ cat > /usr/local/bin/switchSynapticsTouchpad.sh << EOF
#!/bin/bash
echo "\$NAME" | grep -qi "mouse"
if [ \$? -eq 0 ]; then
export DISPLAY=:0.0
USER=`who | grep -m 1 \$DISPLAY | awk '{print \$1}'`
export XAUTHORITY=/home/\$USER/.Xauthority
case \$ACTION in
add)
/usr/bin/synclient TouchpadOff=1
;;
remove)
/usr/bin/synclient TouchpadOff=0
;;
esac
fi
EOF
~$ chmod +x /usr/local/bin/switchSynapticsTouchpad.sh

Synclient must have access to DISPLAY and XAUTHORITY to be able to control the synaptics driver on the running X server. Here we assume there is only one user connected to a local X server.

Here you go, no more erratic mouse moves Wink!

Comments
Add New Search
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Please input the anti-spam code that you can read in the image.

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 

Share

Share on facebook