[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498
Maximiliano Curia
maxy at moszumanska.debian.org
Fri Oct 14 14:27:52 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=05fdbe0
The following commit has been merged in the master branch:
commit 05fdbe0e5b041dc0a1f174d2a8503ece54ebd549
Author: Saikrishna Arcot <saiarcot895 at gmail.com>
Date: Fri Aug 1 12:29:34 2014 +0200
Add support for receiving keyboard entries.
This patch gets the keyboard entries from the Android client and passes
along the keycode.
REVIEW: 119254
---
core/networkpackage.cpp | 10 +++++
core/networkpackage.h | 2 +-
plugins/mousepad/mousepadplugin.cpp | 74 ++++++++++++++++++++++++++++++++++++-
plugins/mousepad/mousepadplugin.h | 14 +++++++
4 files changed, 98 insertions(+), 2 deletions(-)
diff --git a/core/networkpackage.cpp b/core/networkpackage.cpp
index bd3cccd..749a1a4 100644
--- a/core/networkpackage.cpp
+++ b/core/networkpackage.cpp
@@ -120,6 +120,16 @@ bool NetworkPackage::unserialize(const QByteArray& a, NetworkPackage* np)
}
np->mPayloadTransferInfo = variant["payloadTransferInfo"].toMap(); //Will return an empty qvariantmap if was not present, which is ok
+ //uuids contain charcaters that are not exportable in dbus paths
+ np->mId = np->mId.mid(1, np->mId.length() - 2).replace("-", "_");
+
+ if (np->mBody.contains("deviceId"))
+ {
+ QString deviceId = np->get<QString>("deviceId");
+ deviceId = deviceId.mid(1, deviceId.length() - 2).replace("-", "_");
+ np->set("deviceId", deviceId);
+ }
+
return true;
}
diff --git a/core/networkpackage.h b/core/networkpackage.h
index ed26676..0ea80e9 100644
--- a/core/networkpackage.h
+++ b/core/networkpackage.h
@@ -95,7 +95,7 @@ private:
QString mId;
QString mType;
QVariantMap mBody;
-
+
QSharedPointer<QIODevice> mPayload;
int mPayloadSize;
QVariantMap mPayloadTransferInfo;
diff --git a/plugins/mousepad/mousepadplugin.cpp b/plugins/mousepad/mousepadplugin.cpp
index 64aae5c..1431ea0 100644
--- a/plugins/mousepad/mousepadplugin.cpp
+++ b/plugins/mousepad/mousepadplugin.cpp
@@ -22,6 +22,7 @@
#include <core/networkpackage.h>
#include <X11/extensions/XTest.h>
+#include <X11/keysym.h>
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< MousepadPlugin >(); )
K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_mousepad", "kdeconnect-plugins") )
@@ -42,6 +43,33 @@ MousepadPlugin::~MousepadPlugin()
}
}
+XKeyEvent MousepadPlugin::createKeyEvent(Display *display, Window &win, Window &winRoot, bool press, KeyCode keycode, int modifiers)
+{
+ // http://www.doctort.org/adam/nerd-notes/x11-fake-keypress-event.html
+ XKeyEvent event;
+
+ event.display = display;
+ event.window = win;
+ event.root = winRoot;
+ event.subwindow = None;
+ event.time = CurrentTime;
+ event.x = 1;
+ event.y = 1;
+ event.x_root = 1;
+ event.y_root = 1;
+ event.same_screen = true;
+ event.keycode = keycode;
+ event.state = modifiers;
+
+ if (press) {
+ event.type = KeyPress;
+ } else {
+ event.type = KeyRelease;
+ }
+
+ return event;
+}
+
bool MousepadPlugin::receivePackage(const NetworkPackage& np)
{
float dx = np.get<float>("dx", 0);
@@ -52,8 +80,10 @@ bool MousepadPlugin::receivePackage(const NetworkPackage& np)
bool isMiddleClick = np.get<bool>("middleclick", false);
bool isRightClick = np.get<bool>("rightclick", false);
bool isScroll = np.get<bool>("scroll", false);
+ QString key = np.get<QString>("key", "");
+ int modifiers = np.get<int>("modifiers", 0);
- if (isSingleClick || isDoubleClick || isMiddleClick || isRightClick || isScroll) {
+ if (isSingleClick || isDoubleClick || isMiddleClick || isRightClick || isScroll || !key.isEmpty() || modifiers) {
if(!m_display) {
m_display = XOpenDisplay(NULL);
}
@@ -81,6 +111,48 @@ bool MousepadPlugin::receivePackage(const NetworkPackage& np)
XTestFakeButtonEvent(m_display, MouseWheelUp, true, CurrentTime);
XTestFakeButtonEvent(m_display, MouseWheelUp, false, CurrentTime);
}
+ } else if (!key.isEmpty() || modifiers) {
+ Window winRoot = XDefaultRootWindow(m_display);
+
+ Window winFocus;
+ int revert;
+ XGetInputFocus(m_display, &winFocus, &revert);
+
+ KeyCode keycode = 0;
+ int xModifier = 0;
+ if (!key.isEmpty()) {
+ if (key == QLatin1String(".")) {
+ keycode = XKeysymToKeycode(m_display, XK_period);
+ } else if (key == QLatin1String(",")) {
+ keycode = XKeysymToKeycode(m_display, XK_comma);
+ } else {
+ QByteArray keyByteArray = key.toLocal8Bit();
+ KeySym keysym = XStringToKeysym(keyByteArray.constData());
+ keycode = XKeysymToKeycode(m_display, keysym);
+ }
+ } else {
+ // It's a special key
+ if ((modifiers & FunctionalKeys) == Backspace) {
+ keycode = XKeysymToKeycode(m_display, XK_BackSpace);
+ } else if ((modifiers & FunctionalKeys) == Enter) {
+ keycode = XKeysymToKeycode(m_display, XK_Linefeed);
+ } else if ((modifiers & FunctionalKeys) == Tab) {
+ keycode = XKeysymToKeycode(m_display, XK_Tab);
+ }
+ }
+
+ if (modifiers & Shift) {
+ xModifier |= ShiftMask;
+ }
+ if (modifiers & Control) {
+ xModifier |= ControlMask;
+ }
+
+ XKeyEvent event = createKeyEvent(m_display, winFocus, winRoot, true, keycode, xModifier);
+ XSendEvent(event.display, event.window, true, KeyPressMask, (XEvent*)&event);
+
+ event = createKeyEvent(m_display, winFocus, winRoot, false, keycode, xModifier);
+ XSendEvent(event.display, event.window, true, KeyPressMask, (XEvent*)&event);
}
XFlush(m_display);
}
diff --git a/plugins/mousepad/mousepadplugin.h b/plugins/mousepad/mousepadplugin.h
index 64f5d88..3525155 100644
--- a/plugins/mousepad/mousepadplugin.h
+++ b/plugins/mousepad/mousepadplugin.h
@@ -25,6 +25,7 @@
#include <QApplication>
#include <core/kdeconnectplugin.h>
+#include <X11/Xlib.h>
#define PACKAGE_TYPE_MOUSEPAD QLatin1String("kdeconnect.mousepad")
@@ -41,6 +42,17 @@ class MousepadPlugin
MouseWheelDown = 5
};
+ enum SpecialKeys {
+ Backspace = 1,
+ Enter = 1 << 1,
+ Tab = 1 << 1 | 1,
+ // Placeholder for other keys
+ FunctionalKeys = 1 << 2 | 1 << 1 | 1,
+
+ Shift = 1 << 3,
+ Control = 1 << 4
+ };
+
public:
explicit MousepadPlugin(QObject *parent, const QVariantList &args);
virtual ~MousepadPlugin();
@@ -50,6 +62,8 @@ public Q_SLOTS:
virtual void connected() { }
private:
+ XKeyEvent createKeyEvent(Display *display, Window &win, Window &winRoot, bool press, KeyCode keycode, int modifiers);
+
Display *m_display;
};
--
kdeconnect packaging
More information about the pkg-kde-commits
mailing list