Skip to content

Commit 5257608

Browse files
committed
Add UInput support for the resolution parameter in AbsInfo
Creating a UInput device always ignored the resolution parameter since the c implementation was old for current linux kernels.
1 parent 2469689 commit 5257608

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

‎evdev/uinput.c‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,68 @@ uinput_set_phys(PyObject *self, PyObject *args)
7474
}
7575

7676

77+
#if defined(UI_DEV_SETUP) && defined(UI_ABS_SETUP)
78+
// New variant is not supported in old linux kernels and FreeBSD
79+
static PyObject *
80+
uinput_setup(PyObject *self, PyObject *args) {
81+
int fd, len, i;
82+
uint16_t vendor, product, version, bustype;
83+
84+
PyObject *absinfo = NULL, *item = NULL;
85+
86+
struct uinput_abs_setup abs_setup;
87+
88+
const char* name;
89+
int ret = PyArg_ParseTuple(args, "isHHHHO", &fd, &name, &vendor,
90+
&product, &version, &bustype, &absinfo);
91+
if (!ret) return NULL;
92+
93+
// Setup absinfo:
94+
len = PyList_Size(absinfo);
95+
for (i=0; i<len; i++) {
96+
97+
// item -> (ABS_X, 0, 255, 0, 0, 0, 0)
98+
item = PyList_GetItem(absinfo, i);
99+
100+
memset(&abs_setup, 0, sizeof(abs_setup)); // Clear struct
101+
abs_setup.code = PyLong_AsLong(PyList_GetItem(item, 0));
102+
abs_setup.absinfo.value = PyLong_AsLong(PyList_GetItem(item, 1));
103+
abs_setup.absinfo.minimum = PyLong_AsLong(PyList_GetItem(item, 2));
104+
abs_setup.absinfo.maximum = PyLong_AsLong(PyList_GetItem(item, 3));
105+
abs_setup.absinfo.fuzz = PyLong_AsLong(PyList_GetItem(item, 4));
106+
abs_setup.absinfo.flat = PyLong_AsLong(PyList_GetItem(item, 5));
107+
abs_setup.absinfo.resolution = PyLong_AsLong(PyList_GetItem(item, 6));
108+
109+
if(ioctl(fd, UI_ABS_SETUP, &abs_setup) < 0)
110+
goto on_err;
111+
}
112+
113+
114+
// Setup evdev:
115+
struct uinput_setup usetup;
116+
117+
memset(&usetup, 0, sizeof(usetup));
118+
strncpy(usetup.name, name, sizeof(usetup.name) - 1);
119+
usetup.id.vendor = vendor;
120+
usetup.id.product = product;
121+
usetup.id.version = version;
122+
usetup.id.bustype = bustype;
123+
usetup.ff_effects_max = FF_MAX_EFFECTS;
124+
ioctl(fd, UI_DEV_SETUP, &usetup);
125+
126+
if(ioctl(fd, UI_DEV_SETUP, &usetup) < 0)
127+
goto on_err;
128+
129+
130+
Py_RETURN_NONE;
131+
132+
on_err:
133+
_uinput_close(fd);
134+
PyErr_SetFromErrno(PyExc_IOError);
135+
return NULL;
136+
}
137+
#else
138+
// Old variant (fallback):
77139
static PyObject *
78140
uinput_setup(PyObject *self, PyObject *args) {
79141
int fd, len, i, abscode;
@@ -127,6 +189,8 @@ uinput_setup(PyObject *self, PyObject *args) {
127189
PyErr_SetFromErrno(PyExc_IOError);
128190
return NULL;
129191
}
192+
#endif
193+
130194

131195
static PyObject *
132196
uinput_create(PyObject *self, PyObject *args)

0 commit comments

Comments
 (0)