lib/driver/rc.cpp,rcinput.cpp: only do EVIOCGRAB when event bit 0x1E is set in event...
[enigma2.git] / lib / driver / rcinput.cpp
1 #include <lib/driver/rcinput.h>
2
3 #include <lib/base/eerror.h>
4
5 #include <sys/ioctl.h>
6 #include <linux/input.h>
7 #include <sys/stat.h>
8
9 #include <lib/base/ebase.h>
10 #include <lib/base/init.h>
11 #include <lib/base/init_num.h>
12 #include <lib/driver/input_fake.h>
13
14 void eRCDeviceInputDev::handleCode(long rccode)
15 {
16         struct input_event *ev = (struct input_event *)rccode;
17         if (ev->type!=EV_KEY)
18                 return;
19
20 //      eDebug("%x %x %x", ev->value, ev->code, ev->type);
21
22         if (ev->type!=EV_KEY)
23                 return;
24
25         int km = iskeyboard ? input->getKeyboardMode() : eRCInput::kmNone;
26
27 //      eDebug("keyboard mode %d", km);
28         
29         if (km == eRCInput::kmAll)
30                 return;
31
32         if (km == eRCInput::kmAscii)
33         {
34 //              eDebug("filtering.. %d", ev->code);
35                 bool filtered = ( ev->code > 0 && ev->code < 61 );
36                 switch (ev->code)
37                 {
38                         case KEY_RESERVED:
39                         case KEY_ESC:
40                         case KEY_TAB:
41                         case KEY_BACKSPACE:
42                         case KEY_ENTER:
43                         case KEY_LEFTCTRL:
44                         case KEY_RIGHTSHIFT:
45                         case KEY_LEFTALT:
46                         case KEY_CAPSLOCK:
47                         case KEY_INSERT:
48                         case KEY_DELETE:
49                         case KEY_MUTE:
50                                 filtered=false;
51                         default:
52                                 break;
53                 }
54                 if (filtered)
55                         return;
56 //              eDebug("passed!");
57         }
58
59         switch (ev->value)
60         {
61         case 0:
62                 /*emit*/ input->keyPressed(eRCKey(this, ev->code, eRCKey::flagBreak));
63                 break;
64         case 1:
65                 /*emit*/ input->keyPressed(eRCKey(this, ev->code, 0));
66                 break;
67         case 2:
68                 /*emit*/ input->keyPressed(eRCKey(this, ev->code, eRCKey::flagRepeat));
69                 break;
70         }
71 }
72
73 eRCDeviceInputDev::eRCDeviceInputDev(eRCInputEventDriver *driver)
74         :eRCDevice(driver->getDeviceName(), driver), iskeyboard(false)
75 {
76         int len=id.length();
77         int idx=0;
78         while(idx <= len-8)
79         {
80                 if (!strncasecmp(&id[idx++], "KEYBOARD", 8))
81                 {
82                         iskeyboard=true;
83                         break;
84                 }
85         }
86         setExclusive(true);
87         eDebug("Input device \"%s\" is %sa keyboard.", id.c_str(), iskeyboard ? "" : "not ");
88 }
89
90 void eRCDeviceInputDev::setExclusive(bool b)
91 {
92         if (!iskeyboard)
93                 driver->setExclusive(b);
94 }
95
96 const char *eRCDeviceInputDev::getDescription() const
97 {
98         return id.c_str();
99 }
100
101 class eInputDeviceInit
102 {
103         ePtrList<eRCInputEventDriver> m_drivers;
104         ePtrList<eRCDeviceInputDev> m_devices;
105 public:
106         eInputDeviceInit()
107         {
108                 int i = 0;
109                 while (1)
110                 {
111                         struct stat s;
112                         char filename[128];
113                         sprintf(filename, "/dev/input/event%d", i);
114                         if (stat(filename, &s))
115                                 break;
116                         eRCInputEventDriver *p;
117                         m_drivers.push_back(p = new eRCInputEventDriver(filename));
118                         m_devices.push_back(new eRCDeviceInputDev(p));
119                         ++i;
120                 }
121                 eDebug("Found %d input devices!", i);
122         }
123         
124         ~eInputDeviceInit()
125         {
126                 while (m_drivers.size())
127                 {
128                         delete m_devices.back();
129                         m_devices.pop_back();
130                         delete m_drivers.back();
131                         m_drivers.pop_back();
132                 }
133         }
134 };
135
136 eAutoInitP0<eInputDeviceInit> init_rcinputdev(eAutoInitNumbers::rc+1, "input device driver");