2018-04-02 19:20:24 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2018-04-02 19:20:24 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2018-04-02 19:20:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "waylandremoteinput.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QSizeF>
|
2018-04-02 19:20:24 +01:00
|
|
|
|
|
|
|
#include <KLocalizedString>
|
2022-04-12 15:31:08 +01:00
|
|
|
|
|
|
|
#include "qwayland-fake-input.h"
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QtWaylandClient/qwaylandclientextension.h>
|
2022-04-12 15:31:08 +01:00
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
|
|
|
class FakeInput : public QWaylandClientExtensionTemplate<FakeInput>, public QtWayland::org_kde_kwin_fake_input
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FakeInput()
|
|
|
|
: QWaylandClientExtensionTemplate<FakeInput>(4)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
WaylandRemoteInput::WaylandRemoteInput(QObject *parent)
|
2018-04-02 19:20:24 +01:00
|
|
|
: AbstractRemoteInput(parent)
|
|
|
|
, m_waylandAuthenticationRequested(false)
|
|
|
|
{
|
2022-04-12 15:31:08 +01:00
|
|
|
m_fakeInput = new FakeInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaylandRemoteInput::~WaylandRemoteInput()
|
|
|
|
{
|
|
|
|
delete m_fakeInput;
|
2018-04-02 19:20:24 +01:00
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
bool WaylandRemoteInput::handlePacket(const NetworkPacket &np)
|
2018-04-02 19:20:24 +01:00
|
|
|
{
|
2022-04-12 15:31:08 +01:00
|
|
|
if (!m_fakeInput->isActive()) {
|
|
|
|
return true;
|
2018-04-02 19:20:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_waylandAuthenticationRequested) {
|
2022-04-12 15:31:08 +01:00
|
|
|
m_fakeInput->authenticate(i18n("KDE Connect"), i18n("Use your phone as a touchpad and keyboard"));
|
2018-04-02 19:20:24 +01:00
|
|
|
m_waylandAuthenticationRequested = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const float dx = np.get<float>(QStringLiteral("dx"), 0);
|
|
|
|
const float dy = np.get<float>(QStringLiteral("dy"), 0);
|
|
|
|
|
|
|
|
const bool isSingleClick = np.get<bool>(QStringLiteral("singleclick"), false);
|
|
|
|
const bool isDoubleClick = np.get<bool>(QStringLiteral("doubleclick"), false);
|
|
|
|
const bool isMiddleClick = np.get<bool>(QStringLiteral("middleclick"), false);
|
|
|
|
const bool isRightClick = np.get<bool>(QStringLiteral("rightclick"), false);
|
|
|
|
const bool isSingleHold = np.get<bool>(QStringLiteral("singlehold"), false);
|
|
|
|
const bool isSingleRelease = np.get<bool>(QStringLiteral("singlerelease"), false);
|
|
|
|
const bool isScroll = np.get<bool>(QStringLiteral("scroll"), false);
|
|
|
|
const QString key = np.get<QString>(QStringLiteral("key"), QLatin1String(""));
|
|
|
|
const int specialKey = np.get<int>(QStringLiteral("specialKey"), 0);
|
|
|
|
|
2021-07-01 06:38:43 +01:00
|
|
|
if (isSingleClick || isDoubleClick || isMiddleClick || isRightClick || isSingleHold || isSingleRelease || isScroll || !key.isEmpty() || specialKey) {
|
2018-04-02 19:20:24 +01:00
|
|
|
if (isSingleClick) {
|
2022-04-12 15:31:08 +01:00
|
|
|
m_fakeInput->button(BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED);
|
|
|
|
m_fakeInput->button(BTN_LEFT, WL_POINTER_BUTTON_STATE_RELEASED);
|
|
|
|
|
2018-04-02 19:20:24 +01:00
|
|
|
} else if (isDoubleClick) {
|
2022-04-12 15:31:08 +01:00
|
|
|
m_fakeInput->button(BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED);
|
|
|
|
m_fakeInput->button(BTN_LEFT, WL_POINTER_BUTTON_STATE_RELEASED);
|
|
|
|
|
|
|
|
m_fakeInput->button(BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED);
|
|
|
|
m_fakeInput->button(BTN_LEFT, WL_POINTER_BUTTON_STATE_RELEASED);
|
2018-04-02 19:20:24 +01:00
|
|
|
} else if (isMiddleClick) {
|
2022-04-12 15:31:08 +01:00
|
|
|
m_fakeInput->button(BTN_MIDDLE, WL_POINTER_BUTTON_STATE_PRESSED);
|
|
|
|
m_fakeInput->button(BTN_MIDDLE, WL_POINTER_BUTTON_STATE_RELEASED);
|
2018-04-02 19:20:24 +01:00
|
|
|
} else if (isRightClick) {
|
2022-04-12 15:31:08 +01:00
|
|
|
m_fakeInput->button(BTN_RIGHT, WL_POINTER_BUTTON_STATE_PRESSED);
|
|
|
|
m_fakeInput->button(BTN_RIGHT, WL_POINTER_BUTTON_STATE_RELEASED);
|
2022-09-10 22:23:52 +01:00
|
|
|
} else if (isSingleHold) {
|
|
|
|
// For drag'n drop
|
2022-04-12 15:31:08 +01:00
|
|
|
m_fakeInput->button(BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED);
|
2022-09-10 22:23:52 +01:00
|
|
|
} else if (isSingleRelease) {
|
|
|
|
// For drag'n drop. NEVER USED (release is done by tapping, which actually triggers a isSingleClick). Kept here for future-proofness.
|
2022-04-12 15:31:08 +01:00
|
|
|
m_fakeInput->button(BTN_LEFT, WL_POINTER_BUTTON_STATE_RELEASED);
|
2018-04-02 19:20:24 +01:00
|
|
|
} else if (isScroll) {
|
2022-04-12 15:31:08 +01:00
|
|
|
m_fakeInput->axis(WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_double(-dy));
|
|
|
|
|
2018-04-02 19:20:24 +01:00
|
|
|
} else if (!key.isEmpty() || specialKey) {
|
|
|
|
// TODO: implement key support
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
} else { // Is a mouse move event
|
2022-04-12 15:31:08 +01:00
|
|
|
m_fakeInput->pointer_motion(wl_fixed_from_double(dx), wl_fixed_from_double(dy));
|
2018-04-02 19:20:24 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|