Skip to content

Commit

Permalink
Windows QPA: Fix mouse event position for QWindows with Qt::WindowTra…
Browse files Browse the repository at this point in the history
…nsparentForInput

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 <[email protected]>
  • Loading branch information
FriedemannKleint committed Oct 13, 2021
1 parent 58d64b7 commit 36a6d17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/plugins/platforms/windows/qwindowsmousehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/platforms/windows/qwindowspointerhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 36a6d17

Please sign in to comment.