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 | #ifndef QWINDOWSYSTEMINTERFACE_H |
4 | #define QWINDOWSYSTEMINTERFACE_H |
5 | |
6 | // |
7 | // W A R N I N G |
8 | // ------------- |
9 | // |
10 | // This file is part of the QPA API and is not meant to be used |
11 | // in applications. Usage of this API may make your code |
12 | // source and binary incompatible with future versions of Qt. |
13 | // |
14 | |
15 | #include <QtGui/qtguiglobal.h> |
16 | #include <QtCore/QTime> |
17 | #include <QtGui/qwindowdefs.h> |
18 | #include <QtCore/QEvent> |
19 | #include <QtCore/QAbstractEventDispatcher> |
20 | #include <QtGui/QScreen> |
21 | #include <QtGui/QWindow> |
22 | #include <QtCore/QWeakPointer> |
23 | #include <QtCore/QMutex> |
24 | #include <QtGui/QTouchEvent> |
25 | #include <QtCore/QEventLoop> |
26 | #include <QtGui/QVector2D> |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | class QMimeData; |
31 | class QPointingDevice; |
32 | class QPlatformDragQtResponse; |
33 | class QPlatformDropQtResponse; |
34 | |
35 | |
36 | class Q_GUI_EXPORT QWindowSystemInterface |
37 | { |
38 | public: |
39 | struct SynchronousDelivery {}; |
40 | struct AsynchronousDelivery {}; |
41 | struct DefaultDelivery {}; |
42 | |
43 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
44 | static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, |
45 | Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, |
46 | Qt::KeyboardModifiers mods = Qt::NoModifier, |
47 | Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); |
48 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
49 | static bool handleMouseEvent(QWindow *window, const QPointingDevice *device, |
50 | const QPointF &local, const QPointF &global, |
51 | Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, |
52 | Qt::KeyboardModifiers mods = Qt::NoModifier, |
53 | Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); |
54 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
55 | static bool handleMouseEvent(QWindow *window, ulong timestamp, const QPointF &local, |
56 | const QPointF &global, Qt::MouseButtons state, |
57 | Qt::MouseButton button, QEvent::Type type, |
58 | Qt::KeyboardModifiers mods = Qt::NoModifier, |
59 | Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); |
60 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
61 | static bool handleMouseEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, |
62 | const QPointF &local, const QPointF &global, Qt::MouseButtons state, |
63 | Qt::MouseButton button, QEvent::Type type, |
64 | Qt::KeyboardModifiers mods = Qt::NoModifier, |
65 | Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); |
66 | |
67 | static bool handleShortcutEvent(QWindow *window, ulong timestamp, int k, Qt::KeyboardModifiers mods, quint32 nativeScanCode, |
68 | quint32 nativeVirtualKey, quint32 nativeModifiers, const QString & text = QString(), bool autorep = false, ushort count = 1); |
69 | |
70 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
71 | static bool handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1); |
72 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
73 | 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); |
74 | |
75 | static bool handleExtendedKeyEvent(QWindow *window, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, |
76 | quint32 nativeScanCode, quint32 nativeVirtualKey, |
77 | quint32 nativeModifiers, |
78 | const QString& text = QString(), bool autorep = false, |
79 | ushort count = 1); |
80 | static bool handleExtendedKeyEvent(QWindow *window, ulong timestamp, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, |
81 | quint32 nativeScanCode, quint32 nativeVirtualKey, |
82 | quint32 nativeModifiers, |
83 | const QString& text = QString(), bool autorep = false, |
84 | ushort count = 1); |
85 | static bool handleExtendedKeyEvent(QWindow *window, ulong timestamp, const QInputDevice *device, |
86 | QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, |
87 | quint32 nativeScanCode, quint32 nativeVirtualKey, |
88 | quint32 nativeModifiers, |
89 | const QString& text = QString(), bool autorep = false, |
90 | ushort count = 1); |
91 | static bool handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, |
92 | QPoint pixelDelta, QPoint angleDelta, |
93 | Qt::KeyboardModifiers mods = Qt::NoModifier, |
94 | Qt::ScrollPhase phase = Qt::NoScrollPhase, |
95 | Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); |
96 | static bool handleWheelEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, |
97 | QPoint pixelDelta, QPoint angleDelta, |
98 | Qt::KeyboardModifiers mods = Qt::NoModifier, |
99 | Qt::ScrollPhase phase = Qt::NoScrollPhase, |
100 | Qt::MouseEventSource source = Qt::MouseEventNotSynthesized, |
101 | bool inverted = false); |
102 | static bool handleWheelEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, |
103 | const QPointF &local, const QPointF &global, |
104 | QPoint pixelDelta, QPoint angleDelta, |
105 | Qt::KeyboardModifiers mods = Qt::NoModifier, |
106 | Qt::ScrollPhase phase = Qt::NoScrollPhase, |
107 | Qt::MouseEventSource source = Qt::MouseEventNotSynthesized, |
108 | bool inverted = false); |
109 | |
110 | // A very-temporary QPA touchpoint which gets converted to a QEventPoint as early as possible |
111 | // in QWindowSystemInterfacePrivate::fromNativeTouchPoints() |
112 | struct TouchPoint { |
113 | TouchPoint() : id(0), uniqueId(-1), pressure(0), rotation(0), state(QEventPoint::State::Stationary) { } |
114 | int id; // for application use |
115 | qint64 uniqueId; // for TUIO: object/token ID; otherwise empty |
116 | // TODO for TUIO 2.0: add registerPointerUniqueID(QPointingDeviceUniqueId) |
117 | QPointF normalPosition; // touch device coordinates, (0 to 1, 0 to 1) |
118 | QRectF area; // dimensions of the elliptical contact patch, unrotated, and centered at position in screen coordinates |
119 | // width is the horizontal diameter, height is the vertical diameter |
120 | qreal pressure; // 0 to 1 |
121 | qreal rotation; // rotation applied to the elliptical contact patch |
122 | // 0 means pointing straight up; 0 if unknown (like QTabletEvent::rotation) |
123 | QEventPoint::State state; // Pressed|Updated|Stationary|Released |
124 | QVector2D velocity; // in screen coordinate system, pixels / seconds |
125 | QList<QPointF> rawPositions; // in screen coordinates |
126 | }; |
127 | |
128 | static void registerInputDevice(const QInputDevice *device); |
129 | |
130 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
131 | static bool handleTouchEvent(QWindow *window, const QPointingDevice *device, |
132 | const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier); |
133 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
134 | static bool handleTouchEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, |
135 | const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier); |
136 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
137 | static bool handleTouchCancelEvent(QWindow *window, const QPointingDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier); |
138 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
139 | static bool handleTouchCancelEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier); |
140 | |
141 | // rect is relative to parent |
142 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
143 | static void handleGeometryChange(QWindow *window, const QRect &newRect); |
144 | |
145 | // region is in local coordinates, do not confuse with geometry which is parent-relative |
146 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
147 | static bool handleExposeEvent(QWindow *window, const QRegion ®ion); |
148 | |
149 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
150 | static bool handlePaintEvent(QWindow *window, const QRegion ®ion); |
151 | |
152 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
153 | static bool handleCloseEvent(QWindow *window); |
154 | |
155 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
156 | static void handleEnterEvent(QWindow *window, const QPointF &local = QPointF(), const QPointF& global = QPointF()); |
157 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
158 | static void handleLeaveEvent(QWindow *window); |
159 | static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local = QPointF(), const QPointF& global = QPointF()); |
160 | |
161 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
162 | static void handleFocusWindowChanged(QWindow *window, Qt::FocusReason r = Qt::OtherFocusReason); |
163 | |
164 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
165 | static void handleWindowStateChanged(QWindow *window, Qt::WindowStates newState, int oldState = -1); |
166 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
167 | static void handleWindowScreenChanged(QWindow *window, QScreen *newScreen); |
168 | |
169 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
170 | static void handleWindowDevicePixelRatioChanged(QWindow *window); |
171 | |
172 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
173 | static void handleSafeAreaMarginsChanged(QWindow *window); |
174 | |
175 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
176 | static void handleApplicationStateChanged(Qt::ApplicationState newState, bool forcePropagate = false); |
177 | |
178 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
179 | static bool handleApplicationTermination(); |
180 | |
181 | #if QT_CONFIG(draganddrop) |
182 | static QPlatformDragQtResponse handleDrag(QWindow *window, const QMimeData *dropData, |
183 | const QPoint &p, Qt::DropActions supportedActions, |
184 | Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); |
185 | static QPlatformDropQtResponse handleDrop(QWindow *window, const QMimeData *dropData, |
186 | const QPoint &p, Qt::DropActions supportedActions, |
187 | Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); |
188 | #endif // QT_CONFIG(draganddrop) |
189 | |
190 | static bool handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result); |
191 | |
192 | // Changes to the screen |
193 | static void handleScreenAdded(QPlatformScreen *screen, bool isPrimary = false); |
194 | static void handleScreenRemoved(QPlatformScreen *screen); |
195 | static void handlePrimaryScreenChanged(QPlatformScreen *newPrimary); |
196 | |
197 | static void handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation newOrientation); |
198 | static void handleScreenGeometryChange(QScreen *screen, const QRect &newGeometry, const QRect &newAvailableGeometry); |
199 | static void handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal newDpiX, qreal newDpiY); |
200 | static void handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate); |
201 | |
202 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
203 | static void handleThemeChange(QWindow *window = nullptr); |
204 | |
205 | static void handleFileOpenEvent(const QString& fileName); |
206 | static void handleFileOpenEvent(const QUrl &url); |
207 | |
208 | static bool handleTabletEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, |
209 | const QPointF &local, const QPointF &global, |
210 | Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, |
211 | qreal tangentialPressure, qreal rotation, int z, Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
212 | static bool handleTabletEvent(QWindow *window, const QPointingDevice *device, |
213 | const QPointF &local, const QPointF &global, |
214 | Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, |
215 | qreal tangentialPressure, qreal rotation, int z, Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
216 | static bool handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, |
217 | int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, |
218 | qreal tangentialPressure, qreal rotation, int z, qint64 uid, |
219 | Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
220 | static bool handleTabletEvent(QWindow *window, const QPointF &local, const QPointF &global, |
221 | int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, |
222 | qreal tangentialPressure, qreal rotation, int z, qint64 uid, |
223 | Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
224 | static bool handleTabletEnterLeaveProximityEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, |
225 | bool inProximity, const QPointF &local = QPointF(), const QPointF &global = QPointF(), |
226 | Qt::MouseButtons buttons = {}, int xTilt = 0, int yTilt = 0, |
227 | qreal tangentialPressure = 0, qreal rotation = 0, int z = 0, |
228 | Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
229 | static bool handleTabletEnterLeaveProximityEvent(QWindow *window, const QPointingDevice *device, |
230 | bool inProximity, const QPointF &local = QPointF(), const QPointF &global = QPointF(), |
231 | Qt::MouseButtons buttons = {}, int xTilt = 0, int yTilt = 0, |
232 | qreal tangentialPressure = 0, qreal rotation = 0, int z = 0, |
233 | Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
234 | |
235 | // The following 4 functions are deprecated (QTBUG-114560) |
236 | static bool handleTabletEnterProximityEvent(ulong timestamp, int deviceType, int pointerType, qint64 uid); |
237 | static void handleTabletEnterProximityEvent(int deviceType, int pointerType, qint64 uid); |
238 | static bool handleTabletLeaveProximityEvent(ulong timestamp, int deviceType, int pointerType, qint64 uid); |
239 | static void handleTabletLeaveProximityEvent(int deviceType, int pointerType, qint64 uid); |
240 | |
241 | #ifndef QT_NO_GESTURES |
242 | static bool handleGestureEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::NativeGestureType type, |
243 | const QPointF &local, const QPointF &global, int fingerCount = 0); |
244 | static bool handleGestureEventWithRealValue(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::NativeGestureType type, |
245 | qreal value, const QPointF &local, const QPointF &global, int fingerCount = 2); |
246 | static bool handleGestureEventWithValueAndDelta(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::NativeGestureType type, qreal value, |
247 | const QPointF &delta, const QPointF &local, const QPointF &global, int fingerCount = 2); |
248 | #endif // QT_NO_GESTURES |
249 | |
250 | static void handlePlatformPanelEvent(QWindow *window); |
251 | |
252 | #ifndef QT_NO_CONTEXTMENU |
253 | #if QT_GUI_REMOVED_SINCE(6, 8) |
254 | static void handleContextMenuEvent(QWindow *window, bool mouseTriggered, |
255 | const QPoint &pos, const QPoint &globalPos, |
256 | Qt::KeyboardModifiers modifiers); |
257 | #endif |
258 | template<typename Delivery = QWindowSystemInterface::DefaultDelivery> |
259 | static bool handleContextMenuEvent(QWindow *window, bool mouseTriggered, |
260 | const QPoint &pos, const QPoint &globalPos, |
261 | Qt::KeyboardModifiers modifiers); |
262 | #endif |
263 | #if QT_CONFIG(whatsthis) |
264 | static void handleEnterWhatsThisEvent(); |
265 | #endif |
266 | |
267 | // For event dispatcher implementations |
268 | static bool sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags); |
269 | static void setSynchronousWindowSystemEvents(bool enable); |
270 | static bool flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); |
271 | static void deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags); |
272 | static int windowSystemEventsQueued(); |
273 | static bool nonUserInputEventsQueued(); |
274 | }; |
275 | |
276 | #ifndef QT_NO_DEBUG_STREAM |
277 | Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QWindowSystemInterface::TouchPoint &p); |
278 | #endif |
279 | |
280 | QT_END_NAMESPACE |
281 | |
282 | #endif // QWINDOWSYSTEMINTERFACE_H |
283 | |