[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498

Maximiliano Curia maxy at moszumanska.debian.org
Fri Oct 14 14:28:45 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=2506f0e

The following commit has been merged in the master branch:
commit 2506f0e78aecbbf7949e683ad6a4742af1d25114
Author: Martin Gräßlin <mgraesslin at kde.org>
Date:   Fri Jul 3 09:25:34 2015 +0200

    [mousepad] Integrate with KWayland for fake input support
    
    KWayland provides a FakeInput interface which KWin as a compositor
    supports. This can be used to fake input events on Wayland. As it's
    a KWin specific interface it won't work with other Wayland compositors.
    
    If the compositor does not support the required interface, the
    module just doesn't do anything. Support in the implementation is
    completely optional.
    
    Adding fake input events circumvents the Wayland security model.
    Because of that the interface is designed in a way that the security
    decision can be done by the compositor and can be delegated to the
    user.
    
    On first input event kdeconnect tries to "authenticate" with the
    compositor. This gives the compositor the possibility to e.g. ask
    the user whether it should be allowed. It's not done on startup or
    of load module as that would show such a message way to early and
    the user would not be able to connect it with his action on the
    smartphone.
    
    REVIEW: 124238
---
 plugins/mousepad/CMakeLists.txt          | 10 +++-
 plugins/mousepad/config-mousepad.h.cmake |  1 +
 plugins/mousepad/mousepadplugin.cpp      | 94 +++++++++++++++++++++++++++++++-
 plugins/mousepad/mousepadplugin.h        | 20 ++++++-
 4 files changed, 122 insertions(+), 3 deletions(-)

diff --git a/plugins/mousepad/CMakeLists.txt b/plugins/mousepad/CMakeLists.txt
index 88716c7..ecfdbb7 100644
--- a/plugins/mousepad/CMakeLists.txt
+++ b/plugins/mousepad/CMakeLists.txt
@@ -6,9 +6,17 @@ find_package(XTest REQUIRED)
 find_package(X11 REQUIRED)
 find_package(LibFakeKey REQUIRED)
 find_package(Qt5X11Extras REQUIRED)
+find_package(KF5Wayland)
+
+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})
 
 include_directories(${XTEST_INCLUDE_DIRS} ${X11_INCLUDE_DIR} ${LibFakeKey_INCLUDE_DIRS})
 
