Skip to content

Commit 34fe42c

Browse files
committed
Split "create" and "setup" parts for uinput devices creation
In order to be able to enable EV_FF in uinput device, ff_max_effects fields needs to be set to a non-zero value. However the ordering of execution in uinput.py does not allow for that because indvidual events are enabled before _uinput.create() is invoked. In order to accomodate EV_FF, split _uinput.create() into two functions: - _uinput.setup(), which does the majority of device configuration. - _uinput.create(), which only creates the device without changing any of its configuration On top of that, change the code in uinput.py to make the call to setup() before individual events are enabled to enable adding ff_max_effects configuration in follow-up commits.
1 parent 0303d3e commit 34fe42c

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

evdev/uinput.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ uinput_set_phys(PyObject *self, PyObject *args)
6969

7070

7171
static PyObject *
72-
uinput_create(PyObject *self, PyObject *args) {
72+
uinput_setup(PyObject *self, PyObject *args) {
7373
int fd, len, i, abscode;
7474
uint16_t vendor, product, version, bustype;
7575

@@ -113,6 +113,22 @@ uinput_create(PyObject *self, PyObject *args) {
113113
/* goto on_err; */
114114
/* } */
115115

116+
Py_RETURN_NONE;
117+
118+
on_err:
119+
_uinput_close(fd);
120+
PyErr_SetFromErrno(PyExc_IOError);
121+
return NULL;
122+
}
123+
124+
static PyObject *
125+
uinput_create(PyObject *self, PyObject *args)
126+
{
127+
int fd;
128+
129+
int ret = PyArg_ParseTuple(args, "i", &fd);
130+
if (!ret) return NULL;
131+
116132
if (ioctl(fd, UI_DEV_CREATE) < 0)
117133
goto on_err;
118134

@@ -214,6 +230,9 @@ static PyMethodDef MethodTable[] = {
214230
{ "open", uinput_open, METH_VARARGS,
215231
"Open uinput device node."},
216232

233+
{ "setup", uinput_setup, METH_VARARGS,
234+
"Set an uinput device up."},
235+
217236
{ "create", uinput_create, METH_VARARGS,
218237
"Create an uinput device."},
219238

evdev/uinput.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ def __init__(self,
131131
# Set phys name
132132
_uinput.set_phys(self.fd, phys)
133133

134+
_uinput.setup(self.fd, name, vendor, product, version, bustype, absinfo)
135+
134136
# Set device capabilities.
135137
for etype, codes in events.items():
136138
for code in codes:
@@ -149,7 +151,7 @@ def __init__(self,
149151
_uinput.enable(self.fd, etype, code)
150152

151153
# Create the uinput device.
152-
_uinput.create(self.fd, name, vendor, product, version, bustype, absinfo)
154+
_uinput.create(self.fd)
153155

154156
#: An :class:`InputDevice <evdev.device.InputDevice>` instance
155157
#: for the fake input device. ``None`` if the device cannot be

0 commit comments

Comments
 (0)