You are not logged in.

#1 2012-08-08 20:21:58

domac
Member
Registered: 2012-08-06
Posts: 102

[solved] udev rule to disable touchpad when mouse plugged in

Hello!
I tried to disable my touchpad with udev rules according to https://bbs.archlinux.org/viewtopic.php?id=92896 when my mouse is plugged in, but no success yet.

udevadm monitor --property > ./log

produces

UDEV  [253.563697] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/input/input13/mouse1 (input)
ACTION=remove
DEVLINKS=/dev/input/by-id/usb-192f_USB_Optical_Mouse-mouse /dev/input/by-path/pci-0000:00:1d.0-usb-0:1.3:1.0-mouse
DEVNAME=/dev/input/mouse1
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/input/input13/mouse1
ID_BUS=usb
ID_INPUT=1
ID_INPUT_MOUSE=1
ID_MODEL=USB_Optical_Mouse
ID_MODEL_ENC=USB\x20Optical\x20Mouse
ID_MODEL_ID=0616
ID_PATH=pci-0000:00:1d.0-usb-0:1.3:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3_1_0
ID_REVISION=0200
ID_SERIAL=192f_USB_Optical_Mouse
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030102:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=192f
ID_VENDOR_ENC=192f
ID_VENDOR_ID=192f
MAJOR=13
MINOR=33
SEQNUM=1889
SUBSYSTEM=input
USEC_INITIALIZED=789

UDEV  [253.564728] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/input/input13/event13 (input)
ACTION=remove
DEVLINKS=/dev/input/by-id/usb-192f_USB_Optical_Mouse-event-mouse /dev/input/by-path/pci-0000:00:1d.0-usb-0:1.3:1.0-event-mouse
DEVNAME=/dev/input/event13
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/input/input13/event13
ID_BUS=usb
ID_INPUT=1
ID_INPUT_MOUSE=1
ID_MODEL=USB_Optical_Mouse
ID_MODEL_ENC=USB\x20Optical\x20Mouse
ID_MODEL_ID=0616
ID_PATH=pci-0000:00:1d.0-usb-0:1.3:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3_1_0
ID_REVISION=0200
ID_SERIAL=192f_USB_Optical_Mouse
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030102:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=192f
ID_VENDOR_ENC=192f
ID_VENDOR_ID=192f
MAJOR=13
MINOR=77
SEQNUM=1890
SUBSYSTEM=input
USEC_INITIALIZED=839

UDEV  [253.567860] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/input/input13 (input)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/input/input13
EV=17
ID_BUS=usb
ID_FOR_SEAT=input-pci-0000_00_1d_0-usb-0_1_3_1_0
ID_INPUT=1
ID_INPUT_MOUSE=1
ID_MODEL=USB_Optical_Mouse
ID_MODEL_ENC=USB\x20Optical\x20Mouse
ID_MODEL_ID=0616
ID_PATH=pci-0000:00:1d.0-usb-0:1.3:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3_1_0
ID_REVISION=0200
ID_SERIAL=192f_USB_Optical_Mouse
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030102:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=192f
ID_VENDOR_ENC=192f
ID_VENDOR_ID=192f
KEY=1f0000 0 0 0 0
MODALIAS=input:b0003v192Fp0616e0111-e0,1,2,4,k110,111,112,113,114,r0,1,6,8,am4,lsfw
MSC=10
NAME="USB Optical Mouse"
PHYS="usb-0000:00:1d.0-1.3/input0"
PRODUCT=3/192f/616/111
PROP=0
REL=143
SEQNUM=1891
SUBSYSTEM=input
TAGS=:seat:
UNIQ=""
USEC_INITIALIZED=702

UDEV  [253.568169] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/0003:192F:0616.0001/hidraw/hidraw0 (hidraw)
ACTION=remove
DEVNAME=/dev/hidraw0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/0003:192F:0616.0001/hidraw/hidraw0
MAJOR=251
MINOR=0
SEQNUM=1892
SUBSYSTEM=hidraw
USEC_INITIALIZED=3567137

