Sunday, March 4, 2012

RHEL 6 - Toggle trackpad when mouse is plugged in/out

Too often on my RHEL system I hit the mousepad when writing or doing something else, with the result of typing in the wrong part of the document.
This is even more annoying when I am sitting at my desk, with my mouse plugged.
I know that there is a setting to disable the mousepad when typing but I wanted something more robust.

For this reason here is a little guide about how I managed to automatically disable the mousepad when I plug in a usb mouse and how to enable it back when I unplug it.

You need some utility to query your mice.

sudo yum install xorg-x11-apps

Now we can have a list of the recognized plugged input devices on your system:

$ xinput list
⎡ 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)]
⎜   ↳ Macintosh mouse button emulation         id=14 [slave  pointer  (2)]
⎜   ↳ Logitech USB Laser Mouse                 id=16 [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad               id=15 [slave  pointer  (2)]
⎣ Virtual core keyboard                    id=3 [master keyboard (2)]
    ↳ Virtual core XTEST keyboard              id=5 [slave  keyboard (3)]
    ↳ ThinkPad Extra Buttons                   id=6 [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard             id=7 [slave  keyboard (3)]
    ↳ Lid Switch                               id=8 [slave  keyboard (3)]
    ↳ Integrated Camera                        id=9 [slave  keyboard (3)]
    ↳ Sleep Button                             id=10 [slave  keyboard (3)]
    ↳ Video Bus                                id=11 [slave  keyboard (3)]
    ↳ Power Button                             id=12 [slave  keyboard (3)]

My laptop has a touchpad(id=15) and a trackpoint(id=13).
And you can see an entry for my usb mouse (id=16)

If you just want to disable manually the mousepad or any other device it is quite easy.

It is just a matter of:


xinput --set-prop "SynPS/2 Synaptics TouchPad" "Device Enabled" 1 # to enable
xinput --set-prop "SynPS/2 Synaptics TouchPad" "Device Enabled" 0 # to disable


Now if we want to automatically execute this commands when the mouse is plugged/unplugged we need to use udev.

sudo yum install udev

We create a new rules file in udev configuration folder:

sudo gedit /etc/udev/rules.d/61-touchpad.rules

And add this code:

# 61-touchpad.rules
#
# this rules file must be named 61* or later because it won't work
# unless it runs after '/lib/udev/rules.d/60-persistent-input.rules'
#
# NOTE: will only affect DISPLAY :0
#
# run:
#   udevadm test --action=add /sys/devices/platform/i8042/serio1/input/input6/mouse1
# or similar to test the following rules
#

ACTION=="add", SUBSYSTEM=="input",  ENV{DISPLAY}=":0.0", DEVPATH=="*/mouse?", RUN+="/usr/bin/xinput --set-prop 'SynPS/2 Synaptics TouchPad' 'Device Enabled' 0"
ACTION=="remove", SUBSYSTEM=="input",  ENV{DISPLAY}=":0.0", DEVPATH=="*/mouse?", RUN+="/usr/bin/xinput --set-prop 'SynPS/2 Synaptics TouchPad' 'Device Enabled' 1"

And we have done!

Try to plug/unplug if it is behaving like expected!


In case of problems there is a way to debug udev events, in case the rules we defined do not apply exactly to your hardware configuration:

sudo killall udevd
sudo udevd --debug-trace --debug

To restart udevd when you have finished the debug:

/sbin/start_udev

Useful link:

https://wiki.archlinux.org/index.php/Touchpad_Synaptics#Disable_touchpad_upon_external_mouse_detection

4 comments:

  1. Thanks for the post. Worked perfectly first try!

    ReplyDelete
  2. Works like a charm.. Thanks for sharing!

    ReplyDelete
  3. Thanks a lot mate, this worked like a charm :)

    ReplyDelete
  4. Worked for me up to RHEL7/CentOS7
    For CentOS8, ENV{XAUTHORITY} has to be added and you may have to locate your Xauthority file as it
    may no longer be in ~/.Xauthority
    In my setup with lightdm it was under /run/lightdm/MYUSER/xauthority

    ReplyDelete