File indexing completed on 2024-02-25 17:23:40

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 #include "input_event.h"
0010 
0011 namespace KWin
0012 {
0013 
0014 MouseEvent::MouseEvent(QEvent::Type type, const QPointF &pos, Qt::MouseButton button,
0015                        Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, std::chrono::microseconds timestamp,
0016                        const QPointF &delta, const QPointF &deltaNonAccelerated, InputDevice *device)
0017     : QMouseEvent(type, pos, pos, button, buttons, modifiers)
0018     , m_delta(delta)
0019     , m_deltaUnccelerated(deltaNonAccelerated)
0020     , m_timestamp(timestamp)
0021     , m_device(device)
0022 {
0023     setTimestamp(std::chrono::duration_cast<std::chrono::milliseconds>(timestamp).count());
0024 }
0025 
0026 WheelEvent::WheelEvent(const QPointF &pos, qreal delta, qint32 deltaV120, Qt::Orientation orientation,
0027                        Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, InputRedirection::PointerAxisSource source,
0028                        std::chrono::microseconds timestamp, InputDevice *device)
0029     : QWheelEvent(pos, pos, QPoint(), (orientation == Qt::Horizontal) ? QPoint(delta, 0) : QPoint(0, delta), buttons, modifiers, Qt::NoScrollPhase, false)
0030     , m_device(device)
0031     , m_orientation(orientation)
0032     , m_delta(delta)
0033     , m_deltaV120(deltaV120)
0034     , m_source(source)
0035     , m_timestamp(timestamp)
0036 {
0037     setTimestamp(std::chrono::duration_cast<std::chrono::milliseconds>(timestamp).count());
0038 }
0039 
0040 std::chrono::microseconds WheelEvent::timestamp() const
0041 {
0042     return m_timestamp;
0043 }
0044 
0045 KeyEvent::KeyEvent(QEvent::Type type, Qt::Key key, Qt::KeyboardModifiers modifiers, quint32 code, quint32 keysym,
0046                    const QString &text, bool autorepeat, std::chrono::microseconds timestamp, InputDevice *device)
0047     : QKeyEvent(type, key, modifiers, code, keysym, 0, text, autorepeat)
0048     , m_device(device)
0049     , m_timestamp(timestamp)
0050 {
0051     setTimestamp(std::chrono::duration_cast<std::chrono::milliseconds>(timestamp).count());
0052 }
0053 
0054 std::chrono::microseconds KeyEvent::timestamp() const
0055 {
0056     return m_timestamp;
0057 }
0058 
0059 SwitchEvent::SwitchEvent(State state, std::chrono::microseconds timestamp, InputDevice *device)
0060     : QEvent(QEvent::User)
0061     , m_state(state)
0062     , m_timestamp(timestamp)
0063     , m_device(device)
0064 {
0065 }
0066 
0067 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0068 TabletEvent::TabletEvent(Type t, const QPointingDevice *dev, const QPointF &pos, const QPointF &globalPos,
0069                          qreal pressure, float xTilt, float yTilt,
0070                          float tangentialPressure, qreal rotation, float z,
0071                          Qt::KeyboardModifiers keyState, Qt::MouseButton button, Qt::MouseButtons buttons, const TabletToolId &tabletId)
0072     : QTabletEvent(t, dev, pos, globalPos, pressure, xTilt, yTilt, tangentialPressure, rotation, z, keyState, button, buttons)
0073     , m_id(tabletId)
0074 {
0075 }
0076 #else
0077 TabletEvent::TabletEvent(Type t, const QPointF &pos, const QPointF &globalPos,
0078                          int device, int pointerType, qreal pressure, int xTilt, int yTilt,
0079                          qreal tangentialPressure, qreal rotation, int z,
0080                          Qt::KeyboardModifiers keyState, qint64 uniqueID,
0081                          Qt::MouseButton button, Qt::MouseButtons buttons, const TabletToolId &tabletId)
0082     : QTabletEvent(t, pos, globalPos, device, pointerType, pressure, xTilt, yTilt, tangentialPressure, rotation, z, keyState, uniqueID, button, buttons)
0083     , m_id(tabletId)
0084 {
0085 }
0086 #endif
0087 
0088 }