[PATCH v2 10/28] Input: Convert clipAxis, moveAbsolute and moveRelative to double

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


Change all these three to use doubles internally, though the outputs of
moveAbsolute and moveRelative are still truncated to int.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 dix/getevents.c |   48 +++++++++++++++++++++++++-----------------------
 1 files changed, 25 insertions(+), 23 deletions(-)

v2: Squashed in hunks that accidentally crept in to the 'widen acceleration
    types' commit.  Shuffled some code around a tiny bit.  

diff --git a/dix/getevents.c b/dix/getevents.c
index 4bff3cd..cface3c 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -636,7 +636,7 @@ GetMaximumEventsNum(void) {
  * InitValuatorAxisClassStruct.
  */
 static void
-clipAxis(DeviceIntPtr pDev, int axisNum, int *val)
+clipAxis(DeviceIntPtr pDev, int axisNum, double *val)
 {
     AxisInfoPtr axis;
 
@@ -666,9 +666,9 @@ clipValuators(DeviceIntPtr pDev, ValuatorMask *mask)
     for (i = 0; i < valuator_mask_size(mask); i++)
         if (valuator_mask_isset(mask, i))
         {
-            int val = valuator_mask_get(mask, i);
+            double val = valuator_mask_get_double(mask, i);
             clipAxis(pDev, i, &val);
-            valuator_mask_set(mask, i, val);
+            valuator_mask_set_double(mask, i, val);
         }
 }
 
@@ -718,17 +718,18 @@ static void
 moveAbsolute(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
 {
     int i;
-    int x, y;
 
     for (i = 0; i < valuator_mask_size(mask); i++)
     {
-        if (valuator_mask_isset(mask, i))
-        {
-            int val = valuator_mask_get(mask, i);
-            clipAxis(dev, i, &val);
-            dev->last.valuators[i] = val;
-            valuator_mask_set(mask, i, val);
-        }
+        double val;
+
+        if (!valuator_mask_isset(mask, i))
+            continue;
+        val = valuator_mask_get_double(mask, i);
+        clipAxis(dev, i, &val);
+        dev->last.valuators[i] = trunc(val);
+        dev->last.remainder[i] = val - trunc(val);
+        valuator_mask_set_double(mask, i, val);
     }
 
     *x_out = dev->last.valuators[0];
@@ -752,18 +753,19 @@ moveRelative(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
     /* calc other axes, clip, drop back into valuators */
     for (i = 0; i < valuator_mask_size(mask); i++)
     {
-        if (valuator_mask_isset(mask, i))
-        {
-            int val = dev->last.valuators[i];
-            val += valuator_mask_get(mask, i);
-            /* x & y need to go over the limits to cross screens if the SD
-             * isn't currently attached; otherwise, clip to screen bounds. */
-            if (valuator_get_mode(dev, i) == Absolute &&
-                ((i != 0 && i != 1) || clip_xy))
-                clipAxis(dev, i, &val);
-            dev->last.valuators[i] = val;
-            valuator_mask_set(mask, i, val);
-        }
+        double val = dev->last.valuators[i] + dev->last.remainder[i];
+
+        if (!valuator_mask_isset(mask, i))
+            continue;
+        val += valuator_mask_get_double(mask, i);
+        /* x & y need to go over the limits to cross screens if the SD
+         * isn't currently attached; otherwise, clip to screen bounds. */
+        if (valuator_get_mode(dev, i) == Absolute &&
+            ((i != 0 && i != 1) || clip_xy))
+            clipAxis(dev, i, &val);
+        dev->last.valuators[i] = trunc(val);
+        dev->last.remainder[i] = val - trunc(val);
+        valuator_mask_set_double(mask, i, val);
     }
 
     *x_out = dev->last.valuators[0];
-- 
1.7.5.3



More information about the xorg-devel mailing list