add option <grab/> 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).
This commit is contained in:
parent
cd89ce7d0a
commit
b772e5872a
3 changed files with 19 additions and 2 deletions
|
@ -276,6 +276,7 @@ void FGEventInput::AddDevice( FGInputDevice * inputDevice )
|
||||||
inputDevice->AddHandledEvent( FGInputEvent::NewObject( inputDevice, *it ) );
|
inputDevice->AddHandledEvent( FGInputEvent::NewObject( inputDevice, *it ) );
|
||||||
|
|
||||||
inputDevice->SetDebugEvents( deviceNode->getBoolValue("debug-events", inputDevice->GetDebugEvents() ));
|
inputDevice->SetDebugEvents( deviceNode->getBoolValue("debug-events", inputDevice->GetDebugEvents() ));
|
||||||
|
inputDevice->SetGrab( deviceNode->getBoolValue("grab", inputDevice->GetGrab() ));
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// add nodes for the last event:
|
// add nodes for the last event:
|
||||||
|
|
|
@ -164,7 +164,7 @@ typedef class SGSharedPtr<FGInputEvent> FGInputEvent_ptr;
|
||||||
*/
|
*/
|
||||||
class FGInputDevice : public SGReferenced {
|
class FGInputDevice : public SGReferenced {
|
||||||
public:
|
public:
|
||||||
FGInputDevice() : debugEvents(false) {}
|
FGInputDevice() : debugEvents(false), grab(false) {}
|
||||||
FGInputDevice( string aName ) : name(aName) {}
|
FGInputDevice( string aName ) : name(aName) {}
|
||||||
|
|
||||||
virtual ~FGInputDevice();
|
virtual ~FGInputDevice();
|
||||||
|
@ -196,6 +196,9 @@ public:
|
||||||
bool GetDebugEvents () const { return debugEvents; }
|
bool GetDebugEvents () const { return debugEvents; }
|
||||||
void SetDebugEvents( bool value ) { debugEvents = value; }
|
void SetDebugEvents( bool value ) { debugEvents = value; }
|
||||||
|
|
||||||
|
bool GetGrab() const { return grab; }
|
||||||
|
void SetGrab( bool value ) { grab = value; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// A map of events, this device handles
|
// A map of events, this device handles
|
||||||
map<string,FGInputEvent_ptr> handledEvents;
|
map<string,FGInputEvent_ptr> handledEvents;
|
||||||
|
@ -206,6 +209,10 @@ private:
|
||||||
// print out events comming in from the device
|
// print out events comming in from the device
|
||||||
// if true
|
// if true
|
||||||
bool debugEvents;
|
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;
|
typedef SGSharedPtr<FGInputDevice> FGInputDevice_ptr;
|
||||||
|
|
|
@ -251,11 +251,20 @@ void FGLinuxInputDevice::Open()
|
||||||
if( (fd = ::open( devname.c_str(), O_RDWR )) == -1 ) {
|
if( (fd = ::open( devname.c_str(), O_RDWR )) == -1 ) {
|
||||||
throw exception();
|
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()
|
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;
|
fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue