2

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?

Tim Richardson
  • 2,164
  • 2
  • 24
  • 42
  • Ah. according to this it's complicated: https://bbs.archlinux.org/viewtopic.php?id=180079 – Tim Richardson Jun 11 '19 at 10:49
  • Use `xorg.conf` instead, `udev` is an alien. man(4) of libinput contains required info. – user.dz Oct 13 '19 at 23:33
  • The point of udev is to react to hardware changes (I come back to my desk and connect to mouse). Can't do this with x.org as far as I know. – Tim Richardson Oct 13 '19 at 23:37
  • So libinput properties you are trying to change are not for same device (attached mouse)? Could you add contents of the script? – user.dz Oct 13 '19 at 23:39
  • The mouse was not connected when the session began. Later it is connected. – Tim Richardson Oct 13 '19 at 23:40
  • Even so plug-n-play device can have stored options in xorg.conf . Could you please add contents of the script (xinput commands) and full listing of `xinput list-props ...` – user.dz Oct 13 '19 at 23:46
  • Plus I should say that my starting point is a libinput script that sets up my input devices very nicely, but libinput can't configure devices until they exist. – Tim Richardson Oct 13 '19 at 23:46
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/99857/discussion-between-user-dz-and-tim-richardson). – user.dz Oct 13 '19 at 23:48
  • This is relevant part of my script: https://pastebin.com/P8M04Uxh – Tim Richardson Oct 13 '19 at 23:52

1 Answers1

2

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:

user.dz
  • 47,137
  • 13
  • 140
  • 258