From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Brian Cully Newsgroups: gmane.emacs.devel Subject: Re: master 3b41141708: Expose the name of an event's input device to Lisp Date: Sun, 10 Apr 2022 14:08:00 -0400 Message-ID: <87mtgsyeg0.fsf@ditto.jhoto.spork.org> References: <164933858147.29834.15050766441005536059@vcs2.savannah.gnu.org> <87o81bu7zj.fsf@yahoo.com> <83v8vjai4s.fsf@gnu.org> <87bkxbsqfl.fsf@yahoo.com> <835yniah0u.fsf@gnu.org> <8735impqw4.fsf@yahoo.com> <83v8vi8uyu.fsf@gnu.org> <871qy6o9p3.fsf@yahoo.com> <83o81a8qnd.fsf@gnu.org> <87zgkulbuu.fsf@yahoo.com> <83ilri8iag.fsf@gnu.org> <87tub1kbkf.fsf@yahoo.com> <831qy58ofh.fsf@gnu.org> <87sfqlfomt.fsf@yahoo.com> <83wnfx77s0.fsf@gnu.org> <87o819e80r.fsf@yahoo.com> <83sfql73di.fsf@gnu.org> <87ee25cosj.fsf@yahoo.com> <83mtgt712o.fsf@gnu.org> <87r1659jey.fsf@ditto.jhoto.spork.org> <87v8vh845k.fsf@yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32650"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.6.10; emacs 29.0.50 Cc: Eli Zaretskii , emacs-devel@gnu.org, larsi@gnus.org, monnier@iro.umontreal.ca, rms@gnu.org To: Po Lu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 10 20:36:34 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ndcQL-0008Jx-84 for ged-emacs-devel@m.gmane-mx.org; Sun, 10 Apr 2022 20:36:33 +0200 Original-Received: from localhost ([::1]:33840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ndcQJ-0000UV-Qk for ged-emacs-devel@m.gmane-mx.org; Sun, 10 Apr 2022 14:36:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndcPM-00088f-HP for emacs-devel@gnu.org; Sun, 10 Apr 2022 14:35:32 -0400 Original-Received: from coleridge.kublai.com ([166.84.7.167]:54081 helo=mail.spork.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndcPJ-00032f-M6; Sun, 10 Apr 2022 14:35:32 -0400 Original-Received: from ditto (unknown [IPv6:2001:470:1f07:1b9:8650:a942:ec5e:856b]) by mail.spork.org (Postfix) with ESMTPSA id CD122345B; Sun, 10 Apr 2022 14:35:11 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=spork.org; s=dkim; t=1649615728; bh=OGKGxi1GWYOiuPYs2P1cyOmlmB2GwwdUL8brABpaWwQ=; h=References:From:To:Cc:Subject:Date:In-reply-to; b=Iz/BFHUSjai5h3FCrRsHRKylRLqOvPs3iT+AZeCbsCBLi0DA49jAzqczrmxBwr8XJ q3zstWLWKVRwiJv9bB4hznRcGuV4la5EV867jK5ntQdDwAJcBTNvFYYaF4RVC57Yhr FIWCdHyqagFkRtwR7nl0gXIlek9jk2uEgFcltfJ4= In-reply-to: <87v8vh845k.fsf@yahoo.com> Received-SPF: pass client-ip=166.84.7.167; envelope-from=bjc@spork.org; helo=mail.spork.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:288154 Archived-At: Po Lu 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=E2=80=99t 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=E2=80=99ve tried to verify this, and couldn=E2=80=99t. I trawled the = Xorg xserver code, and from what I can tell, the =E2=80=9Cname=E2=80=9D field th= at gets assigned to a device comes from the driver level, which, in my case at least, is libinput. I couldn=E2=80=99t 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=E2=80=99ll 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=E2=80=99s the relevant output from lsusb: ---[snip]--- Bus 001 Device 059: ID 1209:2301 Generic Keyboardio Model 01 Device Descriptor: =E2=8B=AE idProduct 0x2301 Keyboardio Model 01 bcdDevice 1.00 iManufacturer 1 Keyboardio iProduct 2 Model 01 iSerial 3 kbio01D =E2=8B=AE Bus 001 Device 083: ID 1209:2301 Generic Keyboardio Model 01 Device Descriptor: =E2=8B=AE idProduct 0x2301 Keyboardio Model 01 bcdDevice 1.00 iManufacturer 1 Keyboardio iProduct 2 Model 01 iSerial 3 8995E84D0119 =E2=8B=AE ---[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]--- =E2=8B=AE [2308240.861] (II) config/udev: Adding input device Keyboardio Model 01 (/d= ev/input/event28) [2308240.861] (**) Keyboardio Model 01: Applying InputClass "evdev keyboard= catchall" [2308240.861] (**) Keyboardio Model 01: Applying InputClass "libinput keybo= ard catchall" [2308240.861] (**) Keyboardio Model 01: Applying InputClass "system-keyboar= d" [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 0= 1" (type: KEYBOARD, id 8) =E2=8B=AE [2308241.075] (II) config/udev: Adding input device Keyboardio Model 01 (/d= ev/input/event26) [2308241.075] (**) Keyboardio Model 01: Applying InputClass "evdev keyboard= catchall" [2308241.075] (**) Keyboardio Model 01: Applying InputClass "libinput keybo= ard catchall" [2308241.075] (**) Keyboardio Model 01: Applying InputClass "system-keyboar= d" [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 0= 1" (type: KEYBOARD, id 12) =E2=8B=AE ---[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=E2=80=99s presented to toolkit layers. There may be a place where it=E2=80=99s modified by X, but, again, I couldn=E2=80=99t 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