Commit d5fd3c8a authored by Brendan Shanks's avatar Brendan Shanks Committed by Alexandre Julliard

dinput: Block Acquire() until hooks are installed to prevent input being lost.

parent 53cad57e
...@@ -1717,10 +1717,11 @@ static DWORD WINAPI hook_thread_proc(void *param) ...@@ -1717,10 +1717,11 @@ static DWORD WINAPI hook_thread_proc(void *param)
if (msg.message == WM_USER+0x10) if (msg.message == WM_USER+0x10)
{ {
IDirectInputImpl *dinput; IDirectInputImpl *dinput;
HANDLE finished_event = (HANDLE)msg.lParam;
TRACE( "Processing hook change notification lp:%ld\n", msg.lParam ); TRACE( "Processing hook change notification wp:%ld lp:%#lx\n", msg.wParam, msg.lParam );
if (!msg.wParam && !msg.lParam) if (!msg.wParam)
{ {
if (kbd_hook) UnhookWindowsHookEx( kbd_hook ); if (kbd_hook) UnhookWindowsHookEx( kbd_hook );
if (mouse_hook) UnhookWindowsHookEx( mouse_hook ); if (mouse_hook) UnhookWindowsHookEx( mouse_hook );
...@@ -1765,6 +1766,9 @@ static DWORD WINAPI hook_thread_proc(void *param) ...@@ -1765,6 +1766,9 @@ static DWORD WINAPI hook_thread_proc(void *param)
UnhookWindowsHookEx( mouse_hook ); UnhookWindowsHookEx( mouse_hook );
mouse_hook = NULL; mouse_hook = NULL;
} }
if (finished_event)
SetEvent(finished_event);
} }
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessageW(&msg); DispatchMessageW(&msg);
...@@ -1824,6 +1828,7 @@ void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface, BOOL acquired) ...@@ -1824,6 +1828,7 @@ void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface, BOOL acquired)
static HHOOK callwndproc_hook; static HHOOK callwndproc_hook;
static ULONG foreground_cnt; static ULONG foreground_cnt;
IDirectInputDeviceImpl *dev = impl_from_IDirectInputDevice8W(iface); IDirectInputDeviceImpl *dev = impl_from_IDirectInputDevice8W(iface);
HANDLE hook_change_finished_event = NULL;
EnterCriticalSection(&dinput_hook_crit); EnterCriticalSection(&dinput_hook_crit);
...@@ -1851,9 +1856,17 @@ void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface, BOOL acquired) ...@@ -1851,9 +1856,17 @@ void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface, BOOL acquired)
hook_thread_event = NULL; hook_thread_event = NULL;
} }
PostThreadMessageW( hook_thread_id, WM_USER+0x10, 1, 0 ); if (acquired)
hook_change_finished_event = CreateEventW( NULL, FALSE, FALSE, NULL );
PostThreadMessageW( hook_thread_id, WM_USER+0x10, 1, (LPARAM)hook_change_finished_event );
LeaveCriticalSection(&dinput_hook_crit); LeaveCriticalSection(&dinput_hook_crit);
if (acquired)
{
WaitForSingleObject(hook_change_finished_event, INFINITE);
CloseHandle(hook_change_finished_event);
}
} }
void check_dinput_events(void) void check_dinput_events(void)
......
...@@ -798,12 +798,10 @@ static void test_keyboard_events(void) ...@@ -798,12 +798,10 @@ static void test_keyboard_events(void)
data_size = ARRAY_SIZE(obj_data); data_size = ARRAY_SIZE(obj_data);
hr = IDirectInputDevice8_GetDeviceData(di_keyboard, sizeof(DIDEVICEOBJECTDATA), obj_data, &data_size, 0); hr = IDirectInputDevice8_GetDeviceData(di_keyboard, sizeof(DIDEVICEOBJECTDATA), obj_data, &data_size, 0);
ok(SUCCEEDED(hr), "Failed to get data hr=%08x\n", hr); ok(SUCCEEDED(hr), "Failed to get data hr=%08x\n", hr);
todo_wine
ok(data_size == 1, "Expected 1 element, received %d\n", data_size); ok(data_size == 1, "Expected 1 element, received %d\n", data_size);
hr = IDirectInputDevice8_GetDeviceState(di_keyboard, sizeof(kbdata), kbdata); hr = IDirectInputDevice8_GetDeviceState(di_keyboard, sizeof(kbdata), kbdata);
ok(SUCCEEDED(hr), "IDirectInputDevice8_GetDeviceState failed: %08x\n", hr); ok(SUCCEEDED(hr), "IDirectInputDevice8_GetDeviceState failed: %08x\n", hr);
todo_wine
ok(kbdata[DIK_SPACE], "Expected DIK_SPACE key state down\n"); ok(kbdata[DIK_SPACE], "Expected DIK_SPACE key state down\n");
keybd_event(VK_SPACE, DIK_SPACE, KEYEVENTF_KEYUP, 0); keybd_event(VK_SPACE, DIK_SPACE, KEYEVENTF_KEYUP, 0);
...@@ -812,7 +810,6 @@ static void test_keyboard_events(void) ...@@ -812,7 +810,6 @@ static void test_keyboard_events(void)
data_size = ARRAY_SIZE(obj_data); data_size = ARRAY_SIZE(obj_data);
hr = IDirectInputDevice8_GetDeviceData(di_keyboard, sizeof(DIDEVICEOBJECTDATA), obj_data, &data_size, 0); hr = IDirectInputDevice8_GetDeviceData(di_keyboard, sizeof(DIDEVICEOBJECTDATA), obj_data, &data_size, 0);
ok(SUCCEEDED(hr), "Failed to get data hr=%08x\n", hr); ok(SUCCEEDED(hr), "Failed to get data hr=%08x\n", hr);
todo_wine
ok(data_size == 1, "Expected 1 element, received %d\n", data_size); ok(data_size == 1, "Expected 1 element, received %d\n", data_size);
/* Test injecting keyboard events with scancode=0. /* Test injecting keyboard events with scancode=0.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment