user32: Implement GetRegisteredRawInputDevices.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2020-08-10 11:04:13 +02:00 committed by Alexandre Julliard
parent a3aa9ae80a
commit 1e7378d80c
8 changed files with 110 additions and 31 deletions

View File

@ -602,7 +602,6 @@ static void test_mouse_keyboard(void)
raw_devices_count = ARRAY_SIZE(raw_devices);
GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
todo_wine
ok(raw_devices_count == 0, "Unexpected raw devices registered: %d\n", raw_devices_count);
hr = IDirectInputDevice8_Acquire(di_keyboard);
@ -624,7 +623,6 @@ static void test_mouse_keyboard(void)
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
raw_devices_count = ARRAY_SIZE(raw_devices);
GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
todo_wine
ok(raw_devices_count == 0, "Unexpected raw devices registered: %d\n", raw_devices_count);
if (raw_devices[0].hwndTarget != NULL)
@ -662,7 +660,6 @@ static void test_mouse_keyboard(void)
ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %08x\n", hr);
raw_devices_count = ARRAY_SIZE(raw_devices);
GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
todo_wine
ok(raw_devices_count == 0, "Unexpected raw devices registered: %d\n", raw_devices_count);
/* expect dinput8 to take over any activated raw input devices */
@ -689,26 +686,18 @@ static void test_mouse_keyboard(void)
raw_devices_count = ARRAY_SIZE(raw_devices);
memset(raw_devices, 0, sizeof(raw_devices));
hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
todo_wine
ok(hr == 3, "GetRegisteredRawInputDevices returned %d, raw_devices_count: %d\n", hr, raw_devices_count);
todo_wine
ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage);
todo_wine
ok(raw_devices[0].usUsage == 2, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage);
todo_wine
ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %x\n", raw_devices[0].dwFlags);
todo_wine
ok(raw_devices[0].hwndTarget == di_hwnd, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget);
todo_wine
ok(raw_devices[1].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[1].usUsagePage);
todo_wine
ok(raw_devices[1].usUsage == 5, "Unexpected raw device usage: %x\n", raw_devices[1].usUsage);
ok(raw_devices[1].dwFlags == 0, "Unexpected raw device flags: %x\n", raw_devices[1].dwFlags);
todo_wine
ok(raw_devices[1].hwndTarget == hwnd, "Unexpected raw device target: %p\n", raw_devices[1].hwndTarget);
todo_wine
ok(raw_devices[2].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[1].usUsagePage);
todo_wine
ok(raw_devices[2].usUsage == 6, "Unexpected raw device usage: %x\n", raw_devices[1].usUsage);
todo_wine
ok(raw_devices[2].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %x\n", raw_devices[1].dwFlags);
@ -727,12 +716,10 @@ static void test_mouse_keyboard(void)
hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
todo_wine
ok(hr == 1, "GetRegisteredRawInputDevices returned %d, raw_devices_count: %d\n", hr, raw_devices_count);
todo_wine
ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage);
todo_wine
ok(raw_devices[0].usUsage == 5, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage);
ok(raw_devices[0].dwFlags == 0, "Unexpected raw device flags: %x\n", raw_devices[0].dwFlags);
todo_wine
ok(raw_devices[0].hwndTarget == hwnd, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget);
IDirectInputDevice8_Release(di_mouse);

View File

@ -745,14 +745,60 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE handle, UINT command, void *data, UINT
return *data_size;
}
static int compare_raw_input_devices(const void *ap, const void *bp)
{
const RAWINPUTDEVICE a = *(const RAWINPUTDEVICE *)ap;
const RAWINPUTDEVICE b = *(const RAWINPUTDEVICE *)bp;
if (a.usUsagePage != b.usUsagePage) return a.usUsagePage - b.usUsagePage;
if (a.usUsage != b.usUsage) return a.usUsage - b.usUsage;
return 0;
}
/***********************************************************************
* GetRegisteredRawInputDevices (USER32.@)
*/
UINT WINAPI DECLSPEC_HOTPATCH GetRegisteredRawInputDevices(RAWINPUTDEVICE *devices, UINT *device_count, UINT size)
{
FIXME("devices %p, device_count %p, size %u stub!\n", devices, device_count, size);
struct rawinput_device *buffer = NULL;
unsigned int i, status, count = ~0U, buffer_size;
return 0;
TRACE("devices %p, device_count %p, size %u\n", devices, device_count, size);
if (size != sizeof(RAWINPUTDEVICE) || !device_count || (devices && !*device_count))
{
SetLastError(ERROR_INVALID_PARAMETER);
return ~0U;
}
buffer_size = *device_count * sizeof(*buffer);
if (devices && !(buffer = HeapAlloc(GetProcessHeap(), 0, buffer_size)))
return ~0U;
SERVER_START_REQ(get_rawinput_devices)
{
if (buffer) wine_server_set_reply(req, buffer, buffer_size);
status = wine_server_call_err(req);
*device_count = reply->device_count;
}
SERVER_END_REQ;
if (buffer && !status)
{
for (i = 0, count = *device_count; i < count; ++i)
{
devices[i].usUsagePage = buffer[i].usage_page;
devices[i].usUsage = buffer[i].usage;
devices[i].dwFlags = buffer[i].flags;
devices[i].hwndTarget = wine_server_ptr_handle(buffer[i].target);
}
qsort(devices, count, sizeof(*devices), compare_raw_input_devices);
}
if (buffer) HeapFree(GetProcessHeap(), 0, buffer);
else count = 0;
return count;
}

