From 4f1234033ba647dd4d32e87eecb832773d089abc Mon Sep 17 00:00:00 2001 From: Samuel Nevala Date: Mon, 16 Nov 2015 13:21:46 +0200 Subject: wirt: Fix cursor position method. The native position is given in device-independent pixels, so multiply that by the window scale factor. If no cursor is present (e.g. on Windows Phone), the native API returns SHRT_MIN as the coordinate values. Catch that and pass Infinity instead in order to enable the cursorless fall-back behavior in QQuickMenu::popup(). Change-Id: Ibe8ebcdbe257e8df25eea9873e8f4fa647ae1ab2 Task-Id: QTBUG-48265 Reviewed-by: Andrew Knight --- src/plugins/platforms/winrt/qwinrtcursor.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/winrt/qwinrtcursor.cpp b/src/plugins/platforms/winrt/qwinrtcursor.cpp index 707f3bf0ba..1a511f103f 100644 --- a/src/plugins/platforms/winrt/qwinrtcursor.cpp +++ b/src/plugins/platforms/winrt/qwinrtcursor.cpp @@ -161,15 +161,19 @@ void QWinRTCursor::changeCursor(QCursor *windowCursor, QWindow *window) QPoint QWinRTCursor::pos() const { - ICoreWindow *coreWindow = - static_cast(QGuiApplication::primaryScreen()->handle())->coreWindow(); - HRESULT hr; + const QWinRTScreen *screen = static_cast(QGuiApplication::primaryScreen()->handle()); + Q_ASSERT(screen); + ICoreWindow *coreWindow = screen->coreWindow(); + Q_ASSERT(coreWindow); Point point; - hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, &point]() { + HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, &point]() { return coreWindow->get_PointerPosition(&point); }); - RETURN_IF_FAILED("Failed to get native cursor position", QPoint()); - return QPoint(point.X, point.Y); + Q_ASSERT_SUCCEEDED(hr); + const QPoint position = QPoint(point.X, point.Y) * screen->scaleFactor(); + // 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; } QT_END_NAMESPACE -- cgit v1.2.3