summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorSamuel Nevala <samuel.nevala@intopalo.com>2015-11-16 13:21:46 +0200
committerSamuel Nevala <samuel.nevala@intopalo.com>2015-11-17 14:59:47 +0000
commit4f1234033ba647dd4d32e87eecb832773d089abc (patch)
tree04185ff97d8a8730f39906f171c3b784453dbc5e /src/plugins/platforms
parent4e7c0993d555ffa4ed32ffb9c36dab648e4f8bd4 (diff)
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 <andrew.knight@intopalo.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/winrt/qwinrtcursor.cpp16
1 files changed, 10 insertions, 6 deletions
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<QWinRTScreen *>(QGuiApplication::primaryScreen()->handle())->coreWindow();
- HRESULT hr;
+ const QWinRTScreen *screen = static_cast<QWinRTScreen *>(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