Coverage Report

Created: 2025-07-16 07:53

/src/qtbase/src/gui/kernel/qwindowsysteminterface.h
Line
Count
Source (jump to first uncovered line)
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/QMutex>
23
#include <QtGui/QTouchEvent>
24
#include <QtCore/QEventLoop>
25
#include <QtGui/QVector2D>
26
27
QT_BEGIN_NAMESPACE
28
29
class QMimeData;
30
class QPointingDevice;
31
class QPlatformDragQtResponse;
32
class QPlatformDropQtResponse;
33
34
35
class Q_GUI_EXPORT QWindowSystemInterface
36
{
37
public:
38
    struct SynchronousDelivery {};
39
    struct AsynchronousDelivery {};
40
    struct DefaultDelivery {};
41
42
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
43
    static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global,
44
                                 Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type,
45
                                 Qt::KeyboardModifiers mods = Qt::NoModifier,
46
                                 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
47
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
48
    static bool handleMouseEvent(QWindow *window,  const QPointingDevice *device,
49
                                 const QPointF &local, const QPointF &global,
50
                                 Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type,
51
                                 Qt::KeyboardModifiers mods = Qt::NoModifier,
52
                                 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
53
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
54
    static bool handleMouseEvent(QWindow *window, ulong timestamp, const QPointF &local,
55
                                 const QPointF &global, Qt::MouseButtons state,
56
                                 Qt::MouseButton button, QEvent::Type type,
57
                                 Qt::KeyboardModifiers mods = Qt::NoModifier,
58
                                 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
59
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
60
    static bool handleMouseEvent(QWindow *window, ulong timestamp, const QPointingDevice *device,
61
                                 const QPointF &local, const QPointF &global, Qt::MouseButtons state,
62
                                 Qt::MouseButton button, QEvent::Type type,
63
                                 Qt::KeyboardModifiers mods = Qt::NoModifier,
64
                                 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
65
66
    static bool handleShortcutEvent(QWindow *window, ulong timestamp, int k, Qt::KeyboardModifiers mods, quint32 nativeScanCode,
67
                                      quint32 nativeVirtualKey, quint32 nativeModifiers, const QString & text = QString(), bool autorep = false, ushort count = 1);
68
69
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
70
    static bool handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1);
71
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
72
    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);
73
74
    static bool handleExtendedKeyEvent(QWindow *window, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
75
                                       quint32 nativeScanCode, quint32 nativeVirtualKey,
76
                                       quint32 nativeModifiers,
77
                                       const QString& text = QString(), bool autorep = false,
78
                                       ushort count = 1);
79
    static bool handleExtendedKeyEvent(QWindow *window, ulong timestamp, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
80
                                       quint32 nativeScanCode, quint32 nativeVirtualKey,
81
                                       quint32 nativeModifiers,
82
                                       const QString& text = QString(), bool autorep = false,
83
                                       ushort count = 1);
84
    static bool handleExtendedKeyEvent(QWindow *window, ulong timestamp, const QInputDevice *device,
85
                                       QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
86
                                       quint32 nativeScanCode, quint32 nativeVirtualKey,
87
                                       quint32 nativeModifiers,
88
                                       const QString& text = QString(), bool autorep = false,
89
                                       ushort count = 1);
90
    static bool handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global,
91
                                 QPoint pixelDelta, QPoint angleDelta,
92
                                 Qt::KeyboardModifiers mods = Qt::NoModifier,
93
                                 Qt::ScrollPhase phase = Qt::NoScrollPhase,
94
                                 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
95
    static bool handleWheelEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global,
96
                                 QPoint pixelDelta, QPoint angleDelta,
97
                                 Qt::KeyboardModifiers mods = Qt::NoModifier,
98
                                 Qt::ScrollPhase phase = Qt::NoScrollPhase,
99
                                 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized,
100
                                 bool inverted = false);
101
    static bool handleWheelEvent(QWindow *window, ulong timestamp, const QPointingDevice *device,
102
                                 const QPointF &local, const QPointF &global,
103
                                 QPoint pixelDelta, QPoint angleDelta,
104
                                 Qt::KeyboardModifiers mods = Qt::NoModifier,
105
                                 Qt::ScrollPhase phase = Qt::NoScrollPhase,
106
                                 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized,
107
                                 bool inverted = false);
108
109
    // A very-temporary QPA touchpoint which gets converted to a QEventPoint as early as possible
110
    // in QWindowSystemInterfacePrivate::fromNativeTouchPoints()
111
    struct TouchPoint {
112
0
        TouchPoint() : id(0), uniqueId(-1), pressure(0), rotation(0), state(QEventPoint::State::Stationary) { }
113
        int id;                 // for application use
114
        qint64 uniqueId;        // for TUIO: object/token ID; otherwise empty
115
                                // TODO for TUIO 2.0: add registerPointerUniqueID(QPointingDeviceUniqueId)
116
        QPointF normalPosition; // touch device coordinates, (0 to 1, 0 to 1)
117
        QRectF area;            // dimensions of the elliptical contact patch, unrotated, and centered at position in screen coordinates
118
                                // width is the horizontal diameter, height is the vertical diameter
119
        qreal pressure;         // 0 to 1
120
        qreal rotation;         // rotation applied to the elliptical contact patch
121
                                // 0 means pointing straight up; 0 if unknown (like QTabletEvent::rotation)
122
        QEventPoint::State state; // Pressed|Updated|Stationary|Released
123
        QVector2D velocity;     // in screen coordinate system, pixels / seconds
124
        QList<QPointF> rawPositions; // in screen coordinates
125
    };
126
127
    static void registerInputDevice(const QInputDevice *device);
128
129
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
130
    static bool handleTouchEvent(QWindow *window, const QPointingDevice *device,
131
                                 const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier);
132
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
133
    static bool handleTouchEvent(QWindow *window, ulong timestamp, const QPointingDevice *device,
134
                                 const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier);
135
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
136
    static bool handleTouchCancelEvent(QWindow *window, const QPointingDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier);
137
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
138
    static bool handleTouchCancelEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier);
