diff --git a/plugins/mousepad/mousepadplugin.cpp b/plugins/mousepad/mousepadplugin.cpp index 0191f66c7..08e06a447 100644 --- a/plugins/mousepad/mousepadplugin.cpp +++ b/plugins/mousepad/mousepadplugin.cpp @@ -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("singleclick", false); bool isDoubleClick = np.get("doubleclick", false); + bool isMiddleClick = np.get("middleclick", false); + bool isRightClick = np.get("rightclick", false); bool isScroll = np.get("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); diff --git a/plugins/mousepad/mousepadplugin.h b/plugins/mousepad/mousepadplugin.h index 6a0c047d6..64f5d8800 100644 --- a/plugins/mousepad/mousepadplugin.h +++ b/plugins/mousepad/mousepadplugin.h @@ -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();