3

I am pretty new to udev and wanted to write a rule that upon connecting an usb mouse disables my touchpad.

This is what I have come up with(mostly by ear):

ACTION=="add", SUBSYSTEM=="input", ENV{ID_MODEL}=="USB_Mouse", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/nikitautiu/.Xauthority", ENV{REMOVE_CMD}="/usr/bin/synclient TouchpadOff=0", RUN+="/usr/bin/synclient TouchpadOff=1"

Nonetheless it doesn't trigger the desired effect. The command seems to be fine though the rule does not trigger when connecting my usb mouse.

1
  • Yes it does, I am 100% sure.
    – nikitautiu
    Commented Sep 12, 2012 at 8:33

3 Answers 3

5

I don't grasp why your rule is so complex? Especially this section

ENV{ID_MODEL}=="USB_Mouse",\
ENV{DISPLAY}=":0",\
ENV{XAUTHORITY}="/home/nikitautiu/.Xauthority",\   
ENV{REMOVE_CMD}="/usr/bin/synclient TouchpadOff=0"

In the first line you match the environment variable ID_MODEL which is only seen by udev against USB_Mouse. In the following three lines you assign values to environment variables. Again only seen by udev and the executed command synclient if the rule is applied.

I'm pretty sure that this rule is never applied (You can check this by parsing udev's log file.) since it is likely that there is no variable ID_MODEL with content USB_Mouse accessible unless you set ID_MODEL in the udev environment previously.

I suggest that you match against the Action, the vendor-ID and the product-ID of your mouse, which will suffice in most cases. Then your rule looks like

ACTION=="add", ATTRS{idVendor}=="<idVendor>", ATTRS{idProduct}=="<idProduct>", RUN+="/usr/bin/synclient TouchpadOff=1"

You can get <idVendor> and the <idProduct> by parsing the output of

lsusb -v

I don't remember if the given hex-values are allowed in the classical form 0xffff. I always take only the part behind 0x in my rules.

2
  • Well it works, but this is vendor or product dependant. Isn't there any attr or env varaible to identify a usb mouse by? PS: It's hex by default, no need for 0x
    – nikitautiu
    Commented Sep 12, 2012 at 8:02
  • 3
    A more generic approach would be to match against ACTION=="add", ATTRS{bInterfaceProtocol}=="02", ATTRS{bInterfaceClass}=="03", ATTRS{bInterfaceSubClass}=="01". These are specific characteristics for a usb mouse. For further information see lsusb -v and usb.org/developers/defined_class. Commented Sep 12, 2012 at 9:02
2

Since the accepted answer doesn't work on my system here is a udev rule that works with gnome/gdm v. 3.16.2 and udev/systemd v. 226:

ACTION=="add", ATTRS{bInterfaceProtocol}=="02", ATTRS{bInterfaceClass}=="03", \
ATTRS{bInterfaceSubClass}=="01", ENV{XAUTHORITY}="/run/user/1000/gdm/Xauthority", \
ENV{DISPLAY}=":0", ENV{REMOVE_CMD}="/usr/bin/xinput --enable 'SynPS/2 Synaptics TouchPad'", \
RUN+="/usr/bin/xinput --disable 'SynPS/2 Synaptics TouchPad'"

ENV{REMOVE_CMD} is the command used when the device is removed.
SynPS/2 Synaptics TouchPad is the name of the touchpad device as reported by xinput.
The UID used in ENV{XAUTHORITY} (e.g. 1000 in my rule) has to match your user ID.
Note the backslashes at end of lines are needed, as otherwise udev rules cannot span over multiple lines. If you prefer in one line:

 ACTION=="add", ATTRS{bInterfaceProtocol}=="02", ATTRS{bInterfaceClass}=="03", ATTRS{bInterfaceSubClass}=="01", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/run/user/1000/gdm/Xauthority", ENV{REMOVE_CMD}="/usr/bin/xinput --enable 'SynPS/2 Synaptics TouchPad'", RUN+="/usr/bin/xinput --disable 'SynPS/2 Synaptics TouchPad'"
2
  • How would you do that with Xauthority for KDE? There is no such file. All I can see is that echo $XAUTHORITY gives /tmp/xauth-1000-_0. Maybe just ignore this variable? Why did you need that in the first place? Thanks
    – DrBeco
    Commented May 3, 2020 at 13:36
  • @DrBeco - I'm not on linux anymore but as far as I remember on KDE the file is /home/username/.Xauthority i.e. exactly what the OP used. HTH. Commented May 7, 2020 at 11:47
0

Given another answer that works on KDE (plasma, sddm).

I added the rule filename /etc/udev/rules.d/61-touchpadoff.rules with the following content:

ACTION!="add", GOTO="touchpadoff_end"

KERNEL=="mouse[0-9]", SUBSYSTEM=="input", SUBSYSTEMS=="usb", ENV{DISPLAY}=":0", ENV{REMOVE_CMD}="/usr/bin/xinput --enable 'Elan TouchPad'", RUN+="/usr/bin/xinput --disable 'Elan TouchPad'"

LABEL="touchpadoff_end"

You need to thange the name of your touchpad hardware. To see it issue a command % xinput --list

I hope this helps you KDE-heads.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .