[PATCH evdev 5/8] Do not rely on mtdev for devices following mt-protocol B

Benjamin Tissoires benjamin.tissoires at gmail.com
Wed Jan 9 10:21:19 PST 2013


Mtdev is only usefull for protocol A devices (quite a few now).
For all the others, it adds some memory and process which is not required
as it just passes the events to the caller.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
---
 src/evdev.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index 1dccd34..ec38272 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -783,13 +783,19 @@ last_mt_vals_slot(EvdevPtr pEvdev)
     return value < num_slots(pEvdev) ? value : -1;
 }
 
+static int
+EvdevIsMTDevice(EvdevPtr pEvdev)
+{
+    return pEvdev->mtdev || EvdevBitIsSet(pEvdev->abs_bitmask, ABS_MT_SLOT);
+}
+
 static void
 EvdevProcessTouchEvent(InputInfoPtr pInfo, struct input_event *ev)
 {
     EvdevPtr pEvdev = pInfo->private;
     int map;
 
-    if (!pEvdev->mtdev)
+    if (!EvdevIsMTDevice(pEvdev))
         return;
 
     if (ev->code == ABS_MT_SLOT) {
@@ -1395,7 +1401,7 @@ EvdevAddAbsValuatorClass(DeviceIntPtr device)
     }
 
 #ifdef MULTITOUCH
-    if (pEvdev->mtdev && num_mt_axes_total > 0)
+    if (num_mt_axes_total > 0)
     {
         int num_touches = num_slots(pEvdev);
         int mode = pEvdev->flags & EVDEV_TOUCHPAD ?
@@ -2335,7 +2341,8 @@ EvdevSetCalibration(InputInfoPtr pInfo, int num_calibration, int calibration[4])
 #ifdef MULTITOUCH
 /**
  * Open an mtdev device for this device. mtdev is a bit too generous with
- * memory usage, so only do so for devices with multitouch bits set.
+ * memory usage, so only do so for devices with multitouch bits using
+ * protocol A (without ABS_MT_SLOT axis).
  *
  * @return FALSE on error, TRUE if mtdev was initiated or the device doesn't
  * need it
@@ -2380,6 +2387,19 @@ EvdevOpenMTDev(InputInfoPtr pInfo)
         !EvdevBitIsSet(abs_bitmask, ABS_MT_POSITION_Y))
         return TRUE;
 
+    if (EvdevBitIsSet(abs_bitmask, ABS_MT_SLOT)) {
+        /* Use ioctl here too, this may still be called before EvdevCache */
+        len = ioctl(pInfo->fd, EVIOCGABS(ABS_MT_SLOT), &pEvdev->absinfo[ABS_MT_SLOT]);
+        if (len < 0) {
+            xf86IDrvMsg(pInfo, X_ERROR, "ioctl EVIOCGABS(ABS_MT_SLOT) failed: %s\n",
+                        strerror(errno));
+            return FALSE;
+        }
+        pEvdev->cur_slot = pEvdev->absinfo[ABS_MT_SLOT].value;
+        xf86IDrvMsg(pInfo, X_INFO, "Ignoring mtdev for this device\n");
+        return TRUE;
+    }
+
     xf86IDrvMsg(pInfo, X_INFO, "Using mtdev for this device\n");
     pEvdev->mtdev = mtdev_new_open(pInfo->fd);
     if (pEvdev->mtdev)
-- 
1.8.0.2



More information about the xorg-devel mailing list