winebus: Lookup device HID usage and usage page on the PE side.

This commit is contained in:
Rémi Bernon 2024-11-16 23:19:23 +01:00 committed by Alexandre Julliard
parent 29226ef249
commit b787e0654a
Notes: Alexandre Julliard 2024-11-18 23:17:44 +01:00
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/wine/merge_requests/6832
5 changed files with 14 additions and 19 deletions

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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, &params);
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);

View file

@ -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);
}