[PATCH evdev 6/8] Init multitouch valuators axes

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


For non-mtdev multitouch devices, it's possible to retrieve the initial
state of the different touches.

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

diff --git a/src/evdev.c b/src/evdev.c
index ec38272..8d7853b 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1406,6 +1406,9 @@ EvdevAddAbsValuatorClass(DeviceIntPtr device)
         int num_touches = num_slots(pEvdev);
         int mode = pEvdev->flags & EVDEV_TOUCHPAD ?
             XIDependentTouch : XIDirectTouch;
+        int *mt_request;
+        int *mt_request_data;
+        int len;
 
         if (!InitTouchClassDeviceStruct(device, num_touches, mode,
                                         num_mt_axes_total)) {
@@ -1414,16 +1417,35 @@ EvdevAddAbsValuatorClass(DeviceIntPtr device)
             goto out;
         }
 
-        for (i = 0; i < num_slots(pEvdev); i++) {
-            for (axis = ABS_MT_TOUCH_MAJOR; axis < ABS_MAX; axis++) {
-                if (pEvdev->axis_map[axis] >= 0) {
+        if (!(mt_request = calloc(num_touches + 1, sizeof(__s32)))) {
+            xf86Msg(X_ERROR, "%s: failed to allocate touch values request.\n",
+                    device->name);
+            goto out;
+        }
+
+        mt_request_data = mt_request + 1;
+
+        for (axis = ABS_MT_TOUCH_MAJOR; axis < ABS_MAX; axis++) {
+            memset(mt_request, 0, num_touches * sizeof(__s32));
+            if (pEvdev->axis_map[axis] >= 0) {
+                if (!pEvdev->mtdev){
                     /* XXX: read initial values from mtdev when it adds support
                      *      for doing so. */
-                    valuator_mask_set(pEvdev->last_mt_vals[i],
-                                      pEvdev->axis_map[axis], 0);
+                    mt_request[0] = axis;
+                    len = ioctl (pInfo->fd, EVIOCGMTSLOTS ((num_touches + 1) *
+                                 sizeof(__s32)), mt_request);
+                    if (len < 0)
+                        xf86IDrvMsg(pInfo, X_ERROR, "ioctl EVIOCGMTSLOTS failed: %s\n",
+                                    strerror(errno));
                 }
+                for (i = 0; i < num_touches; i++)
+                    valuator_mask_set(pEvdev->last_mt_vals[i],
+                                      pEvdev->axis_map[axis],
+                                      mt_request_data[i]);
             }
         }
+
+        free(mt_request);
     }
 #endif
 
-- 
1.8.0.2



More information about the xorg-devel mailing list