From e9b51781d0dd8badda301da61b08735c256313ca Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Mon, 22 Aug 2016 12:04:59 +0200 Subject: winrt: Fix display of tooltips This touches multiple areas. First adding a tooltip to the window list should not automatically invoke focussing and hence handleWindowActivated should not be invoked. This is the same approach as on the windows qpa. The winrt qpa supports multiple (non-fullscreen) windows since a while. However, pointerUpdated still acted on the top level window, which caused problems resolving the real target of a mouse event. In this case the tooltip received all events, while the application window should get them. Hence identify the target window via the system coordinates. Task-number: QTBUG-50733 Change-Id: Iea1f4cd7406e6cde85ab3fc83f018b871fc30824 Reviewed-by: Oliver Wolff --- src/plugins/platforms/winrt/qwinrtscreen.cpp | 40 +++++++++++++++++++++------- src/plugins/platforms/winrt/qwinrtscreen.h | 1 + 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp index 4574439b1a..9236de58a1 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.cpp +++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp @@ -802,6 +802,17 @@ QWindow *QWinRTScreen::topWindow() const 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); @@ -810,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(); @@ -828,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(); @@ -1044,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; @@ -1081,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; } @@ -1107,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; } @@ -1159,7 +1179,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) @@ -1178,7 +1198,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); diff --git a/src/plugins/platforms/winrt/qwinrtscreen.h b/src/plugins/platforms/winrt/qwinrtscreen.h index 1862c0afcf..e489e208d5 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.h +++ b/src/plugins/platforms/winrt/qwinrtscreen.h @@ -104,6 +104,7 @@ public: Qt::ScreenOrientation orientation() const Q_DECL_OVERRIDE; QWindow *topWindow() const; + QWindow *windowAt(const QPoint &pos); void addWindow(QWindow *window); void removeWindow(QWindow *window); void raise(QWindow *window); -- cgit v1.2.3