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 <qt_ci_bot@qt-project.org> Reviewed-by: Yuhang Zhao <yuhangzhao@deepin.org> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>bb10
parent
3d8e02152a
commit
baa5888807
|
|
@ -937,9 +937,10 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
|
|||
|
||||
MSG msg;
|
||||
msg.hwnd = hwnd; // re-create MSG structure
|
||||
msg.message = message; // time and pt fields ignored
|
||||
msg.message = message;
|
||||
msg.wParam = wParam;
|
||||
msg.lParam = lParam;
|
||||
msg.time = GetMessageTime();
|
||||
msg.pt.x = msg.pt.y = 0;
|
||||
if (et != QtWindows::CursorEvent && (et & (QtWindows::MouseEventFlag | QtWindows::NonClientEventFlag))) {
|
||||
msg.pt.x = GET_X_LPARAM(lParam);
|
||||
|
|
|
|||
|
|
@ -820,7 +820,7 @@ static void showSystemMenu(QWindow* w)
|
|||
qWindowsWndProc(topLevelHwnd, WM_SYSCOMMAND, WPARAM(ret), 0);
|
||||
}
|
||||
|
||||
static inline void sendExtendedPressRelease(QWindow *w, int k,
|
||||
static inline void sendExtendedPressRelease(QWindow *w, unsigned long timestamp, int k,
|
||||
Qt::KeyboardModifiers mods,
|
||||
quint32 nativeScanCode,
|
||||
quint32 nativeVirtualKey,
|
||||
|
|
@ -829,8 +829,8 @@ static inline void sendExtendedPressRelease(QWindow *w, int k,
|
|||
bool autorep = false,
|
||||
ushort count = 1)
|
||||
{
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(w, QEvent::KeyPress, k, mods, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(w, QEvent::KeyRelease, k, mods, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(w, timestamp, QEvent::KeyPress, k, mods, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(w, timestamp, QEvent::KeyRelease, k, mods, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -897,7 +897,7 @@ bool QWindowsKeyMapper::translateMultimediaKeyEventInternal(QWindow *window, con
|
|||
|
||||
const int qtKey = int(CmdTbl[cmd]);
|
||||
if (!skipPressRelease)
|
||||
sendExtendedPressRelease(receiver, qtKey, Qt::KeyboardModifier(state), 0, 0, 0);
|
||||
sendExtendedPressRelease(receiver, msg.time, qtKey, Qt::KeyboardModifier(state), 0, 0, 0);
|
||||
// QTBUG-43343: Make sure to return false if Qt does not handle the key, otherwise,
|
||||
// the keys are not passed to the active media player.
|
||||
# if QT_CONFIG(shortcut)
|
||||
|
|
@ -977,7 +977,7 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg,
|
|||
// A multi-character key or a Input method character
|
||||
// not found by our look-ahead
|
||||
if (msgType == WM_CHAR || msgType == WM_IME_CHAR) {
|
||||
sendExtendedPressRelease(receiver, 0, Qt::KeyboardModifier(state), scancode, vk_key, nModifiers, messageKeyText(msg), false);
|
||||
sendExtendedPressRelease(receiver, msg.time, 0, Qt::KeyboardModifier(state), scancode, vk_key, nModifiers, messageKeyText(msg), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1012,14 +1012,14 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg,
|
|||
if (dirStatus == VK_LSHIFT
|
||||
&& ((msg.wParam == VK_SHIFT && GetKeyState(VK_LCONTROL))
|
||||
|| (msg.wParam == VK_CONTROL && GetKeyState(VK_LSHIFT)))) {
|
||||
sendExtendedPressRelease(receiver, Qt::Key_Direction_L, {},
|
||||
sendExtendedPressRelease(receiver, msg.time, Qt::Key_Direction_L, {},
|
||||
scancode, vk_key, nModifiers, QString(), false);
|
||||
result = true;
|
||||
dirStatus = 0;
|
||||
} else if (dirStatus == VK_RSHIFT
|
||||
&& ( (msg.wParam == VK_SHIFT && GetKeyState(VK_RCONTROL))
|
||||
|| (msg.wParam == VK_CONTROL && GetKeyState(VK_RSHIFT)))) {
|
||||
sendExtendedPressRelease(receiver, Qt::Key_Direction_R, {},
|
||||
sendExtendedPressRelease(receiver, msg.time, Qt::Key_Direction_R, {},
|
||||
scancode, vk_key, nModifiers, QString(), false);
|
||||
result = true;
|
||||
dirStatus = 0;
|
||||
|
|
@ -1232,9 +1232,9 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg,
|
|||
// so, we have an auto-repeating key
|
||||
if (rec) {
|
||||
if (code < Qt::Key_Shift || code > Qt::Key_ScrollLock) {
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(receiver, QEvent::KeyRelease, code,
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(receiver, msg.time, QEvent::KeyRelease, code,
|
||||
Qt::KeyboardModifier(state), scancode, quint32(msg.wParam), nModifiers, rec->text, true);
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(receiver, QEvent::KeyPress, code,
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(receiver, msg.time, QEvent::KeyPress, code,
|
||||
Qt::KeyboardModifier(state), scancode, quint32(msg.wParam), nModifiers, rec->text, true);
|
||||
result = true;
|
||||
}
|
||||
|
|
@ -1260,7 +1260,7 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg,
|
|||
if (msg.wParam == VK_PACKET)
|
||||
code = asciiToKeycode(char(uch.cell()), state);
|
||||
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(receiver, QEvent::KeyPress, code,
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(receiver, msg.time, QEvent::KeyPress, code,
|
||||
modifiers, scancode, quint32(msg.wParam), nModifiers, text, false);
|
||||
result =true;
|
||||
bool store = true;
|
||||
|
|
@ -1302,10 +1302,10 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg,
|
|||
if ((msg.lParam & 0x40000000) == 0 &&
|
||||
Qt::KeyboardModifier(state) == Qt::NoModifier &&
|
||||
((code == Qt::Key_F18) || (code == Qt::Key_F19) || (code == Qt::Key_F20))) {
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(receiver, QEvent::KeyPress, code,
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(receiver, msg.time, QEvent::KeyPress, code,
|
||||
Qt::MetaModifier, scancode,
|
||||
quint32(msg.wParam), MetaLeft);
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(receiver, QEvent::KeyRelease, code,
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(receiver, msg.time, QEvent::KeyRelease, code,
|
||||
Qt::NoModifier, scancode,
|
||||
quint32(msg.wParam), 0);
|
||||
result = true;
|
||||
|
|
@ -1317,7 +1317,7 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg,
|
|||
// Map SHIFT + Tab to SHIFT + BackTab, QShortcutMap knows about this translation
|
||||
if (code == Qt::Key_Tab && (state & Qt::ShiftModifier) == Qt::ShiftModifier)
|
||||
code = Qt::Key_Backtab;
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(receiver, QEvent::KeyRelease, code,
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(receiver, msg.time, QEvent::KeyRelease, code,
|
||||
Qt::KeyboardModifier(state), scancode, quint32(msg.wParam),
|
||||
nModifiers,
|
||||
(rec ? rec->text : QString()), false);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -428,7 +428,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
|
|||
return false;
|
||||
|
||||
if (msg.message == WM_POINTERCAPTURECHANGED) {
|
||||
QWindowSystemInterface::handleTouchCancelEvent(window, m_touchDevice.data(),
|
||||
QWindowSystemInterface::handleTouchCancelEvent(window, msg.time, m_touchDevice.data(),
|
||||
QWindowsKeyMapper::queryKeyboardModifiers());
|
||||
m_lastTouchPoints.clear();
|
||||
return true;
|
||||
|
|
@ -537,7 +537,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
|
|||
if (allStates == QEventPoint::State::Released)
|
||||
m_touchInputIDToTouchPointID.clear();
|
||||
|
||||
QWindowSystemInterface::handleTouchEvent(window, m_touchDevice.data(), touchPoints,
|
||||
QWindowSystemInterface::handleTouchEvent(window, msg.time, m_touchDevice.data(), touchPoints,
|
||||
QWindowsKeyMapper::queryKeyboardModifiers());
|
||||
return false; // Allow mouse messages to be generated.
|
||||
}
|
||||
|
|
@ -635,7 +635,7 @@ bool QWindowsPointerHandler::translatePenEvent(QWindow *window, HWND hwnd, QtWin
|
|||
|
||||
switch (msg.message) {
|
||||
case WM_POINTERENTER: {
|
||||
QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(window, device.data(), true);
|
||||
QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(window, msg.time, device.data(), true);
|
||||
m_windowUnderPointer = window;
|
||||
// The local coordinates may fall outside the window.
|
||||
// Wait until the next update to send the enter event.
|
||||
|
|
@ -648,7 +648,7 @@ bool QWindowsPointerHandler::translatePenEvent(QWindow *window, HWND hwnd, QtWin
|
|||
m_windowUnderPointer = nullptr;
|
||||
m_currentWindow = nullptr;
|
||||
}
|
||||
QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(window, device.data(), false);
|
||||
QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(window, msg.time, device.data(), false);
|
||||
break;
|
||||
case WM_POINTERDOWN:
|
||||
case WM_POINTERUP:
|
||||
|
|
@ -673,7 +673,7 @@ bool QWindowsPointerHandler::translatePenEvent(QWindow *window, HWND hwnd, QtWin
|
|||
}
|
||||
const Qt::KeyboardModifiers keyModifiers = QWindowsKeyMapper::queryKeyboardModifiers();
|
||||
|
||||
QWindowSystemInterface::handleTabletEvent(target, device.data(),
|
||||
QWindowSystemInterface::handleTabletEvent(target, msg.time, device.data(),
|
||||
localPos, hiResGlobalPos, mouseButtons,
|
||||
pressure, xTilt, yTilt, tangentialPressure,
|
||||
rotation, z, keyModifiers);
|
||||
|
|
@ -724,7 +724,7 @@ bool QWindowsPointerHandler::translateMouseWheelEvent(QWindow *window,
|
|||
|
||||
QPoint localPos = QWindowsGeometryHint::mapFromGlobal(receiver, globalPos);
|
||||
|
||||
QWindowSystemInterface::handleWheelEvent(receiver, localPos, globalPos, QPoint(), angleDelta, keyModifiers);
|
||||
QWindowSystemInterface::handleWheelEvent(receiver, msg.time, localPos, globalPos, QPoint(), angleDelta, keyModifiers);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -821,10 +821,10 @@ bool QWindowsPointerHandler::translateMouseEvent(QWindow *window,
|
|||
&& (mouseEvent.type == QEvent::NonClientAreaMouseMove || mouseEvent.type == QEvent::MouseMove)
|
||||
&& (m_lastEventButton & mouseButtons) == 0) {
|
||||
if (mouseEvent.type == QEvent::NonClientAreaMouseMove) {
|
||||
QWindowSystemInterface::handleFrameStrutMouseEvent(window, device, localPos, globalPos, mouseButtons, m_lastEventButton,
|
||||
QWindowSystemInterface::handleFrameStrutMouseEvent(window, msg.time, device, localPos, globalPos, mouseButtons, m_lastEventButton,
|
||||
QEvent::NonClientAreaMouseButtonRelease, keyModifiers, source);
|
||||
} else {
|
||||
QWindowSystemInterface::handleMouseEvent(window, device, localPos, globalPos, mouseButtons, m_lastEventButton,
|
||||
QWindowSystemInterface::handleMouseEvent(window, msg.time, device, localPos, globalPos, mouseButtons, m_lastEventButton,
|
||||
QEvent::MouseButtonRelease, keyModifiers, source);
|
||||
}
|
||||
}
|
||||
|
|
@ -832,7 +832,7 @@ bool QWindowsPointerHandler::translateMouseEvent(QWindow *window,
|
|||
m_lastEventButton = mouseEvent.button;
|
||||
|
||||
if (mouseEvent.type >= QEvent::NonClientAreaMouseMove && mouseEvent.type <= QEvent::NonClientAreaMouseButtonDblClick) {
|
||||
QWindowSystemInterface::handleFrameStrutMouseEvent(window, device, localPos, globalPos, mouseButtons,
|
||||
QWindowSystemInterface::handleFrameStrutMouseEvent(window, msg.time, device, localPos, globalPos, mouseButtons,
|
||||
mouseEvent.button, mouseEvent.type, keyModifiers, source);
|
||||
return false; // Allow further event processing
|
||||
}
|
||||
|
|
@ -852,7 +852,7 @@ bool QWindowsPointerHandler::translateMouseEvent(QWindow *window,
|
|||
handleEnterLeave(window, currentWindowUnderPointer, globalPos);
|
||||
|
||||
if (!discardEvent && mouseEvent.type != QEvent::None) {
|
||||
QWindowSystemInterface::handleMouseEvent(window, device, localPos, globalPos, mouseButtons,
|
||||
QWindowSystemInterface::handleMouseEvent(window, msg.time, device, localPos, globalPos, mouseButtons,
|
||||
mouseEvent.button, mouseEvent.type, keyModifiers, source);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue