[PATCH xf86-input-evdev] Add support for masked valuators

Chase Douglas chase.douglas at canonical.com
Tue Oct 5 13:08:20 PDT 2010


From: Chase Douglas <chase.douglas at ubuntu.com>

With the X server now supporting masked valuators for XI2, enable
support in X evdev.

Note that this leaves around a lot of cruft that should be removed, but
the code allows for backwards compatibility with X servers < 1.10.

Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
---
 src/evdev.c |   52 +++++++++++++++++++++++++++++++++++++---------------
 src/evdev.h |    9 +++++++++
 2 files changed, 46 insertions(+), 15 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index f779138..1ad8797 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -153,22 +153,20 @@ static int EvdevSwitchMode(ClientPtr client, DeviceIntPtr device, int mode)
     return Success;
 }
 
-static size_t CountBits(unsigned long *array, size_t nlongs)
+#ifndef HAVE_MASKED_VALUATORS
+static int
+CountBits(uint8_t *mask, int len)
 {
-    unsigned int i;
-    size_t count = 0;
+    int i;
+    int ret = 0;
 
-    for (i = 0; i < nlongs; i++) {
-        unsigned long x = array[i];
+    for (i = 0; i < len; i++)
+        if (BitIsOn(mask, i))
+            ret++;
 
-        while (x > 0)
-        {
-            count += (x & 0x1);
-            x >>= 1;
-        }
-    }
-    return count;
+    return ret;
 }
+#endif
 
 static int
 EvdevGetMajorMinor(InputInfoPtr pInfo)
@@ -399,6 +397,9 @@ EvdevProcessValuators(InputInfoPtr pInfo, int v[MAX_VALUATORS], int *num_v,
                     first = map;
                 if (map > last)
                     last = map;
+#ifdef HAVE_MASKED_VALUATORS
+                ValuatorMaskSetBit(&pEvdev->mask, map);
+#endif
             }
         }
 
@@ -494,6 +495,7 @@ EvdevProcessRelativeMotionEvent(InputInfoPtr pInfo, struct input_event *ev)
 {
     int value;
     EvdevPtr pEvdev = pInfo->private;
+    int map;
 
     /* Get the signed value, earlier kernels had this as unsigned */
     value = ev->value;
@@ -526,6 +528,10 @@ EvdevProcessRelativeMotionEvent(InputInfoPtr pInfo, struct input_event *ev)
 
             pEvdev->rel = 1;
             pEvdev->delta[ev->code] += value;
+#ifdef HAVE_MASKED_VALUATORS
+            map = pEvdev->axis_map[ev->code];
+            ValuatorMaskSetBit(&pEvdev->mask, map);
+#endif
             break;
     }
 }
@@ -538,6 +544,7 @@ EvdevProcessAbsoluteMotionEvent(InputInfoPtr pInfo, struct input_event *ev)
 {
     int value;
     EvdevPtr pEvdev = pInfo->private;
+    int map;
 
     /* Get the signed value, earlier kernels had this as unsigned */
     value = ev->value;
@@ -552,7 +559,11 @@ EvdevProcessAbsoluteMotionEvent(InputInfoPtr pInfo, struct input_event *ev)
     if (EvdevWheelEmuFilterMotion(pInfo, ev))
         return;
 
-    pEvdev->vals[pEvdev->axis_map[ev->code]] = value;
+    map = pEvdev->axis_map[ev->code];
+    pEvdev->vals[map] = value;
+#ifdef HAVE_MASKED_VALUATORS
+    ValuatorMaskSetBit(&pEvdev->mask, map);
+#endif
     if (ev->code == ABS_X)
         pEvdev->abs |= ABS_X_VALUE;
     else if (ev->code == ABS_Y)
@@ -614,7 +625,11 @@ EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
     EvdevPtr pEvdev = pInfo->private;
 
     if (pEvdev->rel) {
+#ifdef HAVE_MASKED_VALUATORS
+        xf86PostMotionEventM(pInfo->dev, FALSE, &pEvdev->mask, v);
+#else
         xf86PostMotionEventP(pInfo->dev, FALSE, *first_v, *num_v, v + *first_v);
+#endif
     }
 }
 
@@ -637,7 +652,11 @@ EvdevPostAbsoluteMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
      * just work.
      */
     if (pEvdev->abs && pEvdev->tool) {
+#ifdef HAVE_MASKED_VALUATORS
+        xf86PostMotionEventM(pInfo->dev, TRUE, &pEvdev->mask, v);
+#else
         xf86PostMotionEventP(pInfo->dev, TRUE, *first_v, *num_v, v);
+#endif
     }
 }
 
@@ -686,6 +705,9 @@ EvdevProcessSyncEvent(InputInfoPtr pInfo, struct input_event *ev)
 
     memset(pEvdev->delta, 0, sizeof(pEvdev->delta));
     memset(pEvdev->queue, 0, sizeof(pEvdev->queue));
+#ifdef HAVE_MASKED_VALUATORS
+    memset(&pEvdev->mask, 0, sizeof(pEvdev->mask));
+#endif
     pEvdev->num_queue = 0;
     pEvdev->abs = 0;
     pEvdev->rel = 0;
@@ -1157,7 +1179,7 @@ EvdevAddAbsClass(DeviceIntPtr device)
     if (!TestBit(EV_ABS, pEvdev->bitmask))
             return !Success;
 
-    num_axes = CountBits(pEvdev->abs_bitmask, NLONGS(ABS_MAX));
+    num_axes = CountBits((uint8_t *)pEvdev->abs_bitmask, ABS_MAX);
     if (num_axes < 1)
         return !Success;
 
@@ -1255,7 +1277,7 @@ EvdevAddRelClass(DeviceIntPtr device)
     if (!TestBit(EV_REL, pEvdev->bitmask))
         return !Success;
 
-    num_axes = CountBits(pEvdev->rel_bitmask, NLONGS(REL_MAX));
+    num_axes = CountBits((uint8_t *)pEvdev->rel_bitmask, REL_MAX);
     if (num_axes < 1)
         return !Success;
 
diff --git a/src/evdev.h b/src/evdev.h
index 4945140..d67f771 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -76,6 +76,12 @@
 #define HAVE_PROPERTIES 1
 #endif
 
+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 12 ||  \
+    (GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 11 && \
+     GET_ABI_MINOR(ABI_XINPUT_VERSION) >= 1)
+#define HAVE_MASKED_VALUATORS 1
+#endif
+
 #ifndef MAX_VALUATORS
 #define MAX_VALUATORS 36
 #endif
@@ -122,6 +128,9 @@ typedef struct {
     int axis_map[max(ABS_CNT, REL_CNT)]; /* Map evdev <axis> to index */
     int vals[MAX_VALUATORS];
     int old_vals[MAX_VALUATORS]; /* Translate absolute inputs to relative */
+#ifdef HAVE_MASKED_VALUATORS
+    ValuatorMask mask;
+#endif
 
     int flags;
     int tool;
-- 
1.7.1



More information about the xorg-devel mailing list