UDEV  [253.568455] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/0003:192F:0616.0001 (hid)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/0003:192F:0616.0001
HID_ID=0003:0000192F:00000616
HID_NAME=USB Optical Mouse
HID_PHYS=usb-0000:00:1d.0-1.3/input0
MODALIAS=hid:b0003v0000192Fp00000616
SEQNUM=1893
SUBSYSTEM=hid
USEC_INITIALIZED=67560

UDEV  [253.571091] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0 (usb)
ACTION=remove
DEVICE=/proc/bus/usb/004/003
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0
DEVTYPE=usb_interface
INTERFACE=3/1/2
MODALIAS=usb:v192Fp0616d0200dc00dsc00dp00ic03isc01ip02
PRODUCT=192f/616/200
REMOVE_CMD=/usr/bin/synclient TouchpadOff=1
SEQNUM=1894
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=4684

UDEV  [253.573599] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3 (usb)
ACTION=remove
BUSNUM=004
DEVICE=/proc/bus/usb/004/003
DEVNAME=/dev/bus/usb/004/003
DEVNUM=003
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3
DEVTYPE=usb_device
ID_BUS=usb
ID_MODEL=USB_Optical_Mouse
ID_MODEL_ENC=USB\x20Optical\x20Mouse
ID_MODEL_ID=0616
ID_REVISION=0200
ID_SERIAL=192f_USB_Optical_Mouse
ID_USB_INTERFACES=:030102:
ID_VENDOR=192f
ID_VENDOR_ENC=192f
ID_VENDOR_ID=192f
MAJOR=189
MINOR=386
PRODUCT=192f/616/200
REMOVE_CMD=/usr/bin/synclient TouchpadOff=1
SEQNUM=1895
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=834269

UDEV  [255.118611] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3 (usb)
ACTION=add
BUSNUM=004
DEVICE=/proc/bus/usb/004/004
DEVNAME=/dev/bus/usb/004/004
DEVNUM=004
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3
DEVTYPE=usb_device
ID_BUS=usb
ID_MODEL=USB_Optical_Mouse
ID_MODEL_ENC=USB\x20Optical\x20Mouse
ID_MODEL_ID=0616
ID_REVISION=0200
ID_SERIAL=192f_USB_Optical_Mouse
ID_USB_INTERFACES=:030102:
ID_VENDOR=192f
ID_VENDOR_ENC=192f
ID_VENDOR_ID=192f
MAJOR=189
MINOR=387
PRODUCT=192f/616/200
REMOVE_CMD=/usr/bin/synclient TouchpadOff=1
SEQNUM=1896
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=8177

UDEV  [255.126531] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0 (usb)
ACTION=add
DEVICE=/proc/bus/usb/004/004
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0
DEVTYPE=usb_interface
INTERFACE=3/1/2
MODALIAS=usb:v192Fp0616d0200dc00dsc00dp00ic03isc01ip02
PRODUCT=192f/616/200
REMOVE_CMD=/usr/bin/synclient TouchpadOff=1
SEQNUM=1897
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=8525

UDEV  [255.127938] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/0003:192F:0616.0002 (hid)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/0003:192F:0616.0002
HID_ID=0003:0000192F:00000616
HID_NAME=USB Optical Mouse
HID_PHYS=usb-0000:00:1d.0-1.3/input0
MODALIAS=hid:b0003v0000192Fp00000616
SEQNUM=1898
SUBSYSTEM=hid
USEC_INITIALIZED=8670