-target_link_libraries(kdeconnect_mousepad kdeconnectcore Qt5::Gui Qt5::X11Extras ${X11_LIBRARIES} ${XTEST_LIBRARIES} ${LibFakeKey_LIBRARIES})
+target_link_libraries(kdeconnect_mousepad kdeconnectcore Qt5::Gui Qt5::X11Extras ${X11_LIBRARIES} ${XTEST_LIBRARIES} ${LibFakeKey_LIBRARIES} KF5::I18n)
+
+if(HAVE_WAYLAND)
+    target_link_libraries(kdeconnect_mousepad KF5::WaylandClient)
+endif()
diff --git a/plugins/mousepad/config-mousepad.h.cmake b/plugins/mousepad/config-mousepad.h.cmake
new file mode 100644
index 0000000..e683004
--- /dev/null
+++ b/plugins/mousepad/config-mousepad.h.cmake
@@ -0,0 +1 @@
+#cmakedefine01 HAVE_WAYLAND
diff --git a/plugins/mousepad/mousepadplugin.cpp b/plugins/mousepad/mousepadplugin.cpp
index 38b7c8e..89ba532 100644
--- a/plugins/mousepad/mousepadplugin.cpp
+++ b/plugins/mousepad/mousepadplugin.cpp
@@ -1,5 +1,6 @@
 /**
  * Copyright 2014 Ahmed I. Khalil <ahmedibrahimkhali at gmail.com>
+ * Copyright 2015 Martin Gräßlin <mgraesslin at kde.org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -20,12 +21,20 @@
 
 #include "mousepadplugin.h"
 #include <KPluginFactory>
+#include <KLocalizedString>
 #include <QDebug>
+#include <QGuiApplication>
 #include <QX11Info>
 #include <X11/extensions/XTest.h>
 #include <X11/keysym.h>
 #include <fakekey/fakekey.h>
 
+#if HAVE_WAYLAND
+#include <KWayland/Client/connection_thread.h>
+#include <KWayland/Client/fakeinput.h>
+#include <KWayland/Client/registry.h>
+#endif
+
 K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_mousepad.json", registerPlugin< MousepadPlugin >(); )
 
 enum MouseButtons {
@@ -78,8 +87,14 @@ size_t arraySize(T(&arr)[N]) { (void)arr; return N; }
 
 MousepadPlugin::MousepadPlugin(QObject* parent, const QVariantList& args)
     : KdeConnectPlugin(parent, args), m_fakekey(0), m_x11(QX11Info::isPlatformX11())
+#if HAVE_WAYLAND
+    , m_waylandInput(nullptr)
+    , m_waylandAuthenticationRequested(false)
+#endif
 {
-
+#if HAVE_WAYLAND
+    setupWaylandIntegration();
+#endif
 }
 
 MousepadPlugin::~MousepadPlugin()
@@ -95,6 +110,15 @@ bool MousepadPlugin::receivePackage(const NetworkPackage& np)
     if (m_x11) {
         return handlePackageX11(np);
     }
+#if HAVE_WAYLAND
+    if (m_waylandInput) {
+        if (!m_waylandAuthenticationRequested) {
+            m_waylandInput->authenticate(i18n("KDE Connect"), i18n("Use your phone as a touchpad and keyboard"));
+            m_waylandAuthenticationRequested = true;
+        }
+        handPackageWayland(np);
+    }
+#endif
     return false;
 }
 
@@ -203,4 +227,72 @@ bool MousepadPlugin::handlePackageX11(const NetworkPackage &np)
     return true;
 }
 
+#if HAVE_WAYLAND
+void MousepadPlugin::setupWaylandIntegration()
+{
+    if (!QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
+        // not wayland
+        return;
+    }
+    using namespace KWayland::Client;
+    ConnectionThread *connection = ConnectionThread::fromApplication(this);
+    if (!connection) {
+        // failed to get the Connection from Qt
+        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);
+        }
+    );
+    registry->setup();
+}
+
+bool MousepadPlugin::handPackageWayland(const NetworkPackage &np)
+{
+    const float dx = np.get<float>("dx", 0);
+    const float dy = np.get<float>("dy", 0);
+
+    const bool isSingleClick = np.get<bool>("singleclick", false);
+    const bool isDoubleClick = np.get<bool>("doubleclick", false);
+    const bool isMiddleClick = np.get<bool>("middleclick", false);
+    const bool isRightClick = np.get<bool>("rightclick", false);
+    const bool isSingleHold = np.get<bool>("singlehold", false);
+    const bool isSingleRelease = np.get<bool>("singlerelease", false);
+    const bool isScroll = np.get<bool>("scroll", false);
+    const QString key = np.get<QString>("key", "");
+    const int specialKey = np.get<int>("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-proofnes.
+            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;
+}
+#endif
+
 #include "mousepadplugin.moc"
diff --git a/plugins/mousepad/mousepadplugin.h b/plugins/mousepad/mousepadplugin.h
index 4bef0db..0c49988 100644
--- a/plugins/mousepad/mousepadplugin.h
+++ b/plugins/mousepad/mousepadplugin.h
@@ -23,11 +23,22 @@
 
 #include <QtGui/QCursor>
 #include <core/kdeconnectplugin.h>
+#include <config-mousepad.h>
 
 #define PACKAGE_TYPE_MOUSEPAD QLatin1String("kdeconnect.mousepad")
 
 struct FakeKey;
 
+#if HAVE_WAYLAND
+namespace KWayland
+{
+namespace Client
+{
+class FakeInput;
+}
+}
+#endif
+
 class MousepadPlugin
     : public KdeConnectPlugin
 {
@@ -42,10 +53,17 @@ public:
 
 private:
     bool handlePackageX11(const NetworkPackage& np);
+#if HAVE_WAYLAND
+    void setupWaylandIntegration();
+    bool handPackageWayland(const NetworkPackage& np);
+#endif
 
     FakeKey* m_fakekey;
     const bool m_x11;
-
+#if HAVE_WAYLAND
+    KWayland::Client::FakeInput *m_waylandInput;
+    bool m_waylandAuthenticationRequested;
+#endif
 };
 
 #endif

-- 
kdeconnect packaging



More information about the pkg-kde-commits mailing list