diff options
Diffstat (limited to 'src/plugins/platforms/winrt/qwinrtscreen.cpp')
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtscreen.cpp | 83 |
1 files changed, 73 insertions, 10 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp index c120de9d8f..e8e869c04f 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.cpp +++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp @@ -753,12 +753,66 @@ void QWinRTScreen::initialize() onVisibilityChanged(nullptr, nullptr); } +void QWinRTScreen::setCursorRect(const QRectF &cursorRect) +{ + mCursorRect = cursorRect; +} + +void QWinRTScreen::setKeyboardRect(const QRectF &keyboardRect) +{ + Q_D(QWinRTScreen); + QRectF visibleRectF; + HRESULT hr; + Rect windowSize; + + hr = d->coreWindow->get_Bounds(&windowSize); + if (FAILED(hr)) { + qErrnoWarning(hr, "Failed to get window bounds"); + return; + } + d->logicalRect = QRectF(windowSize.X, windowSize.Y, windowSize.Width, windowSize.Height); +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) + Rect visibleRect; + hr = d->view2->get_VisibleBounds(&visibleRect); + if (FAILED(hr)) { + qErrnoWarning(hr, "Failed to get window visible bounds"); + return; + } + visibleRectF = QRectF(visibleRect.X, visibleRect.Y, visibleRect.Width, visibleRect.Height); +#else + visibleRectF = d->logicalRect; +#endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) + // if keyboard is snapped to the bottom of the screen and would cover the cursor the content is + // moved up to make it visible + if (keyboardRect.intersects(mCursorRect) + && qFuzzyCompare(geometry().height(), keyboardRect.y() + keyboardRect.height())) { + visibleRectF.moveTop(visibleRectF.top() - keyboardRect.height() / d->scaleFactor); + } + d->visibleRect = visibleRectF; + + qCDebug(lcQpaWindows) << __FUNCTION__ << d->visibleRect; + QWindowSystemInterface::handleScreenGeometryChange(screen(), geometry(), availableGeometry()); + QPlatformScreen::resizeMaximizedWindows(); + handleExpose(); +} + QWindow *QWinRTScreen::topWindow() const { Q_D(const QWinRTScreen); return d->visibleWindows.isEmpty() ? 0 : d->visibleWindows.first(); } +QWindow *QWinRTScreen::windowAt(const QPoint &pos) +{ + Q_D(const QWinRTScreen); + for (auto w : qAsConst(d->visibleWindows)) { + if (w->geometry().contains(pos)) + return w; + } + qCDebug(lcQpaWindows) << __FUNCTION__ << ": No window found at:" << pos; + return nullptr; +} + void QWinRTScreen::addWindow(QWindow *window) { Q_D(QWinRTScreen); @@ -767,8 +821,12 @@ void QWinRTScreen::addWindow(QWindow *window) return; d->visibleWindows.prepend(window); - updateWindowTitle(window->title()); - QWindowSystemInterface::handleWindowActivated(window, Qt::OtherFocusReason); + const Qt::WindowType type = window->type(); + if (type != Qt::Popup && type != Qt::ToolTip && type != Qt::Tool) { + updateWindowTitle(window->title()); + QWindowSystemInterface::handleWindowActivated(window, Qt::OtherFocusReason); + } + handleExpose(); QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents); @@ -785,7 +843,9 @@ void QWinRTScreen::removeWindow(QWindow *window) const bool wasTopWindow = window == topWindow(); if (!d->visibleWindows.removeAll(window)) return; - if (wasTopWindow) + + const Qt::WindowType type = window->type(); + if (wasTopWindow && type != Qt::Popup && type != Qt::ToolTip && type != Qt::Tool) QWindowSystemInterface::handleWindowActivated(Q_NULLPTR, Qt::OtherFocusReason); handleExpose(); QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents); @@ -1001,9 +1061,12 @@ HRESULT QWinRTScreen::onPointerUpdated(ICoreWindow *, IPointerEventArgs *args) pointerPoint->get_Position(&point); QPointF pos(point.X * d->scaleFactor, point.Y * d->scaleFactor); QPointF localPos = pos; - if (topWindow()) { - const QPointF globalPosDelta = pos - pos.toPoint(); - localPos = topWindow()->mapFromGlobal(pos.toPoint()) + globalPosDelta; + + const QPoint posPoint = pos.toPoint(); + QWindow *targetWindow = windowAt(posPoint); + if (targetWindow) { + const QPointF globalPosDelta = pos - posPoint; + localPos = targetWindow->mapFromGlobal(posPoint) + globalPosDelta; } VirtualKeyModifiers modifiers; @@ -1038,7 +1101,7 @@ HRESULT QWinRTScreen::onPointerUpdated(ICoreWindow *, IPointerEventArgs *args) boolean isHorizontal; properties->get_IsHorizontalMouseWheel(&isHorizontal); QPoint angleDelta(isHorizontal ? delta : 0, isHorizontal ? 0 : delta); - QWindowSystemInterface::handleWheelEvent(topWindow(), localPos, pos, QPoint(), angleDelta, mods); + QWindowSystemInterface::handleWheelEvent(targetWindow, localPos, pos, QPoint(), angleDelta, mods); break; } @@ -1064,7 +1127,7 @@ HRESULT QWinRTScreen::onPointerUpdated(ICoreWindow *, IPointerEventArgs *args) if (isPressed) buttons |= Qt::XButton2; - QWindowSystemInterface::handleMouseEvent(topWindow(), localPos, pos, buttons, mods); + QWindowSystemInterface::handleMouseEvent(targetWindow, localPos, pos, buttons, mods); break; } @@ -1122,7 +1185,7 @@ HRESULT QWinRTScreen::onPointerUpdated(ICoreWindow *, IPointerEventArgs *args) it.value().normalPosition = QPointF(point.X/d->logicalRect.width(), point.Y/d->logicalRect.height()); it.value().pressure = pressure; - QWindowSystemInterface::handleTouchEvent(topWindow(), d->touchDevice, d->touchPoints.values(), mods); + QWindowSystemInterface::handleTouchEvent(targetWindow, d->touchDevice, d->touchPoints.values(), mods); // Fall-through for pen to generate tablet event if (pointerDeviceType != PointerDeviceType_Pen) @@ -1141,7 +1204,7 @@ HRESULT QWinRTScreen::onPointerUpdated(ICoreWindow *, IPointerEventArgs *args) float rotation; properties->get_Twist(&rotation); - QWindowSystemInterface::handleTabletEvent(topWindow(), isPressed, pos, pos, 0, + QWindowSystemInterface::handleTabletEvent(targetWindow, isPressed, pos, pos, 0, pointerType, pressure, xTilt, yTilt, 0, rotation, 0, id, mods); |