udev script to change libinput settings for middle-button scrolling (answered with xorg file, better solution)
ubuntu 18.04.2 on a Thinkpad T480
I want to run a udev script when my mouse is connected. I am happy to assume that a user called tim has a Xsession running (I use kde plasma).
objective is to configure middle button scrolling for a Logitech usb mouse including hot plugging it.
My rule is in:
/etc/udev/rules.d/41-usb-mouse-add.rules
ACTION=="add" \
, ATTRS{idProduct}=="c539" \
, ATTRS{idVendor}=="046d" \
, ENV{DISPLAY}=":0" \
, ENV{XAUTHORITY}="/tmp/xauth-1000-_0" \
, RUN+="/home/tim/scripts/tweak_libinput.sh"
The location of XAUTHORITY is copied from what I see in a shell.
I have a call to logger in the script, and it is getting called, multiple times (why?) So the udev rule is working, although I expected it to be called only once.
It is having some effect, because it breaks my natural scrolling settings ... that same script sets natural scrolling on, but after the udev invocation, the natural scrolling settings are reset. So it is worse than failing, it is actually breaking my settings :)
When the script is run manually, it works fine. Regardless of how many times I invoke it.
Edit
ls -l /tmp/xauth-1000-_0
-rw------- 1 tim tim 53 Jun 11 20:07 /tmp/xauth-1000-_0
is this permission setting going to be a problem?
It is possible to do this with a configuration file on /usr/share/X11/xorg.conf.d/41-libinput-local.conf
These contents work for a specific device:
Section "InputClass"
Identifier "Logitech USB Receiver Mouse"
MatchIsPointer "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
Option "ScrollButton" "2"
Option "ScrollMethod" "button"
Option "NaturalScrolling" "true"
EndSection
It works when the device is hot plugged after the session begins, and it survives during suspend/resume, as reported by Tim (OP).
References:
- man(4) libinput
-
man xorg.conf
- Archlinux: Mouse Acceleration