diff options
Diffstat (limited to 'src/input/x11FakeMouseHandler.cpp')
| -rw-r--r-- | src/input/x11FakeMouseHandler.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/input/x11FakeMouseHandler.cpp b/src/input/x11FakeMouseHandler.cpp new file mode 100644 index 0000000..58415d5 --- /dev/null +++ b/src/input/x11FakeMouseHandler.cpp @@ -0,0 +1,59 @@ +/* + # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg + # + # This program is free software distributed under the GPL version 2. + # See http://openslx.org/COPYING + # + # If you have any feedback please consult http://openslx.org/feedback and + # send your suggestions, praise, or complaints to feedback@openslx.org + # + # General information about OpenSLX can be found at http://openslx.org/ + # -------------------------------------------------------------------------- + # x11FakeMouseHandler.h: + # - Handle mouse events on X11 - implementation + # -------------------------------------------------------------------------- + */ + +#include "x11FakeMouseHandler.h" // need to include before X headers +#include <src/util/consoleLogger.h> +#include <X11/extensions/XTest.h> +#include "x11InputUtils.h" + +void X11FakeMouseButtonHandler::handle(InputEvent const& evt, InputEventContext const*) +{ + quint16 pressedButton = evt.pressedButton(); + + Display* dpy = X11InputUtils::display(); + + XTestGrabControl(dpy, 1); + for(int i = 0; i < 16; i++) { + if((1<<i) == pressedButton) + { + ConsoleLog writeLine(QString("Got mouse button event: button %1 %2").arg(i + 1).arg(evt.isPress() ? "pressed" : "released")); + if(!XTestFakeButtonEvent(dpy, i + 1, evt.isPress(), CurrentTime)) + { + ConsoleLog writeLine("[ERROR] XTestFakeButtonEvent failed"); + } + } + } + XTestGrabControl(dpy, 0); + + // Since there may not be a mainloop running, we need to manually flush the event queue + XFlush(dpy); +} + +void X11FakeMouseMovementHandler::handle(InputEvent const& evt, InputEventContext const*) +{ + ConsoleLog writeLine(QString("Received mouse motion event (%1,%2)").arg(evt.xCoord()).arg(evt.yCoord())); + Display* dpy = X11InputUtils::display(); + int screen = 0 /* DefaultScreen(dpy) */; + XTestGrabControl(dpy, 1); + if(!XTestFakeMotionEvent(dpy, screen, evt.xCoord(), evt.yCoord(), CurrentTime)) + { + ConsoleLog writeLine("[ERROR] XTestFakeMotionEvent failed"); + } + XTestGrabControl(dpy, 0); + + // Since there may not be a mainloop running, we need to manually flush the event queue + XFlush(dpy); +} |
