8

I'm trying to set xinput properties for a USB input device whenever it is connected. I have seen solutions that require a script to run in the background and poll USB devices, but I would like to find a triggered approach rather than one involving user-space polling.

I have tried creating a udev rule that runs a script on device connection, but it appears that the connected device is not yet visible to xinput when the udev add rule is triggered. This appears to be a constant order of events rather than a race condition as adding a sleep command to the script also delays the device being listed in xinput list.

Is there any reliable method of setting xinput properties for devices when they are connected?

  • 1
    why trigger them on udev and not on xinput events? the former requires root, it's tricky, system-dependent, and messes with stuff it has not business messing with. The latter could be done be any x11 client, via the xinput or xinput2 extension. Also have a look here. –  Aug 18 '19 at 08:28

2 Answers2

3

I had the same problem. My solution was to trigger the udev rule with ACTION=="bind" instead of ACTION=="add" (Because I saw with udevadm monitor that it was last action when I connected a mouse)

AsVHEn
  • 31
2

The normal method is to write an xorg.conf file, use the InputClass matching methods, and set properties directly in xorg.conf. No script, no race condition, no explicit meddling with udev; it just works, though it doesn't use xinput directly...

See man xorg.conf for details.

dirkt
  • 32,309
  • xinput has properties listing, but xorg.conf does not. Is there a way to know the property exact name to be used in xorg.conf? – user.dz Oct 13 '19 at 22:57
  • 2
    Ok, never mind, found it man(4) libinput , have nice time. – user.dz Oct 14 '19 at 10:35
  • 2
    +1 for the clue, but for exactly how-to you must look here: https://unix.stackexchange.com/questions/58117/determine-xinput-device-manufacturer-and-model#answer-220082 – WesternGun Apr 14 '21 at 08:08