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 | #include <QtCore/private/qflatmap_p.h> |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | Q_DECLARE_LOGGING_CATEGORY(lcPointerGrab); |
28 | |
29 | class Q_GUI_EXPORT QPointingDevicePrivate : public QInputDevicePrivate |
30 | { |
31 | Q_DECLARE_PUBLIC(QPointingDevice) |
32 | public: |
33 | QPointingDevicePrivate(const QString &name, qint64 id, QInputDevice::DeviceType type, |
34 | QPointingDevice::PointerType pType, QPointingDevice::Capabilities caps, |
35 | int maxPoints, int buttonCount, |
36 | const QString &seatName = QString(), |
37 | QPointingDeviceUniqueId uniqueId = QPointingDeviceUniqueId()) |
38 | : QInputDevicePrivate(name, id, type, caps, seatName), |
39 | uniqueId(uniqueId), |
40 | maximumTouchPoints(qint8(maxPoints)), buttonCount(qint8(buttonCount)), |
41 | pointerType(pType) |
42 | { |
43 | pointingDeviceType = true; |
44 | activePoints.reserve(s: maxPoints); |
45 | } |
46 | ~QPointingDevicePrivate() override; |
47 | |
48 | void sendTouchCancelEvent(QTouchEvent *cancelEvent); |
49 | |
50 | /*! \internal |
51 | This struct (stored in activePoints) holds persistent state between event deliveries. |
52 | */ |
53 | struct EventPointData { |
54 | QEventPoint eventPoint; |
55 | QPointer<QObject> exclusiveGrabber; |
56 | QPointer<QObject> exclusiveGrabberContext; // extra info about where the grab happened |
57 | QList<QPointer <QObject> > passiveGrabbers; |
58 | QList<QPointer <QObject> > passiveGrabbersContext; // parallel list: extra info about where the grabs happened |
59 | }; |
60 | EventPointData *queryPointById(int id) const; |
61 | EventPointData *pointById(int id) const; |
62 | void removePointById(int id); |
63 | QObject *firstActiveTarget() const; |
64 | QWindow *firstActiveWindow() const; |
65 | |
66 | QObject *firstPointExclusiveGrabber() const; |
67 | void setExclusiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *exclusiveGrabber); |
68 | bool removeExclusiveGrabber(const QPointerEvent *event, const QObject *grabber); |
69 | bool addPassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber); |
70 | static bool setPassiveGrabberContext(EventPointData *epd, QObject *grabber, QObject *context); |
71 | bool removePassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber); |
72 | void clearPassiveGrabbers(const QPointerEvent *event, const QEventPoint &point); |
73 | void removeGrabber(QObject *grabber, bool cancel = false); |
74 | |
75 | using EventPointMap = QVarLengthFlatMap<int, EventPointData, 20>; |
76 | mutable EventPointMap activePoints; |
77 | |
78 | QPointingDeviceUniqueId uniqueId; |
79 | quint32 toolId = 0; // only for Wacom tablets |
80 | qint8 maximumTouchPoints = 0; |
81 | qint8 buttonCount = 0; |
82 | QPointingDevice::PointerType pointerType = QPointingDevice::PointerType::Unknown; |
83 | bool toolProximity = false; // only for Wacom tablets |
84 | |
85 | inline static QPointingDevicePrivate *get(QPointingDevice *q) |
86 | { |
87 | return static_cast<QPointingDevicePrivate *>(QObjectPrivate::get(o: q)); |
88 | } |
89 | |
90 | inline static const QPointingDevicePrivate *get(const QPointingDevice *q) |
91 | { |
92 | return static_cast<const QPointingDevicePrivate *>(QObjectPrivate::get(o: q)); |
93 | } |
94 | |
95 | static const QPointingDevice *tabletDevice(QInputDevice::DeviceType deviceType, |
96 | QPointingDevice::PointerType pointerType, |
97 | QPointingDeviceUniqueId uniqueId); |
98 | |
99 | static const QPointingDevice *queryTabletDevice(QInputDevice::DeviceType deviceType, |
100 | QPointingDevice::PointerType pointerType, |
101 | QPointingDeviceUniqueId uniqueId, |
102 | QInputDevice::Capabilities capabilities = QInputDevice::Capability::None, |
103 | qint64 systemId = 0); |
104 | |
105 | static const QPointingDevice *pointingDeviceById(qint64 systemId); |
106 | }; |
107 | |
108 | QT_END_NAMESPACE |
109 | |
110 | #endif // QPOINTINGDEVICE_P_H |
111 | |