1/****************************************************************************
2**
3** Copyright (C) 2016 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 QTouchDevice;
68class QPlatformDragQtResponse;
69class QPlatformDropQtResponse;
70
71
72class Q_GUI_EXPORT QWindowSystemInterface
73{
74public:
75 struct SynchronousDelivery {};
76 struct AsynchronousDelivery {};
77 struct DefaultDelivery {};
78
79#if QT_DEPRECATED_SINCE(5, 11)
80 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
81 QT_DEPRECATED static void handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons b,
82 Qt::KeyboardModifiers mods = Qt::NoModifier,
83 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
84 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
85 QT_DEPRECATED static void handleMouseEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b,
86 Qt::KeyboardModifiers mods = Qt::NoModifier,
87 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
88
89 QT_DEPRECATED static void handleFrameStrutMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons b,
90 Qt::KeyboardModifiers mods = Qt::NoModifier,
91 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
92 QT_DEPRECATED static void handleFrameStrutMouseEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b,
93 Qt::KeyboardModifiers mods = Qt::NoModifier,
94 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
95#endif
96 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
97 static void handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global,
98 Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type,
99 Qt::KeyboardModifiers mods = Qt::NoModifier,
100 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
101 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
102 static void handleMouseEvent(QWindow *window, ulong timestamp, const QPointF &local,
103 const QPointF &global, Qt::MouseButtons state,
104 Qt::MouseButton button, QEvent::Type type,
105 Qt::KeyboardModifiers mods = Qt::NoModifier,
106 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
107
108 static void handleFrameStrutMouseEvent(QWindow *window, const QPointF &local,
109 const QPointF &global, Qt::MouseButtons state,
110 Qt::MouseButton button, QEvent::Type type,
111 Qt::KeyboardModifiers mods = Qt::NoModifier,
112 Qt::MouseEventSource source =
113 Qt::MouseEventNotSynthesized);
114 static void handleFrameStrutMouseEvent(QWindow *window, ulong timestamp, const QPointF &local,
115 const QPointF &global, Qt::MouseButtons state,
116 Qt::MouseButton button, QEvent::Type type,
117 Qt::KeyboardModifiers mods = Qt::NoModifier,
118 Qt::MouseEventSource source =
119 Qt::MouseEventNotSynthesized);
120
121 static bool handleShortcutEvent(QWindow *window, ulong timestamp, int k, Qt::KeyboardModifiers mods, quint32 nativeScanCode,
122 quint32 nativeVirtualKey, quint32 nativeModifiers, const QString & text = QString(), bool autorep = false, ushort count = 1);
123
124 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
125 static bool handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1);
126 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
127 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);
128
129 static bool handleExtendedKeyEvent(QWindow *window, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
130 quint32 nativeScanCode, quint32 nativeVirtualKey,
131 quint32 nativeModifiers,
132 const QString& text = QString(), bool autorep = false,
133 ushort count = 1, bool tryShortcutOverride = true);
134 static bool handleExtendedKeyEvent(QWindow *window, ulong timestamp, 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 void 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 void 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
151#if QT_DEPRECATED_SINCE(5, 10)
152 QT_DEPRECATED static void handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier);
153 QT_DEPRECATED static void handleWheelEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier);
154#endif
155
156 struct TouchPoint {
157 TouchPoint() : id(0), uniqueId(-1), pressure(0), rotation(0), state(Qt::TouchPointStationary) { }
158 int id; // for application use
159 qint64 uniqueId; // for TUIO: object/token ID; otherwise empty
160 // TODO for TUIO 2.0: add registerPointerUniqueID(QPointingDeviceUniqueId)
161 QPointF normalPosition; // touch device coordinates, (0 to 1, 0 to 1)
162 QRectF area; // dimensions of the elliptical contact patch, unrotated, and centered at position in screen coordinates
163 // width is the horizontal diameter, height is the vertical diameter
164 qreal pressure; // 0 to 1
165 qreal rotation; // rotation applied to the elliptical contact patch
166 // 0 means pointing straight up; 0 if unknown (like QTabletEvent::rotation)
167 Qt::TouchPointState state; //Qt::TouchPoint{Pressed|Moved|Stationary|Released}
168 QVector2D velocity; // in screen coordinate system, pixels / seconds
169 QTouchEvent::TouchPoint::InfoFlags flags;
170 QVector<QPointF> rawPositions; // in screen coordinates
171 };
172
173 static void registerTouchDevice(const QTouchDevice *device);
174 static void unregisterTouchDevice(const QTouchDevice *device);
175 static bool isTouchDeviceRegistered(const QTouchDevice *device);
176
177 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
178 static void handleTouchEvent(QWindow *window, QTouchDevice *device,
179 const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier);
180 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
181 static void handleTouchEvent(QWindow *window, ulong timestamp, QTouchDevice *device,
182 const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier);
183 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
184 static void handleTouchCancelEvent(QWindow *window, QTouchDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier);
185 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
186 static void handleTouchCancelEvent(QWindow *window, ulong timestamp, QTouchDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier);
187
188 // rect is relative to parent
189 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
190 static void handleGeometryChange(QWindow *window, const QRect &newRect);
191
192 // region is in local coordinates, do not confuse with geometry which is parent-relative
193 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
194 static void handleExposeEvent(QWindow *window, const QRegion &region);
195
196 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
197 static void handleCloseEvent(QWindow *window, bool *accepted = nullptr);
198
199 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
200 static void handleEnterEvent(QWindow *window, const QPointF &local = QPointF(), const QPointF& global = QPointF());
201 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
202 static void handleLeaveEvent(QWindow *window);
203 static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local = QPointF(), const QPointF& global = QPointF());
204 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
205 static void handleWindowActivated(QWindow *window, Qt::FocusReason r = Qt::OtherFocusReason);
206
207 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
208 static void handleWindowStateChanged(QWindow *window, Qt::WindowStates newState, int oldState = -1);
209 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
210 static void handleWindowScreenChanged(QWindow *window, QScreen *newScreen);
211
212 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
213 static void handleSafeAreaMarginsChanged(QWindow *window);
214
215 template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
216 static void handleApplicationStateChanged(Qt::ApplicationState newState, bool forcePropagate = false);
217
218#if QT_CONFIG(draganddrop)
219#if QT_DEPRECATED_SINCE(5, 11)
220 QT_DEPRECATED static QPlatformDragQtResponse handleDrag(QWindow *window, const QMimeData *dropData,
221 const QPoint &p, Qt::DropActions supportedActions);
222 QT_DEPRECATED static QPlatformDropQtResponse handleDrop(QWindow *window, const QMimeData *dropData,
223 const QPoint &p, Qt::DropActions supportedActions);
224#endif // #if QT_DEPRECATED_SINCE(5, 11)
225 static QPlatformDragQtResponse handleDrag(QWindow *window, const QMimeData *dropData,
226 const QPoint &p, Qt::DropActions supportedActions,
227 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
228 static QPlatformDropQtResponse handleDrop(QWindow *window, const QMimeData *dropData,
229 const QPoint &p, Qt::DropActions supportedActions,
230 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
231#endif // QT_CONFIG(draganddrop)
232
233 static bool handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result);
234
235 // Changes to the screen
236 static void handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation newOrientation);
237 static void handleScreenGeometryChange(QScreen *screen, const QRect &newGeometry, const QRect &newAvailableGeometry);
238 static void handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal newDpiX, qreal newDpiY);
239 static void handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate);
240
241 static void handleThemeChange(QWindow *window);
242
243 static void handleFileOpenEvent(const QString& fileName);
244 static void handleFileOpenEvent(const QUrl &url);
245
246 static void handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global,
247 int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
248 qreal tangentialPressure, qreal rotation, int z, qint64 uid,
249 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
250 static void handleTabletEvent(QWindow *window, const QPointF &local, const QPointF &global,
251 int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
252 qreal tangentialPressure, qreal rotation, int z, qint64 uid,
253 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
254#if QT_DEPRECATED_SINCE(5, 10)
255 QT_DEPRECATED static void handleTabletEvent(QWindow *window, ulong timestamp, bool down, const QPointF &local, const QPointF &global,
256 int device, int pointerType, qreal pressure, int xTilt, int yTilt,
257 qreal tangentialPressure, qreal rotation, int z, qint64 uid,
258 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
259 QT_DEPRECATED static void handleTabletEvent(QWindow *window, bool down, const QPointF &local, const QPointF &global,
260 int device, int pointerType, qreal pressure, int xTilt, int yTilt,
261 qreal tangentialPressure, qreal rotation, int z, qint64 uid,
262 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
263#endif
264 static void handleTabletEnterProximityEvent(ulong timestamp, int device, int pointerType, qint64 uid);
265 static void handleTabletEnterProximityEvent(int device, int pointerType, qint64 uid);
266 static void handleTabletLeaveProximityEvent(ulong timestamp, int device, int pointerType, qint64 uid);
267 static void handleTabletLeaveProximityEvent(int device, int pointerType, qint64 uid);
268
269#ifndef QT_NO_GESTURES
270 static void handleGestureEvent(QWindow *window, QTouchDevice *device, ulong timestamp, Qt::NativeGestureType type,
271 QPointF &local, QPointF &global);
272 static void handleGestureEventWithRealValue(QWindow *window, QTouchDevice *device, ulong timestamp, Qt::NativeGestureType type,
273 qreal value, QPointF &local, QPointF &global);
274 static void handleGestureEventWithSequenceIdAndValue(QWindow *window, QTouchDevice *device, ulong timestamp,Qt::NativeGestureType type,
275 ulong sequenceId, quint64 value, QPointF &local, QPointF &global);
276#endif // QT_NO_GESTURES
277
278 static void handlePlatformPanelEvent(QWindow *window);
279#ifndef QT_NO_CONTEXTMENU
280 static void handleContextMenuEvent(QWindow *window, bool mouseTriggered,
281 const QPoint &pos, const QPoint &globalPos,
282 Qt::KeyboardModifiers modifiers);
283#endif
284#if QT_CONFIG(whatsthis)
285 static void handleEnterWhatsThisEvent();
286#endif
287
288 // For event dispatcher implementations
289 static bool sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags);
290 static void setSynchronousWindowSystemEvents(bool enable);
291 static bool flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
292 static void deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags);
293 static int windowSystemEventsQueued();
294 static bool nonUserInputEventsQueued();
295 static void setPlatformFiltersEvents(bool enable);
296};
297
298#ifndef QT_NO_DEBUG_STREAM
299Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QWindowSystemInterface::TouchPoint &p);
300#endif
301
302QT_END_NAMESPACE
303
304#endif // QWINDOWSYSTEMINTERFACE_H
305