[PATCH evdev 2/4] Export product/vendor ID through a property.
Peter Hutterer
peter.hutterer at who-t.net
Tue May 17 22:00:56 PDT 2011
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
src/evdev.c | 35 +++++++++++++++++++++++++++++++++--
src/evdev.h | 3 +++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/src/evdev.c b/src/evdev.c
index 389ccc8..d93adb4 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -52,6 +52,10 @@
#include <evdev-properties.h>
#include <xserver-properties.h>
+#ifndef XI_PROP_PRODUCT_ID
+#define XI_PROP_PRODUCT_ID "Device Product ID"
+#endif
+
/* removed from server, purge when dropping support for server 1.10 */
#define XI86_SEND_DRAG_EVENTS 0x08
@@ -108,6 +112,7 @@ static void EvdevInitButtonLabels(EvdevPtr pEvdev, int natoms, Atom *atoms);
static void EvdevInitProperty(DeviceIntPtr dev);
static int EvdevSetProperty(DeviceIntPtr dev, Atom atom,
XIPropertyValuePtr val, BOOL checkonly);
+static Atom prop_product_id;
static Atom prop_invert;
static Atom prop_calibration;
static Atom prop_swap;
@@ -1450,6 +1455,7 @@ EvdevCache(InputInfoPtr pInfo)
{
EvdevPtr pEvdev = pInfo->private;
int i, len;
+ unsigned short id[4];
char name[1024] = {0};
unsigned long bitmask[NLONGS(EV_CNT)] = {0};
@@ -1458,6 +1464,16 @@ EvdevCache(InputInfoPtr pInfo)
unsigned long abs_bitmask[NLONGS(ABS_CNT)] = {0};
unsigned long led_bitmask[NLONGS(LED_CNT)] = {0};
+
+ if (ioctl(pInfo->fd, EVIOCGID, id) < 0)
+ {
+ xf86IDrvMsg(pInfo, X_ERROR, "ioctl EVIOCGID failed: %s\n", strerror(errno));
+ goto error;
+ }
+
+ pEvdev->id_vendor = id[ID_VENDOR];
+ pEvdev->id_product = id[ID_PRODUCT];
+
if (ioctl(pInfo->fd, EVIOCGNAME(sizeof(name) - 1), name) < 0) {
xf86IDrvMsg(pInfo, X_ERROR, "ioctl EVIOCGNAME failed: %s\n", strerror(errno));
goto error;
@@ -1567,6 +1583,9 @@ EvdevProbe(InputInfoPtr pInfo)
EvdevPtr pEvdev = pInfo->private;
int rc = 1;
+ xf86IDrvMsg(pInfo, X_PROBED, " Vendor %#hx Product %#hx\n",
+ pEvdev->id_vendor, pEvdev->id_product);
+
/* Trinary state for ignoring axes:
- unset: do the normal thing.
- TRUE: explicitly ignore them.
@@ -2237,6 +2256,17 @@ EvdevInitProperty(DeviceIntPtr dev)
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
int rc;
+ CARD32 product[2];
+
+ prop_product_id = MakeAtom(XI_PROP_PRODUCT_ID, strlen(XI_PROP_PRODUCT_ID), TRUE);
+ product[0] = pEvdev->id_vendor;
+ product[1] = pEvdev->id_product;
+ rc = XIChangeDeviceProperty(dev, prop_product_id, XA_INTEGER, 32,
+ PropModeReplace, 2, product, FALSE);
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_invert, FALSE);
if (pEvdev->flags & (EVDEV_RELATIVE_EVENTS | EVDEV_ABSOLUTE_EVENTS))
{
@@ -2344,8 +2374,9 @@ 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_product_id)
+ return BadAccess; /* Read-only properties */
return Success;
}
diff --git a/src/evdev.h b/src/evdev.h
index c16ccb2..1741e59 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -104,6 +104,9 @@ typedef struct {
} EventQueueRec, *EventQueuePtr;
typedef struct {
+ unsigned short id_vendor;
+ unsigned short id_product;
+
char *device;
int grabDevice; /* grab the event device? */
--
1.7.4.4
More information about the xorg-devel
mailing list