From f4d5f7e88a28c8b3501602aa3bcc80447886a440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Fri, 9 Apr 2021 13:11:34 +0200 Subject: [PATCH] hidclass.sys: Assign rawinput device handle in HID_LinkDevice. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The handles are just numeric values and not real object handles, they are used in the hDevice field of the RAWINPUTHEADER struct. They will also be used as an HID rawinput device array index on the server side. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50506 Signed-off-by: RĂ©mi Bernon Signed-off-by: Arkadiusz Hiler Signed-off-by: Alexandre Julliard --- dlls/hidclass.sys/device.c | 17 +++++++++++++++++ dlls/hidclass.sys/hid.h | 1 + 2 files changed, 18 insertions(+) diff --git a/dlls/hidclass.sys/device.c b/dlls/hidclass.sys/device.c index 6ca5e39e648..7d198b99b34 100644 --- a/dlls/hidclass.sys/device.c +++ b/dlls/hidclass.sys/device.c @@ -71,6 +71,17 @@ NTSTATUS HID_CreateDevice(DEVICE_OBJECT *native_device, HID_MINIDRIVER_REGISTRAT return STATUS_SUCCESS; } +/* user32 reserves 1 & 2 for winemouse and winekeyboard, + * keep this in sync with user_private.h */ +#define WINE_MOUSE_HANDLE 1 +#define WINE_KEYBOARD_HANDLE 2 + +static UINT32 alloc_rawinput_handle(void) +{ + static LONG counter = WINE_KEYBOARD_HANDLE + 1; + return InterlockedIncrement(&counter); +} + NTSTATUS HID_LinkDevice(DEVICE_OBJECT *device) { WCHAR device_instance_id[MAX_DEVICE_ID_LEN]; @@ -125,7 +136,13 @@ NTSTATUS HID_LinkDevice(DEVICE_OBJECT *device) { if (!IoRegisterDeviceInterface(device, &GUID_DEVINTERFACE_MOUSE, NULL, &ext->mouse_link_name)) ext->is_mouse = TRUE; + ext->rawinput_handle = WINE_MOUSE_HANDLE; } + else if (ext->preparseData->caps.UsagePage == HID_USAGE_PAGE_GENERIC + && ext->preparseData->caps.Usage == HID_USAGE_GENERIC_KEYBOARD) + ext->rawinput_handle = WINE_KEYBOARD_HANDLE; + else + ext->rawinput_handle = alloc_rawinput_handle(); return STATUS_SUCCESS; diff --git a/dlls/hidclass.sys/hid.h b/dlls/hidclass.sys/hid.h index 889b8c625c0..41f3766a535 100644 --- a/dlls/hidclass.sys/hid.h +++ b/dlls/hidclass.sys/hid.h @@ -51,6 +51,7 @@ typedef struct _BASE_DEVICE_EXTENSION { struct ReportRingBuffer *ring_buffer; HANDLE halt_event; HANDLE thread; + UINT32 rawinput_handle; KSPIN_LOCK irp_queue_lock; LIST_ENTRY irp_queue;