From b787e0654a68fcd4d09d9c7020ebc58f04f723f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Sat, 16 Nov 2024 23:19:23 +0100 Subject: [PATCH] winebus: Lookup device HID usage and usage page on the PE side. --- dlls/winebus.sys/bus_iohid.c | 9 +++++---- dlls/winebus.sys/bus_sdl.c | 4 ---- dlls/winebus.sys/bus_udev.c | 3 --- dlls/winebus.sys/main.c | 12 +++++++----- dlls/winebus.sys/unixlib.h | 5 ++--- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index 45cca15c82a..5a210fc6bbd 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -275,10 +275,11 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void * .serialnumber = {'0','0','0','0',0}, }; struct iohid_device *impl; + USAGE_AND_PAGE usages; CFStringRef str; - desc.usages.UsagePage = CFNumberToDWORD(IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDPrimaryUsagePageKey))); - desc.usages.Usage = CFNumberToDWORD(IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDPrimaryUsageKey))); + usages.UsagePage = CFNumberToDWORD(IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDPrimaryUsagePageKey))); + usages.Usage = CFNumberToDWORD(IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDPrimaryUsageKey))); desc.vid = CFNumberToDWORD(IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDVendorIDKey))); desc.pid = CFNumberToDWORD(IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDProductIDKey))); @@ -289,8 +290,8 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void * desc.is_bluetooth = !CFStringCompare(str, CFSTR(kIOHIDTransportBluetoothValue), 0) || !CFStringCompare(str, CFSTR(kIOHIDTransportBluetoothLowEnergyValue), 0); - if (desc.usages.UsagePage != HID_USAGE_PAGE_GENERIC || - !(desc.usages.Usage == HID_USAGE_GENERIC_JOYSTICK || desc.usages.Usage == HID_USAGE_GENERIC_GAMEPAD)) + if (usages.UsagePage != HID_USAGE_PAGE_GENERIC || + !(usages.Usage == HID_USAGE_GENERIC_JOYSTICK || usages.Usage == HID_USAGE_GENERIC_GAMEPAD)) { /* winebus isn't currently meant to handle anything but these, and * opening keyboards, mice, or the Touch Bar on older MacBooks triggers diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index cb85fd0fd92..e050742ca66 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -986,8 +986,6 @@ static void sdl_add_device(unsigned int index) if (controller) { desc.is_gamepad = TRUE; - desc.usages.UsagePage = HID_USAGE_PAGE_GENERIC; - desc.usages.Usage = HID_USAGE_GENERIC_GAMEPAD; axis_count = 6; } else @@ -995,8 +993,6 @@ static void sdl_add_device(unsigned int index) int button_count = pSDL_JoystickNumButtons(joystick); axis_count = pSDL_JoystickNumAxes(joystick); desc.is_gamepad = (axis_count == 6 && button_count >= 14); - desc.usages.UsagePage = HID_USAGE_PAGE_GENERIC; - desc.usages.Usage = HID_USAGE_GENERIC_JOYSTICK; } for (axis_offset = 0; axis_offset < axis_count; axis_offset += (options.split_controllers ? 6 : axis_count)) diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index cb16dd39451..561f0cdc0e4 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -1248,7 +1248,6 @@ static void udev_add_device(struct udev_device *dev, int fd) #ifdef HAS_PROPER_INPUT_HEADER else if (!strcmp(subsystem, "input")) { - const USAGE_AND_PAGE device_usage = *what_am_I(dev, fd); static const WCHAR evdev[] = {'e','v','d','e','v',0}; struct input_id device_id = {0}; char buffer[MAX_PATH]; @@ -1269,8 +1268,6 @@ static void udev_add_device(struct udev_device *dev, int fd) if (!desc.serialnumber[0] && ioctl(fd, EVIOCGUNIQ(sizeof(buffer)), buffer) >= 0) ntdll_umbstowcs(buffer, strlen(buffer) + 1, desc.serialnumber, ARRAY_SIZE(desc.serialnumber)); - - desc.usages = device_usage; } #endif diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index 5128f737af1..d267606b2cf 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -684,7 +684,7 @@ static NTSTATUS get_device_descriptors(UINT64 unix_device, BYTE **report_desc, U return STATUS_SUCCESS; } -static USAGE_AND_PAGE get_hidraw_device_usages(UINT64 unix_device) +static USAGE_AND_PAGE get_device_usages(UINT64 unix_device) { HIDP_DEVICE_DESC device_desc; USAGE_AND_PAGE usages = {0}; @@ -749,18 +749,20 @@ static DWORD CALLBACK bus_main_thread(void *args) case BUS_EVENT_TYPE_DEVICE_CREATED: { struct device_desc desc = event->device_created.desc; - if (desc.is_hidraw && !desc.usages.UsagePage) desc.usages = get_hidraw_device_usages(event->device); - if (!desc.is_hidraw != !is_hidraw_enabled(desc.vid, desc.pid, &desc.usages)) + USAGE_AND_PAGE usages; + + usages = get_device_usages(event->device); + if (!desc.is_hidraw != !is_hidraw_enabled(desc.vid, desc.pid, &usages)) { struct device_remove_params params = {.device = event->device}; WARN("ignoring %shidraw device %04x:%04x with usages %04x:%04x\n", desc.is_hidraw ? "" : "non-", - desc.vid, desc.pid, desc.usages.UsagePage, desc.usages.Usage); + desc.vid, desc.pid, usages.UsagePage, usages.Usage); winebus_call(device_remove, ¶ms); break; } TRACE("creating %shidraw device %04x:%04x with usages %04x:%04x\n", desc.is_hidraw ? "" : "non-", - desc.vid, desc.pid, desc.usages.UsagePage, desc.usages.Usage); + desc.vid, desc.pid, usages.UsagePage, usages.Usage); device = bus_create_hid_device(&event->device_created.desc, event->device); if (device) IoInvalidateDeviceRelations(bus_pdo, BusRelations); diff --git a/dlls/winebus.sys/unixlib.h b/dlls/winebus.sys/unixlib.h index b38382cda2c..02e7a1c6953 100644 --- a/dlls/winebus.sys/unixlib.h +++ b/dlls/winebus.sys/unixlib.h @@ -38,7 +38,6 @@ struct device_desc UINT version; UINT input; UINT uid; - USAGE_AND_PAGE usages; BOOL is_gamepad; BOOL is_hidraw; BOOL is_bluetooth; @@ -151,8 +150,8 @@ enum unix_funcs static inline const char *debugstr_device_desc(struct device_desc *desc) { if (!desc) return "(null)"; - return wine_dbg_sprintf("{vid %04x, pid %04x, version %04x, input %d, uid %08x, usage %04x:%04x, is_gamepad %u, is_hidraw %u, is_bluetooth %u}", - desc->vid, desc->pid, desc->version, desc->input, desc->uid, desc->usages.UsagePage, desc->usages.Usage, + return wine_dbg_sprintf("{vid %04x, pid %04x, version %04x, input %d, uid %08x, is_gamepad %u, is_hidraw %u, is_bluetooth %u}", + desc->vid, desc->pid, desc->version, desc->input, desc->uid, desc->is_gamepad, desc->is_hidraw, desc->is_bluetooth); }