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 <maurice.kalinowski@qt.io>
bb10
Oliver Wolff 2018-07-23 15:28:36 +02:00
parent f51fc53844
commit c1f86926a1
1 changed files with 14 additions and 5 deletions

View File

@ -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)