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
28QT_BEGIN_NAMESPACE
29
30class QMimeData;
31class QPointingDevice;
32class QPlatformDragQtResponse;
33class QPlatformDropQtResponse;
34
35
36class Q_GUI_EXPORT QWindowSystemInterface
37{
38public:
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 &region);
148
149 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
150 static bool handlePaintEvent(QWindow *window, const QRegion &region);
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 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
161 static void handleWindowActivated(QWindow *window, Qt::FocusReason r = Qt::OtherFocusReason);
162
163 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
164 static void handleWindowStateChanged(QWindow *window, Qt::WindowStates newState, int oldState = -1);
165 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
166 static void handleWindowScreenChanged(QWindow *window, QScreen *newScreen);
167
168 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
169 static void handleWindowDevicePixelRatioChanged(QWindow *window);
170
171 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
172 static void handleSafeAreaMarginsChanged(QWindow *window);
173
174 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
175 static void handleApplicationStateChanged(Qt::ApplicationState newState, bool forcePropagate = false);
176
177 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
178 static bool handleApplicationTermination();
179
180#if QT_CONFIG(draganddrop)
181 static QPlatformDragQtResponse handleDrag(QWindow *window, const QMimeData *dropData,
182 const QPoint &p, Qt::DropActions supportedActions,
183 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
184 static QPlatformDropQtResponse handleDrop(QWindow *window, const QMimeData *dropData,
185 const QPoint &p, Qt::DropActions supportedActions,
186 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
187#endif // QT_CONFIG(draganddrop)
188
189 static bool handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result);
190
191 // Changes to the screen
192 static void handleScreenAdded(QPlatformScreen *screen, bool isPrimary = false);
193 static void handleScreenRemoved(QPlatformScreen *screen);
194 static void handlePrimaryScreenChanged(QPlatformScreen *newPrimary);
195
196 static void handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation newOrientation);
197 static void handleScreenGeometryChange(QScreen *screen, const QRect &newGeometry, const QRect &newAvailableGeometry);
198 static void handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal newDpiX, qreal newDpiY);
199 static void handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate);
200
201 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
202 static void handleThemeChange(QWindow *window = nullptr);
203
204 static void handleFileOpenEvent(const QString& fileName);
205 static void handleFileOpenEvent(const QUrl &url);
206
207 static bool handleTabletEvent(QWindow *window, ulong timestamp, const QPointingDevice *device,
208 const QPointF &local, const QPointF &global,
209 Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
210 qreal tangentialPressure, qreal rotation, int z, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
211 static bool handleTabletEvent(QWindow *window, const QPointingDevice *device,
212 const QPointF &local, const QPointF &global,
213 Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
214 qreal tangentialPressure, qreal rotation, int z, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
215 static bool handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global,
216 int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
217 qreal tangentialPressure, qreal rotation, int z, qint64 uid,
218 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
219 static bool handleTabletEvent(QWindow *window, const QPointF &local, const QPointF &global,
220 int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
221 qreal tangentialPressure, qreal rotation, int z, qint64 uid,
222 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
223 static bool handleTabletEnterLeaveProximityEvent(QWindow *window, ulong timestamp, const QPointingDevice *device,
224 bool inProximity, const QPointF &local = QPointF(), const QPointF &global = QPointF(),
225 Qt::MouseButtons buttons = {}, int xTilt = 0, int yTilt = 0,
226 qreal tangentialPressure = 0, qreal rotation = 0, int z = 0,
227 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
228 static bool handleTabletEnterLeaveProximityEvent(QWindow *window, const QPointingDevice *device,
229 bool inProximity, const QPointF &local = QPointF(), const QPointF &global = QPointF(),
230 Qt::MouseButtons buttons = {}, int xTilt = 0, int yTilt = 0,
231 qreal tangentialPressure = 0, qreal rotation = 0, int z = 0,
232 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
233
234 // The following 4 functions are deprecated (QTBUG-114560)
235 static bool handleTabletEnterProximityEvent(ulong timestamp, int deviceType, int pointerType, qint64 uid);
236 static void handleTabletEnterProximityEvent(int deviceType, int pointerType, qint64 uid);
237 static bool handleTabletLeaveProximityEvent(ulong timestamp, int deviceType, int pointerType, qint64 uid);
238 static void handleTabletLeaveProximityEvent(int deviceType, int pointerType, qint64 uid);
239
240#ifndef QT_NO_GESTURES
241 static bool handleGestureEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::NativeGestureType type,
242 const QPointF &local, const QPointF &global, int fingerCount = 0);
243 static bool handleGestureEventWithRealValue(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::NativeGestureType type,
244 qreal value, const QPointF &local, const QPointF &global, int fingerCount = 2);
245 static bool handleGestureEventWithValueAndDelta(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::NativeGestureType type, qreal value,
246 const QPointF &delta, const QPointF &local, const QPointF &global, int fingerCount = 2);
247#endif // QT_NO_GESTURES
248
249 static void handlePlatformPanelEvent(QWindow *window);
250#ifndef QT_NO_CONTEXTMENU
251 static void handleContextMenuEvent(QWindow *window, bool mouseTriggered,
252 const QPoint &pos, const QPoint &globalPos,
253 Qt::KeyboardModifiers modifiers);
254#endif
255#if QT_CONFIG(whatsthis)
256 static void handleEnterWhatsThisEvent();
257#endif
258
259 // For event dispatcher implementations
260 static bool sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags);
261 static void setSynchronousWindowSystemEvents(bool enable);
262 static bool flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
263 static void deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags);
264 static int windowSystemEventsQueued();
265 static bool nonUserInputEventsQueued();
266};
267
268#ifndef QT_NO_DEBUG_STREAM
269Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QWindowSystemInterface::TouchPoint &p);
270#endif
271
272QT_END_NAMESPACE
273
274#endif // QWINDOWSYSTEMINTERFACE_H
275

source code of qtbase/src/gui/kernel/qwindowsysteminterface.h