From 91d9819c95b19ca983656f157c9a6cf399063127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Fri, 17 Sep 2021 09:06:22 +0200 Subject: [PATCH] dinput: Fire the notification only after all events have been queued. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RĂ©mi Bernon Signed-off-by: Alexandre Julliard --- dlls/dinput/device.c | 3 --- dlls/dinput/joystick_hid.c | 2 ++ dlls/dinput/joystick_linux.c | 3 +++ dlls/dinput/joystick_linuxinput.c | 3 +++ dlls/dinput/joystick_osx.c | 6 ++++++ dlls/dinput/keyboard.c | 1 + dlls/dinput/mouse.c | 16 ++++++++++++++++ 7 files changed, 31 insertions(+), 3 deletions(-) diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index e04d40e5a7c..17eaff69d50 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -986,9 +986,6 @@ void queue_event( IDirectInputDevice8W *iface, int inst_id, DWORD data, DWORD ti int next_pos, ofs = id_to_offset(&This->data_format, inst_id); ULONGLONG time_ms = GetTickCount64(); - /* Event is being set regardless of the queue state */ - if (This->hEvent) SetEvent(This->hEvent); - if (time_ms - notify_ms > 1000) { PostMessageW(GetDesktopWindow(), WM_WINE_NOTIFY_ACTIVITY, 0, 0); diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 3ef6f0db9cc..709953be8f0 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -908,6 +908,8 @@ static HRESULT hid_joystick_read_state( IDirectInputDevice8W *iface ) enum_value_objects( impl, &filter, DIDFT_ALL, read_device_state_value, ¶ms ); enum_button_objects( impl, &filter, DIDFT_ALL, check_device_state_button, ¶ms ); + if (memcmp( ¶ms.old_state, &impl->state, sizeof(impl->state) ) && impl->base.hEvent) + SetEvent( impl->base.hEvent ); } memset( &impl->read_ovl, 0, sizeof(impl->read_ovl) ); diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c index 3a8b0f07704..c439cca81c3 100644 --- a/dlls/dinput/joystick_linux.c +++ b/dlls/dinput/joystick_linux.c @@ -777,7 +777,10 @@ static void joy_polldev( IDirectInputDevice8W *iface ) } } if (inst_id >= 0) + { queue_event(iface, inst_id, value, GetCurrentTime(), This->generic.base.dinput->evsequence++); + if (This->generic.base.hEvent) SetEvent( This->generic.base.hEvent ); + } } } diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c index 27dd75a8b55..8279ffbf74a 100644 --- a/dlls/dinput/joystick_linuxinput.c +++ b/dlls/dinput/joystick_linuxinput.c @@ -806,8 +806,11 @@ static void joy_polldev( IDirectInputDevice8W *iface ) break; } if (inst_id >= 0) + { queue_event(iface, inst_id, value, GetCurrentTime(), This->generic.base.dinput->evsequence++); + if (This->generic.base.hEvent) SetEvent( This->generic.base.hEvent ); + } } } diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c index 62a063b6da1..e8732bd696c 100644 --- a/dlls/dinput/joystick_osx.c +++ b/dlls/dinput/joystick_osx.c @@ -840,6 +840,8 @@ static void poll_osx_device_state( IDirectInputDevice8W *iface ) { inst_id = DIDFT_MAKEINSTANCE(button_idx) | DIDFT_PSHBUTTON; queue_event(iface,inst_id,newVal,GetCurrentTime(),device->generic.base.dinput->evsequence++); + if (device->generic.base.hEvent) + SetEvent( device->generic.base.hEvent ); } button_idx ++; } @@ -870,6 +872,8 @@ static void poll_osx_device_state( IDirectInputDevice8W *iface ) { inst_id = DIDFT_MAKEINSTANCE(pov_idx) | DIDFT_POV; queue_event(iface,inst_id,newVal,GetCurrentTime(),device->generic.base.dinput->evsequence++); + if (device->generic.base.hEvent) + SetEvent( device->generic.base.hEvent ); } pov_idx ++; break; @@ -947,6 +951,8 @@ static void poll_osx_device_state( IDirectInputDevice8W *iface ) { inst_id = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS; queue_event(iface,inst_id,newVal,GetCurrentTime(),device->generic.base.dinput->evsequence++); + if (device->generic.base.hEvent) + SetEvent( device->generic.base.hEvent ); } break; diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 5d532ab8059..3e1cac1733f 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -127,6 +127,7 @@ int dinput_keyboard_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lpa EnterCriticalSection(&This->base.crit); queue_event(iface, DIDFT_MAKEINSTANCE(dik_code) | DIDFT_PSHBUTTON, new_diks, GetCurrentTime(), This->base.dinput->evsequence++); + if (This->base.hEvent) SetEvent( This->base.hEvent ); LeaveCriticalSection(&This->base.crit); return ret; diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 9f696cb414a..0ab791c69a5 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -234,6 +234,7 @@ void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPA POINT rel, pt; DWORD seq; int i, wdata = 0; + BOOL notify = FALSE; static const USHORT mouse_button_flags[] = { @@ -277,12 +278,18 @@ void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPA } if (rel.x) + { queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS, pt.x, GetCurrentTime(), seq ); + notify = TRUE; + } if (rel.y) + { queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS, pt.y, GetCurrentTime(), seq ); + notify = TRUE; + } if (rel.x || rel.y) { @@ -296,6 +303,7 @@ void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPA This->m_state.lZ += (wdata = (SHORT)ri->data.mouse.usButtonData); queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS, wdata, GetCurrentTime(), seq ); + notify = TRUE; } for (i = 0; i < ARRAY_SIZE(mouse_button_flags); ++i) @@ -305,9 +313,11 @@ void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPA This->m_state.rgbButtons[i / 2] = 0x80 - (i % 2) * 0x80; queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE +(i / 2) ) | DIDFT_PSHBUTTON, This->m_state.rgbButtons[i / 2], GetCurrentTime(), seq ); + notify = TRUE; } } + if (notify && This->base.hEvent) SetEvent( This->base.hEvent ); LeaveCriticalSection( &This->base.crit ); } @@ -317,6 +327,7 @@ int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam; SysMouseImpl *This = impl_from_IDirectInputDevice8W( iface ); int wdata = 0, inst_id = -1, ret = 0; + BOOL notify = FALSE; TRACE("msg %lx @ (%d %d)\n", wparam, hook->pt.x, hook->pt.y); @@ -347,8 +358,11 @@ int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam { /* Already have X, need to queue it */ if (inst_id != -1) + { queue_event(iface, inst_id, wdata, GetCurrentTime(), This->base.dinput->evsequence); + notify = TRUE; + } inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS; wdata = pt1.y; } @@ -408,8 +422,10 @@ int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam _dump_mouse_state(&This->m_state); queue_event(iface, inst_id, wdata, GetCurrentTime(), This->base.dinput->evsequence++); + notify = TRUE; } + if (notify && This->base.hEvent) SetEvent( This->base.hEvent ); LeaveCriticalSection(&This->base.crit); return ret; }