@@ -32,7 +32,7 @@ int test_bit(const char* bitmask, int bit) {
3232}
3333
3434
35- // useful for comparing input events as seen in the extension module
35+ // Useful for comparing input events as seen in the extension module
3636// and as seen in python
3737static void
3838print_event (struct input_event * ev ) {
@@ -137,12 +137,12 @@ ioctl_capabilities(PyObject *self, PyObject *args)
137137 int ret = PyArg_ParseTuple (args , "i" , & fd );
138138 if (!ret ) return NULL ;
139139
140- // @todo: figure out why fd gets zeroed on the ioctls after the
140+ // @todo: figure out why fd gets zeroed on an ioctl after the
141141 // refactoring and get rid of this workaround
142142 const int _fd = fd ;
143143
144144 // Capabilities is a mapping of supported event types to lists of handled
145- // evenes e.g: {1: [272, 273, 274, 275], 2: [0, 1, 6, 8]}
145+ // events e.g: {1: [272, 273, 274, 275], 2: [0, 1, 6, 8]}
146146 PyObject * capabilities = PyDict_New ();
147147 PyObject * eventcodes = NULL ;
148148 PyObject * capability = NULL ;
@@ -157,30 +157,35 @@ ioctl_capabilities(PyObject *self, PyObject *args)
157157 // Build a dictionary of the device's capabilities
158158 for (ev_type = 0 ; ev_type < EV_MAX ; ev_type ++ ) {
159159 if (test_bit (ev_bits , ev_type )) {
160+
160161 capability = PyLong_FromLong (ev_type );
161162 eventcodes = PyList_New (0 );
162163
163164 memset (& code_bits , 0 , sizeof (code_bits ));
164165 ioctl (_fd , EVIOCGBIT (ev_type , KEY_MAX ), code_bits );
166+
165167 for (ev_code = 0 ; ev_code < KEY_MAX ; ev_code ++ ) {
166168 if (test_bit (code_bits , ev_code )) {
169+ // Get abs{min,max,fuzz,flat} values for ABS_* event codes
167170 if (ev_type == EV_ABS ) {
168171 memset (& abs_bits , 0 , sizeof (abs_bits ));
169172 ioctl (_fd , EVIOCGABS (ev_code ), abs_bits );
170173
171- absdata = Py_BuildValue ("(iiiii)" , abs_bits [0 ], abs_bits [1 ],
172- abs_bits [2 ], abs_bits [3 ], abs_bits [4 ],
173- abs_bits [5 ]);
174+ absdata = Py_BuildValue ("(iiiii)" , abs_bits [0 ], abs_bits [1 ], abs_bits [2 ],
175+ abs_bits [3 ], abs_bits [4 ], abs_bits [5 ]);
174176
175177 absitem = Py_BuildValue ("(OO)" , PyLong_FromLong (ev_code ), absdata );
178+
179+ // absitem -> tuple(ABS_X, (0, 255, 0, 0))
176180 PyList_Append (eventcodes , absitem );
177- } else {
181+ }
182+ else {
178183 PyList_Append (eventcodes , PyLong_FromLong (ev_code ));
179184 }
180-
181185 }
182186 }
183-
187+ // capabilities[EV_KEY] = [KEY_A, KEY_B, KEY_C, ...]
188+ // capabilities[EV_ABS] = [(ABS_X, (0, 255, 0, 0)), ...]
184189 PyDict_SetItem (capabilities , capability , eventcodes );
185190 }
186191 }
0 commit comments