/** * SPDX-FileCopyrightText: 2015 Martin Gräßlin * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ #include "waylandremoteinput.h" #include #include #include #include #include #include WaylandRemoteInput::WaylandRemoteInput(QObject* parent) : AbstractRemoteInput(parent) , m_waylandInput(nullptr) , m_waylandAuthenticationRequested(false) { using namespace KWayland::Client; ConnectionThread* connection = ConnectionThread::fromApplication(this); if (!connection) { qDebug() << "failed to get the Connection from Qt, Wayland remote input will not work"; return; } Registry* registry = new Registry(this); registry->create(connection); connect(registry, &Registry::fakeInputAnnounced, this, [this, registry] (quint32 name, quint32 version) { m_waylandInput = registry->createFakeInput(name, version, this); } ); connect(registry, &Registry::fakeInputRemoved, m_waylandInput, &QObject::deleteLater); registry->setup(); } bool WaylandRemoteInput::handlePacket(const NetworkPacket& np) { if (!m_waylandInput) { return false; } if (!m_waylandAuthenticationRequested) { m_waylandInput->authenticate(i18n("KDE Connect"), i18n("Use your phone as a touchpad and keyboard")); m_waylandAuthenticationRequested = true; } const float dx = np.get(QStringLiteral("dx"), 0); const float dy = np.get(QStringLiteral("dy"), 0); const bool isSingleClick = np.get(QStringLiteral("singleclick"), false); const bool isDoubleClick = np.get(QStringLiteral("doubleclick"), false); const bool isMiddleClick = np.get(QStringLiteral("middleclick"), false); const bool isRightClick = np.get(QStringLiteral("rightclick"), false); const bool isSingleHold = np.get(QStringLiteral("singlehold"), false); const bool isSingleRelease = np.get(QStringLiteral("singlerelease"), false); const bool isScroll = np.get(QStringLiteral("scroll"), false); const QString key = np.get(QStringLiteral("key"), QLatin1String("")); const int specialKey = np.get(QStringLiteral("specialKey"), 0); if (isSingleClick || isDoubleClick || isMiddleClick || isRightClick || isSingleHold || isScroll || !key.isEmpty() || specialKey) { if (isSingleClick) { m_waylandInput->requestPointerButtonClick(Qt::LeftButton); } else if (isDoubleClick) { m_waylandInput->requestPointerButtonClick(Qt::LeftButton); m_waylandInput->requestPointerButtonClick(Qt::LeftButton); } else if (isMiddleClick) { m_waylandInput->requestPointerButtonClick(Qt::MiddleButton); } else if (isRightClick) { m_waylandInput->requestPointerButtonClick(Qt::RightButton); } else if (isSingleHold){ //For drag'n drop m_waylandInput->requestPointerButtonPress(Qt::LeftButton); } else if (isSingleRelease){ //For drag'n drop. NEVER USED (release is done by tapping, which actually triggers a isSingleClick). Kept here for future-proofness. m_waylandInput->requestPointerButtonRelease(Qt::LeftButton); } else if (isScroll) { m_waylandInput->requestPointerAxis(Qt::Vertical, -dy); } else if (!key.isEmpty() || specialKey) { // TODO: implement key support } } else { //Is a mouse move event m_waylandInput->requestPointerMove(QSizeF(dx, dy)); } return true; }