From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/tests/joystick8.c | 14 ------ server/process.h | 1 + server/queue.c | 83 ++++++++++++++++------------------- 3 files changed, 40 insertions(+), 58 deletions(-)
diff --git a/dlls/dinput/tests/joystick8.c b/dlls/dinput/tests/joystick8.c index 788f59549c2..0e417c9540f 100644 --- a/dlls/dinput/tests/joystick8.c +++ b/dlls/dinput/tests/joystick8.c @@ -5758,23 +5758,16 @@ static DWORD WINAPI test_rawinput_desktop_thread( void *args ) rawbuffer_size = sizeof(rawbuffer); memset( rawbuffer, 0, sizeof(rawbuffer) ); res = msg_wait_for_events( 1, &rawinput_event, 100 ); - todo_wine ok( res == 0, "WaitForSingleObject returned %#lx\n", res ); - todo_wine ok( rawinput_calls == 1, "got %u WM_INPUT messages\n", rawinput_calls );
rawinput = (RAWINPUT *)rawbuffer; - todo_wine ok( rawinput->header.dwType == RIM_TYPEHID, "got dwType %lu\n", rawinput->header.dwType ); - todo_wine ok( rawinput->header.dwSize == offsetof(RAWINPUT, data.hid.bRawData[desc.caps.InputReportByteLength * rawinput->data.hid.dwCount]), "got header.dwSize %lu\n", rawinput->header.dwSize ); - todo_wine ok( rawinput->header.hDevice != 0, "got hDevice %p\n", rawinput->header.hDevice ); ok( rawinput->header.wParam == 0, "got wParam %#Ix\n", rawinput->header.wParam ); - todo_wine ok( rawinput->data.hid.dwSizeHid == desc.caps.InputReportByteLength, "got dwSizeHid %lu\n", rawinput->data.hid.dwSizeHid ); - todo_wine ok( rawinput->data.hid.dwCount >= 1, "got dwCount %lu\n", rawinput->data.hid.dwCount );
@@ -5866,23 +5859,16 @@ static void test_rawinput_desktop( const char *path, BOOL input ) res = msg_wait_for_events( 1, &rawinput_event, 100 ); if (input) { - todo_wine ok( res == 0, "WaitForSingleObject returned %#lx\n", res ); - todo_wine ok( rawinput_calls == 1, "got %u WM_INPUT messages\n", rawinput_calls );
rawinput = (RAWINPUT *)rawbuffer; - todo_wine ok( rawinput->header.dwType == RIM_TYPEHID, "got dwType %lu\n", rawinput->header.dwType ); - todo_wine ok( rawinput->header.dwSize == offsetof(RAWINPUT, data.hid.bRawData[desc.caps.InputReportByteLength * rawinput->data.hid.dwCount]), "got header.dwSize %lu\n", rawinput->header.dwSize ); - todo_wine ok( rawinput->header.hDevice != 0, "got hDevice %p\n", rawinput->header.hDevice ); ok( rawinput->header.wParam == 0, "got wParam %#Ix\n", rawinput->header.wParam ); - todo_wine ok( rawinput->data.hid.dwSizeHid == desc.caps.InputReportByteLength, "got dwSizeHid %lu\n", rawinput->data.hid.dwSizeHid ); - todo_wine ok( rawinput->data.hid.dwCount >= 1, "got dwCount %lu\n", rawinput->data.hid.dwCount ); } else diff --git a/server/process.h b/server/process.h index 97e0d455ece..5870f4187c3 100644 --- a/server/process.h +++ b/server/process.h @@ -60,6 +60,7 @@ struct process unsigned int is_system:1; /* is it a system process? */ unsigned int debug_children:1;/* also debug all child processes */ unsigned int is_terminating:1;/* is process terminating? */ + unsigned int desktop_enum:1; /* helper flag for desktop process enumeration */ data_size_t imagelen; /* length of image path in bytes */ WCHAR *image; /* main exe image full path */ struct job *job; /* job object associated with this process */ diff --git a/server/queue.c b/server/queue.c index 6fa68f9c6b2..fdec1c6737b 100644 --- a/server/queue.c +++ b/server/queue.c @@ -1894,7 +1894,6 @@ static void rawhid_init( struct rawinput *rawinput, RAWHID *hid, const hw_input_ struct rawinput_message { struct thread *foreground; - struct desktop *desktop; struct hw_msg_source source; unsigned int time; unsigned int message; @@ -1910,12 +1909,10 @@ struct rawinput_message };
/* check if process is supposed to receive a WM_INPUT message and eventually queue it */ -static int queue_rawinput_message( struct process* process, void *arg ) +static void queue_rawinput_message( struct desktop *desktop, struct process *process, void *args ) { - const struct rawinput_message *raw_msg = arg; - const struct rawinput_device *device = NULL; - struct desktop *target_desktop = NULL, *desktop = NULL; - struct thread *target_thread = NULL, *foreground = NULL; + const struct rawinput_message *raw_msg = args; + const struct rawinput_device *device; struct hardware_msg_data *msg_data; struct message *msg; data_size_t report_size = 0, data_size = 0; @@ -1940,26 +1937,16 @@ static int queue_rawinput_message( struct process* process, void *arg ) data_size = offsetof(RAWHID, bRawData[0]); report_size = raw_msg->data.hid.dwCount * raw_msg->data.hid.dwSizeHid; } - if (!device) return 0; - - if (raw_msg->message == WM_INPUT_DEVICE_CHANGE && !(device->flags & RIDEV_DEVNOTIFY)) return 0; - - if (raw_msg->desktop) desktop = (struct desktop *)grab_object( raw_msg->desktop ); - else if (!(desktop = get_desktop_obj( process, process->desktop, 0 ))) goto done; + if (!device) return;
- if (raw_msg->foreground) foreground = (struct thread *)grab_object( raw_msg->foreground ); - else if (!(foreground = get_foreground_thread( desktop, 0 ))) goto done; - - if (process != foreground->process) + if (raw_msg->message == WM_INPUT_DEVICE_CHANGE && !(device->flags & RIDEV_DEVNOTIFY)) return; + if (process != raw_msg->foreground->process) { - if (raw_msg->message == WM_INPUT && !(device->flags & RIDEV_INPUTSINK)) goto done; - if (!(target_thread = get_window_thread( device->target ))) goto done; - if (!(target_desktop = get_thread_desktop( target_thread, 0 ))) goto done; - if (target_desktop != desktop) goto done; + if (raw_msg->message == WM_INPUT && !(device->flags & RIDEV_INPUTSINK)) return; wparam = RIM_INPUTSINK; }
- if (!(msg = alloc_hardware_message( info, raw_msg->source, raw_msg->time, data_size + report_size ))) goto done; + if (!(msg = alloc_hardware_message( info, raw_msg->source, raw_msg->time, data_size + report_size ))) return; msg->win = device->target; msg->msg = raw_msg->message; msg->wparam = wparam; @@ -1978,13 +1965,22 @@ static int queue_rawinput_message( struct process* process, void *arg ) }
queue_hardware_message( desktop, msg, 1 ); +}
-done: - if (target_thread) release_object( target_thread ); - if (target_desktop) release_object( target_desktop ); - if (foreground) release_object( foreground ); - if (desktop) release_object( desktop ); - return 0; +static void dispatch_rawinput_message( struct desktop *desktop, struct rawinput_message *raw_msg ) +{ + struct thread *thread; + + LIST_FOR_EACH_ENTRY( thread, &desktop->threads, struct thread, desktop_entry ) + thread->process->desktop_enum = 1; + + LIST_FOR_EACH_ENTRY( thread, &desktop->threads, struct thread, desktop_entry ) + { + struct process *process = thread->process; + if (!process->desktop_enum) continue; + queue_rawinput_message( desktop, process, raw_msg ); + process->desktop_enum = 0; + } }
/* queue a hardware message for a mouse event */ @@ -2048,7 +2044,6 @@ static int queue_mouse_message( struct desktop *desktop, user_handle_t win, cons { memset( &raw_msg, 0, sizeof(raw_msg) ); raw_msg.foreground = foreground; - raw_msg.desktop = desktop; raw_msg.source = source; raw_msg.time = time; raw_msg.message = WM_INPUT; @@ -2056,7 +2051,7 @@ static int queue_mouse_message( struct desktop *desktop, user_handle_t win, cons rawmouse_init( &raw_msg.rawinput, &raw_msg.data.mouse, x - desktop->cursor.x, y - desktop->cursor.y, raw_msg.flags, input->mouse.data, input->mouse.info );
- enum_processes( queue_rawinput_message, &raw_msg ); + dispatch_rawinput_message( desktop, &raw_msg ); release_object( foreground ); }
@@ -2103,7 +2098,6 @@ static int queue_keyboard_message( struct desktop *desktop, user_handle_t win, c struct hw_msg_source source = { IMDT_KEYBOARD, origin }; const struct rawinput_device *device; struct hardware_msg_data *msg_data; - struct rawinput_message raw_msg; struct message *msg; struct thread *foreground; unsigned char vkey = input->kbd.vkey; @@ -2178,9 +2172,8 @@ static int queue_keyboard_message( struct desktop *desktop, user_handle_t win, c
if ((foreground = get_foreground_thread( desktop, win ))) { - memset( &raw_msg, 0, sizeof(raw_msg) ); + struct rawinput_message raw_msg = {0}; raw_msg.foreground = foreground; - raw_msg.desktop = desktop; raw_msg.source = source; raw_msg.time = time; raw_msg.message = WM_INPUT; @@ -2188,7 +2181,7 @@ static int queue_keyboard_message( struct desktop *desktop, user_handle_t win, c rawkeyboard_init( &raw_msg.rawinput, &raw_msg.data.keyboard, input->kbd.scan, vkey, raw_msg.flags, message_code, input->kbd.info );
- enum_processes( queue_rawinput_message, &raw_msg ); + dispatch_rawinput_message( desktop, &raw_msg ); release_object( foreground ); }
@@ -2234,26 +2227,28 @@ static void queue_custom_hardware_message( struct desktop *desktop, user_handle_ unsigned int origin, const hw_input_t *input ) { struct hw_msg_source source = { IMDT_UNAVAILABLE, origin }; - struct rawinput_message raw_msg; + struct thread *foreground; struct message *msg;
switch (input->hw.msg) { case WM_INPUT: case WM_INPUT_DEVICE_CHANGE: - memset( &raw_msg, 0, sizeof(raw_msg) ); - raw_msg.source = source; - raw_msg.time = get_tick_count(); - raw_msg.message = input->hw.msg; - raw_msg.hid_report = get_req_data(); if (input->hw.hid.length * input->hw.hid.count != get_req_data_size()) - { set_error( STATUS_INVALID_PARAMETER ); - return; + else if ((foreground = get_foreground_thread( desktop, win ))) + { + struct rawinput_message raw_msg = {0}; + raw_msg.foreground = foreground; + raw_msg.source = source; + raw_msg.time = get_tick_count(); + raw_msg.message = input->hw.msg; + raw_msg.hid_report = get_req_data(); + rawhid_init( &raw_msg.rawinput, &raw_msg.data.hid, input ); + + dispatch_rawinput_message( desktop, &raw_msg ); + release_object( foreground ); } - rawhid_init( &raw_msg.rawinput, &raw_msg.data.hid, input ); - - enum_processes( queue_rawinput_message, &raw_msg ); return; }