[PATCH 11/27] Input: Convert clipAxis, moveAbsolute and moveRelative to double

Daniel Stone daniel at fooishbar.org
Fri Jun 3 07:59:47 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 |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/dix/getevents.c b/dix/getevents.c
index 0a91510..1f145ac 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -630,7 +630,7 @@ GetMaximumEventsNum(void) {
  * InitValuatorAxisClassStruct.
  */
 static void
-clipAxis(DeviceIntPtr pDev, int axisNum, int *val)
+clipAxis(DeviceIntPtr pDev, int axisNum, double *val)
 {
     AxisInfoPtr axis;
 
@@ -660,9 +660,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);
         }
 }
 
@@ -712,21 +712,21 @@ static void
 moveAbsolute(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
 {
     int i;
-    int x, y;
+    double x = dev->last.valuators[0], y = dev->last.valuators[1];
 
     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(dev, i, &val);
             dev->last.valuators[i] = val;
-            valuator_mask_set(mask, i, val);
+            valuator_mask_set_double(mask, i, val);
         }
     }
 
-    *x_out = dev->last.valuators[0];
-    *y_out = dev->last.valuators[1];
+    *x_out = round_towards_zero(x);
+    *y_out = round_towards_zero(y);
 }
 
 /**
@@ -748,15 +748,15 @@ moveRelative(DeviceIntPtr dev, int *x_out, int *y_out, ValuatorMask *mask)
     {
         if (valuator_mask_isset(mask, i))
         {
-            int val = dev->last.valuators[i];
-            val += valuator_mask_get(mask, i);
+            double val = dev->last.valuators[i];
+            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] = val;
-            valuator_mask_set(mask, i, val);
+            valuator_mask_set_double(mask, i, val);
         }
     }
 
-- 
1.7.5.3



More information about the xorg-devel mailing list