Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwindowsysteminterface_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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_P_H
4#define QWINDOWSYSTEMINTERFACE_P_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <QtGui/private/qevent_p.h>
18#include <QtGui/private/qtguiglobal_p.h>
20
21#include <QElapsedTimer>
22#include <QPointer>
23#include <QMutex>
24#include <QList>
25#include <QWaitCondition>
26#include <QAtomicInt>
27#include <QLoggingCategory>
28
30
31Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices);
32
34
36public:
37 enum EventType {
38 UserInputEvent = 0x100,
39 Close = UserInputEvent | 0x01,
40 GeometryChange = 0x02,
41 Enter = UserInputEvent | 0x03,
42 Leave = UserInputEvent | 0x04,
43 FocusWindow = 0x05,
44 WindowStateChanged = 0x06,
45 Mouse = UserInputEvent | 0x07,
46 Wheel = UserInputEvent | 0x09,
47 Key = UserInputEvent | 0x0a,
48 Touch = UserInputEvent | 0x0b,
49 ScreenOrientation = 0x0c,
50 ScreenGeometry = 0x0d,
51 ScreenAvailableGeometry = 0x0e,
52 ScreenLogicalDotsPerInch = 0x0f,
53 ScreenRefreshRate = 0x10,
54 ThemeChange = 0x11,
55 Expose = 0x12,
56 FileOpen = UserInputEvent | 0x13,
57 Tablet = UserInputEvent | 0x14,
58 TabletEnterProximity = UserInputEvent | 0x15,
59 TabletLeaveProximity = UserInputEvent | 0x16,
60 PlatformPanel = UserInputEvent | 0x17,
61 ContextMenu = UserInputEvent | 0x18,
62 EnterWhatsThisMode = UserInputEvent | 0x19,
63#ifndef QT_NO_GESTURES
64 Gesture = UserInputEvent | 0x1a,
65#endif
66 ApplicationStateChanged = 0x19,
67 FlushEvents = 0x20,
68 WindowScreenChanged = 0x21,
69 SafeAreaMarginsChanged = 0x22,
70 ApplicationTermination = 0x23,
71 Paint = 0x24,
72 WindowDevicePixelRatioChanged = 0x25,
73 };
74
76 public:
77 enum {
78 Synthetic = 0x1,
79 NullWindow = 0x2
80 };
81
83 : type(t), flags(0), eventAccepted(true) { }
84 virtual ~WindowSystemEvent() { }
85
86 bool synthetic() const { return flags & Synthetic; }
87 bool nullWindow() const { return flags & NullWindow; }
88
90 int flags;
92 };
93
95 public:
96 explicit CloseEvent(QWindow *w)
97 : WindowSystemEvent(Close), window(w)
98 { }
99 QPointer<QWindow> window;
100 };
101
103 public:
104 GeometryChangeEvent(QWindow *window, const QRect &newGeometry);
105 QPointer<QWindow> window;
108 };
109
111 public:
112 explicit EnterEvent(QWindow *enter, const QPointF &local, const QPointF &global)
113 : WindowSystemEvent(Enter), enter(enter), localPos(local), globalPos(global)
114 { }
115 QPointer<QWindow> enter;
118 };
119
121 public:
123 : WindowSystemEvent(Leave), leave(leave)
124 { }
125 QPointer<QWindow> leave;
126 };
127
129 public:
130 explicit FocusWindowEvent(QWindow *focusedWindow, Qt::FocusReason r)
131 : WindowSystemEvent(FocusWindow), focused(focusedWindow), reason(r)
132 { }
133 QPointer<QWindow> focused;
135 };
136
138 public:
139 WindowStateChangedEvent(QWindow *_window, Qt::WindowStates _newState, Qt::WindowStates _oldState)
140 : WindowSystemEvent(WindowStateChanged), window(_window), newState(_newState), oldState(_oldState)
141 { }
142
143 QPointer<QWindow> window;
144 Qt::WindowStates newState;
145 Qt::WindowStates oldState;
146 };
147
149 public:
151 : WindowSystemEvent(WindowScreenChanged), window(w), screen(s)
152 { }
153
154 QPointer<QWindow> window;
155 QPointer<QScreen> screen;
156 };
157
159 public:
161 : WindowSystemEvent(WindowDevicePixelRatioChanged), window(w)
162 { }
163
164 QPointer<QWindow> window;
165 };
166
168 public:
170 : WindowSystemEvent(SafeAreaMarginsChanged), window(w)
171 { }
172
173 QPointer<QWindow> window;
174 };
175
177 public:
179 : WindowSystemEvent(ApplicationStateChanged), newState(newState), forcePropagate(forcePropagate)
180 { }
181
184 };
185
187 public:
188 FlushEventsEvent(QEventLoop::ProcessEventsFlags f = QEventLoop::AllEvents)
189 : WindowSystemEvent(FlushEvents)
190 , flags(f)
191 { }
192 QEventLoop::ProcessEventsFlags flags;
193 };
194
196 public:
198 : WindowSystemEvent(t), window(w), timestamp(time)
199 {
200 if (!w)
201 flags |= NullWindow;
202 }
203 QPointer<QWindow> window;
204 unsigned long timestamp;
205 };
206
207 class InputEvent: public UserEvent {
208 public:
209 InputEvent(QWindow *w, ulong time, EventType t, Qt::KeyboardModifiers mods, const QInputDevice *dev)
210 : UserEvent(w, time, t), modifiers(mods), device(dev) {}
211 Qt::KeyboardModifiers modifiers;
213 };
214
215 class PointerEvent : public InputEvent {
216 public:
217 PointerEvent(QWindow * w, ulong time, EventType t, Qt::KeyboardModifiers mods, const QPointingDevice *device)
218 : InputEvent(w, time, t, mods, device) {}
219 };
220
221 class MouseEvent : public PointerEvent {
222 public:
224 Qt::MouseButtons state, Qt::KeyboardModifiers mods,
228 : PointerEvent(w, time, Mouse, mods, device), localPos(local), globalPos(global),
229 buttons(state), source(src), nonClientArea(frame), button(b), buttonType(type) { }
230
233 Qt::MouseButtons buttons;
238 };
239
240 class WheelEvent : public PointerEvent {
241 public:
242 WheelEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O,
244 bool inverted = false, const QPointingDevice *device = QPointingDevice::primaryPointingDevice())
245 : PointerEvent(w, time, Wheel, mods, device), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D),
246 qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src), inverted(inverted) { }
256 };
257
258 class KeyEvent : public InputEvent {
259 public:
260 KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods,
261 const QString & text = QString(), bool autorep = false, ushort count = 1,
263 : InputEvent(w, time, Key, mods, device), source(nullptr), key(k), unicode(text),
264 repeat(autorep), repeatCount(count), keyType(t),
265 nativeScanCode(0), nativeVirtualKey(0), nativeModifiers(0) { }
266 KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods,
267 quint32 nativeSC, quint32 nativeVK, quint32 nativeMods,
268 const QString & text = QString(), bool autorep = false, ushort count = 1,
270 : InputEvent(w, time, Key, mods, device), source(nullptr), key(k), unicode(text),
271 repeat(autorep), repeatCount(count), keyType(t),
272 nativeScanCode(nativeSC), nativeVirtualKey(nativeVK), nativeModifiers(nativeMods) { }
274 int key;
276 bool repeat;
282 };
283
284 class TouchEvent : public PointerEvent {
285 public:
287 const QList<QEventPoint> &p, Qt::KeyboardModifiers mods)
288 : PointerEvent(w, time, Touch, mods, device), points(p), touchType(t) { }
289 QList<QEventPoint> points;
291 };
292
294 public:
296 : WindowSystemEvent(ScreenOrientation), screen(s), orientation(o) { }
297 QPointer<QScreen> screen;
299 };
300
302 public:
304 : WindowSystemEvent(ScreenGeometry), screen(s), geometry(g), availableGeometry(ag) { }
305 QPointer<QScreen> screen;
308 };
309
311 public:
313 : WindowSystemEvent(ScreenLogicalDotsPerInch), screen(s), dpiX(dx), dpiY(dy) { }
314 QPointer<QScreen> screen;
317 };
318
320 public:
322 : WindowSystemEvent(ScreenRefreshRate), screen(s), rate(r) { }
323 QPointer<QScreen> screen;
325 };
326
328 public:
330 : WindowSystemEvent(ThemeChange), window(w) { }
331 QPointer<QWindow> window;
332 };
333
335 public:
336 ExposeEvent(QWindow *window, const QRegion &region);
337 QPointer<QWindow> window;
340 };
341
343 public:
345 : WindowSystemEvent(Paint), window(window), region(region) {}
346 QPointer<QWindow> window;
348 };
349
351 public:
353 : WindowSystemEvent(FileOpen), url(QUrl::fromLocalFile(fileName))
354 { }
356 : WindowSystemEvent(FileOpen), url(url)
357 { }
359 };
360
361 class Q_GUI_EXPORT TabletEvent : public PointerEvent {
362 public:
363 // TODO take QPointingDevice* instead of types and IDs
364 static void handleTabletEvent(QWindow *w, const QPointF &local, const QPointF &global,
365 int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
366 qreal tangentialPressure, qreal rotation, int z, qint64 uid,
367 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
368 static void setPlatformSynthesizesMouse(bool v);
369
371 const QPointingDevice *device, Qt::MouseButtons b, qreal pressure, int xTilt, int yTilt, qreal tpressure,
372 qreal rotation, int z, Qt::KeyboardModifiers mods)
373 : PointerEvent(w, time, Tablet, mods, device),
374 buttons(b), local(local), global(global),
375 pressure(pressure), xTilt(xTilt), yTilt(yTilt), tangentialPressure(tpressure),
376 rotation(rotation), z(z) { }
377 Qt::MouseButtons buttons;
381 int xTilt;
382 int yTilt;
385 int z;
387 };
388
390 public:
391 // TODO store more info: position and whatever else we can get on most platforms
393 : PointerEvent(nullptr, time, TabletEnterProximity, Qt::NoModifier, device) { }
394 };
395
397 public:
398 // TODO store more info: position and whatever else we can get on most platforms
400 : PointerEvent(nullptr, time, TabletLeaveProximity, Qt::NoModifier, device) { }
401 };
402
404 public:
406 : WindowSystemEvent(PlatformPanel), window(w) { }
407 QPointer<QWindow> window;
408 };
409
410#ifndef QT_NO_CONTEXTMENU
412 public:
413 explicit ContextMenuEvent(QWindow *w, bool mouseTriggered, const QPoint &pos,
414 const QPoint &globalPos, Qt::KeyboardModifiers modifiers)
415 : WindowSystemEvent(ContextMenu), window(w), mouseTriggered(mouseTriggered), pos(pos),
416 globalPos(globalPos), modifiers(modifiers) { }
417 QPointer<QWindow> window;
419 QPoint pos; // Only valid if triggered by mouse
420 QPoint globalPos; // Only valid if triggered by mouse
421 Qt::KeyboardModifiers modifiers;
422 };
423#endif
424
425#ifndef QT_NO_GESTURES
426 class GestureEvent : public PointerEvent {
427 public:
429 int fingerCount, QPointF pos, QPointF globalPos, qreal realValue, QPointF delta)
430 : PointerEvent(window, time, Gesture, Qt::NoModifier, dev), type(type), pos(pos), globalPos(globalPos),
431 delta(delta), fingerCount(fingerCount), realValue(realValue), sequenceId(0), intValue(0) { }
437 // Mac
439 // Windows
442 };
443#endif
444
446 QList<WindowSystemEvent *> impl;
447 mutable QMutex mutex;
448 public:
451
452 void clear()
453 { const QMutexLocker locker(&mutex); qDeleteAll(impl); impl.clear(); }
455 { const QMutexLocker locker(&mutex); impl.prepend(e); }
457 { const QMutexLocker locker(&mutex); return impl.empty() ? nullptr : impl.takeFirst(); }
459 {
460 const QMutexLocker locker(&mutex);
461 for (int i = 0; i < impl.size(); ++i)
462 if (!(impl.at(i)->type & QWindowSystemInterfacePrivate::UserInputEvent))
463 return impl.takeAt(i);
464 return nullptr;
465 }
467 {
468 const QMutexLocker locker(&mutex);
469 for (int i = 0; i < impl.size(); ++i)
470 if (!(impl.at(i)->type & QWindowSystemInterfacePrivate::UserInputEvent))
471 return true;
472 return false;
473 }
475 { const QMutexLocker locker(&mutex); impl.append(e); }
477 { const QMutexLocker locker(&mutex); return impl.size(); }
479 {
480 const QMutexLocker locker(&mutex);
481 for (int i = 0; i < impl.size(); ++i) {
482 if (impl.at(i)->type == t)
483 return impl.at(i);
484 }
485 return nullptr;
486 }
488 {
489 const QMutexLocker locker(&mutex);
490 for (int i = 0; i < impl.size(); ++i) {
491 if (impl.at(i) == e) {
492 delete impl.takeAt(i);
493 break;
494 }
495 }
496 }
497 private:
498 Q_DISABLE_COPY_MOVE(WindowSystemEventList)
499 };
500
502
503 static qsizetype windowSystemEventsQueued();
504 static bool nonUserInputEventsQueued();
505 static WindowSystemEvent *getWindowSystemEvent();
506 static WindowSystemEvent *getNonUserInputWindowSystemEvent();
507 static WindowSystemEvent *peekWindowSystemEvent(EventType t);
508 static void removeWindowSystemEvent(WindowSystemEvent *event);
509
510public:
514
518
519 static QList<QEventPoint>
520 fromNativeTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points,
521 const QWindow *window, QEvent::Type *type = nullptr);
522 template<class EventPointList>
523 static QList<QWindowSystemInterface::TouchPoint>
524 toNativeTouchPoints(const EventPointList &pointList, const QWindow *window)
525 {
526 QList<QWindowSystemInterface::TouchPoint> newList;
527 newList.reserve(pointList.size());
528 for (const auto &point : pointList) {
529 newList.append(toNativeTouchPoint(point, window));
530 }
531 return newList;
532 }
534 toNativeTouchPoint(const QEventPoint &point, const QWindow *window);
535
536 static void installWindowSystemEventHandler(QWindowSystemEventHandler *handler);
537 static void removeWindowSystemEventhandler(QWindowSystemEventHandler *handler);
539};
540
542{
543public:
546};
547
549
550#endif // QWINDOWSYSTEMINTERFACE_P_H
IOBluetoothDevice * device
\inmodule QtCore
Definition qatomic.h:112
\inmodule QtCore
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
The QInputDevice class describes a device from which a QInputEvent originates.
static const QInputDevice * primaryKeyboard(const QString &seatName=QString())
Returns the core or master keyboard on the given seat seatName.
\inmodule QtCore
Definition qmutex.h:313
\inmodule QtCore
Definition qmutex.h:281
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
static const QPointingDevice * primaryPointingDevice(const QString &seatName=QString())
Returns the primary pointing device (the core pointer, traditionally assumed to be a mouse) on the gi...
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
ApplicationStateChangedEvent(Qt::ApplicationState newState, bool forcePropagate=false)
ContextMenuEvent(QWindow *w, bool mouseTriggered, const QPoint &pos, const QPoint &globalPos, Qt::KeyboardModifiers modifiers)
EnterEvent(QWindow *enter, const QPointF &local, const QPointF &global)
FlushEventsEvent(QEventLoop::ProcessEventsFlags f=QEventLoop::AllEvents)
FocusWindowEvent(QWindow *focusedWindow, Qt::FocusReason r)
GestureEvent(QWindow *window, ulong time, Qt::NativeGestureType type, const QPointingDevice *dev, int fingerCount, QPointF pos, QPointF globalPos, qreal realValue, QPointF delta)
InputEvent(QWindow *w, ulong time, EventType t, Qt::KeyboardModifiers mods, const QInputDevice *dev)
KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1, const QInputDevice *device=QInputDevice::primaryKeyboard())
KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods, quint32 nativeSC, quint32 nativeVK, quint32 nativeMods, const QString &text=QString(), bool autorep=false, ushort count=1, const QInputDevice *device=QInputDevice::primaryKeyboard())
MouseEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::KeyboardModifiers mods, Qt::MouseButton b, QEvent::Type type, Qt::MouseEventSource src=Qt::MouseEventNotSynthesized, bool frame=false, const QPointingDevice *device=QPointingDevice::primaryPointingDevice())
PaintEvent(QWindow *window, const QRegion &region)
PointerEvent(QWindow *w, ulong time, EventType t, Qt::KeyboardModifiers mods, const QPointingDevice *device)
ScreenGeometryEvent(QScreen *s, const QRect &g, const QRect &ag)
TabletEnterProximityEvent(ulong time, const QPointingDevice *device)
TabletEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, const QPointingDevice *device, Qt::MouseButtons b, qreal pressure, int xTilt, int yTilt, qreal tpressure, qreal rotation, int z, Qt::KeyboardModifiers mods)
static void handleTabletEvent(QWindow *w, const QPointF &local, const QPointF &global, int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers modifiers=Qt::NoModifier)
TabletLeaveProximityEvent(ulong time, const QPointingDevice *device)
TouchEvent(QWindow *w, ulong time, QEvent::Type t, const QPointingDevice *device, const QList< QEventPoint > &p, Qt::KeyboardModifiers mods)
UserEvent(QWindow *w, ulong time, EventType t)
WheelEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase=Qt::NoScrollPhase, Qt::MouseEventSource src=Qt::MouseEventNotSynthesized, bool inverted=false, const QPointingDevice *device=QPointingDevice::primaryPointingDevice())
WindowStateChangedEvent(QWindow *_window, Qt::WindowStates _newState, Qt::WindowStates _oldState)
static QWindowSystemEventHandler * eventHandler
static WindowSystemEventList windowSystemEventQueue
static QList< QWindowSystemInterface::TouchPoint > toNativeTouchPoints(const EventPointList &pointList, const QWindow *window)
\inmodule QtGui
Definition qwindow.h:63
EGLImageKHR int int EGLuint64KHR * modifiers
b clear()
QString text
QPushButton * button
[2]
qDeleteAll(list.begin(), list.end())
else opt state
[0]
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
Combined button and popup list for selecting options.
Definition qcompare.h:63
MouseButton
Definition qnamespace.h:56
Orientation
Definition qnamespace.h:98
MouseEventSource
@ MouseEventNotSynthesized
ScreenOrientation
Definition qnamespace.h:271
@ NoModifier
ApplicationState
Definition qnamespace.h:262
NativeGestureType
ScrollPhase
@ NoScrollPhase
FocusReason
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLboolean r
[2]
GLenum GLenum GLsizei count
GLfloat GLfloat f
GLenum src
GLenum type
GLbitfield flags
GLboolean GLboolean g
GLsizei GLsizei GLchar * source
struct _cl_event * event
GLfixed GLfixed GLint GLint GLfixed points
GLdouble s
[6]
Definition qopenglext.h:235
GLuint GLenum * rate
GLdouble GLdouble t
Definition qopenglext.h:243
GLfloat GLfloat p
[1]
QScreen * screen
[1]
Definition main.cpp:29
unsigned int quint32
Definition qtypes.h:50
unsigned long ulong
Definition qtypes.h:35
unsigned long long quint64
Definition qtypes.h:61
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
unsigned short ushort
Definition qtypes.h:33
double qreal
Definition qtypes.h:187
#define leave(x)
static QPointingDevice::PointerType pointerType(unsigned currentCursor)
QUrl url("example.com")
[constructor-url-reference]
QObject::connect nullptr
QMutex mutex
[2]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QFrame frame
[0]
QJSValue global