Windows QPA: Fix mouse event position for QWindows with Qt::WindowTransparentForInput

The local position needs to be corrected when the Qt receiver window
does not correspond to the native event receiver window.

Fixes: QTBUG-97095
Pick-to: 6.2 5.15
Change-Id: Ic9fa3d84b6ee84ae5f8fa2408b0d60e35dbfa328
Reviewed-by: André de la Rocha <andre.rocha@qt.io>
This commit is contained in:
Friedemann Kleint 2021-10-12 11:54:11 +02:00
parent 58d64b770a
commit 36a6d17af0
2 changed files with 13 additions and 3 deletions

View File

@ -258,8 +258,13 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd,
globalPosition = winEventPosition;
clientPosition = QWindowsGeometryHint::mapFromGlobal(hwnd, globalPosition);
} else {
clientPosition = winEventPosition;
globalPosition = QWindowsGeometryHint::mapToGlobal(hwnd, winEventPosition);
auto targetHwnd = hwnd;
if (auto *pw = window->handle())
targetHwnd = HWND(pw->winId());
clientPosition = targetHwnd == hwnd
? winEventPosition
: QWindowsGeometryHint::mapFromGlobal(targetHwnd, globalPosition);
}
// Windows sends a mouse move with no buttons pressed to signal "Enter"
@ -476,7 +481,7 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd,
}
if (!discardEvent && mouseEvent.type != QEvent::None) {
QWindowSystemInterface::handleMouseEvent(window, device, winEventPosition, globalPosition, buttons,
QWindowSystemInterface::handleMouseEvent(window, device, clientPosition, globalPosition, buttons,
mouseEvent.button, mouseEvent.type,
keyModifiers, source);
}

View File

@ -768,8 +768,13 @@ bool QWindowsPointerHandler::translateMouseEvent(QWindow *window,
globalPos = eventPos;
localPos = QWindowsGeometryHint::mapFromGlobal(hwnd, eventPos);
} else {
localPos = eventPos;
globalPos = QWindowsGeometryHint::mapToGlobal(hwnd, eventPos);
auto targetHwnd = hwnd;
if (auto *pw = window->handle())
targetHwnd = HWND(pw->winId());
localPos = targetHwnd == hwnd
? eventPos
: QWindowsGeometryHint::mapFromGlobal(targetHwnd, globalPos);
}
const Qt::KeyboardModifiers keyModifiers = QWindowsKeyMapper::queryKeyboardModifiers();