File indexing completed on 2025-11-30 14:58:32
0001 /* 0002 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "fakeinputdevice.h" 0008 #include "wayland/fakeinput_interface.h" 0009 0010 namespace KWin 0011 { 0012 static int s_lastDeviceId = 0; 0013 0014 FakeInputDevice::FakeInputDevice(KWaylandServer::FakeInputDevice *device, QObject *parent) 0015 : InputDevice(parent) 0016 , m_name(QStringLiteral("Fake Input Device %1").arg(++s_lastDeviceId)) 0017 { 0018 connect(device, &KWaylandServer::FakeInputDevice::authenticationRequested, this, [device](const QString &application, const QString &reason) { 0019 // TODO: make secure 0020 device->setAuthentication(true); 0021 }); 0022 connect(device, &KWaylandServer::FakeInputDevice::pointerMotionRequested, this, [this](const QPointF &delta) { 0023 const auto time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()); 0024 Q_EMIT pointerMotion(delta, delta, time, this); 0025 }); 0026 connect(device, &KWaylandServer::FakeInputDevice::pointerMotionAbsoluteRequested, this, [this](const QPointF &pos) { 0027 const auto time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()); 0028 Q_EMIT pointerMotionAbsolute(pos, time, this); 0029 }); 0030 connect(device, &KWaylandServer::FakeInputDevice::pointerButtonPressRequested, this, [this](quint32 button) { 0031 const auto time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()); 0032 Q_EMIT pointerButtonChanged(button, InputRedirection::PointerButtonPressed, time, this); 0033 }); 0034 connect(device, &KWaylandServer::FakeInputDevice::pointerButtonReleaseRequested, this, [this](quint32 button) { 0035 const auto time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()); 0036 Q_EMIT pointerButtonChanged(button, InputRedirection::PointerButtonReleased, time, this); 0037 }); 0038 connect(device, &KWaylandServer::FakeInputDevice::pointerAxisRequested, this, [this](Qt::Orientation orientation, qreal delta) { 0039 InputRedirection::PointerAxis axis; 0040 switch (orientation) { 0041 case Qt::Horizontal: 0042 axis = InputRedirection::PointerAxisHorizontal; 0043 break; 0044 case Qt::Vertical: 0045 axis = InputRedirection::PointerAxisVertical; 0046 break; 0047 default: 0048 Q_UNREACHABLE(); 0049 break; 0050 } 0051 const auto time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()); 0052 Q_EMIT pointerAxisChanged(axis, delta, 0, InputRedirection::PointerAxisSourceUnknown, time, this); 0053 }); 0054 connect(device, &KWaylandServer::FakeInputDevice::touchDownRequested, this, [this](qint32 id, const QPointF &pos) { 0055 const auto time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()); 0056 Q_EMIT touchDown(id, pos, time, this); 0057 }); 0058 connect(device, &KWaylandServer::FakeInputDevice::touchMotionRequested, this, [this](qint32 id, const QPointF &pos) { 0059 const auto time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()); 0060 Q_EMIT touchMotion(id, pos, time, this); 0061 }); 0062 connect(device, &KWaylandServer::FakeInputDevice::touchUpRequested, this, [this](qint32 id) { 0063 const auto time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()); 0064 Q_EMIT touchUp(id, time, this); 0065 }); 0066 connect(device, &KWaylandServer::FakeInputDevice::touchCancelRequested, this, [this]() { 0067 Q_EMIT touchCanceled(this); 0068 }); 0069 connect(device, &KWaylandServer::FakeInputDevice::touchFrameRequested, this, [this]() { 0070 Q_EMIT touchFrame(this); 0071 }); 0072 connect(device, &KWaylandServer::FakeInputDevice::keyboardKeyPressRequested, this, [this](quint32 button) { 0073 const auto time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()); 0074 Q_EMIT keyChanged(button, InputRedirection::KeyboardKeyPressed, time, this); 0075 }); 0076 connect(device, &KWaylandServer::FakeInputDevice::keyboardKeyReleaseRequested, this, [this](quint32 button) { 0077 const auto time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()); 0078 Q_EMIT keyChanged(button, InputRedirection::KeyboardKeyReleased, time, this); 0079 }); 0080 } 0081 0082 QString FakeInputDevice::sysName() const 0083 { 0084 return QString(); 0085 } 0086 0087 QString FakeInputDevice::name() const 0088 { 0089 return m_name; 0090 } 0091 0092 bool FakeInputDevice::isEnabled() const 0093 { 0094 return true; 0095 } 0096 0097 void FakeInputDevice::setEnabled(bool enabled) 0098 { 0099 } 0100 0101 LEDs FakeInputDevice::leds() const 0102 { 0103 return LEDs(); 0104 } 0105 0106 void FakeInputDevice::setLeds(LEDs leds) 0107 { 0108 } 0109 0110 bool FakeInputDevice::isKeyboard() const 0111 { 0112 return true; 0113 } 0114 0115 bool FakeInputDevice::isAlphaNumericKeyboard() const 0116 { 0117 return true; 0118 } 0119 0120 bool FakeInputDevice::isPointer() const 0121 { 0122 return true; 0123 } 0124 0125 bool FakeInputDevice::isTouchpad() const 0126 { 0127 return false; 0128 } 0129 0130 bool FakeInputDevice::isTouch() const 0131 { 0132 return true; 0133 } 0134 0135 bool FakeInputDevice::isTabletTool() const 0136 { 0137 return false; 0138 } 0139 0140 bool FakeInputDevice::isTabletPad() const 0141 { 0142 return false; 0143 } 0144 0145 bool FakeInputDevice::isTabletModeSwitch() const 0146 { 0147 return false; 0148 } 0149 0150 bool FakeInputDevice::isLidSwitch() const 0151 { 0152 return false; 0153 } 0154 0155 } // namespace KWin