]> git.mxchange.org Git - flightgear.git/commitdiff
add option <grab/> to the device configuration. If this is set to 'true', the events...
authortorsten <torsten>
Sat, 22 Aug 2009 08:32:36 +0000 (08:32 +0000)
committerTim Moore <timoore@redhat.com>
Sun, 23 Aug 2009 19:43:10 +0000 (21:43 +0200)
src/Input/FGEventInput.cxx
src/Input/FGEventInput.hxx
src/Input/FGLinuxEventInput.cxx

index 5731bc463968d8f09a8ca243cc5ebe51b33e1c8c..15272087ff2ab81be68ad53275bcb4e29c5029e7 100644 (file)
@@ -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:
index 09806976bcd8f489ce2060b9026c5b96b649fd72..72ded7847a47e216f7f185e5bc845c43757d60e8 100644 (file)
@@ -164,7 +164,7 @@ typedef class SGSharedPtr<FGInputEvent> 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<string,FGInputEvent_ptr> 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> FGInputDevice_ptr;
index 9d7b804ce243d880f55314d1fbe92769c4b3269f..15c4ff67a74bbef9fc450b9b1ab7b36c6d0ff885 100644 (file)
@@ -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;
 }