Commit 178fcc12 authored by Ahmed Ibrahim Khalil's avatar Ahmed Ibrahim Khalil Committed by Albert Vaca Cintora

Implemented scrolling, by sending scroll down or scroll up button events,

according to the difference value.

REVIEW: 119006
parent 4132f0c3
......@@ -21,45 +21,66 @@
#include "mousepadplugin.h"
#include <core/networkpackage.h>
#include <QApplication>
#include <X11/extensions/XTest.h>
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< MousepadPlugin >(); )
K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_mousepad", "kdeconnect-plugins") )
#define LEFT_MOUSE_BUTTON 1 // Source: http://bharathisubramanian.wordpress.com/2010/04/01/x11-fake-mouse-events-generation-using-xtest/
#define MOUSE_WHEEL_UP_BUTTON 4
#define MOUSE_WHEEL_DOWN_BUTTON 5
MousepadPlugin::MousepadPlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args)
: KdeConnectPlugin(parent, args), m_display(0)
{
}
MousepadPlugin::~MousepadPlugin()
{
if (m_display) {
XCloseDisplay(m_display);
m_display = 0;
}
}
bool MousepadPlugin::receivePackage(const NetworkPackage& np)
{
float dx = np.get<float>("dx", 0);
float dy = np.get<float>("dy", 0);
QPoint point = QCursor::pos();
QCursor::setPos(point.x() + (int)dx, point.y() + (int)dy);
bool isSingleClick = np.get<bool>("singleclick", false);
bool isDoubleClick = np.get<bool>("doubleclick", false);
if (isSingleClick || isDoubleClick) {
Display *display = XOpenDisplay(NULL);
if(display) {
if (isSingleClick) {
XTestFakeButtonEvent(display, LEFT_MOUSE_BUTTON, true, CurrentTime);
XTestFakeButtonEvent(display, LEFT_MOUSE_BUTTON, false, CurrentTime);
} else if (isDoubleClick) {
XTestFakeButtonEvent(display, LEFT_MOUSE_BUTTON, true, CurrentTime);
XTestFakeButtonEvent(display, LEFT_MOUSE_BUTTON, false, CurrentTime);
XTestFakeButtonEvent(display, LEFT_MOUSE_BUTTON, true, CurrentTime);
XTestFakeButtonEvent(display, LEFT_MOUSE_BUTTON, false, CurrentTime);
}
XFlush(display);
}
XCloseDisplay(display);
bool isScroll = np.get<bool>("scroll", false);
if (isSingleClick || isDoubleClick || isScroll) {
if(!m_display) {
m_display = XOpenDisplay(NULL);
}
if(m_display) {
if (isSingleClick) {
XTestFakeButtonEvent(m_display, LEFT_MOUSE_BUTTON, true, CurrentTime);
XTestFakeButtonEvent(m_display, LEFT_MOUSE_BUTTON, false, CurrentTime);
} else if (isDoubleClick) {
XTestFakeButtonEvent(m_display, LEFT_MOUSE_BUTTON, true, CurrentTime);
XTestFakeButtonEvent(m_display, LEFT_MOUSE_BUTTON, false, CurrentTime);
XTestFakeButtonEvent(m_display, LEFT_MOUSE_BUTTON, true, CurrentTime);
XTestFakeButtonEvent(m_display, LEFT_MOUSE_BUTTON, false, CurrentTime);
} else if( isScroll ) {
if (dy < 0) {
XTestFakeButtonEvent(m_display, MOUSE_WHEEL_DOWN_BUTTON, true, CurrentTime);
XTestFakeButtonEvent(m_display, MOUSE_WHEEL_DOWN_BUTTON, false, CurrentTime);
} else {
XTestFakeButtonEvent(m_display, MOUSE_WHEEL_UP_BUTTON, true, CurrentTime);
XTestFakeButtonEvent(m_display, MOUSE_WHEEL_UP_BUTTON, false, CurrentTime);
}
}
XFlush(m_display);
}
} else {
QPoint point = QCursor::pos();
QCursor::setPos(point.x() + (int)dx, point.y() + (int)dy);
}
return true;
}
......@@ -22,6 +22,7 @@
#define MOUSEPADPLUGIN_H
#include <QObject>
#include <QApplication>
#include <core/kdeconnectplugin.h>
......@@ -34,10 +35,14 @@ class MousepadPlugin
public:
explicit MousepadPlugin(QObject *parent, const QVariantList &args);
virtual ~MousepadPlugin();
public Q_SLOTS:
virtual bool receivePackage(const NetworkPackage& np);
virtual void connected() { }
private:
Display *m_display;
};
#endif
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