[PATCH 1/2] DInput : Add vendor_id and product_id with Linux joystick API
Corentin Rossignon
corossig at gmail.com
Sat Jul 23 06:01:28 CDT 2016
Signed-off-by: Corentin Rossignon <corossig at gmail.com>
---
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 5b02df4..90b7280 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[MAX_PATH], 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;
+
+ snprintf(sys_path, MAX_PATH, "/sys/class/input/js%d/device/id/vendor", i);
+ sys_fd = open(sys_path, O_RDONLY);
+ if (sys_path > 0)
+ {
+ if (read(sys_fd, id_str, 4) == 4)
+ {
+ id_str[4] = '\0';
+ joydev.vendor_id = strtol(id_str, NULL, 16);
+ }
+
+ close(sys_fd);
+ }
+
+ snprintf(sys_path, MAX_PATH, "/sys/class/input/js%d/device/id/product", i);
+ sys_fd = open(sys_path, O_RDONLY);
+ if (sys_path > 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)
--
2.9.0
More information about the wine-patches
mailing list