| 1 | // Copyright (C) 2020 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QPOINTINGDEVICE_P_H |
| 5 | #define QPOINTINGDEVICE_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/qloggingcategory.h> |
| 19 | #include <QtGui/private/qevent_p.h> |
| 20 | #include <QtGui/qpointingdevice.h> |
| 21 | #include <QtGui/private/qtguiglobal_p.h> |
| 22 | #include <QtGui/private/qinputdevice_p.h> |
| 23 | |
| 24 | #include <QtCore/qpointer.h> |
| 25 | #include <QtCore/private/qflatmap_p.h> |
| 26 | |
| 27 | QT_BEGIN_NAMESPACE |
| 28 | |
| 29 | Q_DECLARE_LOGGING_CATEGORY(lcPointerGrab); |
| 30 | |
| 31 | class Q_GUI_EXPORT QPointingDevicePrivate : public QInputDevicePrivate |
| 32 | { |
| 33 | Q_DECLARE_PUBLIC(QPointingDevice) |
| 34 | public: |
| 35 | QPointingDevicePrivate(const QString &name, qint64 id, QInputDevice::DeviceType type, |
| 36 | QPointingDevice::PointerType pType, QPointingDevice::Capabilities caps, |
| 37 | int maxPoints, int buttonCount, |
| 38 | const QString &seatName = QString(), |
| 39 | QPointingDeviceUniqueId uniqueId = QPointingDeviceUniqueId()) |
| 40 | : QInputDevicePrivate(name, id, type, caps, seatName), |
| 41 | uniqueId(uniqueId), |
| 42 | maximumTouchPoints(qint8(maxPoints)), buttonCount(qint8(buttonCount)), |
| 43 | pointerType(pType) |
| 44 | { |
| 45 | pointingDeviceType = true; |
| 46 | activePoints.reserve(s: maxPoints); |
| 47 | } |
| 48 | ~QPointingDevicePrivate() override; |
| 49 | |
| 50 | void sendTouchCancelEvent(QTouchEvent *cancelEvent); |
| 51 | |
| 52 | /*! \internal |
| 53 | This struct (stored in activePoints) holds persistent state between event deliveries. |
| 54 | */ |
| 55 | struct EventPointData { |
| 56 | QEventPoint eventPoint; |
| 57 | QPointer<QObject> exclusiveGrabber; |
| 58 | QPointer<QObject> exclusiveGrabberContext; // extra info about where the grab happened |
| 59 | QList<QPointer <QObject> > passiveGrabbers; |
| 60 | QList<QPointer <QObject> > passiveGrabbersContext; // parallel list: extra info about where the grabs happened |
| 61 | }; |
| 62 | EventPointData *queryPointById(int id) const; |
| 63 | EventPointData *pointById(int id) const; |
| 64 | void removePointById(int id); |
| 65 | QObject *firstActiveTarget() const; |
| 66 | QWindow *firstActiveWindow() const; |
| 67 | |
| 68 | QObject *firstPointExclusiveGrabber() const; |
| 69 | void setExclusiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *exclusiveGrabber); |
| 70 | bool removeExclusiveGrabber(const QPointerEvent *event, const QObject *grabber); |
| 71 | bool addPassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber); |
| 72 | static bool setPassiveGrabberContext(EventPointData *epd, QObject *grabber, QObject *context); |
| 73 | bool removePassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber); |
| 74 | void clearPassiveGrabbers(const QPointerEvent *event, const QEventPoint &point); |
| 75 | void removeGrabber(QObject *grabber, bool cancel = false); |
| 76 | |
| 77 | using EventPointMap = QVarLengthFlatMap<int, EventPointData, 20>; |
| 78 | mutable EventPointMap activePoints; |
| 79 | |
| 80 | QPointingDeviceUniqueId uniqueId; |
| 81 | quint32 toolId = 0; // only for Wacom tablets |
| 82 | qint8 maximumTouchPoints = 0; |
| 83 | qint8 buttonCount = 0; |
| 84 | QPointingDevice::PointerType pointerType = QPointingDevice::PointerType::Unknown; |
| 85 | bool toolProximity = false; // only for Wacom tablets |
| 86 | |
| 87 | inline static QPointingDevicePrivate *get(QPointingDevice *q) |
| 88 | { |
| 89 | return static_cast<QPointingDevicePrivate *>(QObjectPrivate::get(o: q)); |
| 90 | } |
| 91 | |
| 92 | inline static const QPointingDevicePrivate *get(const QPointingDevice *q) |
| 93 | { |
| 94 | return static_cast<const QPointingDevicePrivate *>(QObjectPrivate::get(o: q)); |
| 95 | } |
| 96 | |
| 97 | static const QPointingDevice *tabletDevice(QInputDevice::DeviceType deviceType, |
| 98 | QPointingDevice::PointerType pointerType, |
| 99 | QPointingDeviceUniqueId uniqueId); |
| 100 | |
| 101 | static const QPointingDevice *queryTabletDevice(QInputDevice::DeviceType deviceType, |
| 102 | QPointingDevice::PointerType pointerType, |
| 103 | QPointingDeviceUniqueId uniqueId, |
| 104 | QInputDevice::Capabilities capabilities = QInputDevice::Capability::None, |
| 105 | qint64 systemId = 0); |
| 106 | |
| 107 | static const QPointingDevice *pointingDeviceById(qint64 systemId); |
| 108 | }; |
| 109 | |
| 110 | QT_END_NAMESPACE |
| 111 | |
| 112 | #endif // QPOINTINGDEVICE_P_H |
| 113 | |