View File

@ -1796,25 +1796,20 @@ static void test_RegisterRawInputDevices(void)
SetLastError(0xdeadbeef);
count = GetRegisteredRawInputDevices(NULL, NULL, 0);
todo_wine
ok(count == ~0U, "GetRegisteredRawInputDevices returned %u\n", count);
todo_wine
ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetRegisteredRawInputDevices unexpected error %08x\n", GetLastError());
SetLastError(0xdeadbeef);
raw_devices_count = 0;
count = GetRegisteredRawInputDevices(NULL, &raw_devices_count, 0);
todo_wine
ok(count == ~0U, "GetRegisteredRawInputDevices returned %u\n", count);
ok(raw_devices_count == 0, "Unexpected registered devices count: %u\n", raw_devices_count);
todo_wine
ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetRegisteredRawInputDevices unexpected error %08x\n", GetLastError());
SetLastError(0xdeadbeef);
raw_devices_count = 0;
count = GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE));
ok(count == 0, "GetRegisteredRawInputDevices returned %u\n", count);
todo_wine
ok(raw_devices_count == 2, "Unexpected registered devices count: %u\n", raw_devices_count);
ok(GetLastError() == 0xdeadbeef, "GetRegisteredRawInputDevices unexpected error %08x\n", GetLastError());
@ -1825,38 +1820,28 @@ static void test_RegisterRawInputDevices(void)
win_skip("Ignoring GetRegisteredRawInputDevices success\n");
else
{
todo_wine
ok(count == ~0U, "GetRegisteredRawInputDevices returned %u\n", count);
ok(raw_devices_count == 0, "Unexpected registered devices count: %u\n", raw_devices_count);
todo_wine
ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetRegisteredRawInputDevices unexpected error %08x\n", GetLastError());
}
SetLastError(0xdeadbeef);
raw_devices_count = 1;
count = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
todo_wine
ok(count == ~0U, "GetRegisteredRawInputDevices returned %u\n", count);
todo_wine
ok(raw_devices_count == 2, "Unexpected registered devices count: %u\n", raw_devices_count);
todo_wine
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetRegisteredRawInputDevices unexpected error %08x\n", GetLastError());
SetLastError(0xdeadbeef);
memset(raw_devices, 0, sizeof(raw_devices));
raw_devices_count = ARRAY_SIZE(raw_devices);
count = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE));
todo_wine
ok(count == 2, "GetRegisteredRawInputDevices returned %u\n", count);
ok(raw_devices_count == 2, "Unexpected registered devices count: %u\n", raw_devices_count);
ok(GetLastError() == 0xdeadbeef, "GetRegisteredRawInputDevices unexpected error %08x\n", GetLastError());
todo_wine
ok(raw_devices[0].usUsagePage == 0x01, "Unexpected usage page: %x\n", raw_devices[0].usUsagePage);
todo_wine
ok(raw_devices[0].usUsage == 0x04, "Unexpected usage: %x\n", raw_devices[0].usUsage);
todo_wine
ok(raw_devices[1].usUsagePage == 0x01, "Unexpected usage page: %x\n", raw_devices[1].usUsagePage);
todo_wine
ok(raw_devices[1].usUsage == 0x05, "Unexpected usage: %x\n", raw_devices[1].usUsage);
/* RIDEV_REMOVE requires hwndTarget == NULL */

View File