UDEV  [255.129902] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/input/input14 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/input/input14
EV=17
ID_BUS=usb
ID_FOR_SEAT=input-pci-0000_00_1d_0-usb-0_1_3_1_0
ID_INPUT=1
ID_INPUT_MOUSE=1
ID_MODEL=USB_Optical_Mouse
ID_MODEL_ENC=USB\x20Optical\x20Mouse
ID_MODEL_ID=0616
ID_PATH=pci-0000:00:1d.0-usb-0:1.3:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3_1_0
ID_REVISION=0200
ID_SERIAL=192f_USB_Optical_Mouse
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030102:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=192f
ID_VENDOR_ENC=192f
ID_VENDOR_ID=192f
KEY=1f0000 0 0 0 0
MODALIAS=input:b0003v192Fp0616e0111-e0,1,2,4,k110,111,112,113,114,r0,1,6,8,am4,lsfw
MSC=10
NAME="USB Optical Mouse"
PHYS="usb-0000:00:1d.0-1.3/input0"
PRODUCT=3/192f/616/111
PROP=0
REL=143
SEQNUM=1899
SUBSYSTEM=input
TAGS=:seat:
UNIQ=""
USEC_INITIALIZED=10869

UDEV  [255.134050] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/input/input14/event13 (input)
ACTION=add
DEVLINKS=/dev/input/by-id/usb-192f_USB_Optical_Mouse-event-mouse /dev/input/by-path/pci-0000:00:1d.0-usb-0:1.3:1.0-event-mouse
DEVNAME=/dev/input/event13
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/input/input14/event13
ID_BUS=usb
ID_INPUT=1
ID_INPUT_MOUSE=1
ID_MODEL=USB_Optical_Mouse
ID_MODEL_ENC=USB\x20Optical\x20Mouse
ID_MODEL_ID=0616
ID_PATH=pci-0000:00:1d.0-usb-0:1.3:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3_1_0
ID_REVISION=0200
ID_SERIAL=192f_USB_Optical_Mouse
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030102:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=192f
ID_VENDOR_ENC=192f
ID_VENDOR_ID=192f
MAJOR=13
MINOR=77
SEQNUM=1901
SUBSYSTEM=input
USEC_INITIALIZED=11079

UDEV  [255.134227] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/input/input14/mouse1 (input)
ACTION=add
DEVLINKS=/dev/input/by-id/usb-192f_USB_Optical_Mouse-mouse /dev/input/by-path/pci-0000:00:1d.0-usb-0:1.3:1.0-mouse
DEVNAME=/dev/input/mouse1
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.3/4-1.3:1.0/input/input14/mouse1
ID_BUS=usb
ID_INPUT=1
ID_INPUT_MOUSE=1
ID_MODEL=USB_Optical_Mouse
ID_MODEL_ENC=USB\x20Optical\x20Mouse
ID_MODEL_ID=0616
ID_PATH=pci-0000:00:1d.0-usb-0:1.3:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3_1_0
ID_REVISION=0200
ID_SERIAL=192f_USB_Optical_Mouse
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030102:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=192f
ID_VENDOR_ENC=192f
ID_VENDOR_ID=192f
MAJOR=13
MINOR=33
SEQNUM=1900
SUBSYSTEM=input
USEC_INITIALIZED=10996

(kernels removed)

and # lsusb -v produces

Bus 004 Device 004: ID 192f:0616 Avago Technologies, Pte. 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x192f Avago Technologies, Pte.
  idProduct          0x0616 
  bcdDevice            2.00
  iManufacturer           0 
  iProduct                2 USB Optical Mouse
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower               98mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      1 Boot Interface Subclass
      bInterfaceProtocol      2 Mouse
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      71
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0006  1x 6 bytes
        bInterval              10
Device Status:     0x0000
  (Bus Powered)

and my /etc/udev/rules.d/01-touchpad.rules does look like

ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="192f", ATTRS{idProduct}=="0616", ENV{REMOVE_CMD}="/usr/bin/synclient TouchpadOff=1", RUN+="/usr/bin/synclient TouchpadOff=0"

Any suggestions? hmm
Thanks in advance!

Last edited by domac (2012-08-09 15:00:00)


domac [ git ]

Offline

