[PATCH 22/28] Input: Make DeviceEvent use doubles internally

Daniel Stone daniel at fooishbar.org
Thu Jun 9 10:17:30 PDT 2011


Change the DeviceEvent InternalEvent to use doubles for its valuators,
instead of data and data_frac.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 Xi/exevents.c                    |    5 +----
 dix/eventconvert.c               |    5 +++--
 dix/getevents.c                  |    4 +---
 include/eventstr.h               |    3 +--
 test/xi2/protocol-eventconvert.c |    7 +++----
 5 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 3e3c67b..1bd9d57 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -776,12 +776,9 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
 
     for (i = 0; i <= last_valuator && i < v->numAxes; i++)
     {
+        /* XXX: Relative/Absolute mode */
         if (BitIsOn(&event->valuators.mask, i))
-        {
-            /* XXX: Relative/Absolute mode */
             v->axisVal[i] = event->valuators.data[i];
-            v->axisVal[i] += (event->valuators.data_frac[i] * 1.0f / (1 << 16) / (1 << 16));
-        }
     }
 
     if (event->type == ET_KeyPress) {
diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index 54e9020..9cc177e 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -633,8 +633,9 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
         if (BitIsOn(ev->valuators.mask, i))
         {
             SetBit(ptr, i);
-            axisval->integral = ev->valuators.data[i];
-            axisval->frac = ev->valuators.data_frac[i];
+            axisval->integral = trunc(ev->valuators.data[i]);
+            axisval->frac = (ev->valuators.data[i] - axisval->integral) *
+                            (1UL << 32);
             axisval++;
         }
     }
diff --git a/dix/getevents.c b/dix/getevents.c
index 331613a..b459375 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -207,9 +207,7 @@ set_valuators(DeviceIntPtr dev, DeviceEvent* event, ValuatorMask *mask)
             SetBit(event->valuators.mask, i);
             if (valuator_get_mode(dev, i) == Absolute)
                 SetBit(event->valuators.mode, i);
-            event->valuators.data[i] = valuator_mask_get(mask, i);
-            event->valuators.data_frac[i] =
-                dev->last.remainder[i] * (1 << 16) * (1 << 16);
+            event->valuators.data[i] = valuator_mask_get_double(mask, i);
         }
         else if (valuator_get_mode(dev, i) == Absolute)
             event->valuators.data[i] = dev->valuator->axisVal[i];
diff --git a/include/eventstr.h b/include/eventstr.h
index 0645585..2de077f 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -95,8 +95,7 @@ struct _DeviceEvent
     struct {
         uint8_t  mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */
         uint8_t  mode[(MAX_VALUATORS + 7)/8]; /**< Valuator mode (Abs or Rel)*/
-        int32_t  data[MAX_VALUATORS];         /**< Valuator data */
-        int32_t  data_frac[MAX_VALUATORS];    /**< Fractional part for data */
+        double   data[MAX_VALUATORS];         /**< Valuator data */
     } valuators;
     struct {
         uint32_t base;    /**< XKB base modifiers */
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index 2e915e8..7db3fd2 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -380,8 +380,8 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
             {
                 FP3232 vi, vo;
 
-                vi.integral = in->valuators.data[i];
-                vi.frac = in->valuators.data_frac[i];
+                vi.integral = trunc(in->valuators.data[i]);
+                vi.frac = (in->valuators.data[i] - vi.integral) * (1UL << 32);
 
                 vo = *values;
 
@@ -624,8 +624,7 @@ static void test_convert_XIDeviceEvent(void)
     {
         XISetMask(in.valuators.mask, i);
 
-        in.valuators.data[i] = i;
-        in.valuators.data_frac[i] = i + 20;
+        in.valuators.data[i] = i + (i * 0.0020);
         test_XIDeviceEvent(&in);
         XIClearMask(in.valuators.mask, i);
     }
-- 
1.7.5.3



More information about the xorg-devel mailing list