From c1f86926a14f911ec7e578f63c96ba2292fa7cbe Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Mon, 23 Jul 2018 15:28:36 +0200 Subject: winrt: Fix QWinRTCursor::pos On winrt top level windows are always considered fullscreen and the core window's bounds are considered the bounds of QScreen. Thus When checking the mouse cursor's position the window bounds have to be taken into consideration. Change-Id: I39f24399bbaeade58d547abc770d4b3094174160 Reviewed-by: Maurice Kalinowski --- src/plugins/platforms/winrt/qwinrtcursor.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/winrt/qwinrtcursor.cpp b/src/plugins/platforms/winrt/qwinrtcursor.cpp index 6236ec1f2b..f22b9a435a 100644 --- a/src/plugins/platforms/winrt/qwinrtcursor.cpp +++ b/src/plugins/platforms/winrt/qwinrtcursor.cpp @@ -174,14 +174,23 @@ QPoint QWinRTCursor::pos() const ICoreWindow *coreWindow = screen->coreWindow(); Q_ASSERT(coreWindow); Point point; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, &point]() { - return coreWindow->get_PointerPosition(&point); + Rect bounds; + HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, &point, &bounds]() { + HRESULT hr = coreWindow->get_PointerPosition(&point); + RETURN_HR_IF_FAILED("Failed to obtain pointer position."); + hr = coreWindow->get_Bounds(&bounds); + RETURN_HR_IF_FAILED("Failed to obtain window bounds."); + return hr; }); Q_ASSERT_SUCCEEDED(hr); - const QPoint position = QPoint(point.X, point.Y) * screen->scaleFactor(); + QPoint position = QPoint(point.X, point.Y); // If no cursor get_PointerPosition returns SHRT_MIN for x and y - return position.x() == SHRT_MIN && position.y() == SHRT_MIN || FAILED(hr) ? QPointF(Q_INFINITY, Q_INFINITY).toPoint() - : position; + if (position.x() == SHRT_MIN && position.y() == SHRT_MIN || FAILED(hr)) + return QPointF(Q_INFINITY, Q_INFINITY).toPoint(); + position.rx() -= bounds.X; + position.ry() -= bounds.Y; + position *= screen->scaleFactor(); + return position; } void QWinRTCursor::setPos(const QPoint &pos) -- cgit v1.2.3