summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2021-04-19 16:00:35 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2021-05-01 19:40:36 +0200
commitc8736e8e614066e46bc267356ee7757e42ed6e5f (patch)
tree915271e1a257ec14a6aa5c176d33711f025450f2 /src
parentf55fc61346dc920b79c7cbab3ed140479af486ab (diff)
Add grabber context pointers
In Qt Quick we now need to keep track of which QQDeliveryAgent is responsible when a point is grabbed, either passively or exclusively. When we re-deliver to that grabber, we need to do it via the same agent, so that the same scene transform is used, and the grabber will see the event in the correct coordinate system. It's easier to track this mapping here instead of in a separate map in Qt Quick. (This is an alternative to 40330b8f0a717098982d1f54f34a18a8262b1f55: it was not possible to use QFlatMap, because we need to keep the passive grabbers in the same order as they were added. We don't use a QList of structs, because QPointerEvent::passiveGrabbers() needs to return a QList of just the grabbers, and it's not as efficient to construct that list in the accessor.) Change-Id: I457114f816736749d2ea5ee48fa03524eb93d2d0 Pick-to: 6.1 Task-number: QTBUG-92944 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/gui/kernel/qpointingdevice.cpp23
-rw-r--r--src/gui/kernel/qpointingdevice_p.h3
2 files changed, 26 insertions, 0 deletions
diff --git a/src/gui/kernel/qpointingdevice.cpp b/src/gui/kernel/qpointingdevice.cpp
index 176a5fedf4..2a09ee3ca9 100644
--- a/src/gui/kernel/qpointingdevice.cpp
+++ b/src/gui/kernel/qpointingdevice.cpp
@@ -508,6 +508,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();
}
/*!
@@ -545,6 +547,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);
@@ -561,6 +574,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;
@@ -583,6 +600,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();
}
/*!
@@ -606,6 +624,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);
@@ -615,6 +634,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 04823a3e86..263bc91864 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<QObject> exclusiveGrabber;
+ QPointer<QObject> exclusiveGrabberContext; // extra info about where the grab happened
QList<QPointer <QObject> > passiveGrabbers;
+ QList<QPointer <QObject> > 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);