1
0
mirror of https://github.com/wine-mirror/wine synced 2024-06-29 06:14:34 +00:00

win32u: Use a custom struct hid_input for NtUserSendHardwareInput.

This commit is contained in:
Rémi Bernon 2024-01-28 12:11:55 +01:00 committed by Alexandre Julliard
parent 66baee8b99
commit bb5f0e122f
7 changed files with 56 additions and 87 deletions

View File

@ -225,7 +225,6 @@ static void hid_device_queue_input( DEVICE_OBJECT *device, HID_XFER_PACKET *pack
struct hid_report *last_report, *report;
struct hid_queue *queue;
LIST_ENTRY completed, *entry;
RAWINPUT *rawinput;
KIRQL irql;
IRP *irp;
@ -233,28 +232,28 @@ static void hid_device_queue_input( DEVICE_OBJECT *device, HID_XFER_PACKET *pack
if (IsEqualGUID( ext->class_guid, &GUID_DEVINTERFACE_HID ))
{
size = offsetof( RAWINPUT, data.hid.bRawData[report_len] );
if (!(rawinput = malloc( size ))) ERR( "Failed to allocate rawinput data!\n" );
struct hid_packet *hid;
size = offsetof( struct hid_packet, data[report_len] );
if (!(hid = malloc( size ))) ERR( "Failed to allocate rawinput data!\n" );
else
{
INPUT input;
INPUT input = {.type = INPUT_HARDWARE};
rawinput->header.dwType = RIM_TYPEHID;
rawinput->header.dwSize = size;
rawinput->header.hDevice = ULongToHandle( ext->u.pdo.rawinput_handle );
rawinput->header.wParam = RIM_INPUT;
rawinput->data.hid.dwCount = 1;
rawinput->data.hid.dwSizeHid = report_len;
memcpy( rawinput->data.hid.bRawData, packet->reportBuffer, packet->reportBufferLen );
memset( rawinput->data.hid.bRawData + packet->reportBufferLen, 0, report_len - packet->reportBufferLen );
input.type = INPUT_HARDWARE;
input.hi.uMsg = WM_INPUT;
input.hi.wParamH = 0;
input.hi.wParamL = 0;
NtUserSendHardwareInput( 0, 0, &input, (LPARAM)rawinput );
input.hi.wParamH = HIWORD(RIM_INPUT);
input.hi.wParamL = LOWORD(RIM_INPUT);
free( rawinput );
hid->head.device = ext->u.pdo.rawinput_handle;
hid->head.usage = MAKELONG(desc->Usage, desc->UsagePage);
hid->head.count = 1;
hid->head.length = report_len;
memcpy( hid->data, packet->reportBuffer, packet->reportBufferLen );
memset( hid->data + packet->reportBufferLen, 0, report_len - packet->reportBufferLen );
NtUserSendHardwareInput( 0, 0, &input, (LPARAM)hid );
free( hid );
}
}

View File

@ -114,27 +114,20 @@ C_ASSERT(offsetof(RAWINPUT, data.hid.bRawData[2 * sizeof(USAGE)]) < sizeof(RAWIN
static void send_wm_input_device_change(BASE_DEVICE_EXTENSION *ext, LPARAM param)
{
HIDP_COLLECTION_DESC *desc = ext->u.pdo.device_desc.CollectionDesc;
RAWINPUT rawinput;
INPUT input;
INPUT input = {.type = INPUT_HARDWARE};
struct hid_packet hid = {0};
TRACE("ext %p, lparam %p\n", ext, (void *)param);
if (!IsEqualGUID( ext->class_guid, &GUID_DEVINTERFACE_HID )) return;
rawinput.header.dwType = RIM_TYPEHID;
rawinput.header.dwSize = offsetof(RAWINPUT, data.hid.bRawData[2 * sizeof(USAGE)]);
rawinput.header.hDevice = ULongToHandle(ext->u.pdo.rawinput_handle);
rawinput.header.wParam = param;
rawinput.data.hid.dwCount = 0;
rawinput.data.hid.dwSizeHid = 0;
((USAGE *)rawinput.data.hid.bRawData)[0] = desc->UsagePage;
((USAGE *)rawinput.data.hid.bRawData)[1] = desc->Usage;
input.type = INPUT_HARDWARE;
input.hi.uMsg = WM_INPUT_DEVICE_CHANGE;
input.hi.wParamH = 0;
input.hi.wParamL = 0;
NtUserSendHardwareInput(0, 0, &input, (LPARAM)&rawinput);
input.hi.wParamH = HIWORD(param);
input.hi.wParamL = LOWORD(param);
hid.head.device = ext->u.pdo.rawinput_handle;
hid.head.usage = MAKELONG(desc->Usage, desc->UsagePage);
NtUserSendHardwareInput(0, 0, &input, (LPARAM)&hid);
}
static NTSTATUS WINAPI driver_add_device(DRIVER_OBJECT *driver, DEVICE_OBJECT *bus_pdo)

View File

@ -3486,7 +3486,6 @@ NTSTATUS send_hardware_message( HWND hwnd, UINT flags, const INPUT *input, LPARA
{
struct send_message_info info;
int prev_x, prev_y, new_x, new_y;
USAGE hid_usage_page, hid_usage;
NTSTATUS ret;
BOOL wait, affects_key_state = FALSE;
@ -3500,25 +3499,6 @@ NTSTATUS send_hardware_message( HWND hwnd, UINT flags, const INPUT *input, LPARA
if (input->type == INPUT_MOUSE && (input->mi.dwFlags & (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_RIGHTDOWN)))
clip_fullscreen_window( hwnd, FALSE );
if (input->type == INPUT_HARDWARE)
{
if (input->hi.uMsg == WM_INPUT_DEVICE_CHANGE)
{
const RAWINPUT *rawinput = (const RAWINPUT *)lparam;
hid_usage_page = ((USAGE *)rawinput->data.hid.bRawData)[0];
hid_usage = ((USAGE *)rawinput->data.hid.bRawData)[1];
}
if (input->hi.uMsg == WM_INPUT)
{
const RAWINPUT *rawinput = (const RAWINPUT *)lparam;
if (!rawinput_device_get_usages( rawinput->header.hDevice, &hid_usage_page, &hid_usage ))
{
WARN( "unable to get HID usages for device %p\n", rawinput->header.hDevice );
return STATUS_INVALID_HANDLE;
}
}
}
SERVER_START_REQ( send_hardware_message )
{
req->win = wine_server_user_handle( hwnd );
@ -3548,29 +3528,20 @@ NTSTATUS send_hardware_message( HWND hwnd, UINT flags, const INPUT *input, LPARA
break;
case INPUT_HARDWARE:
req->input.hw.msg = input->hi.uMsg;
req->input.hw.lparam = MAKELONG( input->hi.wParamL, input->hi.wParamH );
req->input.hw.wparam = MAKELONG( input->hi.wParamL, input->hi.wParamH );
switch (input->hi.uMsg)
{
case WM_INPUT:
case WM_INPUT_DEVICE_CHANGE:
{
const RAWINPUT *rawinput = (const RAWINPUT *)lparam;
switch (rawinput->header.dwType)
{
case RIM_TYPEHID:
req->input.hw.wparam = rawinput->header.wParam;
req->input.hw.hid.device = HandleToUlong( rawinput->header.hDevice );
req->input.hw.hid.usage = MAKELONG(hid_usage, hid_usage_page);
req->input.hw.hid.count = rawinput->data.hid.dwCount;
req->input.hw.hid.length = rawinput->data.hid.dwSizeHid;
wine_server_add_data( req, rawinput->data.hid.bRawData,
rawinput->data.hid.dwCount * rawinput->data.hid.dwSizeHid );
break;
default:
assert( 0 );
break;
}
struct hid_packet *hid = (struct hid_packet *)lparam;
req->input.hw.hid = hid->head;
wine_server_add_data( req, hid->data, hid->head.count * hid->head.length );
break;
}
default:
req->input.hw.lparam = lparam;
break;
}
break;
}

View File

@ -1407,11 +1407,27 @@ static inline BOOL NtUserShowOwnedPopups( HWND hwnd, BOOL show )
return NtUserCallHwndParam( hwnd, show, NtUserCallHwndParam_ShowOwnedPopups );
}
struct hid_input
{
UINT device;
UINT usage;
UINT count;
UINT length;
};
struct hid_packet
{
struct hid_input head;
BYTE data[];
};
C_ASSERT(sizeof(struct hid_packet) == offsetof(struct hid_packet, data[0]));
struct send_hardware_input_params
{
UINT flags;
const INPUT *input;
LPARAM lparam; /* RAWINPUT pointer for WM_INPUT* messages */
LPARAM lparam; /* struct hid_packet pointer for WM_INPUT* messages */
};
static inline BOOL NtUserSendHardwareInput( HWND hwnd, UINT flags, const INPUT *input, LPARAM lparam )

View File

@ -14,6 +14,7 @@
#include <windef.h>
#include <winbase.h>
#include <ntuser.h>
typedef unsigned int obj_handle_t;
typedef unsigned int user_handle_t;
@ -325,13 +326,7 @@ typedef union
unsigned int msg;
lparam_t wparam;
lparam_t lparam;
struct
{
unsigned int device;
unsigned int usage;
unsigned int count;
unsigned int length;
} hid;
struct hid_input hid;
} hw;
} hw_input_t;
@ -6507,7 +6502,7 @@ union generic_reply
/* ### protocol_version begin ### */
#define SERVER_PROTOCOL_VERSION 794
#define SERVER_PROTOCOL_VERSION 795
/* ### protocol_version end ### */

View File

@ -30,6 +30,7 @@
#include <windef.h>
#include <winbase.h>
#include <ntuser.h>
typedef unsigned int obj_handle_t;
typedef unsigned int user_handle_t;
@ -341,13 +342,7 @@ typedef union
unsigned int msg; /* message code */
lparam_t wparam; /* parameters */
lparam_t lparam; /* parameters */
struct
{
unsigned int device; /* rawinput device index */
unsigned int usage; /* HID device usage */
unsigned int count; /* HID report count */
unsigned int length; /* HID report length */
} hid;
struct hid_input hid; /* defined in ntuser.h */
} hw;
} hw_input_t;

View File

@ -2250,7 +2250,7 @@ static void queue_custom_hardware_message( struct desktop *desktop, user_handle_
msg->win = get_user_full_handle( win );
msg->msg = input->hw.msg;
msg->wparam = 0;
msg->wparam = input->hw.wparam;
msg->lparam = input->hw.lparam;
msg->x = desktop->cursor.x;
msg->y = desktop->cursor.y;