diff --git a/src/device.c b/src/device.c index 56adbaf..c7bc5fb 100644 --- a/src/device.c +++ b/src/device.c @@ -41,7 +41,7 @@ * corresponding device should be considered invalid by the caller. */ -static uint8_t resolve_device_capabilities(int fd, int *num_keys, uint8_t *relmask, uint8_t *absmask) +static uint8_t resolve_device_capabilities(int fd, uint32_t *num_keys, uint8_t *relmask, uint8_t *absmask) { const uint32_t keyboard_mask = 1<> 24); + hash = hash*33 + (uint8_t)(num_keys >> 16); + hash = hash*33 + (uint8_t)(num_keys >> 8); + hash = hash*33 + (uint8_t)(num_keys); + hash = hash*33 + absmask; + hash = hash*33 + relmask; + + while (*name) { + hash = hash*33 + *name; + name++; + } + + return hash; +} + static int device_init(const char *path, struct device *dev) { int fd; int capabilities; - int num_keys; + uint32_t num_keys; uint8_t relmask; uint8_t absmask; struct input_absinfo absinfo; @@ -154,11 +174,11 @@ static int device_init(const char *path, struct device *dev) * Attempt to generate a reproducible unique identifier for each device. * The product and vendor ids are insufficient to identify some devices since * they can create multiple device nodes with different capabilities. Thus - * we factor in the capabilities of the resultant evdev node to - * further distinguish between input devices. These should be - * regarded as opaque identifiers by the user. + * we factor in the device name and capabilities of the resultant evdev node + * to further distinguish between input devices. These should be regarded as + * opaque identifiers by the user. */ - snprintf(dev->id, sizeof dev->id, "%04x:%04x:%04x%02x%02x", info.vendor, info.product, num_keys, absmask, relmask); + snprintf(dev->id, sizeof dev->id, "%04x:%04x:%08x", info.vendor, info.product, generate_uid(num_keys, absmask, relmask, dev->name)); dev->fd = fd; dev->capabilities = capabilities;