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 64 QT_BEGIN_NAMESPACE 65 66 class QMimeData; 67 class QTouchDevice; 68 class QPlatformDragQtResponse; 69 class QPlatformDropQtResponse; 70 71 72 class Q_GUI_EXPORT QWindowSystemInterface 73 { 74 public: 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 bool 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 bool 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 bool 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 bool 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 bool 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 bool 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 bool 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 bool 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 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 151 #if QT_DEPRECATED_SINCE(5, 10) 152 QT_DEPRECATED static bool handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier); 153 QT_DEPRECATED static bool 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 { TouchPointTouchPoint157 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 bool handleTouchEvent(QWindow *window, QTouchDevice *device, 179 const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier); 180 template<typename Delivery = QWindowSystemInterface::DefaultDelivery> 181 static bool 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 bool handleTouchCancelEvent(QWindow *window, QTouchDevice *device, Qt::KeyboardModifiers mods = Qt::NoModifier); 185 template<typename Delivery = QWindowSystemInterface::DefaultDelivery> 186 static bool 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 ®ion); 195 196 template<typename Delivery = QWindowSystemInterface::DefaultDelivery> 197 static bool handleCloseEvent(QWindow *window); 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 template<typename Delivery = QWindowSystemInterface::DefaultDelivery> 219 static bool handleApplicationTermination(); 220 221 #if QT_CONFIG(draganddrop) 222 #if QT_DEPRECATED_SINCE(5, 11) 223 QT_DEPRECATED static QPlatformDragQtResponse handleDrag(QWindow *window, const QMimeData *dropData, 224 const QPoint &p, Qt::DropActions supportedActions); 225 QT_DEPRECATED static QPlatformDropQtResponse handleDrop(QWindow *window, const QMimeData *dropData, 226 const QPoint &p, Qt::DropActions supportedActions); 227 #endif // #if QT_DEPRECATED_SINCE(5, 11) 228 static QPlatformDragQtResponse handleDrag(QWindow *window, const QMimeData *dropData, 229 const QPoint &p, Qt::DropActions supportedActions, 230 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); 231 static QPlatformDropQtResponse handleDrop(QWindow *window, const QMimeData *dropData, 232 const QPoint &p, Qt::DropActions supportedActions, 233 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); 234 #endif // QT_CONFIG(draganddrop) 235 236 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 237 static bool handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result); 238 #else 239 static bool handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result); 240 #endif 241 242 // Changes to the screen 243 static void handleScreenAdded(QPlatformScreen *screen, bool isPrimary = false); 244 static void handleScreenRemoved(QPlatformScreen *screen); 245 static void handlePrimaryScreenChanged(QPlatformScreen *newPrimary); 246 247 static void handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation newOrientation); 248 static void handleScreenGeometryChange(QScreen *screen, const QRect &newGeometry, const QRect &newAvailableGeometry); 249 static void handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal newDpiX, qreal newDpiY); 250 static void handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate); 251 252 template<typename Delivery = QWindowSystemInterface::DefaultDelivery> 253 static void handleThemeChange(QWindow *window); 254 255 static void handleFileOpenEvent(const QString& fileName); 256 static void handleFileOpenEvent(const QUrl &url); 257 258 static bool handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global, 259 int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, 260 qreal tangentialPressure, qreal rotation, int z, qint64 uid, 261 Qt::KeyboardModifiers modifiers = Qt::NoModifier); 262 static bool handleTabletEvent(QWindow *window, const QPointF &local, const QPointF &global, 263 int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, 264 qreal tangentialPressure, qreal rotation, int z, qint64 uid, 265 Qt::KeyboardModifiers modifiers = Qt::NoModifier); 266 #if QT_DEPRECATED_SINCE(5, 10) 267 QT_DEPRECATED static void handleTabletEvent(QWindow *window, ulong timestamp, bool down, const QPointF &local, const QPointF &global, 268 int device, int pointerType, qreal pressure, int xTilt, int yTilt, 269 qreal tangentialPressure, qreal rotation, int z, qint64 uid, 270 Qt::KeyboardModifiers modifiers = Qt::NoModifier); 271 QT_DEPRECATED static void handleTabletEvent(QWindow *window, bool down, const QPointF &local, const QPointF &global, 272 int device, int pointerType, qreal pressure, int xTilt, int yTilt, 273 qreal tangentialPressure, qreal rotation, int z, qint64 uid, 274 Qt::KeyboardModifiers modifiers = Qt::NoModifier); 275 #endif 276 static bool handleTabletEnterProximityEvent(ulong timestamp, int device, int pointerType, qint64 uid); 277 static void handleTabletEnterProximityEvent(int device, int pointerType, qint64 uid); 278 static bool handleTabletLeaveProximityEvent(ulong timestamp, int device, int pointerType, qint64 uid); 279 static void handleTabletLeaveProximityEvent(int device, int pointerType, qint64 uid); 280 281 #ifndef QT_NO_GESTURES 282 static bool handleGestureEvent(QWindow *window, QTouchDevice *device, ulong timestamp, Qt::NativeGestureType type, 283 QPointF &local, QPointF &global); 284 static bool handleGestureEventWithRealValue(QWindow *window, QTouchDevice *device, ulong timestamp, Qt::NativeGestureType type, 285 qreal value, QPointF &local, QPointF &global); 286 static bool handleGestureEventWithSequenceIdAndValue(QWindow *window, QTouchDevice *device, ulong timestamp,Qt::NativeGestureType type, 287 ulong sequenceId, quint64 value, QPointF &local, QPointF &global); 288 #endif // QT_NO_GESTURES 289 290 static void handlePlatformPanelEvent(QWindow *window); 291 #ifndef QT_NO_CONTEXTMENU 292 static void handleContextMenuEvent(QWindow *window, bool mouseTriggered, 293 const QPoint &pos, const QPoint &globalPos, 294 Qt::KeyboardModifiers modifiers); 295 #endif 296 #if QT_CONFIG(whatsthis) 297 static void handleEnterWhatsThisEvent(); 298 #endif 299 300 // For event dispatcher implementations 301 static bool sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags); 302 static void setSynchronousWindowSystemEvents(bool enable); 303 static bool flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); 304 static void deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags); 305 static int windowSystemEventsQueued(); 306 static bool nonUserInputEventsQueued(); 307 }; 308 309 #ifndef QT_NO_DEBUG_STREAM 310 Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QWindowSystemInterface::TouchPoint &p); 311 #endif 312 313 QT_END_NAMESPACE 314 315 #endif // QWINDOWSYSTEMINTERFACE_H 316