Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 9cba780f authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Added right and middle click, even though it's not implemented in Android yet

CCMAIL: ahmedibrahimkhali@gmail.com
parent 178fcc12
......@@ -26,9 +26,7 @@
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
// Source: http://bharathisubramanian.wordpress.com/2010/04/01/x11-fake-mouse-events-generation-using-xtest/
MousepadPlugin::MousepadPlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args), m_display(0)
......@@ -51,29 +49,37 @@ bool MousepadPlugin::receivePackage(const NetworkPackage& np)
bool isSingleClick = np.get<bool>("singleclick", false);
bool isDoubleClick = np.get<bool>("doubleclick", false);
bool isMiddleClick = np.get<bool>("middleclick", false);
bool isRightClick = np.get<bool>("rightclick", false);
bool isScroll = np.get<bool>("scroll", false);
if (isSingleClick || isDoubleClick || isScroll) {
if (isSingleClick || isDoubleClick || isMiddleClick || isRightClick || 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);
XTestFakeButtonEvent(m_display, LeftMouseButton, true, CurrentTime);
XTestFakeButtonEvent(m_display, LeftMouseButton, 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);
XTestFakeButtonEvent(m_display, LeftMouseButton, true, CurrentTime);
XTestFakeButtonEvent(m_display, LeftMouseButton, false, CurrentTime);
XTestFakeButtonEvent(m_display, LeftMouseButton, true, CurrentTime);
XTestFakeButtonEvent(m_display, LeftMouseButton, false, CurrentTime);
} else if (isMiddleClick) {
XTestFakeButtonEvent(m_display, MiddleMouseButton, true, CurrentTime);
XTestFakeButtonEvent(m_display, MiddleMouseButton, false, CurrentTime);
} else if (isRightClick) {
XTestFakeButtonEvent(m_display, RightMouseButton, true, CurrentTime);
XTestFakeButtonEvent(m_display, RightMouseButton, 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);
XTestFakeButtonEvent(m_display, MouseWheelDown, true, CurrentTime);
XTestFakeButtonEvent(m_display, MouseWheelDown, false, CurrentTime);
} else {
XTestFakeButtonEvent(m_display, MOUSE_WHEEL_UP_BUTTON, true, CurrentTime);
XTestFakeButtonEvent(m_display, MOUSE_WHEEL_UP_BUTTON, false, CurrentTime);
XTestFakeButtonEvent(m_display, MouseWheelUp, true, CurrentTime);
XTestFakeButtonEvent(m_display, MouseWheelUp, false, CurrentTime);
}
}
XFlush(m_display);
......
......@@ -33,6 +33,14 @@ class MousepadPlugin
{
Q_OBJECT
enum MouseButtons {
LeftMouseButton = 1,
MiddleMouseButton = 2,
RightMouseButton = 3,
MouseWheelUp = 4,
MouseWheelDown = 5
};
public:
explicit MousepadPlugin(QObject *parent, const QVariantList &args);
virtual ~MousepadPlugin();
......
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