[PATCH 23/27] Input: Make DeviceEvent use doubles internally

Daniel Stone daniel at fooishbar.org
Fri Jun 3 07:59:59 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>
---
 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 c6f9d46..a30b629 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 62777db..b52cce8 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -819,8 +819,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 = round_towards_zero(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 2abf0f8..6947846 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -208,9 +208,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 ebe0d7a..58d6b6d 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -103,8 +103,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 0041e7e..81eec6e 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -384,8 +384,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 = round_towards_zero(in->valuators.data[i]);
+                vi.frac = (in->valuators.data[i] - vi.integral) * (1UL << 32);
 
                 vo = *values;
 
@@ -628,8 +628,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