summaryrefslogtreecommitdiffstats
path: root/src/input/x11FakeMouseHandler.cpp
diff options
context:
space:
mode:
authorSebastien Braun2010-10-04 00:22:14 +0200
committerSebastien Braun2010-10-05 18:15:48 +0200
commit266eb5fb14c07e67aa211a5860e9abf3009136e3 (patch)
tree9eeb8b159edf6e83880c056f1177cebec2ad354c /src/input/x11FakeMouseHandler.cpp
parentDefect #715, apply patch by Sébastien (diff)
downloadpvs-266eb5fb14c07e67aa211a5860e9abf3009136e3.tar.gz
pvs-266eb5fb14c07e67aa211a5860e9abf3009136e3.tar.xz
pvs-266eb5fb14c07e67aa211a5860e9abf3009136e3.zip
Implement first version of basic input event support
Diffstat (limited to 'src/input/x11FakeMouseHandler.cpp')
-rw-r--r--src/input/x11FakeMouseHandler.cpp59
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..432e19f
--- /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 <src/util/consoleLogger.h>
+#include <X11/extensions/XTest.h>
+#include "x11InputUtils.h"
+#include "x11FakeMouseHandler.h"
+
+void X11FakeMouseButtonHandler::handle(InputEvent const& evt)
+{
+ 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)
+{
+ 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);
+}