From 4f01bcb85f758f63f08b41201c1e5bd5a6b96f67 Mon Sep 17 00:00:00 2001 From: Corentin Rossignon Date: Sun, 24 Jul 2016 16:46:41 +0100 Subject: [PATCH] dinput: Retrieve vendor ID and product ID in Linux joystick API. Signed-off-by: Corentin Rossignon Signed-off-by: Bruno Jesus <00cpxxx@gmail.com> Signed-off-by: Alexandre Julliard --- dlls/dinput/joystick_linux.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c index 5b02df4e023..1b041c653ef 100644 --- a/dlls/dinput/joystick_linux.c +++ b/dlls/dinput/joystick_linux.c @@ -81,6 +81,8 @@ struct JoyDev BYTE axis_count; BYTE button_count; int *dev_axes_map; + + WORD vendor_id, product_id; }; typedef struct JoystickImpl JoystickImpl; @@ -135,9 +137,10 @@ static INT find_joystick_devices(void) joystick_devices_count = 0; for (i = 0; i < MAX_JOYSTICKS; i++) { - int fd; + int fd, sys_fd; struct JoyDev joydev, *new_joydevs; BYTE axes_map[ABS_MAX + 1]; + char sys_path[sizeof("/sys/class/input/js/device/id/product") + 10], id_str[5]; snprintf(joydev.device, sizeof(joydev.device), "%s%d", JOYDEV_NEW, i); if ((fd = open(joydev.device, O_RDONLY)) < 0) @@ -204,6 +207,36 @@ static INT find_joystick_devices(void) joydev.dev_axes_map[j] = -1; } + /* Find vendor_id and product_id in sysfs */ + joydev.vendor_id = 0; + joydev.product_id = 0; + + sprintf(sys_path, "/sys/class/input/js%d/device/id/vendor", i); + sys_fd = open(sys_path, O_RDONLY); + if (sys_fd > 0) + { + if (read(sys_fd, id_str, 4) == 4) + { + id_str[4] = '\0'; + joydev.vendor_id = strtol(id_str, NULL, 16); + } + + close(sys_fd); + } + + sprintf(sys_path, "/sys/class/input/js%d/device/id/product", i); + sys_fd = open(sys_path, O_RDONLY); + if (sys_fd > 0) + { + if (read(sys_fd, id_str, 4) == 4) + { + id_str[4] = '\0'; + joydev.product_id = strtol(id_str, NULL, 16); + } + + close(sys_fd); + } + close(fd); if (!joystick_devices_count)