[PATCHv3] evdev: add phys property (EVIOCGPHYS) as stable identifier
Peter Korsgaard
peter.korsgaard at barco.com
Wed May 5 00:28:09 PDT 2010
xinput ids are not guaranteed to be stable between reboots (or hotplugs),
so add a "Evdev physical" property containing the output of the
EVIOCGPHYS ioctl as a stable identifier. This is needed to be able to
apply device-specific parameters at runtime (E.G. touchscreen
transformation in multi-head setups).
EVIOCGPHYS is used rather than E.G. the device node or sysfs path,
as it is (supposed to be) unique, simple to access and the remaining
information can be retrieved through /proc/bus/input/devices, which
doesn't require any special privileges.
Signed-off-by: Peter Korsgaard <peter.korsgaard at barco.com>
---
Changes since V2:
- Mark property as not-deletable
Changes since V1:
Incorporated feedback from Peter:
- Renamed property to "Evdev Physical Path"
- Document in man page
include/evdev-properties.h | 3 +++
man/evdev.man | 3 +++
src/evdev.c | 18 ++++++++++++++++--
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/include/evdev-properties.h b/include/evdev-properties.h
index 7df2876..6c30a59 100644
--- a/include/evdev-properties.h
+++ b/include/evdev-properties.h
@@ -66,4 +66,7 @@
/* BOOL */
#define EVDEV_PROP_SWAP_AXES "Evdev Axes Swap"
+/* Physical location of input device as defined by the kernel */
+#define EVDEV_PROP_PHYSICAL "Evdev Physical Path"
+
#endif
diff --git a/man/evdev.man b/man/evdev.man
index 49ab12c..4313204 100644
--- a/man/evdev.man
+++ b/man/evdev.man
@@ -226,6 +226,9 @@ value.
.TP 7
.BI "Evdev Wheel Emulation Timeout"
1 16-bit positive value.
+.TP 7
+.BI "Evdev Physical Path"
+1 string. Output of EVIOCGPHYS ioctl for device (readonly).
.SH AUTHORS
Kristian Høgsberg.
diff --git a/src/evdev.c b/src/evdev.c
index 6d16611..f222567 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -119,6 +119,7 @@ static Atom prop_calibration = 0;
static Atom prop_swap = 0;
static Atom prop_axis_label = 0;
static Atom prop_btn_label = 0;
+static Atom prop_phys = 0;
#endif
/* All devices the evdev driver has allocated and knows about.
@@ -2463,6 +2464,19 @@ EvdevInitProperty(DeviceIntPtr dev)
EvdevPtr pEvdev = pInfo->private;
int rc;
BOOL invert[2];
+ char phys[256];
+
+ if (ioctl(pInfo->fd, EVIOCGPHYS(sizeof(phys) - 1), phys) >= 0)
+ {
+ prop_phys = MakeAtom(EVDEV_PROP_PHYSICAL,
+ strlen(EVDEV_PROP_PHYSICAL), TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_phys, XA_STRING, 8,
+ PropModeReplace, strlen(phys), phys, FALSE);
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_phys, FALSE);
+ }
if (pEvdev->flags & (EVDEV_RELATIVE_EVENTS | EVDEV_ABSOLUTE_EVENTS))
{
@@ -2571,8 +2585,8 @@ EvdevSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
if (!checkonly)
pEvdev->swap_axes = *((BOOL*)val->data);
- } else if (atom == prop_axis_label || atom == prop_btn_label)
- return BadAccess; /* Axis/Button labels can't be changed */
+ } else if (atom == prop_axis_label || atom == prop_btn_label || atom == prop_phys)
+ return BadAccess; /* Axis/Button labels + phys can't be changed */
return Success;
}
--
1.7.0
More information about the xorg-devel
mailing list