diff options
Diffstat (limited to 'src/gui/kernel/qwindowsysteminterface_p.h')
-rw-r--r-- | src/gui/kernel/qwindowsysteminterface_p.h | 216 |
1 files changed, 105 insertions, 111 deletions
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index dd6f29b41f..51ab58fc99 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QWINDOWSYSTEMINTERFACE_P_H #define QWINDOWSYSTEMINTERFACE_P_H @@ -50,6 +14,7 @@ // We mean it. // +#include <QtGui/private/qevent_p.h> #include <QtGui/private/qtguiglobal_p.h> #include "qwindowsysteminterface.h" @@ -59,9 +24,12 @@ #include <QList> #include <QWaitCondition> #include <QAtomicInt> +#include <QLoggingCategory> QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices); + class QWindowSystemEventHandler; class Q_GUI_EXPORT QWindowSystemInterfacePrivate { @@ -72,10 +40,9 @@ public: GeometryChange = 0x02, Enter = UserInputEvent | 0x03, Leave = UserInputEvent | 0x04, - ActivatedWindow = 0x05, + FocusWindow = 0x05, WindowStateChanged = 0x06, Mouse = UserInputEvent | 0x07, - FrameStrutMouse = UserInputEvent | 0x08, // ### Qt6 remove Wheel = UserInputEvent | 0x09, Key = UserInputEvent | 0x0a, Touch = UserInputEvent | 0x0b, @@ -100,7 +67,9 @@ public: FlushEvents = 0x20, WindowScreenChanged = 0x21, SafeAreaMarginsChanged = 0x22, - ApplicationTermination = 0x23 + ApplicationTermination = 0x23, + Paint = 0x24, + WindowDevicePixelRatioChanged = 0x25, }; class WindowSystemEvent { @@ -156,12 +125,12 @@ public: QPointer<QWindow> leave; }; - class ActivatedWindowEvent : public WindowSystemEvent { + class FocusWindowEvent : public WindowSystemEvent { public: - explicit ActivatedWindowEvent(QWindow *activatedWindow, Qt::FocusReason r) - : WindowSystemEvent(ActivatedWindow), activated(activatedWindow), reason(r) + explicit FocusWindowEvent(QWindow *focusedWindow, Qt::FocusReason r) + : WindowSystemEvent(FocusWindow), focused(focusedWindow), reason(r) { } - QPointer<QWindow> activated; + QPointer<QWindow> focused; Qt::FocusReason reason; }; @@ -186,6 +155,15 @@ public: QPointer<QScreen> screen; }; + class WindowDevicePixelRatioChangedEvent : public WindowSystemEvent { + public: + WindowDevicePixelRatioChangedEvent(QWindow *w) + : WindowSystemEvent(WindowDevicePixelRatioChanged), window(w) + { } + + QPointer<QWindow> window; + }; + class SafeAreaMarginsChangedEvent : public WindowSystemEvent { public: SafeAreaMarginsChangedEvent(QWindow *w) @@ -228,26 +206,27 @@ public: class InputEvent: public UserEvent { public: - InputEvent(QWindow * w, ulong time, EventType t, Qt::KeyboardModifiers mods) - : UserEvent(w, time, t), modifiers(mods) {} + InputEvent(QWindow *w, ulong time, EventType t, Qt::KeyboardModifiers mods, const QInputDevice *dev) + : UserEvent(w, time, t), modifiers(mods), device(dev) {} Qt::KeyboardModifiers modifiers; + const QInputDevice *device; + }; + + class PointerEvent : public InputEvent { + public: + PointerEvent(QWindow * w, ulong time, EventType t, Qt::KeyboardModifiers mods, const QPointingDevice *device) + : InputEvent(w, time, t, mods, device) {} }; - class MouseEvent : public InputEvent { + class MouseEvent : public PointerEvent { public: 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) - : InputEvent(w, time, Mouse, mods), localPos(local), globalPos(global), buttons(state), - source(src), nonClientArea(frame), button(b), buttonType(type) { } - - // ### In Qt6 this method can be removed as there won't be need for compatibility code path - bool enhancedMouseEvent() const - { - static const bool disableEnhanced = qEnvironmentVariableIsSet("QT_QPA_DISABLE_ENHANCED_MOUSE"); - return !disableEnhanced && buttonType != QEvent::None; - } + Qt::MouseEventSource src = Qt::MouseEventNotSynthesized, bool frame = false, + const QPointingDevice *device = QPointingDevice::primaryPointingDevice()) + : PointerEvent(w, time, Mouse, mods, device), localPos(local), globalPos(global), + buttons(state), source(src), nonClientArea(frame), button(b), buttonType(type) { } QPointF localPos; QPointF globalPos; @@ -258,10 +237,13 @@ public: QEvent::Type buttonType; }; - class WheelEvent : public InputEvent { + class WheelEvent : public PointerEvent { public: 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); + Qt::KeyboardModifiers mods, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized, + bool inverted = false, const QPointingDevice *device = QPointingDevice::primaryPointingDevice()) + : PointerEvent(w, time, Wheel, mods, device), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), + qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src), inverted(inverted) { } QPoint pixelDelta; QPoint angleDelta; int qt4Delta; @@ -275,16 +257,20 @@ public: class KeyEvent : public InputEvent { public: - KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1) - :InputEvent(w, time, Key, mods), key(k), unicode(text), repeat(autorep), - repeatCount(count), keyType(t), + 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()) + : InputEvent(w, time, Key, mods, device), source(nullptr), key(k), unicode(text), + repeat(autorep), repeatCount(count), keyType(t), nativeScanCode(0), nativeVirtualKey(0), nativeModifiers(0) { } 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) - :InputEvent(w, time, Key, mods), key(k), unicode(text), repeat(autorep), - repeatCount(count), keyType(t), + const QString & text = QString(), bool autorep = false, ushort count = 1, + const QInputDevice *device = QInputDevice::primaryKeyboard()) + : InputEvent(w, time, Key, mods, device), source(nullptr), key(k), unicode(text), + repeat(autorep), repeatCount(count), keyType(t), nativeScanCode(nativeSC), nativeVirtualKey(nativeVK), nativeModifiers(nativeMods) { } + const QInputDevice *source; int key; QString unicode; bool repeat; @@ -295,13 +281,12 @@ public: quint32 nativeModifiers; }; - class TouchEvent : public InputEvent { + class TouchEvent : public PointerEvent { public: - TouchEvent(QWindow *w, ulong time, QEvent::Type t, QTouchDevice *dev, - const QList<QTouchEvent::TouchPoint> &p, Qt::KeyboardModifiers mods) - :InputEvent(w, time, Touch, mods), device(dev), points(p), touchType(t) { } - QTouchDevice *device; - QList<QTouchEvent::TouchPoint> points; + TouchEvent(QWindow *w, ulong time, QEvent::Type t, const QPointingDevice *device, + const QList<QEventPoint> &p, Qt::KeyboardModifiers mods) + : PointerEvent(w, time, Touch, mods, device), points(p), touchType(t) { } + QList<QEventPoint> points; QEvent::Type touchType; }; @@ -354,6 +339,14 @@ public: QRegion region; }; + class PaintEvent : public WindowSystemEvent { + public: + PaintEvent(QWindow *window, const QRegion ®ion) + : WindowSystemEvent(Paint), window(window), region(region) {} + QPointer<QWindow> window; + QRegion region; + }; + class FileOpenEvent : public WindowSystemEvent { public: FileOpenEvent(const QString& fileName) @@ -365,8 +358,9 @@ public: QUrl url; }; - class Q_GUI_EXPORT TabletEvent : public InputEvent { + class Q_GUI_EXPORT TabletEvent : public PointerEvent { public: + // TODO take QPointingDevice* instead of types and IDs 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, @@ -374,45 +368,36 @@ public: static void setPlatformSynthesizesMouse(bool v); TabletEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, - int device, int pointerType, Qt::MouseButtons b, qreal pressure, int xTilt, int yTilt, qreal tpressure, - qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers mods) - : InputEvent(w, time, Tablet, mods), - buttons(b), local(local), global(global), device(device), pointerType(pointerType), + const QPointingDevice *device, Qt::MouseButtons b, qreal pressure, int xTilt, int yTilt, qreal tpressure, + qreal rotation, int z, Qt::KeyboardModifiers mods) + : PointerEvent(w, time, Tablet, mods, device), + buttons(b), local(local), global(global), pressure(pressure), xTilt(xTilt), yTilt(yTilt), tangentialPressure(tpressure), - rotation(rotation), z(z), uid(uid) { } + rotation(rotation), z(z) { } Qt::MouseButtons buttons; QPointF local; QPointF global; - int device; - int pointerType; qreal pressure; int xTilt; int yTilt; qreal tangentialPressure; qreal rotation; int z; - qint64 uid; static bool platformSynthesizesMouse; }; - class TabletEnterProximityEvent : public InputEvent { + class TabletEnterProximityEvent : public PointerEvent { public: - TabletEnterProximityEvent(ulong time, int device, int pointerType, qint64 uid) - : InputEvent(nullptr, time, TabletEnterProximity, Qt::NoModifier), - device(device), pointerType(pointerType), uid(uid) { } - int device; - int pointerType; - qint64 uid; + // TODO store more info: position and whatever else we can get on most platforms + TabletEnterProximityEvent(ulong time, const QPointingDevice *device) + : PointerEvent(nullptr, time, TabletEnterProximity, Qt::NoModifier, device) { } }; - class TabletLeaveProximityEvent : public InputEvent { + class TabletLeaveProximityEvent : public PointerEvent { public: - TabletLeaveProximityEvent(ulong time, int device, int pointerType, qint64 uid) - : InputEvent(nullptr, time, TabletLeaveProximity, Qt::NoModifier), - device(device), pointerType(pointerType), uid(uid) { } - int device; - int pointerType; - qint64 uid; + // TODO store more info: position and whatever else we can get on most platforms + TabletLeaveProximityEvent(ulong time, const QPointingDevice *device) + : PointerEvent(nullptr, time, TabletLeaveProximity, Qt::NoModifier, device) { } }; class PlatformPanelEvent : public WindowSystemEvent { @@ -438,20 +423,22 @@ public: #endif #ifndef QT_NO_GESTURES - class GestureEvent : public InputEvent { + class GestureEvent : public PointerEvent { public: - GestureEvent(QWindow *window, ulong time, Qt::NativeGestureType type, QTouchDevice *dev, QPointF pos, QPointF globalPos) - : InputEvent(window, time, Gesture, Qt::NoModifier), type(type), pos(pos), globalPos(globalPos), - realValue(0), sequenceId(0), intValue(0), device(dev) { } + GestureEvent(QWindow *window, ulong time, Qt::NativeGestureType type, const QPointingDevice *dev, + int fingerCount, QPointF pos, QPointF globalPos, qreal realValue, QPointF delta) + : PointerEvent(window, time, Gesture, Qt::NoModifier, dev), type(type), pos(pos), globalPos(globalPos), + delta(delta), fingerCount(fingerCount), realValue(realValue), sequenceId(0), intValue(0) { } Qt::NativeGestureType type; QPointF pos; QPointF globalPos; + QPointF delta; + int fingerCount; // Mac qreal realValue; // Windows ulong sequenceId; quint64 intValue; - QTouchDevice *device; }; #endif @@ -467,7 +454,7 @@ public: void prepend(WindowSystemEvent *e) { const QMutexLocker locker(&mutex); impl.prepend(e); } WindowSystemEvent *takeFirstOrReturnNull() - { const QMutexLocker locker(&mutex); return impl.empty() ? 0 : impl.takeFirst(); } + { const QMutexLocker locker(&mutex); return impl.empty() ? nullptr : impl.takeFirst(); } WindowSystemEvent *takeFirstNonUserInputOrReturnNull() { const QMutexLocker locker(&mutex); @@ -486,8 +473,8 @@ public: } void append(WindowSystemEvent *e) { const QMutexLocker locker(&mutex); impl.append(e); } - int count() const - { const QMutexLocker locker(&mutex); return impl.count(); } + qsizetype count() const + { const QMutexLocker locker(&mutex); return impl.size(); } WindowSystemEvent *peekAtFirstOfType(EventType t) const { const QMutexLocker locker(&mutex); @@ -513,14 +500,12 @@ public: static WindowSystemEventList windowSystemEventQueue; - static int windowSystemEventsQueued(); + static qsizetype windowSystemEventsQueued(); static bool nonUserInputEventsQueued(); static WindowSystemEvent *getWindowSystemEvent(); static WindowSystemEvent *getNonUserInputWindowSystemEvent(); static WindowSystemEvent *peekWindowSystemEvent(EventType t); static void removeWindowSystemEvent(WindowSystemEvent *event); - template<typename Delivery = QWindowSystemInterface::DefaultDelivery> - static bool handleWindowSystemEvent(WindowSystemEvent *ev); public: static QElapsedTimer eventTime; @@ -531,13 +516,22 @@ public: static QMutex flushEventMutex; static QAtomicInt eventAccepted; - static QList<QTouchEvent::TouchPoint> + static QList<QEventPoint> fromNativeTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points, - const QWindow *window, quint8 deviceId, QEvent::Type *type = nullptr); + const QWindow *window, QEvent::Type *type = nullptr); + template<class EventPointList> static QList<QWindowSystemInterface::TouchPoint> - toNativeTouchPoints(const QList<QTouchEvent::TouchPoint>& pointList, - const QWindow *window); - static void clearPointIdMap(); + toNativeTouchPoints(const EventPointList &pointList, const QWindow *window) + { + QList<QWindowSystemInterface::TouchPoint> newList; + newList.reserve(pointList.size()); + for (const auto &point : pointList) { + newList.append(toNativeTouchPoint(point, window)); + } + return newList; + } + static QWindowSystemInterface::TouchPoint + toNativeTouchPoint(const QEventPoint &point, const QWindow *window); static void installWindowSystemEventHandler(QWindowSystemEventHandler *handler); static void removeWindowSystemEventhandler(QWindowSystemEventHandler *handler); |