diff options
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qevent.cpp | 86 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 9 | ||||
-rw-r--r-- | src/gui/kernel/qevent_p.h | 9 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 103 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication_p.h | 8 | ||||
-rw-r--r-- | src/gui/kernel/qplatformscreen.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qplatformtheme.cpp | 13 | ||||
-rw-r--r-- | src/gui/kernel/qplatformtheme.h | 3 | ||||
-rw-r--r-- | src/gui/kernel/qsurface.cpp | 2 | ||||
-rw-r--r-- | src/gui/kernel/qsurface.h | 3 | ||||
-rw-r--r-- | src/gui/kernel/qtouchdevice.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qtouchdevice_p.h | 7 | ||||
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 119 | ||||
-rw-r--r-- | src/gui/kernel/qwindow.h | 15 | ||||
-rw-r--r-- | src/gui/kernel/qwindow_p.h | 17 | ||||
-rw-r--r-- | src/gui/kernel/qwindowsysteminterface.cpp | 580 | ||||
-rw-r--r-- | src/gui/kernel/qwindowsysteminterface.h | 74 | ||||
-rw-r--r-- | src/gui/kernel/qwindowsysteminterface_p.h | 18 |
18 files changed, 637 insertions, 431 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 254b8926c8..468523ab9c 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3887,7 +3887,7 @@ QDebug operator<<(QDebug dbg, const QTouchEvent::TouchPoint &tp) { QDebugStateSaver saver(dbg); dbg.nospace(); - dbg << "TouchPoint(" << tp.id() << " ("; + dbg << "TouchPoint(" << hex << tp.id() << dec << " ("; QtDebugUtils::formatQRect(dbg, tp.rect()); dbg << ") "; QtDebugUtils::formatQEnum(dbg, tp.state()); @@ -4417,6 +4417,8 @@ QTouchEvent::~QTouchEvent() \brief The TouchPoint class provides information about a touch point in a QTouchEvent. \since 4.6 \inmodule QtGui + + \image touchpoint-metrics.png */ /*! \enum TouchPoint::InfoFlag @@ -4502,7 +4504,7 @@ Qt::TouchPointState QTouchEvent::TouchPoint::state() const */ QPointF QTouchEvent::TouchPoint::pos() const { - return d->rect.center(); + return d->pos; } /*! @@ -4517,7 +4519,7 @@ QPointF QTouchEvent::TouchPoint::pos() const */ QPointF QTouchEvent::TouchPoint::scenePos() const { - return d->sceneRect.center(); + return d->scenePos; } /*! @@ -4527,7 +4529,7 @@ QPointF QTouchEvent::TouchPoint::scenePos() const */ QPointF QTouchEvent::TouchPoint::screenPos() const { - return d->screenRect.center(); + return d->screenPos; } /*! @@ -4650,10 +4652,19 @@ QPointF QTouchEvent::TouchPoint::lastNormalizedPos() const around the point returned by pos(). \note This function returns an empty rect if the device does not report touch point sizes. + + \obsolete This function is deprecated in 5.9 because it returns the outer bounds + of the touchpoint regardless of rotation, whereas a touchpoint is more correctly + modeled as an ellipse at position pos() with ellipseDiameters() + which are independent of rotation(). + + \sa scenePos(), ellipseDiameters() */ QRectF QTouchEvent::TouchPoint::rect() const { - return d->rect; + QRectF ret(QPointF(), d->ellipseDiameters); + ret.moveCenter(d->pos); + return ret; } /*! @@ -4661,11 +4672,18 @@ QRectF QTouchEvent::TouchPoint::rect() const \note This function returns an empty rect if the device does not report touch point sizes. - \sa scenePos(), rect() + \obsolete This function is deprecated in 5.9 because it returns the outer bounds + of the touchpoint regardless of rotation, whereas a touchpoint is more correctly + modeled as an ellipse at position scenePos() with ellipseDiameters() + which are independent of rotation(). + + \sa scenePos(), ellipseDiameters() */ QRectF QTouchEvent::TouchPoint::sceneRect() const { - return d->sceneRect; + QRectF ret(QPointF(), d->ellipseDiameters); + ret.moveCenter(d->scenePos); + return ret; } /*! @@ -4673,11 +4691,18 @@ QRectF QTouchEvent::TouchPoint::sceneRect() const \note This function returns an empty rect if the device does not report touch point sizes. - \sa screenPos(), rect() + \obsolete This function is deprecated because it returns the outer bounds of the + touchpoint regardless of rotation, whereas a touchpoint is more correctly + modeled as an ellipse at position screenPos() with ellipseDiameters() + which are independent of rotation(). + + \sa screenPos(), ellipseDiameters() */ QRectF QTouchEvent::TouchPoint::screenRect() const { - return d->screenRect; + QRectF ret(QPointF(), d->ellipseDiameters); + ret.moveCenter(d->screenPos); + return ret; } /*! @@ -4703,6 +4728,19 @@ qreal QTouchEvent::TouchPoint::rotation() const } /*! + \since 5.9 + Returns the width and height of the bounding ellipse of this touch point. + The return value is in logical pixels. Most touchscreens do not detect the + shape of the contact point, so a null size is the most common value. + In other cases the diameters may be nonzero and equal (the ellipse is + approximated as a circle). +*/ +QSizeF QTouchEvent::TouchPoint::ellipseDiameters() const +{ + return d->ellipseDiameters; +} + +/*! Returns a velocity vector for this touch point. The vector is in the screen's coordinate system, using pixels per seconds for the magnitude. @@ -4773,7 +4811,7 @@ void QTouchEvent::TouchPoint::setPos(const QPointF &pos) { if (d->ref.load() != 1) d = d->detach(); - d->rect.moveCenter(pos); + d->pos = pos; } /*! \internal */ @@ -4781,7 +4819,7 @@ void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos) { if (d->ref.load() != 1) d = d->detach(); - d->sceneRect.moveCenter(scenePos); + d->scenePos = scenePos; } /*! \internal */ @@ -4789,7 +4827,7 @@ void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos) { if (d->ref.load() != 1) d = d->detach(); - d->screenRect.moveCenter(screenPos); + d->screenPos = screenPos; } /*! \internal */ @@ -4864,28 +4902,32 @@ void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalized d->lastNormalizedPos = lastNormalizedPos; } -/*! \internal */ +// ### remove the following 3 setRect functions and their usages soon +/*! \internal \obsolete */ void QTouchEvent::TouchPoint::setRect(const QRectF &rect) { if (d->ref.load() != 1) d = d->detach(); - d->rect = rect; + d->pos = rect.center(); + d->ellipseDiameters = rect.size(); } -/*! \internal */ +/*! \internal \obsolete */ void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect) { if (d->ref.load() != 1) d = d->detach(); - d->sceneRect = sceneRect; + d->scenePos = sceneRect.center(); + d->ellipseDiameters = sceneRect.size(); } -/*! \internal */ +/*! \internal \obsolete */ void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect) { if (d->ref.load() != 1) d = d->detach(); - d->screenRect = screenRect; + d->screenPos = screenRect.center(); + d->ellipseDiameters = screenRect.size(); } /*! \internal */ @@ -4905,6 +4947,14 @@ void QTouchEvent::TouchPoint::setRotation(qreal angle) } /*! \internal */ +void QTouchEvent::TouchPoint::setEllipseDiameters(const QSizeF &dia) +{ + if (d->ref.load() != 1) + d = d->detach(); + d->ellipseDiameters = dia; +} + +/*! \internal */ void QTouchEvent::TouchPoint::setVelocity(const QVector2D &v) { if (d->ref.load() != 1) diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index a062331bd8..d7b7b636b2 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -870,6 +870,8 @@ public: qreal pressure() const; qreal rotation() const; + QSizeF ellipseDiameters() const; + QVector2D velocity() const; InfoFlags flags() const; QVector<QPointF> rawScreenPositions() const; @@ -890,11 +892,12 @@ public: void setLastScenePos(const QPointF &lastScenePos); void setLastScreenPos(const QPointF &lastScreenPos); void setLastNormalizedPos(const QPointF &lastNormalizedPos); - void setRect(const QRectF &rect); - void setSceneRect(const QRectF &sceneRect); - void setScreenRect(const QRectF &screenRect); + void setRect(const QRectF &rect); // deprecated + void setSceneRect(const QRectF &sceneRect); // deprecated + void setScreenRect(const QRectF &screenRect); // deprecated void setPressure(qreal pressure); void setRotation(qreal angle); + void setEllipseDiameters(const QSizeF &dia); void setVelocity(const QVector2D &v); void setFlags(InfoFlags flags); void setRawScreenPositions(const QVector<QPointF> &positions); diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index 7e82b9c654..f67284eebb 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -65,8 +65,9 @@ public: : ref(1), id(id), state(Qt::TouchPointReleased), - pressure(qreal(-1.)), - rotation(qreal(0.)) + pressure(-1), + rotation(0), + ellipseDiameters(0, 0) { } inline QTouchEventTouchPointPrivate *detach() @@ -82,12 +83,12 @@ public: int id; QPointerUniqueId uniqueId; Qt::TouchPointStates state; - QRectF rect, sceneRect, screenRect; - QPointF normalizedPos, + QPointF pos, scenePos, screenPos, normalizedPos, startPos, startScenePos, startScreenPos, startNormalizedPos, lastPos, lastScenePos, lastScreenPos, lastNormalizedPos; qreal pressure; qreal rotation; + QSizeF ellipseDiameters; QVector2D velocity; QTouchEvent::TouchPoint::InfoFlags flags; QVector<QPointF> rawScreenPositions; diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index c189c5b068..d3f3827d6e 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -68,8 +68,8 @@ #include <qpalette.h> #include <qscreen.h> #include "qsessionmanager.h" +#include <private/qcolorprofile_p.h> #include <private/qscreen_p.h> -#include <private/qdrawhelper_p.h> #include <QtGui/qgenericpluginfactory.h> #include <QtGui/qstylehints.h> @@ -84,6 +84,7 @@ #include "private/qcursor_p.h" #include "private/qopenglcontext_p.h" #include "private/qinputdevicemanager_p.h" +#include "private/qtouchdevice_p.h" #include "private/qdnd_p.h" #include <qpa/qplatformthemefactory_p.h> @@ -817,19 +818,11 @@ bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blocking for (int i = 0; i < modalWindowList.count(); ++i) { QWindow *modalWindow = modalWindowList.at(i); - { - // check if the modal window is our window or a (transient) parent of our window - QWindow *w = window; - while (w) { - if (w == modalWindow) { - *blockingWindow = 0; - return false; - } - QWindow *p = w->parent(); - if (!p) - p = w->transientParent(); - w = p; - } + // A window is not blocked by another modal window if the two are + // the same, or if the window is a child of the modal window. + if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients)) { + *blockingWindow = 0; + return false; } Qt::WindowModality windowModality = modalWindow->modality(); @@ -936,15 +929,25 @@ QWindowList QGuiApplication::topLevelWindows() { const QWindowList &list = QGuiApplicationPrivate::window_list; QWindowList topLevelWindows; - for (int i = 0; i < list.size(); i++) { - if (!list.at(i)->parent() && list.at(i)->type() != Qt::Desktop) { - // Top windows of embedded QAxServers do not have QWindow parents, - // but they are not true top level windows, so do not include them. - const bool embedded = list.at(i)->handle() && list.at(i)->handle()->isEmbedded(); - if (!embedded) - topLevelWindows.prepend(list.at(i)); - } + for (int i = 0; i < list.size(); ++i) { + QWindow *window = list.at(i); + if (!window->isTopLevel()) + continue; + + // Desktop windows are special, as each individual desktop window + // will report that it's a top level window, but we don't want to + // include them in the application wide list of top level windows. + if (window->type() == Qt::Desktop) + continue; + + // Windows embedded in native windows do not have QWindow parents, + // but they are not true top level windows, so do not include them. + if (window->handle() && window->handle()->isEmbedded()) + continue; + + topLevelWindows.prepend(window); } + return topLevelWindows; } @@ -1519,7 +1522,8 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate() platform_theme = 0; delete platform_integration; platform_integration = 0; - delete m_gammaTables.load(); + delete m_a8ColorProfile.load(); + delete m_a32ColorProfile.load(); window_list.clear(); } @@ -1954,7 +1958,8 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo points << point; QEvent::Type type; - QList<QTouchEvent::TouchPoint> touchPoints = QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type); + QList<QTouchEvent::TouchPoint> touchPoints = + QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, QTouchDevicePrivate::get(m_fakeTouchDevice)->id, &type); QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, m_fakeTouchDevice, touchPoints, e->modifiers); fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic; @@ -2191,10 +2196,10 @@ void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate:: void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e) { - if (e->tlw.isNull()) + if (e->window.isNull()) return; - QWindow *window = e->tlw.data(); + QWindow *window = e->window.data(); if (!window) return; @@ -2559,7 +2564,10 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To Q_ASSERT(w.data() != 0); // make the *scene* functions return the same as the *screen* functions - touchPoint.d->sceneRect = touchPoint.screenRect(); + // Note: touchPoint is a reference to the one from activeTouchPoints, + // so we can modify it as long as we're careful NOT to call setters and + // otherwise NOT to cause the d-pointer to be detached. + touchPoint.d->scenePos = touchPoint.screenPos(); touchPoint.d->startScenePos = touchPoint.startScreenPos(); touchPoint.d->lastScenePos = touchPoint.lastScreenPos(); @@ -2615,8 +2623,8 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To QTouchEvent touchEvent(eventType, e->device, e->modifiers, - it.value().first, - it.value().second); + it.value().first, // state flags + it.value().second); // list of touchpoints touchEvent.setTimestamp(e->timestamp); touchEvent.setWindow(w); @@ -2625,13 +2633,14 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To QTouchEvent::TouchPoint &touchPoint = touchEvent._touchPoints[i]; // preserve the sub-pixel resolution - QRectF rect = touchPoint.screenRect(); - const QPointF screenPos = rect.center(); + const QPointF screenPos = touchPoint.screenPos(); const QPointF delta = screenPos - screenPos.toPoint(); - rect.moveCenter(w->mapFromGlobal(screenPos.toPoint()) + delta); - touchPoint.d->rect = rect; + touchPoint.d->pos = w->mapFromGlobal(screenPos.toPoint()) + delta; if (touchPoint.state() == Qt::TouchPointPressed) { + // touchPoint is actually a reference to one that is stored in activeTouchPoints, + // and we are now going to store the startPos and lastPos there, for the benefit + // of future moves and releases. It's important that the d-pointer is NOT detached. touchPoint.d->startPos = w->mapFromGlobal(touchPoint.startScreenPos().toPoint()) + delta; touchPoint.d->lastPos = w->mapFromGlobal(touchPoint.lastScreenPos().toPoint()) + delta; } @@ -3671,14 +3680,30 @@ void QGuiApplicationPrivate::notifyDragStarted(const QDrag *drag) } #endif -const QDrawHelperGammaTables *QGuiApplicationPrivate::gammaTables() +const QColorProfile *QGuiApplicationPrivate::colorProfileForA8Text() +{ +#ifdef Q_OS_WIN + QColorProfile *result = m_a8ColorProfile.load(); + if (!result){ + QColorProfile *cs = QColorProfile::fromGamma(2.31); // This is a hard-coded thing for Windows text rendering + if (!m_a8ColorProfile.testAndSetRelease(0, cs)) + delete cs; + result = m_a8ColorProfile.load(); + } + return result; +#else + return colorProfileForA32Text(); +#endif +} + +const QColorProfile *QGuiApplicationPrivate::colorProfileForA32Text() { - QDrawHelperGammaTables *result = m_gammaTables.load(); + QColorProfile *result = m_a32ColorProfile.load(); if (!result){ - QDrawHelperGammaTables *tables = new QDrawHelperGammaTables(fontSmoothingGamma); - if (!m_gammaTables.testAndSetRelease(0, tables)) - delete tables; - result = m_gammaTables.load(); + QColorProfile *cs = QColorProfile::fromGamma(fontSmoothingGamma); + if (!m_a32ColorProfile.testAndSetRelease(0, cs)) + delete cs; + result = m_a32ColorProfile.load(); } return result; } diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 0d62490c75..3804667ef3 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -66,10 +66,10 @@ QT_BEGIN_NAMESPACE +class QColorProfile; class QPlatformIntegration; class QPlatformTheme; class QPlatformDragQtResponse; -struct QDrawHelperGammaTables; #ifndef QT_NO_DRAGANDDROP class QDrag; #endif // QT_NO_DRAGANDDROP @@ -293,7 +293,8 @@ public: static QInputDeviceManager *inputDeviceManager(); - const QDrawHelperGammaTables *gammaTables(); + const QColorProfile *colorProfileForA8Text(); + const QColorProfile *colorProfileForA32Text(); // hook reimplemented in QApplication to apply the QStyle function on the QIcon virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; } @@ -317,7 +318,8 @@ private: static QGuiApplicationPrivate *self; static QTouchDevice *m_fakeTouchDevice; static int m_fakeMouseSourcePointId; - QAtomicPointer<QDrawHelperGammaTables> m_gammaTables; + QAtomicPointer<QColorProfile> m_a8ColorProfile; + QAtomicPointer<QColorProfile> m_a32ColorProfile; bool ownGlobalShareContext; diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h index 030edea880..2d3cbaf170 100644 --- a/src/gui/kernel/qplatformscreen.h +++ b/src/gui/kernel/qplatformscreen.h @@ -66,7 +66,6 @@ QT_BEGIN_NAMESPACE class QPlatformBackingStore; -class QPlatformOpenGLContext; class QPlatformScreenPrivate; class QPlatformWindow; class QPlatformCursor; diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 9c140f1d68..eef8b817fd 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -149,6 +149,11 @@ QT_BEGIN_NAMESPACE \value ContextMenuOnMouseRelease (bool) Whether the context menu should be shown on mouse release. + \value TouchDoubleTapDistance (int) The maximum distance in logical pixels which a touchpoint can travel + between taps in order for the tap sequence to be handled as a double tap. + The default value is double the MouseDoubleClickDistance, or 10 logical pixels + if that is not specified. + \sa themeHint(), QStyle::pixelMetric() */ @@ -533,6 +538,14 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint) } case WheelScrollLines: return QVariant(3); + case TouchDoubleTapDistance: + { + bool ok = false; + int dist = qEnvironmentVariableIntValue("QT_DBL_TAP_DIST", &ok); + if (!ok) + dist = defaultThemeHint(MouseDoubleClickDistance).toInt(&ok) * 2; + return QVariant(ok ? dist : 10); + } } return QVariant(); } diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index 686dbed4b1..4135e31517 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -114,7 +114,8 @@ public: ContextMenuOnMouseRelease, MousePressAndHoldInterval, MouseDoubleClickDistance, - WheelScrollLines + WheelScrollLines, + TouchDoubleTapDistance }; enum DialogType { diff --git a/src/gui/kernel/qsurface.cpp b/src/gui/kernel/qsurface.cpp index afe4cf93e1..3cdd11de8c 100644 --- a/src/gui/kernel/qsurface.cpp +++ b/src/gui/kernel/qsurface.cpp @@ -76,6 +76,8 @@ QT_BEGIN_NAMESPACE \value RasterGLSurface The surface can be rendered to using a software rasterizer, and also supports OpenGL. This surface type is intended for internal Qt use, and requires the use of private API. + \value OpenVGSurface The surface is an OpenVG compatible surface and can be used + in conjunction with OpenVG contexts. */ diff --git a/src/gui/kernel/qsurface.h b/src/gui/kernel/qsurface.h index d9ccdc096d..a96b7a6422 100644 --- a/src/gui/kernel/qsurface.h +++ b/src/gui/kernel/qsurface.h @@ -64,7 +64,8 @@ public: enum SurfaceType { RasterSurface, OpenGLSurface, - RasterGLSurface + RasterGLSurface, + OpenVGSurface, }; virtual ~QSurface(); diff --git a/src/gui/kernel/qtouchdevice.h b/src/gui/kernel/qtouchdevice.h index 0fb24e47bf..c98aa69236 100644 --- a/src/gui/kernel/qtouchdevice.h +++ b/src/gui/kernel/qtouchdevice.h @@ -87,6 +87,7 @@ public: private: QTouchDevicePrivate *d; + friend class QTouchDevicePrivate; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QTouchDevice::Capabilities) diff --git a/src/gui/kernel/qtouchdevice_p.h b/src/gui/kernel/qtouchdevice_p.h index 203d9fca74..18d2af46a7 100644 --- a/src/gui/kernel/qtouchdevice_p.h +++ b/src/gui/kernel/qtouchdevice_p.h @@ -64,16 +64,21 @@ public: : type(QTouchDevice::TouchScreen), caps(QTouchDevice::Position), maxTouchPoints(1) - { } + { + static quint8 nextId = 2; // device 0 is not used, device 1 is for mouse device + id = nextId++; + } QTouchDevice::DeviceType type; QTouchDevice::Capabilities caps; QString name; int maxTouchPoints; + quint8 id; static void registerDevice(const QTouchDevice *dev); static void unregisterDevice(const QTouchDevice *dev); static bool isRegistered(const QTouchDevice *dev); + static QTouchDevicePrivate *get(QTouchDevice *q) { return q->d; } }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 94a34b5c27..93edfe6331 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -343,6 +343,30 @@ void QWindowPrivate::updateVisibility() emit q->visibilityChanged(visibility); } +void QWindowPrivate::updateSiblingPosition(SiblingPosition position) +{ + Q_Q(QWindow); + + if (!q->parent()) + return; + + QObjectList &siblings = q->parent()->d_ptr->children; + + const int siblingCount = siblings.size() - 1; + if (siblingCount == 0) + return; + + const int currentPosition = siblings.indexOf(q); + Q_ASSERT(currentPosition >= 0); + + const int targetPosition = position == PositionTop ? siblingCount : 0; + + if (currentPosition == targetPosition) + return; + + siblings.move(currentPosition, targetPosition); +} + inline bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen) const { Q_Q(const QWindow); @@ -605,6 +629,22 @@ WId QWindow::winId() const return d->platformWindow->winId(); } + /*! + Returns the parent window, if any. + + If \a mode is IncludeTransients, then the transient parent is returned + if there is no parent. + + A window without a parent is known as a top level window. + + \since 5.9 +*/ +QWindow *QWindow::parent(AncestorMode mode) const +{ + Q_D(const QWindow); + return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() : nullptr); +} + /*! Returns the parent window, if any. @@ -797,10 +837,15 @@ QSurfaceFormat QWindow::format() const The actual window flags might differ from the flags set with setFlags() if the requested flags could not be fulfilled. + + \sa setFlag() */ void QWindow::setFlags(Qt::WindowFlags flags) { Q_D(QWindow); + if (d->windowFlags == flags) + return; + if (d->platformWindow) d->platformWindow->setWindowFlags(flags); d->windowFlags = flags; @@ -813,6 +858,23 @@ Qt::WindowFlags QWindow::flags() const } /*! + \since 5.9 + + Sets the window flag \a flag on this window if \a on is true; + otherwise clears the flag. + + \sa setFlags(), flags(), type() +*/ +void QWindow::setFlag(Qt::WindowType flag, bool on) +{ + Q_D(QWindow); + if (on) + setFlags(d->windowFlags | flag); + else + setFlags(d->windowFlags & ~flag); +} + +/*! Returns the type of the window. This returns the part of the window flags that represents @@ -920,6 +982,9 @@ QIcon QWindow::icon() const void QWindow::raise() { Q_D(QWindow); + + d->updateSiblingPosition(QWindowPrivate::PositionTop); + if (d->platformWindow) d->platformWindow->raise(); } @@ -932,6 +997,9 @@ void QWindow::raise() void QWindow::lower() { Q_D(QWindow); + + d->updateSiblingPosition(QWindowPrivate::PositionBottom); + if (d->platformWindow) d->platformWindow->lower(); } @@ -1065,11 +1133,10 @@ bool QWindow::isActive() const if (focus == this) return true; - if (!parent() && !transientParent()) { + if (QWindow *p = parent(IncludeTransients)) + return p->isActive(); + else return isAncestorOf(focus); - } else { - return (parent() && parent()->isActive()) || (transientParent() && transientParent()->isActive()); - } } /*! @@ -1233,8 +1300,10 @@ bool QWindow::isAncestorOf(const QWindow *child, AncestorMode mode) const if (child->parent() == this || (mode == IncludeTransients && child->transientParent() == this)) return true; - return (child->parent() && isAncestorOf(child->parent(), mode)) - || (mode == IncludeTransients && child->transientParent() && isAncestorOf(child->transientParent(), mode)); + if (child->parent(mode) && isAncestorOf(child->parent(mode), mode)) + return true; + + return false; } /*! @@ -1455,6 +1524,8 @@ void QWindow::setSizeIncrement(const QSize &size) Sets the geometry of the window, excluding its window frame, to a rectangle constructed from \a posx, \a posy, \a w and \a h. + The geometry is in relation to the virtualGeometry() of its screen. + \sa geometry() */ void QWindow::setGeometry(int posx, int posy, int w, int h) @@ -1465,6 +1536,8 @@ void QWindow::setGeometry(int posx, int posy, int w, int h) /*! \brief Sets the geometry of the window, excluding its window frame, to \a rect. + The geometry is in relation to the virtualGeometry() of its screen. + \sa geometry() */ void QWindow::setGeometry(const QRect &rect) @@ -1526,6 +1599,8 @@ QScreen *QWindowPrivate::screenForGeometry(const QRect &newGeometry) /*! Returns the geometry of the window, excluding its window frame. + The geometry is in relation to the virtualGeometry() of its screen. + \sa frameMargins(), frameGeometry() */ QRect QWindow::geometry() const @@ -1552,6 +1627,8 @@ QMargins QWindow::frameMargins() const /*! Returns the geometry of the window, including its window frame. + The geometry is in relation to the virtualGeometry() of its screen. + \sa geometry(), frameMargins() */ QRect QWindow::frameGeometry() const @@ -1584,6 +1661,8 @@ QPoint QWindow::framePosition() const /*! Sets the upper left position of the window (\a point) including its window frame. + The position is in relation to the virtualGeometry() of its screen. + \sa setGeometry(), frameGeometry() */ void QWindow::setFramePosition(const QPoint &point) @@ -1601,6 +1680,8 @@ void QWindow::setFramePosition(const QPoint &point) /*! \brief set the position of the window on the desktop to \a pt + The position is in relation to the virtualGeometry() of its screen. + \sa position() */ void QWindow::setPosition(const QPoint &pt) @@ -1611,6 +1692,8 @@ void QWindow::setPosition(const QPoint &pt) /*! \brief set the position of the window on the desktop to \a posx, \a posy + The position is in relation to the virtualGeometry() of its screen. + \sa position() */ void QWindow::setPosition(int posx, int posy) @@ -1787,8 +1870,9 @@ QScreen *QWindow::screen() const If the window has been created, it will be recreated on the \a newScreen. - Note that if the screen is part of a virtual desktop of multiple screens, - the window can appear on any of the screens returned by QScreen::virtualSiblings(). + \note If the screen is part of a virtual desktop of multiple screens, + the window will not move automatically to \a newScreen. To place the + window relative to the screen, use the screen's topLeft() position. This function only works for top level windows. @@ -2377,6 +2461,20 @@ QPoint QWindow::mapFromGlobal(const QPoint &pos) const return pos - d->globalPosition(); } +QPoint QWindowPrivate::globalPosition() const +{ + Q_Q(const QWindow); + QPoint offset = q->position(); + for (const QWindow *p = q->parent(); p; p = p->parent()) { + if (p->type() != Qt::ForeignWindow) { + offset += p->position(); + } else { // Use mapToGlobal() for foreign windows + offset += p->mapToGlobal(QPoint(0, 0)); + break; + } + } + return offset; +} Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window) { @@ -2416,10 +2514,7 @@ QWindow *QWindowPrivate::topLevelWindow() const QWindow *window = const_cast<QWindow *>(q); while (window) { - QWindow *parent = window->parent(); - if (!parent) - parent = window->transientParent(); - + QWindow *parent = window->parent(QWindow::IncludeTransients); if (!parent) break; diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h index bf25cf64c9..2883749d2e 100644 --- a/src/gui/kernel/qwindow.h +++ b/src/gui/kernel/qwindow.h @@ -132,6 +132,12 @@ public: }; Q_ENUM(Visibility) + enum AncestorMode { + ExcludeTransients, + IncludeTransients + }; + Q_ENUM(AncestorMode) + explicit QWindow(QScreen *screen = Q_NULLPTR); explicit QWindow(QWindow *parent); virtual ~QWindow(); @@ -148,7 +154,8 @@ public: WId winId() const; - QWindow *parent() const; + QWindow *parent(AncestorMode mode) const; + QWindow *parent() const; // ### Qt6: Merge with above void setParent(QWindow *parent); bool isTopLevel() const; @@ -163,6 +170,7 @@ public: void setFlags(Qt::WindowFlags flags); Qt::WindowFlags flags() const; + void setFlag(Qt::WindowType, bool on = true); Qt::WindowType type() const; QString title() const; @@ -186,11 +194,6 @@ public: void setTransientParent(QWindow *parent); QWindow *transientParent() const; - enum AncestorMode { - ExcludeTransients, - IncludeTransients - }; - bool isAncestorOf(const QWindow *child, AncestorMode mode = IncludeTransients) const; bool isExposed() const; diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h index b8a9f5d3de..95c6abf428 100644 --- a/src/gui/kernel/qwindow_p.h +++ b/src/gui/kernel/qwindow_p.h @@ -123,19 +123,7 @@ public: void deliverUpdateRequest(); - QPoint globalPosition() const { - Q_Q(const QWindow); - QPoint offset = q->position(); - for (const QWindow *p = q->parent(); p; p = p->parent()) { - if (p->type() != Qt::ForeignWindow) { - offset += p->position(); - } else { // QTBUG-43252, mapToGlobal() for foreign children. - offset += p->mapToGlobal(QPoint(0, 0)); - break; - } - } - return offset; - } + QPoint globalPosition() const; QWindow *topLevelWindow() const; @@ -144,6 +132,9 @@ public: void updateVisibility(); void _q_clearAlert(); + enum SiblingPosition { PositionTop, PositionBottom }; + void updateSiblingPosition(SiblingPosition); + bool windowRecreationRequired(QScreen *newScreen) const; void create(bool recursive); void setTopLevelScreen(QScreen *newScreen, bool recreate); diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 667304859e..813b0f72bb 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -59,41 +59,57 @@ QWaitCondition QWindowSystemInterfacePrivate::eventsFlushed; QMutex QWindowSystemInterfacePrivate::flushEventMutex; QAtomicInt QWindowSystemInterfacePrivate::eventAccepted; QWindowSystemEventHandler *QWindowSystemInterfacePrivate::eventHandler; - -//------------------------------------------------------------ -// -// Callback functions for plugins: -// - QWindowSystemInterfacePrivate::WindowSystemEventList QWindowSystemInterfacePrivate::windowSystemEventQueue; extern QPointer<QWindow> qt_last_mouse_receiver; + +// ------------------- QWindowSystemInterfacePrivate ------------------- + /*! Handles a window system event asynchronously by posting the event to Qt Gui. - \sa postWindowSystemEvent() + This function posts the event on the window system event queue and wakes the + Gui event dispatcher. Qt Gui will then handle the event asynchonously at a + later point. */ template<> bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::AsynchronousDelivery>(WindowSystemEvent *ev) { - QWindowSystemInterfacePrivate::postWindowSystemEvent(ev); + windowSystemEventQueue.append(ev); + if (QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher()) + dispatcher->wakeUp(); return true; } /*! Handles a window system event synchronously. + Qt Gui will process the event immediately. The return value indicates if Qt + accepted the event. + If the event is delivered from another thread than the Qt main thread the window system event queue is flushed, which may deliver other events as well. - - \sa processWindowSystemEvent() */ template<> bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::SynchronousDelivery>(WindowSystemEvent *ev) { - return QWindowSystemInterfacePrivate::processWindowSystemEvent(ev); + bool accepted = true; + if (QThread::currentThread() == QGuiApplication::instance()->thread()) { + // Process the event immediately on the current thread and return the accepted state. + QGuiApplicationPrivate::processWindowSystemEvent(ev); + accepted = ev->eventAccepted; + delete ev; + } else { + // Post the event on the Qt main thread queue and flush the queue. + // This will wake up the Gui thread which will process the event. + // Return the accepted state for the last event on the queue, + // which is the event posted by this function. + handleWindowSystemEvent<QWindowSystemInterface::AsynchronousDelivery>(ev); + accepted = QWindowSystemInterface::flushWindowSystemEvents(); + } + return accepted; } /*! @@ -109,7 +125,7 @@ bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterfa than the Qt main thread the window system event queue is flushed, which may deliver other events as well. - \sa flushWindowSystemEvents(), processWindowSystemEvent(), setSynchronousWindowSystemEvents() + \sa flushWindowSystemEvents(), setSynchronousWindowSystemEvents() */ template<> bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::DefaultDelivery>(QWindowSystemInterfacePrivate::WindowSystemEvent *ev) @@ -120,6 +136,59 @@ bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterfa return handleWindowSystemEvent<QWindowSystemInterface::AsynchronousDelivery>(ev); } +int QWindowSystemInterfacePrivate::windowSystemEventsQueued() +{ + return windowSystemEventQueue.count(); +} + +QWindowSystemInterfacePrivate::WindowSystemEvent * QWindowSystemInterfacePrivate::getWindowSystemEvent() +{ + return windowSystemEventQueue.takeFirstOrReturnNull(); +} + +QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() +{ + return windowSystemEventQueue.takeFirstNonUserInputOrReturnNull(); +} + +QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::peekWindowSystemEvent(EventType t) +{ + return windowSystemEventQueue.peekAtFirstOfType(t); +} + +void QWindowSystemInterfacePrivate::removeWindowSystemEvent(WindowSystemEvent *event) +{ + windowSystemEventQueue.remove(event); +} + +void QWindowSystemInterfacePrivate::installWindowSystemEventHandler(QWindowSystemEventHandler *handler) +{ + if (!eventHandler) + eventHandler = handler; +} + +void QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(QWindowSystemEventHandler *handler) +{ + if (eventHandler == handler) + eventHandler = 0; +} + +QWindowSystemEventHandler::~QWindowSystemEventHandler() +{ + QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(this); +} + +bool QWindowSystemEventHandler::sendEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e) +{ + QGuiApplicationPrivate::processWindowSystemEvent(e); + return true; +} + +//------------------------------------------------------------ +// +// Callback functions for plugins: +// + #define QT_DEFINE_QPA_EVENT_HANDLER(ReturnType, HandlerName, ...) \ template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::DefaultDelivery>(__VA_ARGS__); \ template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::SynchronousDelivery>(__VA_ARGS__); \ @@ -138,17 +207,17 @@ bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterfa until sendWindowSystemEvents() is called by the event dispatcher. */ -QT_DEFINE_QPA_EVENT_HANDLER(void, handleEnterEvent, QWindow *tlw, const QPointF &local, const QPointF &global) +QT_DEFINE_QPA_EVENT_HANDLER(void, handleEnterEvent, QWindow *window, const QPointF &local, const QPointF &global) { - if (tlw) { - QWindowSystemInterfacePrivate::EnterEvent *e = new QWindowSystemInterfacePrivate::EnterEvent(tlw, local, global); + if (window) { + QWindowSystemInterfacePrivate::EnterEvent *e = new QWindowSystemInterfacePrivate::EnterEvent(window, local, global); QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e); } } -QT_DEFINE_QPA_EVENT_HANDLER(void, handleLeaveEvent, QWindow *tlw) +QT_DEFINE_QPA_EVENT_HANDLER(void, handleLeaveEvent, QWindow *window) { - QWindowSystemInterfacePrivate::LeaveEvent *e = new QWindowSystemInterfacePrivate::LeaveEvent(tlw); + QWindowSystemInterfacePrivate::LeaveEvent *e = new QWindowSystemInterfacePrivate::LeaveEvent(window); QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e); } @@ -165,24 +234,24 @@ void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leav handleEnterEvent(enter, local, global); } -QT_DEFINE_QPA_EVENT_HANDLER(void, handleWindowActivated, QWindow *tlw, Qt::FocusReason r) +QT_DEFINE_QPA_EVENT_HANDLER(void, handleWindowActivated, QWindow *window, Qt::FocusReason r) { QWindowSystemInterfacePrivate::ActivatedWindowEvent *e = - new QWindowSystemInterfacePrivate::ActivatedWindowEvent(tlw, r); + new QWindowSystemInterfacePrivate::ActivatedWindowEvent(window, r); QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e); } -void QWindowSystemInterface::handleWindowStateChanged(QWindow *tlw, Qt::WindowState newState) +void QWindowSystemInterface::handleWindowStateChanged(QWindow *window, Qt::WindowState newState) { QWindowSystemInterfacePrivate::WindowStateChangedEvent *e = - new QWindowSystemInterfacePrivate::WindowStateChangedEvent(tlw, newState); + new QWindowSystemInterfacePrivate::WindowStateChangedEvent(window, newState); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } -void QWindowSystemInterface::handleWindowScreenChanged(QWindow *tlw, QScreen *screen) +void QWindowSystemInterface::handleWindowScreenChanged(QWindow *window, QScreen *screen) { QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e = - new QWindowSystemInterfacePrivate::WindowScreenChangedEvent(tlw, screen); + new QWindowSystemInterfacePrivate::WindowScreenChangedEvent(window, screen); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } @@ -197,9 +266,9 @@ void QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationState /*! If \a oldRect is null, Qt will use the previously reported geometry instead. */ -QT_DEFINE_QPA_EVENT_HANDLER(void, handleGeometryChange, QWindow *tlw, const QRect &newRect, const QRect &oldRect) +QT_DEFINE_QPA_EVENT_HANDLER(void, handleGeometryChange, QWindow *window, const QRect &newRect, const QRect &oldRect) { - QWindowSystemInterfacePrivate::GeometryChangeEvent *e = new QWindowSystemInterfacePrivate::GeometryChangeEvent(tlw, QHighDpi::fromNativePixels(newRect, tlw), QHighDpi::fromNativePixels(oldRect, tlw)); + QWindowSystemInterfacePrivate::GeometryChangeEvent *e = new QWindowSystemInterfacePrivate::GeometryChangeEvent(window, QHighDpi::fromNativePixels(newRect, window), QHighDpi::fromNativePixels(oldRect, window)); QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e); } @@ -211,18 +280,18 @@ QWindowSystemInterfacePrivate::ExposeEvent::ExposeEvent(QWindow *window, const Q { } -QT_DEFINE_QPA_EVENT_HANDLER(void, handleExposeEvent, QWindow *tlw, const QRegion ®ion) +QT_DEFINE_QPA_EVENT_HANDLER(void, handleExposeEvent, QWindow *window, const QRegion ®ion) { QWindowSystemInterfacePrivate::ExposeEvent *e = - new QWindowSystemInterfacePrivate::ExposeEvent(tlw, QHighDpi::fromNativeLocalExposedRegion(region, tlw)); + new QWindowSystemInterfacePrivate::ExposeEvent(window, QHighDpi::fromNativeLocalExposedRegion(region, window)); QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e); } -void QWindowSystemInterface::handleCloseEvent(QWindow *tlw, bool *accepted) +void QWindowSystemInterface::handleCloseEvent(QWindow *window, bool *accepted) { - if (tlw) { + if (window) { QWindowSystemInterfacePrivate::CloseEvent *e = - new QWindowSystemInterfacePrivate::CloseEvent(tlw, accepted); + new QWindowSystemInterfacePrivate::CloseEvent(window, accepted); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } } @@ -232,35 +301,35 @@ void QWindowSystemInterface::handleCloseEvent(QWindow *tlw, bool *accepted) \a w == 0 means that the event is in global coords only, \a local will be ignored in this case */ -QT_DEFINE_QPA_EVENT_HANDLER(void, handleMouseEvent, QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b, +QT_DEFINE_QPA_EVENT_HANDLER(void, handleMouseEvent, QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods, Qt::MouseEventSource source) { unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - handleMouseEvent<Delivery>(w, time, local, global, b, mods, source); + handleMouseEvent<Delivery>(window, time, local, global, b, mods, source); } -QT_DEFINE_QPA_EVENT_HANDLER(void, handleMouseEvent, QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b, +QT_DEFINE_QPA_EVENT_HANDLER(void, handleMouseEvent, QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods, Qt::MouseEventSource source) { QWindowSystemInterfacePrivate::MouseEvent * e = - new QWindowSystemInterfacePrivate::MouseEvent(w, timestamp, QHighDpi::fromNativeLocalPosition(local, w), QHighDpi::fromNativePixels(global, w), b, mods, source); + new QWindowSystemInterfacePrivate::MouseEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), b, mods, source); QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e); } -void QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b, +void QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods, Qt::MouseEventSource source) { const unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - handleFrameStrutMouseEvent(w, time, local, global, b, mods, source); + handleFrameStrutMouseEvent(window, time, local, global, b, mods, source); } -void QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b, +void QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods, Qt::MouseEventSource source) { QWindowSystemInterfacePrivate::MouseEvent * e = - new QWindowSystemInterfacePrivate::MouseEvent(w, timestamp, + new QWindowSystemInterfacePrivate::MouseEvent(window, timestamp, QWindowSystemInterfacePrivate::FrameStrutMouse, - QHighDpi::fromNativeLocalPosition(local, w), QHighDpi::fromNativePixels(global, w), b, mods, source); + QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), b, mods, source); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } @@ -309,35 +378,35 @@ bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestam #endif } -QT_DEFINE_QPA_EVENT_HANDLER(bool, handleKeyEvent, QWindow *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count) { +QT_DEFINE_QPA_EVENT_HANDLER(bool, handleKeyEvent, QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count) { unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - return handleKeyEvent<Delivery>(w, time, t, k, mods, text, autorep, count); + return handleKeyEvent<Delivery>(window, time, t, k, mods, text, autorep, count); } -QT_DEFINE_QPA_EVENT_HANDLER(bool, handleKeyEvent, QWindow *tlw, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count) +QT_DEFINE_QPA_EVENT_HANDLER(bool, handleKeyEvent, QWindow *window, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count) { #if defined(Q_OS_OSX) - if (t == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(tlw, timestamp, k, mods, 0, 0, 0, text, autorep, count)) + if (t == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(window, timestamp, k, mods, 0, 0, 0, text, autorep, count)) return true; #endif QWindowSystemInterfacePrivate::KeyEvent * e = - new QWindowSystemInterfacePrivate::KeyEvent(tlw, timestamp, t, k, mods, text, autorep, count); + new QWindowSystemInterfacePrivate::KeyEvent(window, timestamp, t, k, mods, text, autorep, count); return QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e); } -bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *w, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, +bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString& text, bool autorep, ushort count, bool tryShortcutOverride) { unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - return handleExtendedKeyEvent(w, time, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, + return handleExtendedKeyEvent(window, time, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count, tryShortcutOverride); } -bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *tlw, ulong timestamp, QEvent::Type type, int key, +bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, ulong timestamp, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, @@ -345,7 +414,7 @@ bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *tlw, ulong timestam ushort count, bool tryShortcutOverride) { #if defined(Q_OS_OSX) - if (tryShortcutOverride && type == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(tlw, + if (tryShortcutOverride && type == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(window, timestamp, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count)) { return true; } @@ -354,29 +423,36 @@ bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *tlw, ulong timestam #endif QWindowSystemInterfacePrivate::KeyEvent * e = - new QWindowSystemInterfacePrivate::KeyEvent(tlw, timestamp, type, key, modifiers, + new QWindowSystemInterfacePrivate::KeyEvent(window, timestamp, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count); return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } -void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods) { +QWindowSystemInterfacePrivate::WheelEvent::WheelEvent(QWindow *window, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD, + QPoint angleD, int qt4D, Qt::Orientation qt4O, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource src, bool inverted) + : InputEvent(window, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), + qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src), inverted(inverted) +{ +} + +void QWindowSystemInterface::handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods) { unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - handleWheelEvent(w, time, local, global, d, o, mods); + handleWheelEvent(window, time, local, global, d, o, mods); } -void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods) +void QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods) { QPoint point = (o == Qt::Vertical) ? QPoint(0, d) : QPoint(d, 0); - handleWheelEvent(tlw, timestamp, local, global, QPoint(), point, mods); + handleWheelEvent(window, timestamp, local, global, QPoint(), point, mods); } -void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source) +void QWindowSystemInterface::handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source) { unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - handleWheelEvent(w, time, local, global, pixelDelta, angleDelta, mods, phase, source); + handleWheelEvent(window, time, local, global, pixelDelta, angleDelta, mods, phase, source); } -void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, +void QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source, bool invertedScrolling) { // Qt 4 sends two separate wheel events for horizontal and vertical @@ -395,7 +471,7 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, con // Simple case: vertical deltas only: if (angleDelta.y() != 0 && angleDelta.x() == 0) { - e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, + e = new QWindowSystemInterfacePrivate::WheelEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); return; @@ -403,7 +479,7 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, con // Simple case: horizontal deltas only: if (angleDelta.y() == 0 && angleDelta.x() != 0) { - e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling); + e = new QWindowSystemInterfacePrivate::WheelEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); return; } @@ -411,106 +487,65 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, con // Both horizontal and vertical deltas: Send two wheel events. // The first event contains the Qt 5 pixel and angle delta as points, // and in addition the Qt 4 compatibility vertical angle delta. - e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling); + e = new QWindowSystemInterfacePrivate::WheelEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); // The second event contains null pixel and angle points and the // Qt 4 compatibility horizontal angle delta. - e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling); + e = new QWindowSystemInterfacePrivate::WheelEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } -int QWindowSystemInterfacePrivate::windowSystemEventsQueued() -{ - return windowSystemEventQueue.count(); -} - -QWindowSystemInterfacePrivate::WindowSystemEvent * QWindowSystemInterfacePrivate::getWindowSystemEvent() +void QWindowSystemInterface::registerTouchDevice(const QTouchDevice *device) { - return windowSystemEventQueue.takeFirstOrReturnNull(); + QTouchDevicePrivate::registerDevice(device); } -QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() +void QWindowSystemInterface::unregisterTouchDevice(const QTouchDevice *device) { - return windowSystemEventQueue.takeFirstNonUserInputOrReturnNull(); + QTouchDevicePrivate::unregisterDevice(device); } -QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::peekWindowSystemEvent(EventType t) +bool QWindowSystemInterface::isTouchDeviceRegistered(const QTouchDevice *device) { - return windowSystemEventQueue.peekAtFirstOfType(t); + return QTouchDevicePrivate::isRegistered(device); } -void QWindowSystemInterfacePrivate::removeWindowSystemEvent(WindowSystemEvent *event) -{ - windowSystemEventQueue.remove(event); -} +static int g_nextPointId = 1; -/*! - Posts a window system event to be handled asynchronously by Qt Gui. - - This function posts the event on the window system event queue and wakes the - Gui event dispatcher. Qt Gui will then handle the event asynchonously at a - later point. - - \sa flushWindowSystemEvents(), processWindowSystemEvent(), handleWindowSystemEvent() -*/ -void QWindowSystemInterfacePrivate::postWindowSystemEvent(WindowSystemEvent *ev) -{ - windowSystemEventQueue.append(ev); - QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher(); - if (dispatcher) - dispatcher->wakeUp(); -} +// map from device-independent point id (arbitrary) to "Qt point" ids +typedef QMap<quint64, int> PointIdMap; +Q_GLOBAL_STATIC(PointIdMap, g_pointIdMap) /*! - Processes a window system event synchronously. - - Qt Gui will process the event immediately. The return value indicates if Qt - accepted the event. - - If the event is delivered from another thread than the Qt main thread the - window system event queue is flushed, which may deliver other events as - well. - - \sa flushWindowSystemEvents(), postWindowSystemEvent(), handleWindowSystemEvent() + \internal + This function maps potentially arbitrary point ids \a pointId in the 32 bit + value space to start from 1 and increase incrementally for each touch point + held down. If all touch points are released it will reset the id back to 1 + for the following touch point. + + We can then assume that the touch points ids will never become too large, + and it will then put the device identifier \a deviceId in the upper 8 bits. + This leaves us with max 255 devices, and 16.7M taps without full release + before we run out of value space. */ -bool QWindowSystemInterfacePrivate::processWindowSystemEvent(WindowSystemEvent *ev) -{ - bool accepted = true; - if (QThread::currentThread() == QGuiApplication::instance()->thread()) { - // Process the event immediately on the current thread and return the accepted state. - QGuiApplicationPrivate::processWindowSystemEvent(ev); - accepted = ev->eventAccepted; - delete ev; +static int acquireCombinedPointId(quint8 deviceId, int pointId) +{ + quint64 combinedId64 = (quint64(deviceId) << 32) + pointId; + auto it = g_pointIdMap->constFind(combinedId64); + int uid; + if (it == g_pointIdMap->constEnd()) { + uid = g_nextPointId++; + g_pointIdMap->insert(combinedId64, uid); } else { - // Post the event on the Qt main thread queue and flush the queue. - // This will wake up the Gui thread which will process the event. - // Return the accepted state for the last event on the queue, - // which is the event posted by this function. - postWindowSystemEvent(ev); - accepted = QWindowSystemInterface::flushWindowSystemEvents(); + uid = *it; } - return accepted; -} - -void QWindowSystemInterface::registerTouchDevice(const QTouchDevice *device) -{ - QTouchDevicePrivate::registerDevice(device); -} - -void QWindowSystemInterface::unregisterTouchDevice(const QTouchDevice *device) -{ - QTouchDevicePrivate::unregisterDevice(device); -} - -bool QWindowSystemInterface::isTouchDeviceRegistered(const QTouchDevice *device) -{ - return QTouchDevicePrivate::isRegistered(device); + return (deviceId << 24) + uid; } QList<QTouchEvent::TouchPoint> QWindowSystemInterfacePrivate::fromNativeTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points, - const QWindow *window, + const QWindow *window, quint8 deviceId, QEvent::Type *type) { QList<QTouchEvent::TouchPoint> touchPoints; @@ -521,7 +556,7 @@ QList<QTouchEvent::TouchPoint> QList<QWindowSystemInterface::TouchPoint>::const_iterator point = points.constBegin(); QList<QWindowSystemInterface::TouchPoint>::const_iterator end = points.constEnd(); while (point != end) { - p.setId(point->id); + p.setId(acquireCombinedPointId(deviceId, point->id)); if (point->uniqueId >= 0) p.setUniqueId(point->uniqueId); p.setPressure(point->pressure); @@ -554,6 +589,11 @@ QList<QTouchEvent::TouchPoint> *type = QEvent::TouchEnd; } + if (states == Qt::TouchPointReleased) { + g_nextPointId = 1; + g_pointIdMap->clear(); + } + return touchPoints; } @@ -578,14 +618,14 @@ QList<QWindowSystemInterface::TouchPoint> return newList; } -QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchEvent, QWindow *w, QTouchDevice *device, +QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchEvent, QWindow *window, QTouchDevice *device, const QList<TouchPoint> &points, Qt::KeyboardModifiers mods) { unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - handleTouchEvent<Delivery>(w, time, device, points, mods); + handleTouchEvent<Delivery>(window, time, device, points, mods); } -QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchEvent, QWindow *tlw, ulong timestamp, QTouchDevice *device, +QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchEvent, QWindow *window, ulong timestamp, QTouchDevice *device, const QList<TouchPoint> &points, Qt::KeyboardModifiers mods) { if (!points.size()) // Touch events must have at least one point @@ -595,25 +635,26 @@ QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchEvent, QWindow *tlw, ulong timestam return; QEvent::Type type; - QList<QTouchEvent::TouchPoint> touchPoints = QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, tlw, &type); + QList<QTouchEvent::TouchPoint> touchPoints = + QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, QTouchDevicePrivate::get(device)->id, &type); QWindowSystemInterfacePrivate::TouchEvent *e = - new QWindowSystemInterfacePrivate::TouchEvent(tlw, timestamp, type, device, touchPoints, mods); + new QWindowSystemInterfacePrivate::TouchEvent(window, timestamp, type, device, touchPoints, mods); QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e); } -QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchCancelEvent, QWindow *w, QTouchDevice *device, +QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchCancelEvent, QWindow *window, QTouchDevice *device, Qt::KeyboardModifiers mods) { unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - handleTouchCancelEvent<Delivery>(w, time, device, mods); + handleTouchCancelEvent<Delivery>(window, time, device, mods); } -QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchCancelEvent, QWindow *w, ulong timestamp, QTouchDevice *device, +QT_DEFINE_QPA_EVENT_HANDLER(void, handleTouchCancelEvent, QWindow *window, ulong timestamp, QTouchDevice *device, Qt::KeyboardModifiers mods) { QWindowSystemInterfacePrivate::TouchEvent *e = - new QWindowSystemInterfacePrivate::TouchEvent(w, timestamp, QEvent::TouchCancel, device, + new QWindowSystemInterfacePrivate::TouchEvent(window, timestamp, QEvent::TouchCancel, device, QList<QTouchEvent::TouchPoint>(), mods); QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e); } @@ -646,113 +687,21 @@ void QWindowSystemInterface::handleScreenRefreshRateChange(QScreen *screen, qrea QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } -void QWindowSystemInterface::handleThemeChange(QWindow *tlw) +void QWindowSystemInterface::handleThemeChange(QWindow *window) { - QWindowSystemInterfacePrivate::ThemeChangeEvent *e = new QWindowSystemInterfacePrivate::ThemeChangeEvent(tlw); + QWindowSystemInterfacePrivate::ThemeChangeEvent *e = new QWindowSystemInterfacePrivate::ThemeChangeEvent(window); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } -void QWindowSystemInterface::deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags) -{ - Q_ASSERT(QThread::currentThread() == QGuiApplication::instance()->thread()); - - QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex); - sendWindowSystemEvents(flags); - QWindowSystemInterfacePrivate::eventsFlushed.wakeOne(); -} - -/*! - Make Qt Gui process all events on the event queue immediately. Return the - accepted state for the last event on the queue. -*/ -bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags) -{ - const int count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count(); - if (!count) - return false; - if (!QGuiApplication::instance()) { - qWarning().nospace() - << "QWindowSystemInterface::flushWindowSystemEvents() invoked after " - "QGuiApplication destruction, discarding " << count << " events."; - QWindowSystemInterfacePrivate::windowSystemEventQueue.clear(); - return false; - } - if (QThread::currentThread() != QGuiApplication::instance()->thread()) { - // Post a FlushEvents event which will trigger a call back to - // deferredFlushWindowSystemEvents from the Gui thread. - QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex); - QWindowSystemInterfacePrivate::FlushEventsEvent *e = new QWindowSystemInterfacePrivate::FlushEventsEvent(flags); - QWindowSystemInterfacePrivate::handleWindowSystemEvent<AsynchronousDelivery>(e); - QWindowSystemInterfacePrivate::eventsFlushed.wait(&QWindowSystemInterfacePrivate::flushEventMutex); - } else { - sendWindowSystemEvents(flags); - } - return QWindowSystemInterfacePrivate::eventAccepted.load() > 0; -} - -bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags) -{ - int nevents = 0; - - while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) { - QWindowSystemInterfacePrivate::WindowSystemEvent *event = - (flags & QEventLoop::ExcludeUserInputEvents) ? - QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() : - QWindowSystemInterfacePrivate::getWindowSystemEvent(); - if (!event) - break; - - if (QWindowSystemInterfacePrivate::eventHandler) { - if (QWindowSystemInterfacePrivate::eventHandler->sendEvent(event)) - nevents++; - } else { - nevents++; - QGuiApplicationPrivate::processWindowSystemEvent(event); - } - - // Record the accepted state for the processed event - // (excluding flush events). This state can then be - // returned by flushWindowSystemEvents(). - if (event->type != QWindowSystemInterfacePrivate::FlushEvents) - QWindowSystemInterfacePrivate::eventAccepted.store(event->eventAccepted); - - delete event; - } - - return (nevents > 0); -} - -void QWindowSystemInterfacePrivate::installWindowSystemEventHandler(QWindowSystemEventHandler *handler) -{ - if (!eventHandler) - eventHandler = handler; -} - -void QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(QWindowSystemEventHandler *handler) -{ - if (eventHandler == handler) - eventHandler = 0; -} - -void QWindowSystemInterface::setSynchronousWindowSystemEvents(bool enable) -{ - QWindowSystemInterfacePrivate::synchronousWindowSystemEvents = enable; -} - -int QWindowSystemInterface::windowSystemEventsQueued() -{ - return QWindowSystemInterfacePrivate::windowSystemEventsQueued(); -} - #ifndef QT_NO_DRAGANDDROP -QPlatformDragQtResponse QWindowSystemInterface::handleDrag(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions) +QPlatformDragQtResponse QWindowSystemInterface::handleDrag(QWindow *window, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions) { - return QGuiApplicationPrivate::processDrag(w, dropData, QHighDpi::fromNativeLocalPosition(p, w) ,supportedActions); + return QGuiApplicationPrivate::processDrag(window, dropData, QHighDpi::fromNativeLocalPosition(p, window) ,supportedActions); } -QPlatformDropQtResponse QWindowSystemInterface::handleDrop(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions) +QPlatformDropQtResponse QWindowSystemInterface::handleDrop(QWindow *window, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions) { - return QGuiApplicationPrivate::processDrop(w, dropData, QHighDpi::fromNativeLocalPosition(p, w),supportedActions); + return QGuiApplicationPrivate::processDrop(window, dropData, QHighDpi::fromNativeLocalPosition(p, window),supportedActions); } #endif // QT_NO_DRAGANDDROP @@ -780,45 +729,50 @@ void QWindowSystemInterface::handleFileOpenEvent(const QUrl &url) QGuiApplicationPrivate::processWindowSystemEvent(&e); } -void QWindowSystemInterface::handleTabletEvent(QWindow *w, ulong timestamp, const QPointF &local, const QPointF &global, +void QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(bool v) +{ + platformSynthesizesMouse = v; +} + +void QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers modifiers) { QWindowSystemInterfacePrivate::TabletEvent *e = - new QWindowSystemInterfacePrivate::TabletEvent(w,timestamp, - QHighDpi::fromNativeLocalPosition(local, w), - QHighDpi::fromNativePixels(global, w), + new QWindowSystemInterfacePrivate::TabletEvent(window, timestamp, + QHighDpi::fromNativeLocalPosition(local, window), + QHighDpi::fromNativePixels(global, window), device, pointerType, buttons, pressure, xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } -void QWindowSystemInterface::handleTabletEvent(QWindow *w, const QPointF &local, const QPointF &global, +void QWindowSystemInterface::handleTabletEvent(QWindow *window, const QPointF &local, const QPointF &global, int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers modifiers) { ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - handleTabletEvent(w, time, local, global, device, pointerType, buttons, pressure, + handleTabletEvent(window, time, local, global, device, pointerType, buttons, pressure, xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers); } -void QWindowSystemInterface::handleTabletEvent(QWindow *w, ulong timestamp, bool down, const QPointF &local, const QPointF &global, +void QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp, bool down, const QPointF &local, const QPointF &global, int device, int pointerType, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers modifiers) { - handleTabletEvent(w, timestamp, local, global, device, pointerType, (down ? Qt::LeftButton : Qt::NoButton), pressure, + handleTabletEvent(window, timestamp, local, global, device, pointerType, (down ? Qt::LeftButton : Qt::NoButton), pressure, xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers); } -void QWindowSystemInterface::handleTabletEvent(QWindow *w, bool down, const QPointF &local, const QPointF &global, +void QWindowSystemInterface::handleTabletEvent(QWindow *window, bool down, const QPointF &local, const QPointF &global, int device, int pointerType, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers modifiers) { - handleTabletEvent(w, local, global, device, pointerType, (down ? Qt::LeftButton : Qt::NoButton), pressure, + handleTabletEvent(window, local, global, device, pointerType, (down ? Qt::LeftButton : Qt::NoButton), pressure, xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers); } @@ -885,12 +839,12 @@ void QWindowSystemInterface::handlePlatformPanelEvent(QWindow *w) } #ifndef QT_NO_CONTEXTMENU -void QWindowSystemInterface::handleContextMenuEvent(QWindow *w, bool mouseTriggered, +void QWindowSystemInterface::handleContextMenuEvent(QWindow *window, bool mouseTriggered, const QPoint &pos, const QPoint &globalPos, Qt::KeyboardModifiers modifiers) { QWindowSystemInterfacePrivate::ContextMenuEvent *e = - new QWindowSystemInterfacePrivate::ContextMenuEvent(w, mouseTriggered, pos, + new QWindowSystemInterfacePrivate::ContextMenuEvent(window, mouseTriggered, pos, globalPos, modifiers); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } @@ -915,18 +869,102 @@ Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QWindowSystemInterface::TouchPo } #endif +// ------------------ Event dispatcher functionality ------------------ + +/*! + Make Qt Gui process all events on the event queue immediately. Return the + accepted state for the last event on the queue. +*/ +bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags) +{ + const int count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count(); + if (!count) + return false; + if (!QGuiApplication::instance()) { + qWarning().nospace() + << "QWindowSystemInterface::flushWindowSystemEvents() invoked after " + "QGuiApplication destruction, discarding " << count << " events."; + QWindowSystemInterfacePrivate::windowSystemEventQueue.clear(); + return false; + } + if (QThread::currentThread() != QGuiApplication::instance()->thread()) { + // Post a FlushEvents event which will trigger a call back to + // deferredFlushWindowSystemEvents from the Gui thread. + QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex); + QWindowSystemInterfacePrivate::FlushEventsEvent *e = new QWindowSystemInterfacePrivate::FlushEventsEvent(flags); + QWindowSystemInterfacePrivate::handleWindowSystemEvent<AsynchronousDelivery>(e); + QWindowSystemInterfacePrivate::eventsFlushed.wait(&QWindowSystemInterfacePrivate::flushEventMutex); + } else { + sendWindowSystemEvents(flags); + } + return QWindowSystemInterfacePrivate::eventAccepted.load() > 0; +} + +void QWindowSystemInterface::deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags) +{ + Q_ASSERT(QThread::currentThread() == QGuiApplication::instance()->thread()); + + QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex); + sendWindowSystemEvents(flags); + QWindowSystemInterfacePrivate::eventsFlushed.wakeOne(); +} + +bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags) +{ + int nevents = 0; + + while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) { + QWindowSystemInterfacePrivate::WindowSystemEvent *event = + (flags & QEventLoop::ExcludeUserInputEvents) ? + QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() : + QWindowSystemInterfacePrivate::getWindowSystemEvent(); + if (!event) + break; + + if (QWindowSystemInterfacePrivate::eventHandler) { + if (QWindowSystemInterfacePrivate::eventHandler->sendEvent(event)) + nevents++; + } else { + nevents++; + QGuiApplicationPrivate::processWindowSystemEvent(event); + } + + // Record the accepted state for the processed event + // (excluding flush events). This state can then be + // returned by flushWindowSystemEvents(). + if (event->type != QWindowSystemInterfacePrivate::FlushEvents) + QWindowSystemInterfacePrivate::eventAccepted.store(event->eventAccepted); + + delete event; + } + + return (nevents > 0); +} + +void QWindowSystemInterface::setSynchronousWindowSystemEvents(bool enable) +{ + QWindowSystemInterfacePrivate::synchronousWindowSystemEvents = enable; +} + +int QWindowSystemInterface::windowSystemEventsQueued() +{ + return QWindowSystemInterfacePrivate::windowSystemEventsQueued(); +} + +// --------------------- QtTestLib support --------------------- + // The following functions are used by testlib, and need to be synchronous to avoid // race conditions with plugins delivering native events from secondary threads. -Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *w, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods, int timestamp) +Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods, int timestamp) { - const qreal factor = QHighDpiScaling::factor(w); - QWindowSystemInterface::handleMouseEvent<QWindowSystemInterface::SynchronousDelivery>(w, timestamp, local * factor, global * factor, b, mods); + const qreal factor = QHighDpiScaling::factor(window); + QWindowSystemInterface::handleMouseEvent<QWindowSystemInterface::SynchronousDelivery>(window, timestamp, local * factor, global * factor, b, mods); } -Q_GUI_EXPORT void qt_handleKeyEvent(QWindow *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1) +Q_GUI_EXPORT void qt_handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1) { - QWindowSystemInterface::handleKeyEvent<QWindowSystemInterface::SynchronousDelivery>(w, t, k, mods, text, autorep, count); + QWindowSystemInterface::handleKeyEvent<QWindowSystemInterface::SynchronousDelivery>(window, t, k, mods, text, autorep, count); } Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString &text = QString(), bool autorep = false, ushort count = 1) @@ -977,35 +1015,13 @@ namespace QTest } } -Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *w, QTouchDevice *device, +Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *window, QTouchDevice *device, const QList<QTouchEvent::TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier) { - QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(w, device, - QWindowSystemInterfacePrivate::toNativeTouchPoints(points, w), mods); -} - -QWindowSystemEventHandler::~QWindowSystemEventHandler() -{ - QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(this); -} - -bool QWindowSystemEventHandler::sendEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e) -{ - QGuiApplicationPrivate::processWindowSystemEvent(e); - return true; + QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(window, device, + QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window), mods); } -QWindowSystemInterfacePrivate::WheelEvent::WheelEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD, - QPoint angleD, int qt4D, Qt::Orientation qt4O, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource src, bool inverted) - : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), - qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src), inverted(inverted) -{ -} - -void QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(bool v) -{ - platformSynthesizesMouse = v; -} QT_END_NAMESPACE diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h index 3be3c3188c..b6b57e01f5 100644 --- a/src/gui/kernel/qwindowsysteminterface.h +++ b/src/gui/kernel/qwindowsysteminterface.h @@ -77,44 +77,44 @@ public: struct DefaultDelivery {}; template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static void handleMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b, + static void handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods = Qt::NoModifier, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static void handleMouseEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b, + static void handleMouseEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods = Qt::NoModifier, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); - static void handleFrameStrutMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b, + static void handleFrameStrutMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods = Qt::NoModifier, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); - static void handleFrameStrutMouseEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b, + static void handleFrameStrutMouseEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods = Qt::NoModifier, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); - static bool handleShortcutEvent(QWindow *w, ulong timestamp, int k, Qt::KeyboardModifiers mods, quint32 nativeScanCode, + static bool handleShortcutEvent(QWindow *window, ulong timestamp, int k, Qt::KeyboardModifiers mods, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString & text = QString(), bool autorep = false, ushort count = 1); template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static bool handleKeyEvent(QWindow *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1); + static bool handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1); template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static bool handleKeyEvent(QWindow *w, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1); + static bool handleKeyEvent(QWindow *window, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1); - static bool handleExtendedKeyEvent(QWindow *w, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, + static bool handleExtendedKeyEvent(QWindow *window, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString& text = QString(), bool autorep = false, ushort count = 1, bool tryShortcutOverride = true); - static bool handleExtendedKeyEvent(QWindow *w, ulong timestamp, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, + static bool handleExtendedKeyEvent(QWindow *window, ulong timestamp, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString& text = QString(), bool autorep = false, ushort count = 1, bool tryShortcutOverride = true); - static void handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, + static void handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods = Qt::NoModifier, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); - static void handleWheelEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, + static void handleWheelEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods = Qt::NoModifier, Qt::ScrollPhase phase = Qt::NoScrollPhase, @@ -122,8 +122,8 @@ public: bool inverted = false); // Wheel event compatibility functions. Will be removed: do not use. - static void handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier); - static void handleWheelEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier); + static void handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier); + static void handleWheelEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier); struct TouchPoint { TouchPoint() : id(0), uniqueId(-1), pressure(0), rotation(0), state(Qt::TouchPointStationary) { } @@ -131,9 +131,11 @@ public: qint64 uniqueId; // for TUIO: object/token ID; otherwise empty // TODO for TUIO 2.0: add registerPointerUniqueID(QPointerUniqueId) QPointF normalPosition; // touch device coordinates, (0 to 1, 0 to 1) - QRectF area; // the touched area, centered at position in screen coordinates + QRectF area; // dimensions of the elliptical contact patch, unrotated, and centered at position in screen coordinates + // width is the horizontal diameter, height is the vertical diameter qreal pressure; // 0 to 1 - qreal rotation; // 0 means pointing straight up; 0 if unknown (like QTabletEvent::rotation) + qreal rotation; // rotation applied to the elliptical contact patch + // 0 means pointing straight up; 0 if unknown (like QTabletEvent::rotation) Qt::TouchPointState state; //Qt::TouchPoint{Pressed|Moved|Stationary|Released} QVector2D velocity; // in screen coordinate system, pixels / seconds QTouchEvent::TouchPoint::InfoFlags flags; @@ -145,43 +147,43 @@ public: static bool isTouchDeviceRegistered(const QTouchDevice *device); template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static void handleTouchEvent(QWindow *w, QTouchDevice *device, + static void handleTouchEvent(QWindow *window, QTouchDevice *device, const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier); template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static void handleTouchEvent(QWindow *w, ulong timestamp, QTouchDevice *device, + static void handleTouchEvent(QWindow *window, ulong timestamp, QTouchDevice *device, const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier); template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static void handleTouchCancelEvent(QWindow *w, QTouchDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier); + static void handleTouchCancelEvent(QWindow *window, QTouchDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier); template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static void handleTouchCancelEvent(QWindow *w, ulong timestamp, QTouchDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier); + static void handleTouchCancelEvent(QWindow *window, ulong timestamp, QTouchDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier); // rect is relative to parent template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static void handleGeometryChange(QWindow *w, const QRect &newRect, const QRect &oldRect = QRect()); + static void handleGeometryChange(QWindow *window, const QRect &newRect, const QRect &oldRect = QRect()); // region is in local coordinates, do not confuse with geometry which is parent-relative template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static void handleExposeEvent(QWindow *tlw, const QRegion ®ion); + static void handleExposeEvent(QWindow *window, const QRegion ®ion); - static void handleCloseEvent(QWindow *w, bool *accepted = Q_NULLPTR); + static void handleCloseEvent(QWindow *window, bool *accepted = Q_NULLPTR); template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static void handleEnterEvent(QWindow *w, const QPointF &local = QPointF(), const QPointF& global = QPointF()); + static void handleEnterEvent(QWindow *window, const QPointF &local = QPointF(), const QPointF& global = QPointF()); template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static void handleLeaveEvent(QWindow *w); + static void handleLeaveEvent(QWindow *window); static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local = QPointF(), const QPointF& global = QPointF()); template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static void handleWindowActivated(QWindow *w, Qt::FocusReason r = Qt::OtherFocusReason); + static void handleWindowActivated(QWindow *window, Qt::FocusReason r = Qt::OtherFocusReason); - static void handleWindowStateChanged(QWindow *w, Qt::WindowState newState); - static void handleWindowScreenChanged(QWindow *w, QScreen *newScreen); + static void handleWindowStateChanged(QWindow *window, Qt::WindowState newState); + static void handleWindowScreenChanged(QWindow *window, QScreen *newScreen); static void handleApplicationStateChanged(Qt::ApplicationState newState, bool forcePropagate = false); #ifndef QT_NO_DRAGANDDROP // Drag and drop. These events are sent immediately. - static QPlatformDragQtResponse handleDrag(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions); - static QPlatformDropQtResponse handleDrop(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions); + static QPlatformDragQtResponse handleDrag(QWindow *window, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions); + static QPlatformDropQtResponse handleDrop(QWindow *window, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions); #endif static bool handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result); @@ -192,24 +194,24 @@ public: static void handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal newDpiX, qreal newDpiY); static void handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate); - static void handleThemeChange(QWindow *tlw); + static void handleThemeChange(QWindow *window); static void handleFileOpenEvent(const QString& fileName); static void handleFileOpenEvent(const QUrl &url); - static void handleTabletEvent(QWindow *w, ulong timestamp, const QPointF &local, const QPointF &global, + static void handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers modifiers = Qt::NoModifier); - static void handleTabletEvent(QWindow *w, const QPointF &local, const QPointF &global, + static void handleTabletEvent(QWindow *window, const QPointF &local, const QPointF &global, int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers modifiers = Qt::NoModifier); - static void handleTabletEvent(QWindow *w, ulong timestamp, bool down, const QPointF &local, const QPointF &global, + static void handleTabletEvent(QWindow *window, ulong timestamp, bool down, const QPointF &local, const QPointF &global, int device, int pointerType, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers modifiers = Qt::NoModifier); // ### remove in Qt 6 - static void handleTabletEvent(QWindow *w, bool down, const QPointF &local, const QPointF &global, + static void handleTabletEvent(QWindow *window, bool down, const QPointF &local, const QPointF &global, int device, int pointerType, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers modifiers = Qt::NoModifier); // ### remove in Qt 6 @@ -227,9 +229,9 @@ public: ulong sequenceId, quint64 value, QPointF &local, QPointF &global); #endif // QT_NO_GESTURES - static void handlePlatformPanelEvent(QWindow *w); + static void handlePlatformPanelEvent(QWindow *window); #ifndef QT_NO_CONTEXTMENU - static void handleContextMenuEvent(QWindow *w, bool mouseTriggered, + static void handleContextMenuEvent(QWindow *window, bool mouseTriggered, const QPoint &pos, const QPoint &globalPos, Qt::KeyboardModifiers modifiers); #endif diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index 7c9b1f2852..1db60e8cb8 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -131,10 +131,10 @@ public: class GeometryChangeEvent : public WindowSystemEvent { public: - GeometryChangeEvent(QWindow *tlw, const QRect &newGeometry, const QRect &oldGeometry) - : WindowSystemEvent(GeometryChange), tlw(tlw), newGeometry(newGeometry), oldGeometry(oldGeometry) + GeometryChangeEvent(QWindow *window, const QRect &newGeometry, const QRect &oldGeometry) + : WindowSystemEvent(GeometryChange), window(window), newGeometry(newGeometry), oldGeometry(oldGeometry) { } - QPointer<QWindow> tlw; + QPointer<QWindow> window; QRect newGeometry; QRect oldGeometry; }; @@ -226,11 +226,11 @@ public: class MouseEvent : public InputEvent { public: - MouseEvent(QWindow * w, ulong time, const QPointF & local, const QPointF & global, + MouseEvent(QWindow * w, ulong time, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized) : InputEvent(w, time, Mouse, mods), localPos(local), globalPos(global), buttons(b), source(src) { } - MouseEvent(QWindow * w, ulong time, EventType t, const QPointF & local, const QPointF & global, + MouseEvent(QWindow * w, ulong time, EventType t, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized) : InputEvent(w, time, t, mods), localPos(local), globalPos(global), buttons(b), source(src) { } @@ -242,7 +242,7 @@ public: class WheelEvent : public InputEvent { public: - WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O, + WheelEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized, bool inverted = false); QPoint pixelDelta; QPoint angleDelta; @@ -494,10 +494,6 @@ public: template<typename Delivery = QWindowSystemInterface::DefaultDelivery> static bool handleWindowSystemEvent(WindowSystemEvent *ev); -private: - static void postWindowSystemEvent(WindowSystemEvent *ev); - static bool processWindowSystemEvent(WindowSystemEvent *ev); - public: static QElapsedTimer eventTime; static bool synchronousWindowSystemEvents; @@ -508,7 +504,7 @@ public: static QList<QTouchEvent::TouchPoint> fromNativeTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points, - const QWindow *window, QEvent::Type *type = Q_NULLPTR); + const QWindow *window, quint8 deviceId, QEvent::Type *type = Q_NULLPTR); static QList<QWindowSystemInterface::TouchPoint> toNativeTouchPoints(const QList<QTouchEvent::TouchPoint>& pointList, const QWindow *window); |