emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master 3b41141708: Expose the name of an event's input device to Lis


From: Brian Cully
Subject: Re: master 3b41141708: Expose the name of an event's input device to Lisp
Date: Sun, 10 Apr 2022 14:08:00 -0400
User-agent: mu4e 1.6.10; emacs 29.0.50

Po Lu <luangruo@yahoo.com> writes:

> That's not true on X.  This is implementation dependent, but the X.Org
> server will always try to reuse a device ID that is currently available.

        From what I could make out from the code, you are correct, but I
was speaking of how Linux assigns USB device addresses. In any event,
the index into the inputInfo.devices array isn’t useful as a stable
identifier.

> That's only a last resort.  On X Windows, the input driver is supposed
> to take care of that using serial numbers and any other information that
> might serve to identify a device uniquely.

        So I’ve tried to verify this, and couldn’t. I trawled the Xorg
xserver code, and from what I can tell, the “name” field that gets
assigned to a device comes from the driver level, which, in my case at
least, is libinput. I couldn’t find any place in the X server code that
changes the name as passed in from the driver level (although I may have
missed it, but I doubt it, as I’ll show below).

        Moreover, it appears as though, at least with udev and libinput,
device names are *not* unique. This time, rather than trying to go
through their code, I created a simple test: I updated the firmware on a
USB device to have the same name, model, vid, and pid as my keyboard,
but a different serial number. I think this reflects how this would work
in the real world.

        When I plugged it in, here’s the relevant output from lsusb:
---[snip]---
Bus 001 Device 059: ID 1209:2301 Generic Keyboardio Model 01
Device Descriptor:
        ⋮
  idProduct          0x2301 Keyboardio Model 01
  bcdDevice            1.00
  iManufacturer           1 Keyboardio
  iProduct                2 Model 01
  iSerial                 3 kbio01D
        ⋮
Bus 001 Device 083: ID 1209:2301 Generic Keyboardio Model 01
Device Descriptor:
        ⋮
  idProduct          0x2301 Keyboardio Model 01
  bcdDevice            1.00
  iManufacturer           1 Keyboardio
  iProduct                2 Model 01
  iSerial                 3 8995E84D0119
        ⋮
---[snip]---

        You can see the only difference is the serial number. This is reflected
in the Linux device names in /dev/input/by-id:
---[snip]---
usb-Keyboardio_Model_01_8995E84D0119-if02-event-kbd -> ../event28
usb-Keyboardio_Model_01_kbio01D-if03-event-kbd -> ../event26
---[snip]---

        The serial number is clearly visible (8995... is my mock
device), and you can see that they reference separate event devices in
/dev/input.

        From there, I launched an X session to see how the name would be
reported in the logs:
---[snip]---
        ⋮
[2308240.861] (II) config/udev: Adding input device Keyboardio Model 01 
(/dev/input/event28)
[2308240.861] (**) Keyboardio Model 01: Applying InputClass "evdev keyboard 
catchall"
[2308240.861] (**) Keyboardio Model 01: Applying InputClass "libinput keyboard 
catchall"
[2308240.861] (**) Keyboardio Model 01: Applying InputClass "system-keyboard"
[2308240.861] (II) Using input driver 'libinput' for 'Keyboardio Model 01'
[2308240.861]   Option "_source" "server/udev"
[2308240.861]   Option "name" "Keyboardio Model 01"
[2308240.861]   Option "path" "/dev/input/event28"
[2308240.861]   Option "device" "/dev/input/event28"
[2308240.861]   Option "major" "13"
[2308240.861]   Option "minor" "92"
[2308240.899] (II) XINPUT: Adding extended input device "Keyboardio Model 01" 
(type: KEYBOARD, id 8)
        ⋮
[2308241.075] (II) config/udev: Adding input device Keyboardio Model 01 
(/dev/input/event26)
[2308241.075] (**) Keyboardio Model 01: Applying InputClass "evdev keyboard 
catchall"
[2308241.075] (**) Keyboardio Model 01: Applying InputClass "libinput keyboard 
catchall"
[2308241.075] (**) Keyboardio Model 01: Applying InputClass "system-keyboard"
[2308241.075] (II) Using input driver 'libinput' for 'Keyboardio Model 01'
[2308241.075]   Option "_source" "server/udev"
[2308241.075]   Option "name" "Keyboardio Model 01"
[2308241.075]   Option "path" "/dev/input/event26"
[2308241.075]   Option "device" "/dev/input/event26"
[2308241.075]   Option "major" "13"
[2308241.075]   Option "minor" "90"
[2308241.125] (II) XINPUT: Adding extended input device "Keyboardio Model 01" 
(type: KEYBOARD, id 12)
        ⋮
---[snip]---

        And here you can see that the two input devices have the same
name (Keyboardio Model 01). In particular the last set of XINPUT lines
which echo the name come from device activation in xf86input.c at line
412 of the xserver code, just before the device is enabled, and I would
assume far too late in the process to adjust the name (but again, I
admit I may be missing something).

        AFAICT this is the name that’s presented to
toolkit layers. There may be a place where it’s modified by X, but,
again, I couldn’t find it.

        So, the tl;dr here is that I flashed a USB device to look like one of my
existing ones, and from everything I can tell, they have the same name,
at least coming out of X.

-bjc



reply via email to

[Prev in Thread] Current Thread [Next in Thread]