Skip to content

Commit

Permalink
[win] Ignore random WM_MOUSEMOVE messages in the same mouse position
Browse files Browse the repository at this point in the history
This solves a lot of issues when multiple pointer devices (e.g. a
mouse and a pen) are plugged in and we receive random WM_MOUSEMOVE
messages from the mouse position even when the device is not moved at
all (so these messages are usually mixed up with the pen messages from
WM_POINTERUPDATE).

Fixes aseprite/aseprite#3433
  • Loading branch information
dacap committed Sep 2, 2022
1 parent b5d92d9 commit 758319c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions os/win/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,27 @@ LRESULT WindowWin::wndProc(UINT msg, WPARAM wparam, LPARAM lparam)
Event ev;
mouseEvent(lparam, ev);

// Filter spurious mouse move messages out. Sometimes we receive
// periodic (e.g. each 2 seconds) WM_MOUSEMOVE messages in the
// same mouse position even when the mouse is not moved. This is
// specially problematic when a mouse and a stylus are plugged
// in, because there are random jumps between the pen position
// and the mouse position (receiving a random WM_MOUSEMOVE from
// the mouse position in the middle of a flow of
// WM_POINTERUPDATE messages from the pen).
{
static HWND lastHwnd = nullptr;
static gfx::Point lastPoint;
if (lastHwnd == m_hwnd &&
lastPoint == ev.position()) {
MOUSE_TRACE("SAME MOUSEMOVE xy=%d,%d\n",
ev.position().x, ev.position().y);
break;
}
lastHwnd = m_hwnd;
lastPoint = ev.position();
}

MOUSE_TRACE("MOUSEMOVE xy=%d,%d\n",
ev.position().x, ev.position().y);

Expand Down Expand Up @@ -2085,6 +2106,11 @@ void WindowWin::handlePointerButtonChange(Event& ev, POINTER_INFO& pi)
if (m_emulateDoubleClick)
m_pointerDownCount = 0;
#endif

// Update the internal last mouse position because if a pointer
// button wasn't change, the position might have changed anyway
// (i.e. we're in a WM_POINTERUPDATE event).
system()->_setInternalMousePosition(ev);
return;
}

Expand Down

0 comments on commit 758319c

Please sign in to comment.