Commit e7578cc1 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Refactor capabilities together with Albert

He is committing a similar patch to kdeconnect-android
parent 0b5fbe00
......@@ -24,7 +24,7 @@
#include <QLoggingCategory>
#include <core/kdeconnectplugin.h>
#define PACKAGE_TYPE_BATTERY QLatin1String("kdeconnect.battery")
#define PACKAGE_TYPE_BATTERY QLatin1String("kdeconnect.battery.request")
Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_BATTERY)
class BatteryDbusInterface;
......
......@@ -67,9 +67,9 @@
"Website": "http://albertvaka.wordpress.com"
},
"X-KdeConnect-OutgoingPackageType": [
"kdeconnect.battery"
"kdeconnect.battery.request"
],
"X-KdeConnect-SupportedPackageType": [
"kdeconnect.battery"
]
}
\ No newline at end of file
}
......@@ -25,7 +25,7 @@
#include <core/kdeconnectplugin.h>
#define PACKAGE_TYPE_FINDMYPHONE QStringLiteral("kdeconnect.findmyphone")
#define PACKAGE_TYPE_FINDMYPHONE QStringLiteral("kdeconnect.findmyphone.request")
class FindMyPhonePlugin
: public KdeConnectPlugin
......
......@@ -47,6 +47,6 @@
"Website": "http://kde.org"
},
"X-KdeConnect-OutgoingPackageType": [
"kdeconnect.findmyphone"
"kdeconnect.findmyphone.request"
]
}
\ No newline at end of file
}
......@@ -64,9 +64,11 @@
"Website": "https://kde.org"
},
"X-KdeConnect-OutgoingPackageType": [
"kdeconnect.lock.request",
"kdeconnect.lock"
],
"X-KdeConnect-SupportedPackageType": [
"kdeconnect.lock.request",
"kdeconnect.lock"
]
}
\ No newline at end of file
}
......@@ -52,7 +52,7 @@ bool LockDevicePlugin::isLocked() const
}
void LockDevicePlugin::setLocked(bool locked)
{
NetworkPackage np(PACKAGE_TYPE_LOCK);
NetworkPackage np(PACKAGE_TYPE_LOCK_REQUEST);
np.set("setLocked", locked);
sendPackage(np);
}
......@@ -95,7 +95,7 @@ void LockDevicePlugin::connected()
{
QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents);
NetworkPackage np(PACKAGE_TYPE_LOCK);
NetworkPackage np(PACKAGE_TYPE_LOCK_REQUEST);
np.set("requestLocked", QVariant());
sendPackage(np);
}
......
......@@ -28,6 +28,7 @@
class OrgFreedesktopScreenSaverInterface;
#define PACKAGE_TYPE_LOCK QLatin1String("kdeconnect.lock")
#define PACKAGE_TYPE_LOCK_REQUEST QLatin1String("kdeconnect.lock.request")
class Q_DECL_EXPORT LockDevicePlugin
: public KdeConnectPlugin
......
set(kdeconnect_mousepad_SRCS
mousepadplugin.cpp
)
find_package(LibFakeKey)
set_package_properties(LibFakeKey PROPERTIES DESCRIPTION "fake key events"
URL "https://www.yoctoproject.org/tools-resources/projects/matchbox"
TYPE OPTIONAL
PURPOSE "Needed for the remote mousepad plugin"
)
find_package(XTest REQUIRED)
find_package(X11 REQUIRED)
find_package(LibFakeKey REQUIRED)
find_package(Qt5X11Extras REQUIRED)
if (LibFakeKey_FOUND)
find_package(XTest REQUIRED)
find_package(X11 REQUIRED)
find_package(Qt5X11Extras REQUIRED)
endif()
find_package(KF5Wayland 5.3.90)
set(HAVE_X11 ${LibFakeKey_FOUND})
set(HAVE_WAYLAND ${KF5Wayland_FOUND})
configure_file(config-mousepad.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-mousepad.h )
kdeconnect_add_plugin(kdeconnect_mousepad JSON kdeconnect_mousepad.json SOURCES ${kdeconnect_mousepad_SRCS})
kdeconnect_add_plugin(kdeconnect_mousepad JSON kdeconnect_mousepad.json SOURCES mousepadplugin.cpp)
include_directories(${XTEST_INCLUDE_DIRS} ${X11_INCLUDE_DIR} ${LibFakeKey_INCLUDE_DIRS})
if (HAVE_X11)
include_directories(${XTEST_INCLUDE_DIRS} ${X11_INCLUDE_DIR} ${LibFakeKey_INCLUDE_DIRS})
endif()
target_link_libraries(kdeconnect_mousepad kdeconnectcore Qt5::Gui Qt5::X11Extras ${X11_LIBRARIES} ${XTEST_LIBRARIES} ${LibFakeKey_LIBRARIES} KF5::I18n)
target_link_libraries(kdeconnect_mousepad kdeconnectcore Qt5::Gui KF5::I18n)
if(HAVE_WAYLAND)
target_link_libraries(kdeconnect_mousepad KF5::WaylandClient)
endif()
if(HAVE_X11)
target_link_libraries(kdeconnect_mousepad Qt5::X11Extras ${X11_LIBRARIES} ${XTEST_LIBRARIES} ${LibFakeKey_LIBRARIES})
endif()
#cmakedefine01 HAVE_WAYLAND
#cmakedefine01 HAVE_X11
......@@ -67,6 +67,6 @@
},
"X-KdeConnect-OutgoingPackageType": [],
"X-KdeConnect-SupportedPackageType": [
"kdeconnect.mousepad"
"kdeconnect.input.request"
]
}
\ No newline at end of file
}
......@@ -24,10 +24,13 @@
#include <KLocalizedString>
#include <QDebug>
#include <QGuiApplication>
#if HAVE_X11
#include <QX11Info>
#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
#include <fakekey/fakekey.h>
#endif
#if HAVE_WAYLAND
#include <KWayland/Client/connection_thread.h>
......@@ -45,6 +48,7 @@ enum MouseButtons {
MouseWheelDown = 5
};
#if HAVE_X11
//Translation table to keep in sync within all the implementations
int SpecialKeysMap[] = {
0, // Invalid
......@@ -81,12 +85,19 @@ int SpecialKeysMap[] = {
XK_F11, // 31
XK_F12, // 32
};
#endif
template <typename T, size_t N>
size_t arraySize(T(&arr)[N]) { (void)arr; return N; }
MousepadPlugin::MousepadPlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args), m_fakekey(nullptr), m_x11(QX11Info::isPlatformX11())
: KdeConnectPlugin(parent, args)
#if HAVE_X11
, m_fakekey(nullptr)
, m_x11(QX11Info::isPlatformX11())
#else
, m_x11(false)
#endif
#if HAVE_WAYLAND
, m_waylandInput(nullptr)
, m_waylandAuthenticationRequested(false)
......@@ -99,17 +110,21 @@ MousepadPlugin::MousepadPlugin(QObject* parent, const QVariantList& args)
MousepadPlugin::~MousepadPlugin()
{
#if HAVE_X11
if (m_fakekey) {
free(m_fakekey);
m_fakekey = nullptr;
}
#endif
}
bool MousepadPlugin::receivePackage(const NetworkPackage& np)
{
#if HAVE_X11
if (m_x11) {
return handlePackageX11(np);
}
#endif
#if HAVE_WAYLAND
if (m_waylandInput) {
if (!m_waylandAuthenticationRequested) {
......@@ -122,6 +137,7 @@ bool MousepadPlugin::receivePackage(const NetworkPackage& np)
return false;
}
#if HAVE_X11
bool MousepadPlugin::handlePackageX11(const NetworkPackage &np)
{
//qDebug() << np.serialize();
......@@ -229,6 +245,7 @@ bool MousepadPlugin::handlePackageX11(const NetworkPackage &np)
}
return true;
}
#endif
#if HAVE_WAYLAND
void MousepadPlugin::setupWaylandIntegration()
......
......@@ -25,7 +25,7 @@
#include <core/kdeconnectplugin.h>
#include <config-mousepad.h>
#define PACKAGE_TYPE_MOUSEPAD QLatin1String("kdeconnect.mousepad")
#define PACKAGE_TYPE_INPUT_REQUEST QLatin1String("kdeconnect.input.request")
struct FakeKey;
......@@ -52,13 +52,17 @@ public:
virtual void connected() override { }
private:
#if HAVE_X11
bool handlePackageX11(const NetworkPackage& np);
#endif
#if HAVE_WAYLAND
void setupWaylandIntegration();
bool handPackageWayland(const NetworkPackage& np);
#endif
#if HAVE_X11
FakeKey* m_fakekey;
#endif
const bool m_x11;
#if HAVE_WAYLAND
KWayland::Client::FakeInput *m_waylandInput;
......
......@@ -70,6 +70,6 @@
"kdeconnect.mpris"
],
"X-KdeConnect-SupportedPackageType": [
"kdeconnect.mpris"
"kdeconnect.mpris.request"
]
}
\ No newline at end of file
}
......@@ -28,7 +28,7 @@
#include <core/kdeconnectplugin.h>
#define PACKAGE_TYPE_MPRIS QLatin1String("kdeconnect.mpris")
#define PACKAGE_TYPE_MPRIS QLatin1String("kdeconnect.mpris.request")
Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_MPRIS)
......
......@@ -51,9 +51,9 @@
"Website": "https://kde.org"
},
"X-KdeConnect-OutgoingPackageType": [
"kdeconnect.mpris"
"kdeconnect.mpris.request"
],
"X-KdeConnect-SupportedPackageType": [
"kdeconnect.mpris"
]
}
\ No newline at end of file
}
......@@ -52,7 +52,7 @@ MprisRemotePlugin::~MprisRemotePlugin()
bool MprisRemotePlugin::receivePackage(const NetworkPackage& np)
{
if (np.type() != PACKAGE_TYPE_MPRIS)
if (np.type() != PACKAGE_TYPE_MPRIS_REQUEST)
return false;
if (np.has("nowPlaying") || np.has("volume") || np.has("isPlaying") || np.has("length") || np.has("pos")) {
......@@ -97,7 +97,7 @@ QString MprisRemotePlugin::dbusPath() const
void MprisRemotePlugin::requestPlayerStatus()
{
NetworkPackage np(PACKAGE_TYPE_MPRIS);
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("player",m_player);
np.set("requestNowPlaying",true);
np.set("requestVolume",true);
......@@ -106,14 +106,14 @@ void MprisRemotePlugin::requestPlayerStatus()
void MprisRemotePlugin::requestPlayerList()
{
NetworkPackage np(PACKAGE_TYPE_MPRIS);
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("requestPlayerList", true);
sendPackage(np);
}
void MprisRemotePlugin::sendAction(const QString& action)
{
NetworkPackage np(PACKAGE_TYPE_MPRIS);
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("player", m_player);
np.set("action", action);
sendPackage(np);
......@@ -121,7 +121,7 @@ void MprisRemotePlugin::sendAction(const QString& action)
void MprisRemotePlugin::seek(int offset) const
{
NetworkPackage np(PACKAGE_TYPE_MPRIS);
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("player", m_player);
np.set("Seek", offset);
sendPackage(np);
......@@ -129,7 +129,7 @@ void MprisRemotePlugin::seek(int offset) const
void MprisRemotePlugin::setVolume(int volume)
{
NetworkPackage np(PACKAGE_TYPE_MPRIS);
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("player", m_player);
np.set("setVolume",volume);
sendPackage(np);
......@@ -137,7 +137,7 @@ void MprisRemotePlugin::setVolume(int volume)
void MprisRemotePlugin::setPosition(int position)
{
NetworkPackage np(PACKAGE_TYPE_MPRIS);
NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("player", m_player);
np.set("SetPosition", position);
sendPackage(np);
......
......@@ -25,7 +25,7 @@
#include <core/kdeconnectplugin.h>
#define PACKAGE_TYPE_MPRIS QLatin1String("kdeconnect.mpris")
#define PACKAGE_TYPE_MPRIS_REQUEST QLatin1String("kdeconnect.mpris.request")
class Q_DECL_EXPORT MprisRemotePlugin
: public KdeConnectPlugin
......
......@@ -21,9 +21,9 @@
"Website": "http://albertvaka.wordpress.com"
},
"X-KdeConnect-OutgoingPackageType": [
"kdeconnect.notification"
"kdeconnect.notification.request"
],
"X-KdeConnect-SupportedPackageType": [
"kdeconnect.notification"
]
}
\ No newline at end of file
}
......@@ -70,7 +70,7 @@ void NotificationsDbusInterface::processPackage(const NetworkPackage& np)
removeNotification(id);
} else if (np.get<bool>("isRequest")) {
for (const auto& n: mNotifications) {
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION);
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST);
np.set("id", n->internalId());
np.set("appName", n->appName());
np.set("ticker", n->ticker());
......@@ -152,7 +152,7 @@ void NotificationsDbusInterface::removeNotification(const QString& internalId)
void NotificationsDbusInterface::dismissRequested(const QString& internalId)
{
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION);
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST);
np.set<QString>("cancel", internalId);
mPlugin->sendPackage(np);
......
......@@ -37,7 +37,7 @@ NotificationsPlugin::NotificationsPlugin(QObject* parent, const QVariantList& ar
void NotificationsPlugin::connected()
{
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION);
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST);
np.set("request", true);
sendPackage(np);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment