Skip to content

Commit 1073296

Browse files
committed
enable setting absolute axis options for uinput devices
1 parent c109e6c commit 1073296

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

‎evdev/uinput.c‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ uinput_open(PyObject *self, PyObject *args)
4545

4646
static PyObject *
4747
uinput_create(PyObject *self, PyObject *args) {
48-
int fd;
48+
int fd, len, i, abscode;
4949
__u16 vendor, product, version, bustype;
5050

51+
PyObject *absdata = NULL, *item = NULL;
52+
5153
struct uinput_user_dev uidev;
5254
const char* name;
5355

54-
int ret = PyArg_ParseTuple(args, "ishhhh", &fd, &name, &vendor,
55-
&product, &version, &bustype);
56+
int ret = PyArg_ParseTuple(args, "ishhhhO", &fd, &name, &vendor,
57+
&product, &version, &bustype, &absdata);
5658
if (!ret) return NULL;
5759

5860
memset(&uidev, 0, sizeof(uidev));
@@ -62,6 +64,18 @@ uinput_create(PyObject *self, PyObject *args) {
6264
uidev.id.version = version;
6365
uidev.id.bustype = bustype;
6466

67+
len = PyList_Size(absdata);
68+
for (i=0; i<len; i++) {
69+
// item -> (ABS_X, 0, 255, 0, 0)
70+
item = PyList_GetItem(absdata, i);
71+
abscode = (int)PyLong_AsLong(PyList_GetItem(item, 0));
72+
73+
uidev.absmin[abscode] = PyLong_AsLong(PyList_GetItem(item, 1));
74+
uidev.absmax[abscode] = PyLong_AsLong(PyList_GetItem(item, 2));
75+
uidev.absfuzz[abscode] = PyLong_AsLong(PyList_GetItem(item, 3));
76+
uidev.absflat[abscode] = PyLong_AsLong(PyList_GetItem(item, 4));
77+
}
78+
6579
if (write(fd, &uidev, sizeof(uidev)) != sizeof(uidev))
6680
goto on_err;
6781

‎evdev/uinput.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ def __init__(self,
5656
self.bustype = bustype #: device bustype - eg. ``BUS_USB``
5757
self.devnode = devnode #: uinput device node - eg. ``/dev/uinput/``
5858

59-
if not events: events = {ecodes.EV_KEY: ecodes.keys.keys()}
59+
if not events:
60+
events = {ecodes.EV_KEY: ecodes.keys.keys()}
61+
62+
# the min, max, fuzz and flat values for the absolute axis for
63+
# a given code
64+
absdata = []
6065

6166
self._verify()
6267

@@ -66,11 +71,18 @@ def __init__(self,
6671
# set device capabilities
6772
for etype, codes in events.items():
6873
for code in codes:
74+
# handle max,min,fuzz,flat
75+
if isinstance(code, (tuple, list, device.AbsInfo)):
76+
# flatten (ABS_Y, (0,255,0,0)) to (ABS_Y,0,255,0,0)
77+
f = [code[0]] ; f += code[1]
78+
absdata.append(f)
79+
code = code[0]
80+
6981
#:todo: a lot of unnecessary packing/unpacking
7082
_uinput.enable(self.fd, etype, code)
7183

7284
# create uinput device
73-
_uinput.create(self.fd, name, vendor, product, version, bustype)
85+
_uinput.create(self.fd, name, vendor, product, version, bustype, absdata)
7486

7587
#: an :class:`InputDevice <evdev.device.InputDevice>` instance
7688
# to the fake input device

0 commit comments

Comments
 (0)