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