Add support for receiving keyboard entries.
This patch gets the keyboard entries from the Android client and passes along the keycode. REVIEW: 119254
This commit is contained in:
parent
e809fa441c
commit
05fdbe0e5b
4 changed files with 98 additions and 2 deletions
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ private:
|
|||
QString mId;
|
||||
QString mType;
|
||||
QVariantMap mBody;
|
||||
|
||||
|
||||
QSharedPointer<QIODevice> mPayload;
|
||||
int mPayloadSize;
|
||||
QVariantMap mPayloadTransferInfo;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue