You are not logged in.

#1 2014-10-25 11:54:36

yarmash
Member
Registered: 2012-03-21
Posts: 12

Disabling touchpad upon external mouse detection

I want to automatically disable the touchpad if an external mouse has been plugged in. I tried this solution from wiki:

/etc/udev/rules.d/01-touchpad.rules

SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="add", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/username/.Xauthority", RUN+="/usr/bin/synclient TouchpadOff=1"
SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="remove", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/username/.Xauthority", RUN+="/usr/bin/synclient TouchpadOff=0"

But this rule doesn't work with my Logitech wireless mouse.
The device is detected as following:

Oct 25 14:27:04 myhost kernel: logitech-djreceiver 0003:046D:C52B.0003: hiddev0,hidraw0: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-3/input2
Oct 25 14:27:04 myhost kernel: input: Logitech Unifying Device. Wireless PID:1025 as /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.2/0003:046D:C52B.0003/0003:046D:C52B.0004/input/input2
Oct 25 14:27:04 myhost kernel: logitech-djdevice 0003:046D:C52B.0004: input,hidraw1: USB HID v1.11 Mouse [Logitech Unifying Device. Wireless PID:1025] on usb-0000:00:14.0-3:1
Oct 25 14:27:04 myhost kernel: usb 3-1: new high-speed USB device number 2 using ehci-pci

How do I make the rule from wiki work with this device?

Offline

#2 2014-10-25 16:05:40

TE
Member
Registered: 2014-06-21
Posts: 76

Re: Disabling touchpad upon external mouse detection

In general udev works on "when this == that, foo = bar". First, find out the device that your USB mouse using -- there are many ways to get at it (the sysfs interface has a lot of choices), I'll use my USB Optical mouse on this laptop as an example.

Find the device node it's linked to:

$ ls -l /dev/input/by-id/*mouse
lrwxrwxrwx 1 root root 9 Oct 21 11:25 /dev/input/by-id/usb-0461_USB_Optical_Mouse-event-mouse -> ../event1
lrwxrwxrwx 1 root root 9 Oct 21 11:25 /dev/input/by-id/usb-0461_USB_Optical_Mouse-mouse -> ../mouse0

OK, so now I know mouse0 is what's plugged in, I'll use udevadm to query it's attributes for VENDOR and MODEL (Product):

$ udevadm info --query=property --path=/class/input/mouse0 | grep _ID=
ID_MODEL_ID=4d81
ID_VENDOR_ID=0461

Now that I have these, I can write udev rules to do anything - so taking your code from the wiki I can write something like:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="4d81", ATTRS{idProduct}=="0461", ACTION=="add", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/username/.Xauthority", RUN+="/usr/bin/synclient TouchpadOff=1"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="4d81", ATTRS{idProduct}=="0461", ACTION=="remove", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/username/.Xauthority", RUN+="/usr/bin/synclient TouchpadOff=0"

I don't know those exact items on the right, so you can start with more basic rules and work your way up to ensure you're trapping the "right" thing, like so:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="4d81", ATTRS{idProduct}=="0461", ACTION=="add", RUN+="/usr/bin/echo 'add event' >> /tmp/debug.log"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="4d81", ATTRS{idProduct}=="0461", ACTION=="remove", RUN+="/usr/bin/echo 'remove event' >> /tmp/debug.log"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="4d81", ATTRS{idProduct}=="0461", ACTION=="change", RUN+="/usr/bin/echo 'change event' >> /tmp/debug.log"

See udev(7) and udevadm(8) man pages for udev rules that can be used and ways to test them. Here's a pretty good link that can walk you through more of udev, it's a complex beast: http://www.reactivated.net/writing_udev_rules.html

Offline

Board footer

Powered by FluxBB