lib/driver/rc.cpp,rcinput.cpp: only do EVIOCGRAB when event bit 0x1E is set in event...
[vuplus_dvbapp] / lib / driver / rc.cpp
index d943352..c1ff13e 100644 (file)
@@ -79,9 +79,8 @@ eRCShortDriver::eRCShortDriver(const char *filename): eRCDriver(eRCInput::getIns
                sn=0;
        } else
        {
-               sn=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
+               sn=eSocketNotifier::create(eApp, handle, eSocketNotifier::Read);
                CONNECT(sn->activated, eRCShortDriver::keyPressed);
-               eRCInput::getInstance()->setFile(handle);
        }
 }
 
@@ -89,8 +88,6 @@ eRCShortDriver::~eRCShortDriver()
 {
        if (handle>=0)
                close(handle);
-       if (sn)
-               delete sn;
 }
 
 void eRCInputEventDriver::keyPressed(int)
@@ -115,9 +112,8 @@ eRCInputEventDriver::eRCInputEventDriver(const char *filename): eRCDriver(eRCInp
                sn=0;
        } else
        {
-               sn=new eSocketNotifier(eApp, handle, eSocketNotifier::Read);
+               sn=eSocketNotifier::create(eApp, handle, eSocketNotifier::Read);
                CONNECT(sn->activated, eRCInputEventDriver::keyPressed);
-               eRCInput::getInstance()->setFile(handle);
        }
 }
 
@@ -129,12 +125,23 @@ std::string eRCInputEventDriver::getDeviceName()
        return name;
 }
 
+void eRCInputEventDriver::setExclusive(bool b)
+{
+       if (handle >= 0)
+       {
+               long evbits;
+               int grab = b;
+               if (::ioctl(handle, EVIOCGBIT(0, EV_MAX+1), &evbits) < 0)
+                       perror("EVIOCGBIT");
+               else if ((evbits & (1 << 0x1E)) && ::ioctl(handle, EVIOCGRAB, grab) < 0)
+                       perror("EVIOCGRAB");
+       }
+}
+
 eRCInputEventDriver::~eRCInputEventDriver()
 {
        if (handle>=0)
                close(handle);
-       if (sn)
-               delete sn;
 }
 
 eRCConfig::eRCConfig()
@@ -169,7 +176,6 @@ eRCInput::eRCInput()
 {
        ASSERT( !instance);
        instance=this;
-       handle = -1;
        locked = 0;
        keyboardMode = kmNone;
 }
@@ -187,21 +193,18 @@ bool eRCInput::open()
        return false;
 }
 
-int eRCInput::lock()
+void eRCInput::lock()
 {
        locked=1;
-       return handle;
+       for (std::map<std::string,eRCDevice*>::iterator i=devices.begin(); i != devices.end(); ++i)
+               i->second->setExclusive(false);
 }
 
 void eRCInput::unlock()
 {
-       if (locked)
-               locked=0;
-}
-
-void eRCInput::setFile(int newh)
-{
-       handle=newh;
+       locked=0;
+       for (std::map<std::string,eRCDevice*>::iterator i=devices.begin(); i != devices.end(); ++i)
+               i->second->setExclusive(true);
 }
 
 void eRCInput::addDevice(const std::string &id, eRCDevice *dev)
@@ -220,7 +223,7 @@ eRCDevice *eRCInput::getDevice(const std::string &id)
        if (i == devices.end())
        {
                eDebug("failed, possible choices are:");
-               for (std::map<std::string,eRCDevice*>::iterator i=devices.begin(); i != devices.end(); ++i)     
+               for (std::map<std::string,eRCDevice*>::iterator i=devices.begin(); i != devices.end(); ++i)
                        eDebug("%s", i->first.c_str());
                return 0;
        }