--- qtbase/src/plugins/platforms/windows/qwindowscontext.cpp +++ qtbase/src/plugins/platforms/windows/qwindowscontext.cpp @@ -1360,11 +1360,24 @@ case QtWindows::MouseEvent: case QtWindows::LeaveEvent: { - QWindow *window = platformWindow->window(); + QWindow *const platform_win = platformWindow->window(); + QWindow *window = platform_win; while (window && (window->flags() & Qt::WindowTransparentForInput)) window = window->parent(); if (!window) return false; + if (window != platform_win) { + // In the case that a message is being redirected up to the parent window, remap + // msg.lParam (window coordinates) and msg.hwnd to refer to that parent window. + msg.hwnd = QWindowsBaseWindow::handleOf(window); + // Mouse wheel and non-client events have screen coordinates in msg.lParam and so + // don't need to be remapped. + if ((et != QtWindows::MouseWheelEvent) && !(et & QtWindows::NonClientEventFlag)) { + POINT new_pos = { msg.pt.x, msg.pt.y }; + screenToClient(msg.hwnd, &new_pos); + msg.lParam = MAKELPARAM(static_cast(new_pos.x), static_cast(new_pos.y)); + } + } if (d->m_systemInfo & QWindowsContext::SI_SupportsPointer) return sessionManagerInteractionBlocked() || d->m_pointerHandler.translateMouseEvent(window, hwnd, et, msg, result); else --- qtbase/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ qtbase/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -268,9 +268,9 @@ return translateMouseWheelEvent(window, hwnd, msg, result); QPoint winEventPosition(GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam)); - if ((et & QtWindows::NonClientEventFlag) == 0 && QWindowsBaseWindow::isRtlLayout(hwnd)) { + if ((et & QtWindows::NonClientEventFlag) == 0 && QWindowsBaseWindow::isRtlLayout(msg.hwnd)) { RECT clientArea; - GetClientRect(hwnd, &clientArea); + GetClientRect(msg.hwnd, &clientArea); winEventPosition.setX(clientArea.right - winEventPosition.x()); } @@ -278,10 +278,10 @@ QPoint globalPosition; if (et & QtWindows::NonClientEventFlag) { globalPosition = winEventPosition; - clientPosition = QWindowsGeometryHint::mapFromGlobal(hwnd, globalPosition); + clientPosition = QWindowsGeometryHint::mapFromGlobal(msg.hwnd, globalPosition); } else { clientPosition = winEventPosition; - globalPosition = QWindowsGeometryHint::mapToGlobal(hwnd, winEventPosition); + globalPosition = QWindowsGeometryHint::mapToGlobal(msg.hwnd, winEventPosition); } // Windows sends a mouse move with no buttons pressed to signal "Enter" --- qtbase/src/plugins/platforms/windows/qwindowspointerhandler.cpp +++ qtbase/src/plugins/platforms/windows/qwindowspointerhandler.cpp @@ -699,9 +699,9 @@ *result = 0; QPoint eventPos(GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam)); - if ((et & QtWindows::NonClientEventFlag) == 0 && QWindowsBaseWindow::isRtlLayout(hwnd)) { + if ((et & QtWindows::NonClientEventFlag) == 0 && QWindowsBaseWindow::isRtlLayout(msg.hwnd)) { RECT clientArea; - GetClientRect(hwnd, &clientArea); + GetClientRect(msg.hwnd, &clientArea); eventPos.setX(clientArea.right - eventPos.x()); } @@ -710,10 +710,10 @@ if ((et == QtWindows::MouseWheelEvent) || (et & QtWindows::NonClientEventFlag)) { globalPos = eventPos; - localPos = QWindowsGeometryHint::mapFromGlobal(hwnd, eventPos); + localPos = QWindowsGeometryHint::mapFromGlobal(msg.hwnd, eventPos); } else { localPos = eventPos; - globalPos = QWindowsGeometryHint::mapToGlobal(hwnd, eventPos); + globalPos = QWindowsGeometryHint::mapToGlobal(msg.hwnd, eventPos); } const Qt::KeyboardModifiers keyModifiers = QWindowsKeyMapper::queryKeyboardModifiers();