diff options
| author | Fabian Schillinger | 2010-11-01 17:35:27 +0100 |
|---|---|---|
| committer | Fabian Schillinger | 2010-11-01 17:35:27 +0100 |
| commit | ea3fb17345e5f82db9f2e98a8062e95797700ace (patch) | |
| tree | 1da0d1a8ec9455364386af78762d0f6fed187824 /src/input/x11FakeMouseHandler.cpp | |
| parent | Process start/stop/view functionality (diff) | |
| parent | [PVSGUI] No X required for --help and --version (diff) | |
| download | pvs-ea3fb17345e5f82db9f2e98a8062e95797700ace.tar.gz pvs-ea3fb17345e5f82db9f2e98a8062e95797700ace.tar.xz pvs-ea3fb17345e5f82db9f2e98a8062e95797700ace.zip | |
Merge branch 'master' of openslx.org:pvs
Conflicts:
CMakeLists.txt
src/core/pvsConnectionManager.cpp
src/pvs.cpp
src/pvs.h
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); +} |
