Expose vendor ID and product ID of gamepads
Motivating background
Currently gamepads can only be identified with Gamepad::uuid()
. Due to the limited platform implementations (#153) and the fact it mixes some device model information (vendor ID, product ID) with some OS information (USB bus; at least on Linux and macOS/SDL), Gamepad::uuid()
is hard to use correctly. The semantic of calling it "UUID" is also misleading, as it can imply a unique ID per device, whereas this is not the case in practice for the only 2 platform implementations I saw; they build a UUID which may change if the device is unplugged and replugged. In fact, after reading around, there's no way I found to uniquely identify a single gamepad even across unplugging; the best you can get is the OS retaining some unique ID while the device is plugged, which is already of limited use for wired gamepads but becomes useless for wireless ones. I mean useless in the sense this becomes no more valuable than using the vendor ID / product ID pair, which will also not allow discriminating between two instances of the same product (2 identical gamepads).
Suggested feature
A more "honest" approach (or, less surprising) I think would be to directly expose a Gamepad::vendor_id() -> u16
and Gamepad::product_id() -> u16
of the device. This has a number of advantages:
- This is available in more platforms (this is being added to
rusty-xinput
, PR here, so will be available on Windows). - The IDs can be matched against official lists, for example by using the
usb_ids
crate, to obtain a human readable display name of the vendor and the device. This is not currently possible unless you look at thegilrs
code and assume all platforms follow the same UUID composing pattern, which is brittle. - The application can recognize a device type and display a specific UI e.g. for button mapping with a picture of the controller. This requires identifying the kind of controller, but not the specific physical device used (i.e. all Xbox gamepads share a same UI, it doesn't matter if it's mine or the one of my brother for example).