#2 2012-08-09 11:42:41

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] udev rule to disable touchpad when mouse plugged in

No one familiar with udev? Really could need more tips for this. I even went through the article of how-to creating udev rules, but didn't succeed yet.
So, help is appreciated! wink
Thanks in advance.

Last edited by domac (2012-08-09 11:43:15)


domac [ git ]

Offline

#3 2012-08-09 12:22:56

brain0
Developer
From: Aachen - Germany
Registered: 2005-01-03
Posts: 1,382

Re: [solved] udev rule to disable touchpad when mouse plugged in

Okay, this is nowhere near optimal, and only tested with a bluetooth mouse, but here it goes:

ACTION=="add",    SUBSYSTEM=="hid", ENV{HID_UNIQ}=="00:11:22:33:44:55", RUN+="/usr/local/bin/touchpad-disable"
ACTION=="remove", SUBSYSTEM=="hid", ENV{HID_UNIQ}=="00:11:22:33:44:55", RUN+="/usr/local/bin/touchpad-enable"

Here, 00:11:22:33:44:55 is the BDID of my mouse. This can certainly be adapted to USB mice. Now comes the tricky part: As synclient uses the xinput extension, you need to access the X server. For that, you need an xauth cookie, which the root user usually doesn't have.

#!/bin/bash

if [ "$(basename $0)" = "touchpad-enable" ]; then
        val=0
elif [ "$(basename $0)" = "touchpad-disable" ]; then
        val=1
else
        exit 1
fi

for f in /var/run/xauth/*; do
        if [ -e "${f}" ]; then
                XAUTHORITY="${f}" \
                DISPLAY=":$(basename "${f}" | cut -d- -f1 | cut -d: -f2)" \
                /usr/bin/synclient TouchpadOff=${val}
        fi
done

As far as I know, this will only work with kdm. kdm creates the file /var/run/xauth/A:$DISPLAY-$RANDOMCHARACTERS. From that filename, I parse $DISPLAY and use it as X authority database. This allows the script to access the X server and run synclient.

I suspect something similar is possible with other login manager. I don't know how to do it with startx at all. Still, I hope you get the idea and understand why your approach will fail.

Offline

#4 2012-08-09 13:00:34

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] udev rule to disable touchpad when mouse plugged in

So if I add (according to https://wiki.archlinux.org/index.php/To … _detection) the following:

ENV{XAUTHORITY}="/home/domac/.Xauthority"

it should work, I guess. Let me try, I'll give feedback here.

Edit: Still no success with

$domac.vex cat /etc/udev/rules.d/01-touchpad.rules 
ACTION=="add", SUBSYSTEM=="usb", ENV{XAUTHORITY}="/home/domac/.Xauthority", ATTRS{idVendor}=="192f", ATTRS{idProduct}=="0616", ENV{REMOVE_CMD}="/usr/bin/synclient TouchpadOff=1", RUN+="/usr/bin/synclient TouchpadOff=0"

sad

Last edited by domac (2012-08-09 13:10:04)


domac [ git ]

Offline

#5 2012-08-09 14:00:20

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [solved] udev rule to disable touchpad when mouse plugged in

Works now!

$domac.vex cat /etc/udev/rules.d/01-touchpad.rules 
ACTION=="add", SUBSYSTEM=="usb", ENV{XAUTHORITY}="/home/domac/.Xauthority", ENV{DISPLAY}=":0", ATTRS{idVendor}=="192f", ATTRS{idProduct}=="0616", ENV{REMOVE_CMD}="/usr/bin/synclient TouchpadOff=0", RUN+="/usr/bin/synclient TouchpadOff=1"

Thanks for the help!

Edit: More informations:

$domac.vex ls /etc/udev/rules.d/
total 4
-rw-r--r-- 1 root root 238 Aug  9 15:59 01-touchpad.rules

Last edited by domac (2012-08-09 15:07:45)


domac [ git ]

Offline

Board footer

Powered by FluxBB