Skip to content

Commit f7b53f7

Browse files
committed
Added IOCTL to retrieve the destination uniq as well as phys if available, added uniq as a property to InputDevice
Needed because some later kernels (at least from 4.15) have started reporting the bluetooth controller MAC for bluetooth devices as the phys, rather than the actual physical address of the device (which is obviously the bit you actually care about in most cases). As with phys, there's no guarantee that uniq is actually set.
1 parent fd0ecf2 commit f7b53f7

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎evdev/device.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class InputDevice(EventIO):
107107
A linux input device from which input events can be read.
108108
'''
109109

110-
__slots__ = ('fn', 'fd', 'info', 'name', 'phys', '_rawcapabilities',
110+
__slots__ = ('fn', 'fd', 'info', 'name', 'phys', 'uniq', '_rawcapabilities',
111111
'version', 'ff_effects_count')
112112

113113
def __init__(self, dev):
@@ -143,6 +143,9 @@ def __init__(self, dev):
143143
#: The physical topology of the device.
144144
self.phys = info_res[5]
145145

146+
#: The unique address of the device
147+
self.uniq = info_res[6]
148+
146149
#: The evdev protocol version.
147150
self.version = _input.ioctl_EVIOCGVERSION(self.fd)
148151

‎evdev/input.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ ioctl_devinfo(PyObject *self, PyObject *args)
216216
struct input_id iid;
217217
char name[MAX_NAME_SIZE];
218218
char phys[MAX_NAME_SIZE] = {0};
219+
char uniq[MAX_NAME_SIZE] = {0};
219220

220221
int ret = PyArg_ParseTuple(args, "i", &fd);
221222
if (!ret) return NULL;
@@ -225,11 +226,13 @@ ioctl_devinfo(PyObject *self, PyObject *args)
225226
if (ioctl(fd, EVIOCGID, &iid) < 0) goto on_err;
226227
if (ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0) goto on_err;
227228

229+
ioctl(fd, EVIOCGUNIQ(sizeof(uniq)), uniq);
230+
228231
// Some devices do not have a physical topology associated with them
229232
ioctl(fd, EVIOCGPHYS(sizeof(phys)), phys);
230233

231-
return Py_BuildValue("hhhhss", iid.bustype, iid.vendor, iid.product, iid.version,
232-
name, phys);
234+
return Py_BuildValue("hhhhsss", iid.bustype, iid.vendor, iid.product, iid.version,
235+
name, phys, uniq);
233236

234237
on_err:
235238
PyErr_SetFromErrno(PyExc_IOError);

0 commit comments

Comments
 (0)