diff --git a/src/gui/kernel/qpointingdevice.cpp b/src/gui/kernel/qpointingdevice.cpp index 6ef032098f2..8281011c706 100644 --- a/src/gui/kernel/qpointingdevice.cpp +++ b/src/gui/kernel/qpointingdevice.cpp @@ -504,6 +504,8 @@ void QPointingDevicePrivate::setExclusiveGrabber(const QPointerEvent *event, con QMutableEventPoint::from(persistentPoint->eventPoint).setGlobalGrabPosition(point.globalPosition()); if (exclusiveGrabber) emit q->grabChanged(exclusiveGrabber, QPointingDevice::GrabExclusive, event, point); + else + persistentPoint->exclusiveGrabberContext.clear(); } /*! @@ -541,6 +543,17 @@ bool QPointingDevicePrivate::addPassiveGrabber(const QPointerEvent *event, const return true; } +bool QPointingDevicePrivate::setPassiveGrabberContext(QPointingDevicePrivate::EventPointData *epd, QObject *grabber, QObject *context) +{ + int i = epd->passiveGrabbers.indexOf(grabber); + if (i < 0) + return false; + if (epd->passiveGrabbersContext.size() <= i) + epd->passiveGrabbersContext.resize(i + 1); + epd->passiveGrabbersContext[i] = context; + return true; +} + bool QPointingDevicePrivate::removePassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber) { Q_Q(QPointingDevice); @@ -557,6 +570,10 @@ bool QPointingDevicePrivate::removePassiveGrabber(const QPointerEvent *event, co } emit q->grabChanged(grabber, QPointingDevice::UngrabPassive, event, point); persistentPoint->passiveGrabbers.removeAt(i); + if (persistentPoint->passiveGrabbersContext.size()) { + Q_ASSERT(persistentPoint->passiveGrabbersContext.size() > i); + persistentPoint->passiveGrabbersContext.removeAt(i); + } return true; } return false; @@ -579,6 +596,7 @@ void QPointingDevicePrivate::clearPassiveGrabbers(const QPointerEvent *event, co for (auto g : persistentPoint->passiveGrabbers) emit q->grabChanged(g, QPointingDevice::UngrabPassive, event, point); persistentPoint->passiveGrabbers.clear(); + persistentPoint->passiveGrabbersContext.clear(); } /*! @@ -602,6 +620,7 @@ void QPointingDevicePrivate::removeGrabber(QObject *grabber, bool cancel) << "@" << epd.eventPoint.scenePosition() << ": grab" << grabber << "-> nullptr"; epd.exclusiveGrabber.clear(); + epd.exclusiveGrabberContext.clear(); emit q->grabChanged(grabber, cancel ? QPointingDevice::CancelGrabExclusive : QPointingDevice::UngrabExclusive, nullptr, epd.eventPoint); @@ -611,6 +630,10 @@ void QPointingDevicePrivate::removeGrabber(QObject *grabber, bool cancel) qCDebug(lcPointerGrab) << name << "point" << epd.eventPoint.id() << epd.eventPoint.state() << ": removing passive grabber" << grabber; epd.passiveGrabbers.removeAt(pi); + if (epd.passiveGrabbersContext.size()) { + Q_ASSERT(epd.passiveGrabbersContext.size() > pi); + epd.passiveGrabbersContext.removeAt(pi); + } emit q->grabChanged(grabber, cancel ? QPointingDevice::CancelGrabPassive : QPointingDevice::UngrabPassive, nullptr, epd.eventPoint); diff --git a/src/gui/kernel/qpointingdevice_p.h b/src/gui/kernel/qpointingdevice_p.h index 645c82673b8..ddf71a74e95 100644 --- a/src/gui/kernel/qpointingdevice_p.h +++ b/src/gui/kernel/qpointingdevice_p.h @@ -88,7 +88,9 @@ public: struct EventPointData { QEventPoint eventPoint; QPointer exclusiveGrabber; + QPointer exclusiveGrabberContext; // extra info about where the grab happened QList > passiveGrabbers; + QList > passiveGrabbersContext; // parallel list: extra info about where the grabs happened }; EventPointData *queryPointById(int id) const; EventPointData *pointById(int id) const; @@ -100,6 +102,7 @@ public: void setExclusiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *exclusiveGrabber); bool removeExclusiveGrabber(const QPointerEvent *event, const QObject *grabber); bool addPassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber); + static bool setPassiveGrabberContext(EventPointData *epd, QObject *grabber, QObject *context); bool removePassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber); void clearPassiveGrabbers(const QPointerEvent *event, const QEventPoint &point); void removeGrabber(QObject *grabber, bool cancel = false);