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:
*/
class FGInputDevice : public SGReferenced {
public:
- FGInputDevice() : debugEvents(false) {}
+ FGInputDevice() : debugEvents(false), grab(false) {}
FGInputDevice( string aName ) : name(aName) {}
virtual ~FGInputDevice();
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;
// 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;
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;
}