139
140
    // rect is relative to parent
141
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
142
    static void handleGeometryChange(QWindow *window, const QRect &newRect);
143
144
    // region is in local coordinates, do not confuse with geometry which is parent-relative
145
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
146
    static bool handleExposeEvent(QWindow *window, const QRegion &region);
147
148
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
149
    static bool handlePaintEvent(QWindow *window, const QRegion &region);
150
151
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
152
    static bool handleCloseEvent(QWindow *window);
153
154
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
155
    static void handleEnterEvent(QWindow *window, const QPointF &local = QPointF(), const QPointF& global = QPointF());
156
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
157
    static void handleLeaveEvent(QWindow *window);
158
    static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local = QPointF(), const QPointF& global = QPointF());
159
160
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
161
    static void handleFocusWindowChanged(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();
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, qreal xTilt, qreal 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, qreal xTilt, qreal 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, qreal xTilt, qreal 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, qreal xTilt, qreal 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 = {}, qreal xTilt = 0, qreal 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 = {}, qreal xTilt = 0 , qreal 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
251
#ifndef QT_NO_CONTEXTMENU
252
#if QT_GUI_REMOVED_SINCE(6, 8)
253
    static void handleContextMenuEvent(QWindow *window, bool mouseTriggered,
254
                                       const QPoint &pos, const QPoint &globalPos,
255
                                       Qt::KeyboardModifiers modifiers);
256
#endif
257
    template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
258
    static bool handleContextMenuEvent(QWindow *window, bool mouseTriggered,
259
                                       const QPoint &pos, const QPoint &globalPos,
260
                                       Qt::KeyboardModifiers modifiers);
261
#endif
262
#if QT_CONFIG(whatsthis)
263
    static void handleEnterWhatsThisEvent();
264
#endif
265
266
    // For event dispatcher implementations
267
    static bool sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags);
268
    static void setSynchronousWindowSystemEvents(bool enable);
269
    static bool flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
270
    static void deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags);
271
    static int windowSystemEventsQueued();
272
    static bool nonUserInputEventsQueued();
273
};
274
275
#ifndef QT_NO_DEBUG_STREAM
276
Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QWindowSystemInterface::TouchPoint &p);
277
#endif
278
279
QT_END_NAMESPACE
280
281
#endif // QWINDOWSYSTEMINTERFACE_H