From b772e5872a042badd6022405bc6de0355810082c Mon Sep 17 00:00:00 2001 From: torsten Date: Sat, 22 Aug 2009 08:32:36 +0000 Subject: [PATCH] add option to the device configuration. If this is set to 'true', the events from this devices are exclusively handled by our handler and are not distributed to other driver(s). --- src/Input/FGEventInput.cxx | 1 + src/Input/FGEventInput.hxx | 9 ++++++++- src/Input/FGLinuxEventInput.cxx | 11 ++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Input/FGEventInput.cxx b/src/Input/FGEventInput.cxx index 5731bc463..15272087f 100644 --- a/src/Input/FGEventInput.cxx +++ b/src/Input/FGEventInput.cxx @@ -276,6 +276,7 @@ void FGEventInput::AddDevice( FGInputDevice * inputDevice ) inputDevice->AddHandledEvent( FGInputEvent::NewObject( inputDevice, *it ) ); inputDevice->SetDebugEvents( deviceNode->getBoolValue("debug-events", inputDevice->GetDebugEvents() )); + inputDevice->SetGrab( deviceNode->getBoolValue("grab", inputDevice->GetGrab() )); // TODO: // add nodes for the last event: diff --git a/src/Input/FGEventInput.hxx b/src/Input/FGEventInput.hxx index 09806976b..72ded7847 100644 --- a/src/Input/FGEventInput.hxx +++ b/src/Input/FGEventInput.hxx @@ -164,7 +164,7 @@ typedef class SGSharedPtr FGInputEvent_ptr; */ class FGInputDevice : public SGReferenced { public: - FGInputDevice() : debugEvents(false) {} + FGInputDevice() : debugEvents(false), grab(false) {} FGInputDevice( string aName ) : name(aName) {} virtual ~FGInputDevice(); @@ -196,6 +196,9 @@ public: bool GetDebugEvents () const { return debugEvents; } void SetDebugEvents( bool value ) { debugEvents = value; } + bool GetGrab() const { return grab; } + void SetGrab( bool value ) { grab = value; } + private: // A map of events, this device handles map handledEvents; @@ -206,6 +209,10 @@ private: // print out events comming in from the device // if true bool debugEvents; + + // grab the device exclusively, if O/S supports this + // so events are not sent to other applications + bool grab; }; typedef SGSharedPtr FGInputDevice_ptr; diff --git a/src/Input/FGLinuxEventInput.cxx b/src/Input/FGLinuxEventInput.cxx index 9d7b804ce..15c4ff67a 100644 --- a/src/Input/FGLinuxEventInput.cxx +++ b/src/Input/FGLinuxEventInput.cxx @@ -251,11 +251,20 @@ void FGLinuxInputDevice::Open() if( (fd = ::open( devname.c_str(), O_RDWR )) == -1 ) { throw exception(); } + + if( GetGrab() && ioctl( fd, EVIOCGRAB, 2 ) != 0 ) { + SG_LOG( SG_INPUT, SG_WARN, "Can't grab " << devname << " for exclusive access" ); + } } void FGLinuxInputDevice::Close() { - if( fd != -1 ) ::close(fd); + if( fd != -1 ) { + if( GetGrab() && ioctl( fd, EVIOCGRAB, 0 ) != 0 ) { + SG_LOG( SG_INPUT, SG_WARN, "Can't ungrab " << devname ); + } + ::close(fd); + } fd = -1; }