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>
This commit is contained in:
Samuel Nevala 2015-11-16 13:21:46 +02:00
parent 4e7c0993d5
commit 4f1234033b

View File

@ -161,15 +161,19 @@ void QWinRTCursor::changeCursor(QCursor *windowCursor, QWindow *window)
QPoint QWinRTCursor::pos() const QPoint QWinRTCursor::pos() const
{ {
ICoreWindow *coreWindow = const QWinRTScreen *screen = static_cast<QWinRTScreen *>(QGuiApplication::primaryScreen()->handle());
static_cast<QWinRTScreen *>(QGuiApplication::primaryScreen()->handle())->coreWindow(); Q_ASSERT(screen);
HRESULT hr; ICoreWindow *coreWindow = screen->coreWindow();
Q_ASSERT(coreWindow);
Point point; Point point;
hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, &point]() { HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, &point]() {
return coreWindow->get_PointerPosition(&point); return coreWindow->get_PointerPosition(&point);
}); });
RETURN_IF_FAILED("Failed to get native cursor position", QPoint()); Q_ASSERT_SUCCEEDED(hr);
return QPoint(point.X, point.Y); 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 QT_END_NAMESPACE