summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qevent.h
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-05-31 08:38:16 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-06-16 22:06:56 +0200
commit6589f2ed0cf78c9b8a5bdffcdc458dc40a974c60 (patch)
tree61f29061a4cbaf925ef0ab7ba9fafc1db9ee4ef3 /src/gui/kernel/qevent.h
parent0a2e3ce85ce788b8a07380a458faf4ed3817d0c0 (diff)
Introduce QInputDevice hierarchy; replace QTouchDevice
We have seen during the Qt 5 series that QMouseEvent::source() does not provide enough information: if it is synthesized, it could have come from any device for which mouse events are synthesized, not only from a touchscreen. By providing in every QInputEvent as complete information about the actual source device as possible, we will enable very fine-tuned behavior in the object that handles each event. Further, we would like to support multiple keyboards, pointing devices, and named groups of devices that are known as "seats" in Wayland. In Qt 5, QPA plugins registered each touchscreen as it was discovered. Now we extend this pattern to all input devices. This new requirement can be implemented gradually; for now, if a QTWSI input event is received wtihout a device pointer, a default "core" device will be created on-the-fly, and a warning emitted. In Qt 5, QTouchEvent::TouchPoint::id() was forced to be unique even when multiple devices were in use simultaneously. Now that each event identifies the device it came from, this hack is no longer needed. A stub of the new QPointerEvent is added; it will be developed further in subsequent patches. [ChangeLog][QtGui][QInputEvent] Every QInputEvent now carries a pointer to an instance of QInputDevice, or the subclass QPointingDevice in case of mouse, touch and tablet events. Each platform plugin is expected to create the device instances, register them, and provide valid pointers with all input events. If this is not done, warnings are emitted and default devices are created as necessary. When the device has accurate information, it provides the opportunity to fine-tune behavior depending on device type and capabilities: for example if a QMouseEvent is synthesized from a touchscreen, the recipient can see which touchscreen it came from. Each device also has a seatName to distinguish users on multi-user windowing systems. Touchpoint IDs are no longer unique on their own, but the combination of ID and device is. Fixes: QTBUG-46412 Fixes: QTBUG-72167 Task-number: QTBUG-69433 Task-number: QTBUG-52430 Change-Id: I933fb2b86182efa722037b7a33e404c5daf5292a Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/gui/kernel/qevent.h')
-rw-r--r--src/gui/kernel/qevent.h100
1 files changed, 37 insertions, 63 deletions
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index 8ee0382c42..0039be5ae9 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -49,6 +49,7 @@
#include <QtCore/qvariant.h>
#include <QtCore/qvector.h>
#include <QtCore/qurl.h>
+#include <QtGui/qpointingdevice.h>
#include <QtGui/qregion.h>
#include <QtGui/qvector2d.h>
#include <QtGui/qwindowdefs.h>
@@ -61,8 +62,9 @@ QT_BEGIN_NAMESPACE
class QFile;
class QAction;
+class QInputDevice;
+class QPointingDevice;
class QScreen;
-class QTouchDevice;
#if QT_CONFIG(gestures)
class QGesture;
#endif
@@ -70,17 +72,30 @@ class QGesture;
class Q_GUI_EXPORT QInputEvent : public QEvent
{
public:
- explicit QInputEvent(Type type, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ explicit QInputEvent(Type type, const QInputDevice *m_dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
~QInputEvent();
+ const QInputDevice *device() const { return m_dev; }
+ QInputDevice::DeviceType deviceType() const { return m_dev ? m_dev->type() : QInputDevice::DeviceType::Unknown; }
inline Qt::KeyboardModifiers modifiers() const { return modState; }
inline void setModifiers(Qt::KeyboardModifiers amodifiers) { modState = amodifiers; }
inline ulong timestamp() const { return ts; }
inline void setTimestamp(ulong atimestamp) { ts = atimestamp; }
protected:
+ const QInputDevice *m_dev = nullptr;
Qt::KeyboardModifiers modState;
ulong ts;
};
+class Q_GUI_EXPORT QPointerEvent : public QInputEvent
+{
+public:
+ explicit QPointerEvent(Type type, const QPointingDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ const QPointingDevice *pointingDevice() const;
+ QPointingDevice::PointerType pointerType() const {
+ return pointingDevice() ? pointingDevice()->pointerType() : QPointingDevice::PointerType::Unknown;
+ }
+};
+
class Q_GUI_EXPORT QEnterEvent : public QEvent
{
public:
@@ -118,7 +133,7 @@ protected:
QPointF l, s, g;
};
-class Q_GUI_EXPORT QMouseEvent : public QInputEvent
+class Q_GUI_EXPORT QMouseEvent : public QPointerEvent
{
public:
QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
@@ -207,7 +222,7 @@ protected:
};
#if QT_CONFIG(wheelevent)
-class Q_GUI_EXPORT QWheelEvent : public QInputEvent
+class Q_GUI_EXPORT QWheelEvent : public QPointerEvent
{
public:
enum { DefaultDeltasPerStep = 120 };
@@ -247,20 +262,20 @@ protected:
#endif
#if QT_CONFIG(tabletevent)
-class Q_GUI_EXPORT QTabletEvent : public QInputEvent
+class Q_GUI_EXPORT QTabletEvent : public QPointerEvent
{
Q_GADGET
public:
- enum TabletDevice { NoDevice, Puck, Stylus, Airbrush, FourDMouse, RotationStylus };
- Q_ENUM(TabletDevice)
- enum PointerType { UnknownPointer, Pen, Cursor, Eraser };
- Q_ENUM(PointerType)
-
QTabletEvent(Type t, const QPointF &pos, const QPointF &globalPos,
- int device, int pointerType, qreal pressure, int xTilt, int yTilt,
+ int deviceType, int pointerType, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z,
Qt::KeyboardModifiers keyState, qint64 uniqueID,
Qt::MouseButton button, Qt::MouseButtons buttons);
+ QTabletEvent(Type t, const QPointingDevice *dev, const QPointF &pos, const QPointF &globalPos,
+ qreal pressure, int xTilt, int yTilt,
+ qreal tangentialPressure, qreal rotation, int z,
+ Qt::KeyboardModifiers keyState,
+ Qt::MouseButton button, Qt::MouseButtons buttons);
~QTabletEvent();
#if QT_DEPRECATED_SINCE(6, 0)
@@ -288,35 +303,31 @@ public:
#endif
inline QPointF position() const { return mPos; }
inline QPointF globalPosition() const { return mGPos; }
- inline TabletDevice deviceType() const { return TabletDevice(mDev); }
- inline PointerType pointerType() const { return PointerType(mPointerType); }
- inline qint64 uniqueId() const { return mUnique; }
+ inline qint64 uniqueId() const { return pointingDevice() ? pointingDevice()->uniqueId().numericId() : -1; }
inline qreal pressure() const { return mPress; }
inline int z() const { return mZ; }
inline qreal tangentialPressure() const { return mTangential; }
inline qreal rotation() const { return mRot; }
inline int xTilt() const { return mXT; }
inline int yTilt() const { return mYT; }
- Qt::MouseButton button() const;
- Qt::MouseButtons buttons() const;
+ inline Qt::MouseButton button() const { return mButton; }
+ inline Qt::MouseButtons buttons() const { return mButtons; }
protected:
QPointF mPos, mGPos;
- int mDev, mPointerType, mXT, mYT, mZ;
+ int mXT, mYT, mZ;
qreal mPress, mTangential, mRot;
- qint64 mUnique;
-
- // QTabletEventPrivate for extra storage.
- // ### Qt 6: QPointingEvent will have Buttons, QTabletEvent will inherit
- void *mExtra;
+ // TODO refactor to parent class along with QMouseEvent's button storage
+ Qt::MouseButton mButton;
+ Qt::MouseButtons mButtons;
};
#endif // QT_CONFIG(tabletevent)
#if QT_CONFIG(gestures)
-class Q_GUI_EXPORT QNativeGestureEvent : public QInputEvent
+class Q_GUI_EXPORT QNativeGestureEvent : public QPointerEvent
{
public:
- QNativeGestureEvent(Qt::NativeGestureType type, const QTouchDevice *dev, const QPointF &localPos, const QPointF &scenePos,
+ QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *dev, const QPointF &localPos, const QPointF &scenePos,
const QPointF &globalPos, qreal value, ulong sequenceId, quint64 intArgument);
~QNativeGestureEvent();
Qt::NativeGestureType gestureType() const { return mGestureType; }
@@ -341,8 +352,6 @@ public:
QPointF scenePosition() const { return mScenePos; }
QPointF globalPosition() const { return mGlobalPos; }
- const QTouchDevice *device() const { return mDevice; }
-
protected:
Qt::NativeGestureType mGestureType;
QPointF mLocalPos;
@@ -351,7 +360,6 @@ protected:
qreal mRealValue;
ulong mSequenceId;
quint64 mIntValue;
- const QTouchDevice *mDevice;
};
#endif // QT_CONFIG(gestures)
@@ -817,38 +825,8 @@ inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key){return (e ?
inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e){return (e ? e->matches(key) : false);}
#endif // QT_CONFIG(shortcut)
-class Q_GUI_EXPORT QPointingDeviceUniqueId
-{
- Q_GADGET
- Q_PROPERTY(qint64 numericId READ numericId CONSTANT)
-public:
- Q_ALWAYS_INLINE
- Q_DECL_CONSTEXPR QPointingDeviceUniqueId() noexcept : m_numericId(-1) {}
- // compiler-generated copy/move ctor/assignment operators are ok!
- // compiler-generated dtor is ok!
-
- static QPointingDeviceUniqueId fromNumericId(qint64 id);
-
- Q_ALWAYS_INLINE Q_DECL_CONSTEXPR bool isValid() const noexcept { return m_numericId != -1; }
- qint64 numericId() const noexcept;
-
-private:
- // TODO: for TUIO 2, or any other type of complex token ID, an internal
- // array (or hash) can be added to hold additional properties.
- // In this case, m_numericId will then turn into an index into that array (or hash).
- qint64 m_numericId;
-};
-Q_DECLARE_TYPEINFO(QPointingDeviceUniqueId, Q_MOVABLE_TYPE);
-
-Q_GUI_EXPORT bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept;
-inline bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
-{ return !operator==(lhs, rhs); }
-Q_GUI_EXPORT size_t qHash(QPointingDeviceUniqueId key, size_t seed = 0) noexcept;
-
-
-
class QTouchEventTouchPointPrivate;
-class Q_GUI_EXPORT QTouchEvent : public QInputEvent
+class Q_GUI_EXPORT QTouchEvent : public QPointerEvent
{
public:
class Q_GUI_EXPORT TouchPoint
@@ -963,7 +941,7 @@ public:
};
explicit QTouchEvent(QEvent::Type eventType,
- QTouchDevice *device = nullptr,
+ const QPointingDevice *source = nullptr,
Qt::KeyboardModifiers modifiers = Qt::NoModifier,
Qt::TouchPointStates touchPointStates = Qt::TouchPointStates(),
const QList<QTouchEvent::TouchPoint> &touchPoints = QList<QTouchEvent::TouchPoint>());
@@ -973,21 +951,17 @@ public:
inline QObject *target() const { return _target; }
inline Qt::TouchPointStates touchPointStates() const { return _touchPointStates; }
inline const QList<QTouchEvent::TouchPoint> &touchPoints() const { return _touchPoints; }
- inline QTouchDevice *device() const { return _device; }
// ### Qt 6: move private, rename appropriately, only friends can call them; or just let friends modify variables directly
#if QT_DEPRECATED_SINCE(6, 0)
inline void setWindow(QWindow *awindow) { _window = awindow; }
inline void setTarget(QObject *atarget) { _target = atarget; }
- inline void setTouchPointStates(Qt::TouchPointStates aTouchPointStates) { _touchPointStates = aTouchPointStates; }
inline void setTouchPoints(const QList<QTouchEvent::TouchPoint> &atouchPoints) { _touchPoints = atouchPoints; }
- inline void setDevice(QTouchDevice *adevice) { _device = adevice; }
#endif // QT_DEPRECATED_SINCE(6, 0)
protected:
QWindow *_window;
QObject *_target;
- QTouchDevice *_device;
Qt::TouchPointStates _touchPointStates;
QList<QTouchEvent::TouchPoint> _touchPoints;