@ -5343,6 +5343,19 @@ struct update_rawinput_devices_reply
};
struct get_rawinput_devices_request
{
struct request_header __header;
char __pad_12[4];
};
struct get_rawinput_devices_reply
{
struct reply_header __header;
unsigned int device_count;
/* VARARG(devices,rawinput_devices); */
char __pad_12[4];
};
struct create_job_request
{
@ -5759,6 +5772,7 @@ enum request
REQ_set_cursor,
REQ_get_rawinput_buffer,
REQ_update_rawinput_devices,
REQ_get_rawinput_devices,
REQ_create_job,
REQ_open_job,
REQ_assign_job,
@ -6049,6 +6063,7 @@ union generic_request
struct set_cursor_request set_cursor_request;
struct get_rawinput_buffer_request get_rawinput_buffer_request;
struct update_rawinput_devices_request update_rawinput_devices_request;
struct get_rawinput_devices_request get_rawinput_devices_request;
struct create_job_request create_job_request;
struct open_job_request open_job_request;
struct assign_job_request assign_job_request;
@ -6337,6 +6352,7 @@ union generic_reply
struct set_cursor_reply set_cursor_reply;
struct get_rawinput_buffer_reply get_rawinput_buffer_reply;
struct update_rawinput_devices_reply update_rawinput_devices_reply;
struct get_rawinput_devices_reply get_rawinput_devices_reply;
struct create_job_reply create_job_reply;
struct open_job_reply open_job_reply;
struct assign_job_reply assign_job_reply;
@ -6351,7 +6367,7 @@ union generic_reply
/* ### protocol_version begin ### */
#define SERVER_PROTOCOL_VERSION 634
#define SERVER_PROTOCOL_VERSION 635
/* ### protocol_version end ### */

View File

@ -3658,6 +3658,12 @@ struct handle_info
VARARG(devices,rawinput_devices);
@END
/* Retrieve the list of registered rawinput devices */
@REQ(get_rawinput_devices)
@REPLY
unsigned int device_count;
VARARG(devices,rawinput_devices);
@END
/* Create a new job object */
@REQ(create_job)

View File

@ -3277,3 +3277,24 @@ DECL_HANDLER(update_rawinput_devices)
e = find_rawinput_device( 1, 6 );
current->process->rawinput_kbd = e ? &e->device : NULL;
}
DECL_HANDLER(get_rawinput_devices)
{
struct rawinput_device_entry *e;
struct rawinput_device *devices;
unsigned int i = 0, device_count = list_count( &current->process->rawinput_devices );
unsigned int size = device_count * sizeof(*devices);
reply->device_count = device_count;
/* no buffer provided, nothing else to do */
if (!get_reply_max_size()) return;
if (size > get_reply_max_size())
set_error( STATUS_BUFFER_TOO_SMALL );
else if ((devices = set_reply_data_size( size )))
{
LIST_FOR_EACH_ENTRY( e, &current->process->rawinput_devices, struct rawinput_device_entry, entry )
devices[i++] = e->device;
}
}

View File

@ -392,6 +392,7 @@ DECL_HANDLER(free_user_handle);
DECL_HANDLER(set_cursor);
DECL_HANDLER(get_rawinput_buffer);
DECL_HANDLER(update_rawinput_devices);
DECL_HANDLER(get_rawinput_devices);
DECL_HANDLER(create_job);
DECL_HANDLER(open_job);
DECL_HANDLER(assign_job);
@ -681,6 +682,7 @@ static const req_handler req_handlers[REQ_NB_REQUESTS] =
(req_handler)req_set_cursor,
(req_handler)req_get_rawinput_buffer,
(req_handler)req_update_rawinput_devices,
(req_handler)req_get_rawinput_devices,
(req_handler)req_create_job,
(req_handler)req_open_job,
(req_handler)req_assign_job,
@ -2265,6 +2267,9 @@ C_ASSERT( FIELD_OFFSET(struct get_rawinput_buffer_reply, next_size) == 8 );
C_ASSERT( FIELD_OFFSET(struct get_rawinput_buffer_reply, count) == 12 );
C_ASSERT( sizeof(struct get_rawinput_buffer_reply) == 16 );
C_ASSERT( sizeof(struct update_rawinput_devices_request) == 16 );
C_ASSERT( sizeof(struct get_rawinput_devices_request) == 16 );
C_ASSERT( FIELD_OFFSET(struct get_rawinput_devices_reply, device_count) == 8 );
C_ASSERT( sizeof(struct get_rawinput_devices_reply) == 16 );
C_ASSERT( FIELD_OFFSET(struct create_job_request, access) == 12 );
C_ASSERT( sizeof(struct create_job_request) == 16 );
C_ASSERT( FIELD_OFFSET(struct create_job_reply, handle) == 8 );

View File

@ -4359,6 +4359,16 @@ static void dump_update_rawinput_devices_request( const struct update_rawinput_d
dump_varargs_rawinput_devices( " devices=", cur_size );
}
static void dump_get_rawinput_devices_request( const struct get_rawinput_devices_request *req )
{
}
static void dump_get_rawinput_devices_reply( const struct get_rawinput_devices_reply *req )
{
fprintf( stderr, " device_count=%08x", req->device_count );
dump_varargs_rawinput_devices( ", devices=", cur_size );
}
static void dump_create_job_request( const struct create_job_request *req )
{
fprintf( stderr, " access=%08x", req->access );
@ -4709,6 +4719,7 @@ static const dump_func req_dumpers[REQ_NB_REQUESTS] = {
(dump_func)dump_set_cursor_request,
(dump_func)dump_get_rawinput_buffer_request,
(dump_func)dump_update_rawinput_devices_request,
(dump_func)dump_get_rawinput_devices_request,
(dump_func)dump_create_job_request,
(dump_func)dump_open_job_request,
(dump_func)dump_assign_job_request,
@ -4995,6 +5006,7 @@ static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {
(dump_func)dump_set_cursor_reply,
(dump_func)dump_get_rawinput_buffer_reply,
NULL,
(dump_func)dump_get_rawinput_devices_reply,
(dump_func)dump_create_job_reply,
(dump_func)dump_open_job_reply,
NULL,
@ -5281,6 +5293,7 @@ static const char * const req_names[REQ_NB_REQUESTS] = {
"set_cursor",
"get_rawinput_buffer",
"update_rawinput_devices",
"get_rawinput_devices",
"create_job",
"open_job",
"assign_job",