diff options
author | Giuseppe D'Angelo <[email protected]> | 2023-01-05 03:46:45 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <[email protected]> | 2023-01-23 15:51:55 +0100 |
commit | baa5888807d3db57603398ae7aa27866efdbd711 (patch) | |
tree | c7d8801e3a9dfa5de03fb449e6403890bd46dcf4 /src/plugins/platforms/windows/qwindowsmousehandler.cpp | |
parent | 3d8e02152a4c83a45f616dcad6852bc71fc3996d (diff) |
Windows: use MSG timestamps for input events
Input events have a timestamp. When dispatching an event through QPA, a
platform plugin can either provide it, or QPA will use an internal
QElapsedTimer to provide a timestamp.
Windows input messages do come with a timestamp already, so we can use
that instead of the QPA.
The two methods are not equivalent.
For instance: for various reasons, Qt does not honor Windows' "double
clicked" message, but uses the delta between two mouse events to
establish if the second click is actually a double click.
Now suppose that the user double clicks on a widget. On the first click,
the application does something that freezes it for a bit (e.g. some
heavy repainting or whatever). Does the second click register as a
double click or not?
* If we're using Qt's own timer, the answer is NO; the event is pulled
from the WM queue after the freeze, given a timestamp far away from
the last click, and so it will be deemed another single click
* If we use the OS' timestamps, then the second click will be seen as
"close" to the first click, and correctly registered as second click.
This reasoning can be extended to many other QPA events, but looks like
the APIs for some are missing (e.g. enter events), so I'm not tackling
them here.
Task-number: QTBUG-109833
Change-Id: I149361a844feac86cafa885c109a1903b1e49545
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Yuhang Zhao <[email protected]>
Reviewed-by: Oliver Wolff <[email protected]>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowsmousehandler.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsmousehandler.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index ceb33f6141c..8d57e75c964 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -287,10 +287,10 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd, && (mouseEvent.type == QEvent::NonClientAreaMouseMove || mouseEvent.type == QEvent::MouseMove) && (m_lastEventButton & buttons) == 0) { if (mouseEvent.type == QEvent::NonClientAreaMouseMove) { - QWindowSystemInterface::handleFrameStrutMouseEvent(window, device, clientPosition, globalPosition, buttons, m_lastEventButton, + QWindowSystemInterface::handleFrameStrutMouseEvent(window, msg.time, device, clientPosition, globalPosition, buttons, m_lastEventButton, QEvent::NonClientAreaMouseButtonRelease, keyModifiers, source); } else { - QWindowSystemInterface::handleMouseEvent(window, device, clientPosition, globalPosition, buttons, m_lastEventButton, + QWindowSystemInterface::handleMouseEvent(window, msg.time, device, clientPosition, globalPosition, buttons, m_lastEventButton, QEvent::MouseButtonRelease, keyModifiers, source); } } @@ -298,7 +298,7 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd, m_lastEventButton = mouseEvent.button; if (mouseEvent.type >= QEvent::NonClientAreaMouseMove && mouseEvent.type <= QEvent::NonClientAreaMouseButtonDblClick) { - QWindowSystemInterface::handleFrameStrutMouseEvent(window, device, clientPosition, + QWindowSystemInterface::handleFrameStrutMouseEvent(window, msg.time, device, clientPosition, globalPosition, buttons, mouseEvent.button, mouseEvent.type, keyModifiers, source); @@ -448,7 +448,7 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd, } if (!discardEvent && mouseEvent.type != QEvent::None) { - QWindowSystemInterface::handleMouseEvent(window, device, clientPosition, globalPosition, buttons, + QWindowSystemInterface::handleMouseEvent(window, msg.time, device, clientPosition, globalPosition, buttons, mouseEvent.button, mouseEvent.type, keyModifiers, source); } @@ -472,7 +472,7 @@ static bool isValidWheelReceiver(QWindow *candidate) return false; } -static void redirectWheelEvent(QWindow *window, const QPoint &globalPos, int delta, +static void redirectWheelEvent(QWindow *window, unsigned long timestamp, const QPoint &globalPos, int delta, Qt::Orientation orientation, Qt::KeyboardModifiers mods) { // Redirect wheel event to one of the following, in order of preference: @@ -493,6 +493,7 @@ static void redirectWheelEvent(QWindow *window, const QPoint &globalPos, int del if (handleEvent) { const QPoint point = (orientation == Qt::Vertical) ? QPoint(0, delta) : QPoint(delta, 0); QWindowSystemInterface::handleWheelEvent(receiver, + timestamp, QWindowsGeometryHint::mapFromGlobal(receiver, globalPos), globalPos, QPoint(), point, mods); } @@ -521,7 +522,7 @@ bool QWindowsMouseHandler::translateMouseWheelEvent(QWindow *window, HWND, delta = -delta; const QPoint globalPos(GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam)); - redirectWheelEvent(window, globalPos, delta, orientation, mods); + redirectWheelEvent(window, msg.time, globalPos, delta, orientation, mods); return true; } @@ -552,7 +553,7 @@ bool QWindowsMouseHandler::translateScrollEvent(QWindow *window, HWND, return false; } - redirectWheelEvent(window, QCursor::pos(), delta, Qt::Horizontal, Qt::NoModifier); + redirectWheelEvent(window, msg.time, QCursor::pos(), delta, Qt::Horizontal, Qt::NoModifier); return true; } @@ -633,6 +634,7 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND, m_touchInputIDToTouchPointID.clear(); QWindowSystemInterface::handleTouchEvent(window, + msg.time, m_touchDevice.data(), touchPoints, QWindowsKeyMapper::queryKeyboardModifiers()); |