File indexing completed on 2024-12-01 05:01:39

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #pragma once
0010 
0011 #include "input.h"
0012 
0013 #include <QInputEvent>
0014 #include <chrono>
0015 
0016 namespace KWin
0017 {
0018 
0019 class InputDevice;
0020 
0021 class MouseEvent : public QMouseEvent
0022 {
0023 public:
0024     explicit MouseEvent(QEvent::Type type, const QPointF &pos, Qt::MouseButton button, Qt::MouseButtons buttons,
0025                         Qt::KeyboardModifiers modifiers, std::chrono::microseconds timestamp,
0026                         const QPointF &delta, const QPointF &deltaNonAccelerated, InputDevice *device);
0027 
0028     QPointF delta() const
0029     {
0030         return m_delta;
0031     }
0032 
0033     QPointF deltaUnaccelerated() const
0034     {
0035         return m_deltaUnccelerated;
0036     }
0037 
0038     std::chrono::microseconds timestamp() const
0039     {
0040         return m_timestamp;
0041     }
0042 
0043     InputDevice *device() const
0044     {
0045         return m_device;
0046     }
0047 
0048     Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const
0049     {
0050         return m_modifiersRelevantForShortcuts;
0051     }
0052 
0053     void setModifiersRelevantForGlobalShortcuts(const Qt::KeyboardModifiers &mods)
0054     {
0055         m_modifiersRelevantForShortcuts = mods;
0056     }
0057 
0058     quint32 nativeButton() const
0059     {
0060         return m_nativeButton;
0061     }
0062 
0063     void setNativeButton(quint32 button)
0064     {
0065         m_nativeButton = button;
0066     }
0067 
0068 private:
0069     QPointF m_delta;
0070     QPointF m_deltaUnccelerated;
0071     std::chrono::microseconds m_timestamp;
0072     InputDevice *m_device;
0073     Qt::KeyboardModifiers m_modifiersRelevantForShortcuts = Qt::KeyboardModifiers();
0074     quint32 m_nativeButton = 0;
0075 };
0076 
0077 // TODO: Don't derive from QWheelEvent, this event is quite domain specific.
0078 class WheelEvent : public QWheelEvent
0079 {
0080 public:
0081     explicit WheelEvent(const QPointF &pos, qreal delta, qint32 deltaV120, Qt::Orientation orientation,
0082                         Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, InputRedirection::PointerAxisSource source,
0083                         std::chrono::microseconds timestamp, InputDevice *device);
0084 
0085     Qt::Orientation orientation() const
0086     {
0087         return m_orientation;
0088     }
0089 
0090     qreal delta() const
0091     {
0092         return m_delta;
0093     }
0094 
0095     qint32 deltaV120() const
0096     {
0097         return m_deltaV120;
0098     }
0099 
0100     InputRedirection::PointerAxisSource axisSource() const
0101     {
0102         return m_source;
0103     }
0104 
0105     InputDevice *device() const
0106     {
0107         return m_device;
0108     }
0109 
0110     Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const
0111     {
0112         return m_modifiersRelevantForShortcuts;
0113     }
0114 
0115     void setModifiersRelevantForGlobalShortcuts(const Qt::KeyboardModifiers &mods)
0116     {
0117         m_modifiersRelevantForShortcuts = mods;
0118     }
0119 
0120     std::chrono::microseconds timestamp() const;
0121 
0122 private:
0123     InputDevice *m_device;
0124     Qt::Orientation m_orientation;
0125     qreal m_delta;
0126     qint32 m_deltaV120;
0127     InputRedirection::PointerAxisSource m_source;
0128     Qt::KeyboardModifiers m_modifiersRelevantForShortcuts = Qt::KeyboardModifiers();
0129     const std::chrono::microseconds m_timestamp;
0130 };
0131 
0132 class KWIN_EXPORT KeyEvent : public QKeyEvent
0133 {
0134 public:
0135     explicit KeyEvent(QEvent::Type type, Qt::Key key, Qt::KeyboardModifiers modifiers, quint32 code, quint32 keysym,
0136                       const QString &text, bool autorepeat, std::chrono::microseconds timestamp, InputDevice *device);
0137 
0138     InputDevice *device() const
0139     {
0140         return m_device;
0141     }
0142 
0143     Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const
0144     {
0145         return m_modifiersRelevantForShortcuts;
0146     }
0147 
0148     void setModifiersRelevantForGlobalShortcuts(const Qt::KeyboardModifiers &mods)
0149     {
0150         m_modifiersRelevantForShortcuts = mods;
0151     }
0152 
0153     Qt::KeyboardModifiers modifiersRelevantForTabBox() const
0154     {
0155         return m_modifiersRelevantForTabBox;
0156     }
0157 
0158     void setModifiersRelevantForTabBox(const Qt::KeyboardModifiers &mods)
0159     {
0160         m_modifiersRelevantForTabBox = mods;
0161     }
0162 
0163     std::chrono::microseconds timestamp() const;
0164 
0165 private:
0166     InputDevice *m_device;
0167     Qt::KeyboardModifiers m_modifiersRelevantForShortcuts = Qt::KeyboardModifiers();
0168     Qt::KeyboardModifiers m_modifiersRelevantForTabBox = Qt::KeyboardModifiers();
0169     const std::chrono::microseconds m_timestamp;
0170 };
0171 
0172 class SwitchEvent : public QEvent
0173 {
0174 public:
0175     enum class State {
0176         Off,
0177         On
0178     };
0179     explicit SwitchEvent(State state, std::chrono::microseconds timestamp, InputDevice *device);
0180 
0181     State state() const
0182     {
0183         return m_state;
0184     }
0185 
0186     std::chrono::microseconds timestamp() const
0187     {
0188         return m_timestamp;
0189     }
0190 
0191     InputDevice *device() const
0192     {
0193         return m_device;
0194     }
0195 
0196 private:
0197     State m_state;
0198     std::chrono::microseconds m_timestamp;
0199     InputDevice *m_device;
0200 };
0201 
0202 class TabletToolId
0203 {
0204 public:
0205     QString deviceSysName;
0206     InputRedirection::TabletToolType m_toolType;
0207     QList<InputRedirection::Capability> m_capabilities;
0208     quint64 m_serialId;
0209     quint64 m_uniqueId;
0210     void *m_deviceGroupData;
0211     QString m_name;
0212 };
0213 
0214 class TabletPadId
0215 {
0216 public:
0217     const QString name;
0218     void *data;
0219 };
0220 
0221 class TabletEvent : public QTabletEvent
0222 {
0223 public:
0224     TabletEvent(Type t, const QPointingDevice *dev, const QPointF &pos, const QPointF &globalPos,
0225                 qreal pressure, float xTilt, float yTilt,
0226                 float tangentialPressure, qreal rotation, float z,
0227                 Qt::KeyboardModifiers keyState, Qt::MouseButton button, Qt::MouseButtons buttons, const TabletToolId &tabletId);
0228 
0229     const TabletToolId &tabletId() const
0230     {
0231         return m_id;
0232     }
0233 
0234 private:
0235     const TabletToolId m_id;
0236 };
0237 
0238 }