From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/dinput_main.c | 50 +++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 23 deletions(-)
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index f264c367305..0bbe299cc6c 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -54,6 +54,7 @@ struct input_thread_state UINT devices_count; HHOOK mouse_ll_hook; HHOOK keyboard_ll_hook; + HHOOK callwndproc_hook; struct dinput_device *devices[INPUT_THREAD_MAX_DEVICES]; HANDLE events[INPUT_THREAD_MAX_DEVICES]; }; @@ -251,24 +252,45 @@ static LRESULT CALLBACK callwndproc_proc( int code, WPARAM wparam, LPARAM lparam
static void input_thread_update_device_list( struct input_thread_state *state ) { - UINT count = 0, keyboard_count, mouse_count; + UINT count = 0, keyboard_count = 0, mouse_count = 0, foreground_count = 0; struct dinput_device *device;
EnterCriticalSection( &dinput_hook_crit ); LIST_FOR_EACH_ENTRY( device, &acquired_device_list, struct dinput_device, entry ) { + if (device->dwCoopLevel & DISCL_FOREGROUND) foreground_count++; if (!device->read_event || !device->vtbl->read) continue; state->events[count] = device->read_event; dinput_device_internal_addref( (state->devices[count] = device) ); if (++count >= INPUT_THREAD_MAX_DEVICES) break; } state->events_count = count; - state->devices_count = count;
- keyboard_count = list_count( &acquired_keyboard_list ); - mouse_count = list_count( &acquired_mouse_list ); + LIST_FOR_EACH_ENTRY( device, &acquired_rawmouse_list, struct dinput_device, entry ) + { + if (device->dwCoopLevel & DISCL_FOREGROUND) foreground_count++; + } + LIST_FOR_EACH_ENTRY( device, &acquired_mouse_list, struct dinput_device, entry ) + { + if (device->dwCoopLevel & DISCL_FOREGROUND) foreground_count++; + mouse_count++; + } + LIST_FOR_EACH_ENTRY( device, &acquired_keyboard_list, struct dinput_device, entry ) + { + if (device->dwCoopLevel & DISCL_FOREGROUND) foreground_count++; + keyboard_count++; + } + state->devices_count = count; LeaveCriticalSection( &dinput_hook_crit );
+ if (foreground_count && !state->callwndproc_hook) + state->callwndproc_hook = SetWindowsHookExW( WH_CALLWNDPROC, callwndproc_proc, DINPUT_instance, GetCurrentThreadId() ); + else if (!foreground_count && state->callwndproc_hook) + { + UnhookWindowsHookEx( state->callwndproc_hook ); + state->callwndproc_hook = NULL; + } + if (keyboard_count && !state->keyboard_ll_hook) state->keyboard_ll_hook = SetWindowsHookExW( WH_KEYBOARD_LL, input_thread_ll_hook_proc, DINPUT_instance, 0 ); else if (!keyboard_count && state->keyboard_ll_hook) @@ -341,6 +363,7 @@ static DWORD WINAPI dinput_thread_proc( void *params )
done: while (state.devices_count--) dinput_device_internal_release( state.devices[state.devices_count] ); + if (state.callwndproc_hook) UnhookWindowsHookEx( state.callwndproc_hook ); if (state.keyboard_ll_hook) UnhookWindowsHookEx( state.keyboard_ll_hook ); if (state.mouse_ll_hook) UnhookWindowsHookEx( state.mouse_ll_hook ); DestroyWindow( di_em_win ); @@ -385,30 +408,11 @@ void input_thread_remove_user(void)
void check_dinput_hooks( IDirectInputDevice8W *iface, BOOL acquired ) { - static HHOOK callwndproc_hook; - static ULONG foreground_cnt; struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface ); HANDLE hook_change_finished_event = NULL;
EnterCriticalSection(&dinput_hook_crit);
- if (impl->dwCoopLevel & DISCL_FOREGROUND) - { - if (acquired) - foreground_cnt++; - else - foreground_cnt--; - } - - if (foreground_cnt && !callwndproc_hook) - callwndproc_hook = SetWindowsHookExW( WH_CALLWNDPROC, callwndproc_proc, - DINPUT_instance, GetCurrentThreadId() ); - else if (!foreground_cnt && callwndproc_hook) - { - UnhookWindowsHookEx( callwndproc_hook ); - callwndproc_hook = NULL; - } - if (impl->use_raw_input) { if (acquired)
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/device_private.h | 2 -- dlls/dinput/dinput_main.c | 39 ++++++++++++------------------------ dlls/dinput/mouse.c | 4 ---- 3 files changed, 13 insertions(+), 32 deletions(-)
diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index fd48a602b97..f6030c5d088 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -94,9 +94,7 @@ struct dinput_device DWORD dwCoopLevel; HWND win; enum device_status status; - BOOL use_raw_input; /* use raw input instead of low-level messages */ - RAWINPUTDEVICE raw_device; /* raw device to (un)register */
LPDIDEVICEOBJECTDATA data_queue; /* buffer for 'GetDeviceData'. */ int queue_len; /* valid size of the queue */ diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 0bbe299cc6c..f609faffc5d 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -35,6 +35,7 @@ #include "objbase.h" #include "rpcproxy.h" #include "devguid.h" +#include "hidusage.h" #include "initguid.h" #include "dinputd.h"
@@ -55,6 +56,7 @@ struct input_thread_state HHOOK mouse_ll_hook; HHOOK keyboard_ll_hook; HHOOK callwndproc_hook; + RAWINPUTDEVICE rawinput_devices[2]; struct dinput_device *devices[INPUT_THREAD_MAX_DEVICES]; HANDLE events[INPUT_THREAD_MAX_DEVICES]; }; @@ -252,6 +254,7 @@ static LRESULT CALLBACK callwndproc_proc( int code, WPARAM wparam, LPARAM lparam
static void input_thread_update_device_list( struct input_thread_state *state ) { + RAWINPUTDEVICE rawinput_mouse = {.usUsagePage = HID_USAGE_PAGE_GENERIC, .usUsage = HID_USAGE_GENERIC_MOUSE, .dwFlags = RIDEV_REMOVE}; UINT count = 0, keyboard_count = 0, mouse_count = 0, foreground_count = 0; struct dinput_device *device;
@@ -269,6 +272,10 @@ static void input_thread_update_device_list( struct input_thread_state *state ) LIST_FOR_EACH_ENTRY( device, &acquired_rawmouse_list, struct dinput_device, entry ) { if (device->dwCoopLevel & DISCL_FOREGROUND) foreground_count++; + if (device->dwCoopLevel & DISCL_BACKGROUND) rawinput_mouse.dwFlags |= RIDEV_INPUTSINK; + if (device->dwCoopLevel & DISCL_EXCLUSIVE) rawinput_mouse.dwFlags |= RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; + rawinput_mouse.dwFlags &= ~RIDEV_REMOVE; + rawinput_mouse.hwndTarget = di_em_win; } LIST_FOR_EACH_ENTRY( device, &acquired_mouse_list, struct dinput_device, entry ) { @@ -306,6 +313,12 @@ static void input_thread_update_device_list( struct input_thread_state *state ) UnhookWindowsHookEx( state->mouse_ll_hook ); state->mouse_ll_hook = NULL; } + + if (!rawinput_mouse.hwndTarget != !state->rawinput_devices[0].hwndTarget && + !RegisterRawInputDevices( &rawinput_mouse, 1, sizeof(RAWINPUTDEVICE) )) + WARN( "Failed to (un)register rawinput mouse device.\n" ); + + state->rawinput_devices[0] = rawinput_mouse; }
static DWORD WINAPI dinput_thread_proc( void *params ) @@ -408,36 +421,10 @@ void input_thread_remove_user(void)
void check_dinput_hooks( IDirectInputDevice8W *iface, BOOL acquired ) { - struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface ); HANDLE hook_change_finished_event = NULL;
EnterCriticalSection(&dinput_hook_crit);
- if (impl->use_raw_input) - { - if (acquired) - { - impl->raw_device.dwFlags = 0; - if (impl->dwCoopLevel & DISCL_BACKGROUND) - impl->raw_device.dwFlags |= RIDEV_INPUTSINK; - if (impl->dwCoopLevel & DISCL_EXCLUSIVE) - impl->raw_device.dwFlags |= RIDEV_NOLEGACY; - if ((impl->dwCoopLevel & DISCL_EXCLUSIVE) && impl->raw_device.usUsage == 2) - impl->raw_device.dwFlags |= RIDEV_CAPTUREMOUSE; - if ((impl->dwCoopLevel & DISCL_EXCLUSIVE) && impl->raw_device.usUsage == 6) - impl->raw_device.dwFlags |= RIDEV_NOHOTKEYS; - impl->raw_device.hwndTarget = di_em_win; - } - else - { - impl->raw_device.dwFlags = RIDEV_REMOVE; - impl->raw_device.hwndTarget = NULL; - } - - if (!RegisterRawInputDevices( &impl->raw_device, 1, sizeof(RAWINPUTDEVICE) )) - WARN( "Unable to (un)register raw device %x:%x\n", impl->raw_device.usUsagePage, impl->raw_device.usUsage ); - } - hook_change_finished_event = CreateEventW( NULL, FALSE, FALSE, NULL ); PostThreadMessageW( dinput_thread_id, WM_USER + 0x10, 1, (LPARAM)hook_change_finished_event );
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 6aab20a631c..502ee797716 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -148,11 +148,7 @@ HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInp if (hkey) RegCloseKey(hkey);
if (dinput->dwVersion >= 0x0800) - { impl->base.use_raw_input = TRUE; - impl->base.raw_device.usUsagePage = 1; /* HID generic device page */ - impl->base.raw_device.usUsage = 2; /* HID generic mouse */ - }
*out = &impl->base.IDirectInputDevice8W_iface; return DI_OK;
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/dinput_main.c | 92 +++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 46 deletions(-)
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index f609faffc5d..491db22861f 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -127,52 +127,6 @@ static void dinput_device_internal_unacquire( IDirectInputDevice8W *iface, DWORD LeaveCriticalSection( &impl->crit ); }
-static LRESULT WINAPI di_em_win_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -{ - struct dinput_device *impl; - RAWINPUT ri; - UINT size = sizeof(ri); - int rim = GET_RAWINPUT_CODE_WPARAM( wparam ); - - TRACE( "%p %d %Ix %Ix\n", hwnd, msg, wparam, lparam ); - - if (msg == WM_INPUT && (rim == RIM_INPUT || rim == RIM_INPUTSINK)) - { - size = GetRawInputData( (HRAWINPUT)lparam, RID_INPUT, &ri, &size, sizeof(RAWINPUTHEADER) ); - if (size == (UINT)-1 || size < sizeof(RAWINPUTHEADER)) - WARN( "Unable to read raw input data\n" ); - else if (ri.header.dwType == RIM_TYPEMOUSE) - { - EnterCriticalSection( &dinput_hook_crit ); - LIST_FOR_EACH_ENTRY( impl, &acquired_rawmouse_list, struct dinput_device, entry ) - dinput_mouse_rawinput_hook( &impl->IDirectInputDevice8W_iface, wparam, lparam, &ri ); - LeaveCriticalSection( &dinput_hook_crit ); - } - } - - return DefWindowProcW( hwnd, msg, wparam, lparam ); -} - -static void register_di_em_win_class(void) -{ - WNDCLASSEXW class; - - memset(&class, 0, sizeof(class)); - class.cbSize = sizeof(class); - class.lpfnWndProc = di_em_win_wndproc; - class.hInstance = DINPUT_instance; - class.lpszClassName = L"DIEmWin"; - - if (!RegisterClassExW( &class ) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) - WARN( "Unable to register message window class\n" ); -} - -static void unregister_di_em_win_class(void) -{ - if (!UnregisterClassW( L"DIEmWin", NULL ) && GetLastError() != ERROR_CLASS_DOES_NOT_EXIST) - WARN( "Unable to unregister message window class\n" ); -} - static LRESULT CALLBACK input_thread_ll_hook_proc( int code, WPARAM wparam, LPARAM lparam ) { struct dinput_device *impl; @@ -321,6 +275,52 @@ static void input_thread_update_device_list( struct input_thread_state *state ) state->rawinput_devices[0] = rawinput_mouse; }
+static LRESULT WINAPI di_em_win_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) +{ + struct dinput_device *impl; + RAWINPUT ri; + UINT size = sizeof(ri); + int rim = GET_RAWINPUT_CODE_WPARAM( wparam ); + + TRACE( "%p %d %Ix %Ix\n", hwnd, msg, wparam, lparam ); + + if (msg == WM_INPUT && (rim == RIM_INPUT || rim == RIM_INPUTSINK)) + { + size = GetRawInputData( (HRAWINPUT)lparam, RID_INPUT, &ri, &size, sizeof(RAWINPUTHEADER) ); + if (size == (UINT)-1 || size < sizeof(RAWINPUTHEADER)) + WARN( "Unable to read raw input data\n" ); + else if (ri.header.dwType == RIM_TYPEMOUSE) + { + EnterCriticalSection( &dinput_hook_crit ); + LIST_FOR_EACH_ENTRY( impl, &acquired_rawmouse_list, struct dinput_device, entry ) + dinput_mouse_rawinput_hook( &impl->IDirectInputDevice8W_iface, wparam, lparam, &ri ); + LeaveCriticalSection( &dinput_hook_crit ); + } + } + + return DefWindowProcW( hwnd, msg, wparam, lparam ); +} + +static void register_di_em_win_class(void) +{ + WNDCLASSEXW class; + + memset(&class, 0, sizeof(class)); + class.cbSize = sizeof(class); + class.lpfnWndProc = di_em_win_wndproc; + class.hInstance = DINPUT_instance; + class.lpszClassName = L"DIEmWin"; + + if (!RegisterClassExW( &class ) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) + WARN( "Unable to register message window class\n" ); +} + +static void unregister_di_em_win_class(void) +{ + if (!UnregisterClassW( L"DIEmWin", NULL ) && GetLastError() != ERROR_CLASS_DOES_NOT_EXIST) + WARN( "Unable to unregister message window class\n" ); +} + static DWORD WINAPI dinput_thread_proc( void *params ) { struct input_thread_state state = {0};
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/device.c | 2 - dlls/dinput/dinput_main.c | 74 +++++++++++++++++------------------- dlls/dinput/dinput_private.h | 1 - 3 files changed, 34 insertions(+), 43 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 04788b22f9a..c7b29da9271 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -565,7 +565,6 @@ static HRESULT WINAPI dinput_device_Acquire( IDirectInputDevice8W *iface ) if (hr != DI_OK) return hr;
dinput_hooks_acquire_device( iface ); - check_dinput_hooks( iface, TRUE );
return hr; } @@ -585,7 +584,6 @@ static HRESULT WINAPI dinput_device_Unacquire( IDirectInputDevice8W *iface ) if (hr != DI_OK) return hr;
dinput_hooks_unacquire_device( iface ); - check_dinput_hooks( iface, FALSE );
return hr; } diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 491db22861f..a81afa82950 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -51,6 +51,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(dinput);
struct input_thread_state { + BOOL running; UINT events_count; UINT devices_count; HHOOK mouse_ll_hook; @@ -69,10 +70,9 @@ static inline struct dinput_device *impl_from_IDirectInputDevice8W( IDirectInput HINSTANCE DINPUT_instance;
static HWND di_em_win; - static HANDLE dinput_thread; -static DWORD dinput_thread_id; static UINT input_thread_user_count; +static struct input_thread_state *input_thread_state;
static CRITICAL_SECTION dinput_hook_crit; static CRITICAL_SECTION_DEBUG dinput_critsect_debug = @@ -100,6 +100,8 @@ void dinput_hooks_acquire_device( IDirectInputDevice8W *iface ) else list_add_tail( &acquired_device_list, &impl->entry ); LeaveCriticalSection( &dinput_hook_crit ); + + SendMessageW( di_em_win, WM_USER + 0x10, 1, 0 ); }
void dinput_hooks_unacquire_device( IDirectInputDevice8W *iface ) @@ -109,6 +111,8 @@ void dinput_hooks_unacquire_device( IDirectInputDevice8W *iface ) EnterCriticalSection( &dinput_hook_crit ); list_remove( &impl->entry ); LeaveCriticalSection( &dinput_hook_crit ); + + SendMessageW( di_em_win, WM_USER + 0x10, 1, 0 ); }
static void dinput_device_internal_unacquire( IDirectInputDevice8W *iface, DWORD status ) @@ -298,6 +302,22 @@ static LRESULT WINAPI di_em_win_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPAR } }
+ if (msg == WM_USER + 0x10) + { + struct input_thread_state *state = input_thread_state; + + TRACE( "Processing hook change notification wparam %#Ix, lparam %#Ix.\n", wparam, lparam ); + + if (!wparam) state->running = FALSE; + else + { + while (state->devices_count--) dinput_device_internal_release( state->devices[state->devices_count] ); + input_thread_update_device_list( state ); + } + + return 0; + } + return DefWindowProcW( hwnd, msg, wparam, lparam ); }
@@ -323,19 +343,18 @@ static void unregister_di_em_win_class(void)
static DWORD WINAPI dinput_thread_proc( void *params ) { - struct input_thread_state state = {0}; + struct input_thread_state state = {.running = TRUE}; struct dinput_device *device; HANDLE start_event = params; DWORD ret; MSG msg;
+ input_thread_state = &state; di_em_win = CreateWindowW( L"DIEmWin", L"DIEmWin", 0, 0, 0, 0, 0, HWND_MESSAGE, 0, DINPUT_instance, NULL ); - - /* Force creation of the message queue */ PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE ); SetEvent( start_event );
- while ((ret = MsgWaitForMultipleObjectsEx( state.events_count, state.events, INFINITE, QS_ALLINPUT, 0 )) <= state.events_count) + while (state.running && (ret = MsgWaitForMultipleObjectsEx( state.events_count, state.events, INFINITE, QS_ALLINPUT, 0 )) <= state.events_count) { if (ret < state.events_count) { @@ -354,27 +373,17 @@ static DWORD WINAPI dinput_thread_proc( void *params )
while (PeekMessageW( &msg, 0, 0, 0, PM_REMOVE )) { - if (msg.message != WM_USER+0x10) - { - TranslateMessage(&msg); - DispatchMessageW(&msg); - continue; - } - - TRACE( "Processing hook change notification wparam %#Ix, lparam %#Ix.\n", msg.wParam, msg.lParam ); - - if (!msg.wParam) goto done; - - while (state.devices_count--) dinput_device_internal_release( state.devices[state.devices_count] ); - input_thread_update_device_list( &state ); - SetEvent( (HANDLE)msg.lParam ); + TranslateMessage(&msg); + DispatchMessageW(&msg); } }
- ERR( "Unexpected termination, ret %#lx\n", ret ); - dinput_unacquire_window_devices( 0 ); + if (state.running) + { + ERR( "Unexpected termination, ret %#lx\n", ret ); + dinput_unacquire_window_devices( 0 ); + }
-done: while (state.devices_count--) dinput_device_internal_release( state.devices[state.devices_count] ); if (state.callwndproc_hook) UnhookWindowsHookEx( state.callwndproc_hook ); if (state.keyboard_ll_hook) UnhookWindowsHookEx( state.keyboard_ll_hook ); @@ -395,7 +404,7 @@ void input_thread_add_user(void)
if (!(start_event = CreateEventW( NULL, FALSE, FALSE, NULL ))) ERR( "Failed to create start event, error %lu\n", GetLastError() ); - else if (!(dinput_thread = CreateThread( NULL, 0, dinput_thread_proc, start_event, 0, &dinput_thread_id ))) + else if (!(dinput_thread = CreateThread( NULL, 0, dinput_thread_proc, start_event, 0, NULL ))) ERR( "Failed to create internal thread, error %lu\n", GetLastError() ); else WaitForSingleObject( start_event, INFINITE ); @@ -412,28 +421,13 @@ void input_thread_remove_user(void) { TRACE( "Stopping input thread.\n" );
- PostThreadMessageW( dinput_thread_id, WM_USER + 0x10, 0, 0 ); + SendMessageW( di_em_win, WM_USER + 0x10, 0, 0 ); WaitForSingleObject( dinput_thread, INFINITE ); CloseHandle( dinput_thread ); } LeaveCriticalSection( &dinput_hook_crit ); }
-void check_dinput_hooks( IDirectInputDevice8W *iface, BOOL acquired ) -{ - HANDLE hook_change_finished_event = NULL; - - EnterCriticalSection(&dinput_hook_crit); - - hook_change_finished_event = CreateEventW( NULL, FALSE, FALSE, NULL ); - PostThreadMessageW( dinput_thread_id, WM_USER + 0x10, 1, (LPARAM)hook_change_finished_event ); - - LeaveCriticalSection(&dinput_hook_crit); - - WaitForSingleObject(hook_change_finished_event, INFINITE); - CloseHandle(hook_change_finished_event); -} - void check_dinput_events(void) { /* Windows does not do that, but our current implementation of winex11 diff --git a/dlls/dinput/dinput_private.h b/dlls/dinput/dinput_private.h index f10d5120c89..6e7ffeb0841 100644 --- a/dlls/dinput/dinput_private.h +++ b/dlls/dinput/dinput_private.h @@ -73,7 +73,6 @@ extern int dinput_keyboard_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPA extern void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam, RAWINPUT *raw );
-extern void check_dinput_hooks( IDirectInputDevice8W *iface, BOOL acquired ) DECLSPEC_HIDDEN; extern void check_dinput_events(void) DECLSPEC_HIDDEN;
extern HRESULT _configure_devices(IDirectInput8W *iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback, LPDICONFIGUREDEVICESPARAMSW lpdiCDParams, DWORD dwFlags, LPVOID pvRefData) DECLSPEC_HIDDEN;
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/dinput_main.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index a81afa82950..149dd402aa8 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -234,6 +234,8 @@ static void input_thread_update_device_list( struct input_thread_state *state ) if (device->dwCoopLevel & DISCL_EXCLUSIVE) rawinput_mouse.dwFlags |= RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; rawinput_mouse.dwFlags &= ~RIDEV_REMOVE; rawinput_mouse.hwndTarget = di_em_win; + dinput_device_internal_addref( (state->devices[count] = device) ); + if (++count >= INPUT_THREAD_MAX_DEVICES) break; } LIST_FOR_EACH_ENTRY( device, &acquired_mouse_list, struct dinput_device, entry ) { @@ -281,10 +283,10 @@ static void input_thread_update_device_list( struct input_thread_state *state )
static LRESULT WINAPI di_em_win_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - struct dinput_device *impl; - RAWINPUT ri; - UINT size = sizeof(ri); + struct input_thread_state *state = input_thread_state; int rim = GET_RAWINPUT_CODE_WPARAM( wparam ); + UINT i, size = sizeof(RAWINPUT); + RAWINPUT ri;
TRACE( "%p %d %Ix %Ix\n", hwnd, msg, wparam, lparam );
@@ -295,17 +297,25 @@ static LRESULT WINAPI di_em_win_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPAR WARN( "Unable to read raw input data\n" ); else if (ri.header.dwType == RIM_TYPEMOUSE) { - EnterCriticalSection( &dinput_hook_crit ); - LIST_FOR_EACH_ENTRY( impl, &acquired_rawmouse_list, struct dinput_device, entry ) - dinput_mouse_rawinput_hook( &impl->IDirectInputDevice8W_iface, wparam, lparam, &ri ); - LeaveCriticalSection( &dinput_hook_crit ); + for (i = state->events_count; i < state->devices_count; ++i) + { + struct dinput_device *device = state->devices[i]; + if (!device->use_raw_input) continue; + if (device->instance.dwDevType & DIDEVTYPE_HID) continue; + switch (GET_DIDEVICE_TYPE( device->instance.dwDevType )) + { + case DIDEVTYPE_MOUSE: + case DI8DEVTYPE_MOUSE: + dinput_mouse_rawinput_hook( &device->IDirectInputDevice8W_iface, wparam, lparam, &ri ); + break; + default: break; + } + } } }
if (msg == WM_USER + 0x10) { - struct input_thread_state *state = input_thread_state; - TRACE( "Processing hook change notification wparam %#Ix, lparam %#Ix.\n", wparam, lparam );
if (!wparam) state->running = FALSE; @@ -349,9 +359,8 @@ static DWORD WINAPI dinput_thread_proc( void *params ) DWORD ret; MSG msg;
- input_thread_state = &state; di_em_win = CreateWindowW( L"DIEmWin", L"DIEmWin", 0, 0, 0, 0, 0, HWND_MESSAGE, 0, DINPUT_instance, NULL ); - PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE ); + input_thread_state = &state; SetEvent( start_event );
while (state.running && (ret = MsgWaitForMultipleObjectsEx( state.events_count, state.events, INFINITE, QS_ALLINPUT, 0 )) <= state.events_count)