Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4#ifndef QWINDOWSYSTEMINTERFACE_P_H
5#define QWINDOWSYSTEMINTERFACE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/private/qevent_p.h>
19#include <QtGui/private/qtguiglobal_p.h>
21
22#include <QElapsedTimer>
23#include <QPointer>
24#include <QMutex>
25#include <QList>
26#include <QWaitCondition>
27#include <QAtomicInt>
28#include <QLoggingCategory>
29
31
32QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY(lcQpaInputDevices, Q_GUI_EXPORT)
33
34class QWindowSystemEventHandler;
35
37public:
38 enum EventType {
39 UserInputEvent = 0x100,
40 Close = UserInputEvent | 0x01,
41 GeometryChange = 0x02,
42 Enter = UserInputEvent | 0x03,
43 Leave = UserInputEvent | 0x04,
44 FocusWindow = 0x05,
45 WindowStateChanged = 0x06,
46 Mouse = UserInputEvent | 0x07,
47 Wheel = UserInputEvent | 0x09,
48 Key = UserInputEvent | 0x0a,
49 Touch = UserInputEvent | 0x0b,
50 ScreenOrientation = 0x0c,
51 ScreenGeometry = 0x0d,
52 ScreenAvailableGeometry = 0x0e,
53 ScreenLogicalDotsPerInch = 0x0f,
54 ScreenRefreshRate = 0x10,
55 ThemeChange = 0x11,
56 Expose = 0x12,
57 FileOpen = UserInputEvent | 0x13,
58 Tablet = UserInputEvent | 0x14,
59 TabletEnterProximity = UserInputEvent | 0x15,
60 TabletLeaveProximity = UserInputEvent | 0x16,
61 PlatformPanel = UserInputEvent | 0x17,
62 ContextMenu = UserInputEvent | 0x18,
63 EnterWhatsThisMode = UserInputEvent | 0x19,
64#ifndef QT_NO_GESTURES
65 Gesture = UserInputEvent | 0x1a,
66#endif
67 ApplicationStateChanged = 0x19,
68 FlushEvents = 0x20,
69 WindowScreenChanged = 0x21,
70 SafeAreaMarginsChanged = 0x22,
71 ApplicationTermination = 0x23,
72 Paint = 0x24,
73 WindowDevicePixelRatioChanged = 0x25,
74 };
75
76 class WindowSystemEvent {
77 public:
78 enum {
79 Synthetic = 0x1,
80 NullWindow = 0x2
81 };
82
83 explicit WindowSystemEvent(EventType t)
84 : type(t), flags(0), eventAccepted(true) { }
85 virtual ~WindowSystemEvent() { }
86
87 bool synthetic() const { return flags & Synthetic; }
88 bool nullWindow() const { return flags & NullWindow; }
89
90 EventType type;
91 int flags;
92 bool eventAccepted;
93 };
94
95 class CloseEvent : public WindowSystemEvent {
96 public:
97 explicit CloseEvent(QWindow *w)
98 : WindowSystemEvent(Close), window(w)
99 { }
100 QPointer<QWindow> window;
101 };
102
103 class GeometryChangeEvent : public WindowSystemEvent {
104 public:
105 GeometryChangeEvent(QWindow *window, QRect requestedGeometry, QRect newGeometry);
106 QPointer<QWindow> window;
107 QRect requestedGeometry;
108 QRect newGeometry;
109 };
110
111 class EnterEvent : public WindowSystemEvent {
112 public:
113 explicit EnterEvent(QWindow *enter, const QPointF &local, const QPointF &global)
114 : WindowSystemEvent(Enter), enter(enter), localPos(local), globalPos(global)
115 { }
116 QPointer<QWindow> enter;
117 const QPointF localPos;
118 const QPointF globalPos;
119 };
120
121 class LeaveEvent : public WindowSystemEvent {
122 public:
123 explicit LeaveEvent(QWindow *leave)
124 : WindowSystemEvent(Leave), leave(leave)
125 { }
126 QPointer<QWindow> leave;
127 };
128
129 class FocusWindowEvent : public WindowSystemEvent {
130 public:
131 explicit FocusWindowEvent(QWindow *focusedWindow, Qt::FocusReason r)
132 : WindowSystemEvent(FocusWindow), focused(focusedWindow), reason(r)
133 { }
134 QPointer<QWindow> focused;
135 Qt::FocusReason reason;
136 };
137
138 class WindowStateChangedEvent : public WindowSystemEvent {
139 public:
140 WindowStateChangedEvent(QWindow *_window, Qt::WindowStates _newState, Qt::WindowStates _oldState)
141 : WindowSystemEvent(WindowStateChanged), window(_window), newState(_newState), oldState(_oldState)
142 { }
143
144 QPointer<QWindow> window;
145 Qt::WindowStates newState;
146 Qt::WindowStates oldState;
147 };
148
149 class WindowScreenChangedEvent : public WindowSystemEvent {
150 public:
151 WindowScreenChangedEvent(QWindow *w, QScreen *s)
152 : WindowSystemEvent(WindowScreenChanged), window(w), screen(s)
153 { }
154
155 QPointer<QWindow> window;
156 QPointer<QScreen> screen;
157 };
158
159 class WindowDevicePixelRatioChangedEvent : public WindowSystemEvent {
160 public:
161 WindowDevicePixelRatioChangedEvent(QWindow *w)
162 : WindowSystemEvent(WindowDevicePixelRatioChanged), window(w)
163 { }
164
165 QPointer<QWindow> window;
166 };
167
168 class SafeAreaMarginsChangedEvent : public WindowSystemEvent {
169 public:
170 SafeAreaMarginsChangedEvent(QWindow *w)
171 : WindowSystemEvent(SafeAreaMarginsChanged), window(w)
172 { }
173
174 QPointer<QWindow> window;
175 };
176
177 class ApplicationStateChangedEvent : public WindowSystemEvent {
178 public:
179 ApplicationStateChangedEvent(Qt::ApplicationState newState, bool forcePropagate = false)
180 : WindowSystemEvent(ApplicationStateChanged), newState(newState), forcePropagate(forcePropagate)
181 { }
182
183 Qt::ApplicationState newState;
184 bool forcePropagate;
185 };
186
187 class FlushEventsEvent : public WindowSystemEvent {
188 public:
189 FlushEventsEvent(QEventLoop::ProcessEventsFlags f = QEventLoop::AllEvents)
190 : WindowSystemEvent(FlushEvents)
191 , flags(f)
192 { }
193 QEventLoop::ProcessEventsFlags flags;
194 };
195
196 class UserEvent : public WindowSystemEvent {
197 public:
198 UserEvent(QWindow * w, ulong time, EventType t)
199 : WindowSystemEvent(t), window(w), timestamp(time)
200 {
201 if (!w)
202 flags |= NullWindow;
203 }
204 QPointer<QWindow> window;
205 unsigned long timestamp;
206 };
207
208 class InputEvent: public UserEvent {
209 public:
210 InputEvent(QWindow *w, ulong time, EventType t, Qt::KeyboardModifiers mods, const QInputDevice *dev)
211 : UserEvent(w, time, t), modifiers(mods), device(dev) {}
212 Qt::KeyboardModifiers modifiers;
213 const QInputDevice *device;
214 };
215
216 class PointerEvent : public InputEvent {
217 public:
218 PointerEvent(QWindow * w, ulong time, EventType t, Qt::KeyboardModifiers mods, const QPointingDevice *device)
219 : InputEvent(w, time, t, mods, device) {}
220 };
221
222 class MouseEvent : public PointerEvent {
223 public:
224 MouseEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global,
225 Qt::MouseButtons state, Qt::KeyboardModifiers mods,
226 Qt::MouseButton b, QEvent::Type type,
227 Qt::MouseEventSource src = Qt::MouseEventNotSynthesized, bool frame = false,
228 const QPointingDevice *device = QPointingDevice::primaryPointingDevice(),
229 int evPtId = -1)
230 : PointerEvent(w, time, Mouse, mods, device), localPos(local), globalPos(global),
231 buttons(state), source(src), nonClientArea(frame), button(b), buttonType(type),
232 eventPointId(evPtId) { }
233
234 QPointF localPos;
235 QPointF globalPos;
236 Qt::MouseButtons buttons;
237 Qt::MouseEventSource source;
238 bool nonClientArea;
239 Qt::MouseButton button;
240 QEvent::Type buttonType;
241 int eventPointId; // from the original device if synth-mouse, otherwise -1
242 };
243
244 class WheelEvent : public PointerEvent {
245 public:
246 WheelEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O,
247 Qt::KeyboardModifiers mods, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized,
248 bool inverted = false, const QPointingDevice *device = QPointingDevice::primaryPointingDevice())
249 : PointerEvent(w, time, Wheel, mods, device), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D),
250 qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src), inverted(inverted) { }
251 QPoint pixelDelta;
252 QPoint angleDelta;
253 int qt4Delta;
254 Qt::Orientation qt4Orientation;
255 QPointF localPos;
256 QPointF globalPos;
257 Qt::ScrollPhase phase;
258 Qt::MouseEventSource source;
259 bool inverted;
260 };
261
262 class KeyEvent : public InputEvent {
263 public:
264 KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods,
265 const QString & text = QString(), bool autorep = false, ushort count = 1,
266 const QInputDevice *device = QInputDevice::primaryKeyboard())
267 : InputEvent(w, time, Key, mods, device), source(nullptr), key(k), unicode(text),
268 repeat(autorep), repeatCount(count), keyType(t),
269 nativeScanCode(0), nativeVirtualKey(0), nativeModifiers(0) { }
270 KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods,
271 quint32 nativeSC, quint32 nativeVK, quint32 nativeMods,
272 const QString & text = QString(), bool autorep = false, ushort count = 1,
273 const QInputDevice *device = QInputDevice::primaryKeyboard())
274 : InputEvent(w, time, Key, mods, device), source(nullptr), key(k), unicode(text),
275 repeat(autorep), repeatCount(count), keyType(t),
276 nativeScanCode(nativeSC), nativeVirtualKey(nativeVK), nativeModifiers(nativeMods) { }
277 const QInputDevice *source;
278 int key;
279 QString unicode;
280 bool repeat;
281 ushort repeatCount;
282 QEvent::Type keyType;
283 quint32 nativeScanCode;
284 quint32 nativeVirtualKey;
285 quint32 nativeModifiers;
286 };
287
288 class TouchEvent : public PointerEvent {
289 public:
290 TouchEvent(QWindow *w, ulong time, QEvent::Type t, const QPointingDevice *device,
291 const QList<QEventPoint> &p, Qt::KeyboardModifiers mods)
292 : PointerEvent(w, time, Touch, mods, device), points(p), touchType(t) { }
293 QList<QEventPoint> points;
294 QEvent::Type touchType;
295 };
296
297 class ScreenOrientationEvent : public WindowSystemEvent {
298 public:
299 ScreenOrientationEvent(QScreen *s, Qt::ScreenOrientation o)
300 : WindowSystemEvent(ScreenOrientation), screen(s), orientation(o) { }
301 QPointer<QScreen> screen;
302 Qt::ScreenOrientation orientation;
303 };
304
305 class ScreenGeometryEvent : public WindowSystemEvent {
306 public:
307 ScreenGeometryEvent(QScreen *s, const QRect &g, const QRect &ag)
308 : WindowSystemEvent(ScreenGeometry), screen(s), geometry(g), availableGeometry(ag) { }
309 QPointer<QScreen> screen;
310 QRect geometry;
311 QRect availableGeometry;
312 };
313
314 class ScreenLogicalDotsPerInchEvent : public WindowSystemEvent {
315 public:
316 ScreenLogicalDotsPerInchEvent(QScreen *s, qreal dx, qreal dy)
317 : WindowSystemEvent(ScreenLogicalDotsPerInch), screen(s), dpiX(dx), dpiY(dy) { }
318 QPointer<QScreen> screen;
319 qreal dpiX;
320 qreal dpiY;
321 };
322
323 class ScreenRefreshRateEvent : public WindowSystemEvent {
324 public:
325 ScreenRefreshRateEvent(QScreen *s, qreal r)
326 : WindowSystemEvent(ScreenRefreshRate), screen(s), rate(r) { }
327 QPointer<QScreen> screen;
328 qreal rate;
329 };
330
331 class ThemeChangeEvent : public WindowSystemEvent {
332 public:
333 explicit ThemeChangeEvent()
334 : WindowSystemEvent(ThemeChange) { }
335 };
336
337 class ExposeEvent : public WindowSystemEvent {
338 public:
339 ExposeEvent(QWindow *window, const QRegion &region);
340 QPointer<QWindow> window;
341 bool isExposed;
342 QRegion region;
343 };
344
345 class PaintEvent : public WindowSystemEvent {
346 public:
347 PaintEvent(QWindow *window, const QRegion &region)
348 : WindowSystemEvent(Paint), window(window), region(region) {}
349 QPointer<QWindow> window;
350 QRegion region;
351 };
352
353 class FileOpenEvent : public WindowSystemEvent {
354 public:
355 FileOpenEvent(const QString& fileName)
356 : WindowSystemEvent(FileOpen), url(QUrl::fromLocalFile(fileName))
357 { }
358 FileOpenEvent(const QUrl &url)
359 : WindowSystemEvent(FileOpen), url(url)
360 { }
361 QUrl url;
362 };
363
364 class Q_GUI_EXPORT TabletEvent : public PointerEvent {
365 public:
366 // TODO take QPointingDevice* instead of types and IDs
367 static void handleTabletEvent(QWindow *w, const QPointF &local, const QPointF &global,
368 int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
369 qreal tangentialPressure, qreal rotation, qreal z, qint64 uid,
370 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
371 static void setPlatformSynthesizesMouse(bool v);
372
373 TabletEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global,
374 const QPointingDevice *device, Qt::MouseButtons b, qreal pressure, qreal xTilt, qreal yTilt, qreal tpressure,
375 qreal rotation, qreal z, Qt::KeyboardModifiers mods)
376 : PointerEvent(w, time, Tablet, mods, device),
377 buttons(b), local(local), global(global),
378 pressure(pressure), xTilt(xTilt), yTilt(yTilt), tangentialPressure(tpressure),
379 rotation(rotation), z(z) { }
380 Qt::MouseButtons buttons;
381 QPointF local;
382 QPointF global;
383 qreal pressure = 0;
384 qreal xTilt = 0;
385 qreal yTilt = 0;
386 qreal tangentialPressure = 0;
387 qreal rotation = 0;
388 qreal z = 0;
389 static bool platformSynthesizesMouse;
390 };
391
392 class TabletEnterProximityEvent : public TabletEvent {
393 public:
394 TabletEnterProximityEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global,
395 const QPointingDevice *device, Qt::MouseButtons b, qreal xTilt, qreal yTilt,
396 qreal tpressure, qreal rotation, qreal z, Qt::KeyboardModifiers mods)
397 : TabletEvent(w, time, local, global, device, b, 0, xTilt, yTilt, tpressure, rotation, z, mods)
398 {
399 type = TabletEnterProximity;
400 }
401 };
402
403 class TabletLeaveProximityEvent : public TabletEvent {
404 public:
405 TabletLeaveProximityEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global,
406 const QPointingDevice *device, Qt::MouseButtons b, qreal xTilt, qreal yTilt,
407 qreal tpressure, qreal rotation, qreal z, Qt::KeyboardModifiers mods)
408 : TabletEvent(w, time, local, global, device, b, 0, xTilt, yTilt, tpressure, rotation, z, mods)
409 {
410 type = TabletLeaveProximity;
411 }
412 };
413
414 class PlatformPanelEvent : public WindowSystemEvent {
415 public:
416 explicit PlatformPanelEvent(QWindow *w)
417 : WindowSystemEvent(PlatformPanel), window(w) { }
418 QPointer<QWindow> window;
419 };
420
421#ifndef QT_NO_CONTEXTMENU
422 class ContextMenuEvent : public WindowSystemEvent {
423 public:
424 explicit ContextMenuEvent(QWindow *w, bool mouseTriggered, const QPoint &pos,
425 const QPoint &globalPos, Qt::KeyboardModifiers modifiers)
426 : WindowSystemEvent(ContextMenu), window(w), mouseTriggered(mouseTriggered), pos(pos),
427 globalPos(globalPos), modifiers(modifiers) { }
428 QPointer<QWindow> window;
429 bool mouseTriggered;
430 QPoint pos; // Only valid if triggered by mouse
431 QPoint globalPos; // Only valid if triggered by mouse
432 Qt::KeyboardModifiers modifiers;
433 };
434#endif
435
436#ifndef QT_NO_GESTURES
437 class GestureEvent : public PointerEvent {
438 public:
439 GestureEvent(QWindow *window, ulong time, Qt::NativeGestureType type, const QPointingDevice *dev,
440 int fingerCount, QPointF pos, QPointF globalPos, qreal realValue, QPointF delta)
441 : PointerEvent(window, time, Gesture, Qt::NoModifier, dev), type(type), pos(pos), globalPos(globalPos),
442 delta(delta), fingerCount(fingerCount), realValue(realValue), sequenceId(0), intValue(0) { }
443 Qt::NativeGestureType type;
444 QPointF pos;
445 QPointF globalPos;
446 QPointF delta;
447 int fingerCount;
448 // Mac
449 qreal realValue;
450 // Windows
451 ulong sequenceId;
452 quint64 intValue;
453 };
454#endif
455
456 class WindowSystemEventList {
457 QList<WindowSystemEvent *> impl;
458 mutable QMutex mutex;
459 public:
460 WindowSystemEventList() : impl(), mutex() {}
461 ~WindowSystemEventList() { clear(); }
462
463 void clear()
464 { const QMutexLocker locker(&mutex); qDeleteAll(impl); impl.clear(); }
465 void prepend(WindowSystemEvent *e)
466 { const QMutexLocker locker(&mutex); impl.prepend(e); }
467 WindowSystemEvent *takeFirstOrReturnNull()
468 { const QMutexLocker locker(&mutex); return impl.empty() ? nullptr : impl.takeFirst(); }
469 WindowSystemEvent *takeFirstNonUserInputOrReturnNull()
470 {
471 const QMutexLocker locker(&mutex);
472 for (int i = 0; i < impl.size(); ++i)
473 if (!(impl.at(i)->type & QWindowSystemInterfacePrivate::UserInputEvent))
474 return impl.takeAt(i);
475 return nullptr;
476 }
477 bool nonUserInputEventsQueued()
478 {
479 const QMutexLocker locker(&mutex);
480 for (int i = 0; i < impl.size(); ++i)
481 if (!(impl.at(i)->type & QWindowSystemInterfacePrivate::UserInputEvent))
482 return true;
483 return false;
484 }
485 void append(WindowSystemEvent *e)
486 { const QMutexLocker locker(&mutex); impl.append(e); }
487 qsizetype count() const
488 { const QMutexLocker locker(&mutex); return impl.size(); }
489 WindowSystemEvent *peekAtFirstOfType(EventType t) const
490 {
491 const QMutexLocker locker(&mutex);
492 for (int i = 0; i < impl.size(); ++i) {
493 if (impl.at(i)->type == t)
494 return impl.at(i);
495 }
496 return nullptr;
497 }
498 void remove(const WindowSystemEvent *e)
499 {
500 const QMutexLocker locker(&mutex);
501 for (int i = 0; i < impl.size(); ++i) {
502 if (impl.at(i) == e) {
503 delete impl.takeAt(i);
504 break;
505 }
506 }
507 }
508 private:
509 Q_DISABLE_COPY_MOVE(WindowSystemEventList)
510 };
511
512 static WindowSystemEventList windowSystemEventQueue;
513
514 static qsizetype windowSystemEventsQueued();
515 static bool nonUserInputEventsQueued();
516 static WindowSystemEvent *getWindowSystemEvent();
517 static WindowSystemEvent *getNonUserInputWindowSystemEvent();
518 static WindowSystemEvent *peekWindowSystemEvent(EventType t);
519 static void removeWindowSystemEvent(WindowSystemEvent *event);
520
521public:
522 static QElapsedTimer eventTime;
523 static bool synchronousWindowSystemEvents;
524 static bool platformFiltersEvents;
525
526 static QWaitCondition eventsFlushed;
527 static QMutex flushEventMutex;
528 static QAtomicInt eventAccepted;
529
530 static QList<QEventPoint>
531 fromNativeTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points,
532 const QWindow *window, QEvent::Type *type = nullptr);
533 template<class EventPointList>
534 static QList<QWindowSystemInterface::TouchPoint>
535 toNativeTouchPoints(const EventPointList &pointList, const QWindow *window)
536 {
537 QList<QWindowSystemInterface::TouchPoint> newList;
538 newList.reserve(pointList.size());
539 for (const auto &point : pointList) {
540 newList.append(toNativeTouchPoint(point, window));
541 }
542 return newList;
543 }
544 static QWindowSystemInterface::TouchPoint
545 toNativeTouchPoint(const QEventPoint &point, const QWindow *window);
546
547 static void installWindowSystemEventHandler(QWindowSystemEventHandler *handler);
548 static void removeWindowSystemEventhandler(QWindowSystemEventHandler *handler);
549 static QWindowSystemEventHandler *eventHandler;
550};
551
553{
554public:
555 virtual ~QWindowSystemEventHandler();
556 virtual bool sendEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *event);
557};
558
559QT_END_NAMESPACE
560
561#endif // QWINDOWSYSTEMINTERFACE_P_H
The QInputDevice class describes a device from which a QInputEvent originates.
Combined button and popup list for selecting options.