From 058f7c7c90ba727748202e52cce67ab67464ea33 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Wed, 22 Jul 2015 03:19:29 +0200 Subject: [PATCH] Implement the touchpad forwarding into kcapp This way the computer's cursor can be controlled from the device. Keyboard is not yet implemented. --- app/qml/main.qml | 7 ++ app/qml/mousepad.qml | 64 +++++++++++++++++ app/resources.qrc | 1 + interfaces/CMakeLists.txt | 2 +- interfaces/dbusinterfaces.cpp | 9 +++ interfaces/dbusinterfaces.h | 10 +++ .../kdeconnectdeclarativeplugin.cpp | 8 +++ plugins/CMakeLists.txt | 1 + plugins/remotecontrol/CMakeLists.txt | 7 ++ .../kdeconnect_remotecontrol.json | 26 +++++++ plugins/remotecontrol/remotecontrolplugin.cpp | 70 +++++++++++++++++++ plugins/remotecontrol/remotecontrolplugin.h | 50 +++++++++++++ 12 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 app/qml/mousepad.qml create mode 100644 plugins/remotecontrol/CMakeLists.txt create mode 100644 plugins/remotecontrol/kdeconnect_remotecontrol.json create mode 100644 plugins/remotecontrol/remotecontrolplugin.cpp create mode 100644 plugins/remotecontrol/remotecontrolplugin.h diff --git a/app/qml/main.qml b/app/qml/main.qml index 9b4cf8251..c2db4314b 100644 --- a/app/qml/main.qml +++ b/app/qml/main.qml @@ -122,6 +122,13 @@ ApplicationWindow properties: { mprisInterface: MprisDbusInterfaceFactory.create(deviceView.currentDevice.id()) } } ); } + Button { + text: i18n("Mouse Pad") + onClicked: stack.push( { + item: "qrc:/qml/mousepad.qml", + properties: { remoteControlInterface: RemoteControlDbusInterfaceFactory.create(deviceView.currentDevice.id()) } + } ); + } Button { text: i18n("Remote touch and keyboard") enabled: false diff --git a/app/qml/mousepad.qml b/app/qml/mousepad.qml new file mode 100644 index 000000000..b8e441860 --- /dev/null +++ b/app/qml/mousepad.qml @@ -0,0 +1,64 @@ +/* + * Copyright 2015 Aleix Pol Gonzalez + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.5 +import QtQuick.Controls 1.2 +import QtQuick.Layouts 1.2 + +ColumnLayout +{ + id: mousepad + property QtObject remoteControlInterface + + MouseArea { + id: area + Layout.fillWidth: true + Layout.fillHeight: true + property var lastPos: Qt.point(-1, -1) + + onClicked: mousepad.remoteControlInterface.sendCommand("singleclick", true); + + onPositionChanged: { + if (lastPos.x > -1) { +// console.log("move", mouse.x, mouse.y, lastPos) + var delta = Qt.point(mouse.x-lastPos.x, mouse.y-lastPos.y); + + remoteControlInterface.moveCursor(delta); + } + lastPos = Qt.point(mouse.x, mouse.y); + } + } + RowLayout { + Layout.fillWidth: true + + Button { + Layout.fillWidth: true + onClicked: mousepad.remoteControlInterface.sendCommand("singleclick", true); + } + Button { + Layout.fillWidth: true + onClicked: mousepad.remoteControlInterface.sendCommand("middleclick", true); + } + Button { + Layout.fillWidth: true + onClicked: mousepad.remoteControlInterface.sendCommand("rightclick", true); + } + } +} diff --git a/app/resources.qrc b/app/resources.qrc index 3731e0ac0..225f85136 100644 --- a/app/resources.qrc +++ b/app/resources.qrc @@ -3,5 +3,6 @@ qml/main.qml qml/DeviceDelegate.qml qml/mpris.qml + qml/mousepad.qml diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt index 0220af8e5..c2e41a9da 100644 --- a/interfaces/CMakeLists.txt +++ b/interfaces/CMakeLists.txt @@ -39,7 +39,7 @@ geninterface(${CMAKE_SOURCE_DIR}/plugins/sftp/sftpplugin.h devicesftpinterface.h geninterface(${CMAKE_SOURCE_DIR}/plugins/notifications/notificationsdbusinterface.h devicenotificationsinterface.h) geninterface(${CMAKE_SOURCE_DIR}/plugins/notifications/notification.h notificationinterface.h) geninterface(${CMAKE_SOURCE_DIR}/plugins/mprisremote/mprisremoteplugin.h mprisremoteinterface) - +geninterface(${CMAKE_SOURCE_DIR}/plugins/remotecontrol/remotecontrolplugin.h remotecontrolinterface) add_library(kdeconnectinterfaces SHARED ${libkdeconnect_SRC}) set_target_properties(kdeconnectinterfaces PROPERTIES diff --git a/interfaces/dbusinterfaces.cpp b/interfaces/dbusinterfaces.cpp index 68b4c64ae..5f5479a0e 100644 --- a/interfaces/dbusinterfaces.cpp +++ b/interfaces/dbusinterfaces.cpp @@ -113,3 +113,12 @@ MprisDbusInterface::MprisDbusInterface(const QString& id, QObject* parent) MprisDbusInterface::~MprisDbusInterface() { } + +RemoteControlDbusInterface::RemoteControlDbusInterface(const QString& id, QObject* parent) + : OrgKdeKdeconnectDeviceRemotecontrolInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + id + "/remotecontrol", QDBusConnection::sessionBus(), parent) +{ +} + +RemoteControlDbusInterface::~RemoteControlDbusInterface() +{ +} diff --git a/interfaces/dbusinterfaces.h b/interfaces/dbusinterfaces.h index d42a28f9e..a2befb494 100644 --- a/interfaces/dbusinterfaces.h +++ b/interfaces/dbusinterfaces.h @@ -30,6 +30,7 @@ #include "interfaces/devicenotificationsinterface.h" #include "interfaces/notificationinterface.h" #include "interfaces/mprisremoteinterface.h" +#include "interfaces/remotecontrolinterface.h" /** * Using these "proxy" classes just in case we need to rename the @@ -124,4 +125,13 @@ Q_SIGNALS: void propertiesChangedProxy(); }; +class KDECONNECTINTERFACES_EXPORT RemoteControlDbusInterface + : public OrgKdeKdeconnectDeviceRemotecontrolInterface +{ + Q_OBJECT +public: + RemoteControlDbusInterface(const QString& deviceId, QObject* parent = 0); + ~RemoteControlDbusInterface() override; +}; + #endif diff --git a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp index 0db9e8bce..dfa92e9af 100644 --- a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp +++ b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp @@ -49,6 +49,11 @@ QObject* createSftpInterface(QVariant deviceId) return new SftpDbusInterface(deviceId.toString()); } +QObject* createRemoteControlInterface(QVariant deviceId) +{ + return new RemoteControlDbusInterface(deviceId.toString()); +} + QObject* createMprisInterface(QVariant deviceId) { return new MprisDbusInterface(deviceId.toString()); @@ -85,6 +90,9 @@ void KdeConnectDeclarativePlugin::initializeEngine(QQmlEngine* engine, const cha engine->rootContext()->setContextProperty("MprisDbusInterfaceFactory" , new ObjectFactory(engine, createMprisInterface)); + + engine->rootContext()->setContextProperty("RemoteControlDbusInterfaceFactory" + , new ObjectFactory(engine, createRemoteControlInterface)); engine->rootContext()->setContextProperty("DBusResponseFactory" , new ObjectFactory(engine, createDBusResponse)); diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 35aec662e..10d26e6b0 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -16,6 +16,7 @@ add_subdirectory(screensaver-inhibit) if(EXPERIMENTALAPP_ENABLED) add_subdirectory(mprisremote) + add_subdirectory(remotecontrol) endif() #FIXME: If we split notifications in several files, they won't appear in the same group in the Notifications KCM diff --git a/plugins/remotecontrol/CMakeLists.txt b/plugins/remotecontrol/CMakeLists.txt new file mode 100644 index 000000000..c33d932d3 --- /dev/null +++ b/plugins/remotecontrol/CMakeLists.txt @@ -0,0 +1,7 @@ +kdeconnect_add_plugin(kdeconnect_remotecontrol JSON kdeconnect_remotecontrol.json SOURCES remotecontrolplugin.cpp) + +target_link_libraries(kdeconnect_remotecontrol + kdeconnectcore + Qt5::DBus + KF5::I18n +) diff --git a/plugins/remotecontrol/kdeconnect_remotecontrol.json b/plugins/remotecontrol/kdeconnect_remotecontrol.json new file mode 100644 index 000000000..5ff9ca307 --- /dev/null +++ b/plugins/remotecontrol/kdeconnect_remotecontrol.json @@ -0,0 +1,26 @@ +{ + "Encoding": "UTF-8", + "KPlugin": { + "Authors": [ + { + "Email": "aleixpol@kde.org", + "Name": "Aleix Pol" + } + ], + "Description": "Control Remote systems", + "EnabledByDefault": true, + "Icon": "applications-multimedia", + "Id": "kdeconnect_remotecontrol", + "License": "GPL", + "Name": "RemoteControl", + "ServiceTypes": [ + "KdeConnect/Plugin" + ], + "Version": "0.1", + "Website": "https://kde.org" + }, + "X-KdeConnect-OutgoingPackageType": [ + "kdeconnect.mousepad" + ], + "X-KdeConnect-SupportedPackageType": [] +} diff --git a/plugins/remotecontrol/remotecontrolplugin.cpp b/plugins/remotecontrol/remotecontrolplugin.cpp new file mode 100644 index 000000000..935f3b93b --- /dev/null +++ b/plugins/remotecontrol/remotecontrolplugin.cpp @@ -0,0 +1,70 @@ +/** + * Copyright 2013 Albert Vaca + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "remotecontrolplugin.h" + +#include +#include + +#include +#include +#include +#include + +#include + +K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_remotecontrol.json", registerPlugin< RemoteControlPlugin >(); ) + +Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_REMOTECONTROL, "kdeconnect.plugin.remotecontrol") + +RemoteControlPlugin::RemoteControlPlugin(QObject *parent, const QVariantList &args) + : KdeConnectPlugin(parent, args) +{ +} + +RemoteControlPlugin::~RemoteControlPlugin() +{} + +void RemoteControlPlugin::moveCursor(const QPoint &p) +{ + NetworkPackage np(PACKAGE_TYPE_MOUSEPAD); + np.set("dx", p.x()); + np.set("dy", p.y()); + sendPackage(np); +} + +void RemoteControlPlugin::sendCommand(const QString &name, bool val) +{ + NetworkPackage np(PACKAGE_TYPE_MOUSEPAD); + np.set(name, val); + sendPackage(np); +} + +void RemoteControlPlugin::connected() +{ + QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents); +} + +QString RemoteControlPlugin::dbusPath() const +{ + return "/modules/kdeconnect/devices/" + device()->id() + "/remotecontrol"; +} + +#include "remotecontrolplugin.moc" diff --git a/plugins/remotecontrol/remotecontrolplugin.h b/plugins/remotecontrol/remotecontrolplugin.h new file mode 100644 index 000000000..0c2fbc967 --- /dev/null +++ b/plugins/remotecontrol/remotecontrolplugin.h @@ -0,0 +1,50 @@ +/** + * Copyright 2013 Albert Vaca + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef MPRISREMOTEPLUGIN_H +#define MPRISREMOTEPLUGIN_H + +#include + +#include + +#define PACKAGE_TYPE_MOUSEPAD QLatin1String("kdeconnect.mousepad") + +class Q_DECL_EXPORT RemoteControlPlugin + : public KdeConnectPlugin +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.remotecontrol") + +public: + explicit RemoteControlPlugin(QObject *parent, const QVariantList &args); + ~RemoteControlPlugin() override; + + bool receivePackage(const NetworkPackage& /*np*/) override { return false; } + void connected() override; + + Q_INVOKABLE void moveCursor(const QPoint &p); + Q_INVOKABLE void sendCommand(const QString &name, bool val); + +private: + QString dbusPath() const; +}; + +#endif