How To Auto-Disable The Touchpad When The Mouse Is Plugged In (Fedora 13)
Hello all, hopefully this brief how-to will help others, this issue has been bugging me for years. I want the same capability in Fedora that exists in most recent versions of Windows -- disable the touchpad on my laptop if an external mouse is plugged in. Note that my how-to is a little hardware-specific regarding the actual disabling of the touchpad; I'll discuss that more at the end of the guide.
So, here goes:
For my OS (Fedora 13 x86_64) and hardware (Dell Precision M4500) - I needed a specific utility and three scripts. This Dell's trackpad and nipple-stick are seen as an 'internal' PS/2 mouse by Fedora, so I had to install 'xinput' to disable it (and use a very arcane little command-line).
# yum -y install xorg-x11-apps
The enable/disable commands may be different for different hardware ... I had to use some xinput commands to figure out the values I needed:
$ xinput list
? Virtual core pointer id=2 [master pointer (3)]
? ? Virtual core XTEST pointer id=4 [slave pointer (2)]
? ? USB Optical Mouse id=10 [slave pointer (2)]
? ? PS/2 Generic Mouse id=13 [slave pointer (2)]
$ xinput list-props "PS/2 Generic Mouse"
Device 'PS/2 Generic Mouse':
Device Enabled (119): 1
...
This told me that I could use the following:
to disable touchpad:
xinput --set-prop "PS/2 Generic Mouse" "Device Enabled" 0
to enable touchpad:
xinput --set-prop "PS/2 Generic Mouse" "Device Enabled" 1
Google to learn more about using xinput.
Then, 3 scripts:
- Add the following as /etc/udev/rules.d/61-touchpad.rules:
# 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 # # disable PS/2 touchpad on DISPLAY :0 if a mouse is added to the system ACTION=="add", SUBSYSTEM=="input", ENV{ID_INPUT_MOUSE}=="1", RUN+="/bin/sh -c 'DISPLAY=:0 /usr/bin/xinput --set-prop PS/2\ Generic\ Mouse Device\ Enabled 0'"
# enable PS/2 touchpad on DISPLAY :0 if a mouse is removed from the system ACTION=="remove", SUBSYSTEM=="input", ENV{ID_INPUT_MOUSE}=="1", RUN+="/bin/sh -c 'DISPLAY=:0 /usr/bin/xinput --set-prop PS/2\ Generic\ Mouse Device\ Enabled 1'"
- Update /etc/gdm/Init/Default.
- Add the following just before the 'exit 0' at the end of the file:
# disable touchpad if more than one mouse is available if [ `ls -d /sys/class/input/mouse* | wc -l` -gt 1 ]; then /usr/bin/xinput --set-prop PS/2\ Generic\ Mouse Device\ Enabled 0
fi
- Add the following as /etc/pm/sleep.d/99touchpad:
#!/bin/sh # # disable touchpad if more than one mouse is available # # NOTE: will only affect DISPLAY :0 # disable_touchpad() { /bin/sh -c 'DISPLAY=:0 /usr/bin/xinput --set-prop PS/2\ Generic\ Mouse Device\ Enabled 0'
} case "$1" in thaw|resume) if [ `ls -d /sys/class/input/mouse* | wc -l` -gt 1 ]; then disable_touchpad fi ;; *) exit $NA ;; esac
The udev rules notice when a mouse is hot-plugged, and enable or disable the touchpad as necessary. The gdm script is necessary to handle the situation where the system is booted with a mouse plugged in (and therefore a hot-plug event doesn't occur). I thought that was it, but after a suspend and resume, I discovered that the touchpad was active again. So, more googling, and I added the /etc/pm/sleep.d script to handle things on resume.
The actual disabling utility will be specific to different types of hardware; synaptic touchpads would use the 'syndaemon' utility, I believe. There are lots of little subtleties to this process - the naming of the udev rules file and the sleep.d script is significant (the rules have to run after other mouse setup rules have run), the DISPLAY variable has to be set in the disable commands (because the daemons executing the scripts are not running in the X server), and the determining of whether or not you have multiple mice is maybe not as robust as I'd like. But, it is working for me. Also, different versions of Fedora may require different udev rules, or different directories for script placement, or different numbers in the filenames ... this isn't pretty, it should really be handled by a utility bundled with the distribution.
Finally, note that I am assuming that DISPLAY :0 is the DISPLAY of interest, and that the udev rules won't work right if you plug in more than two mice (???) ... If someone is interested they might be able to make this more robust ... go for it!
So, this isn't the most complete how-to ever, but I wanted to get it out there. My apologies if a better how-to exists, or if a better procedure is available. If you know of something better ... please follow up.
Addendum:
FYI - the udev stuff was not easy to figure out. Here are some commands I ran while I was trying to get this sorted:
- Get udev environment info for the touchpad:
udevadm info --query=all --name=/dev/input/mouse1
- Testing specific udev rules:
# udevadm test --action=add /sys/devices/platform/i8042/serio1/input/input6/mouse1 2>&1 | grep "run:"
udevadm_test: run: '/bin/sh -c 'DISPLAY=:0 /usr/bin/xinput --set-prop PS/2\ Generic\ Mouse Device\ Enabled 0''
udevadm_test: run: 'socket:@/org/freedesktop/hal/udev_event'
# udevadm test --action=remove /sys/devices/platform/i8042/serio1/input/input6/mouse1 2>&1 | grep "run:"
udevadm_test: run: '/bin/sh -c 'DISPLAY=:0 /usr/bin/xinput --set-prop PS/2\ Generic\ Mouse Device\ Enabled 1''
udevadm_test: run: 'socket:@/org/freedesktop/hal/udev_event'