[PATCH 24/27] Input: Convert DeviceIntRec::last to use doubles

Daniel Stone daniel at fooishbar.org
Fri Jun 3 08:00:00 PDT 2011


Change the last real user of a split integer/fractional co-ordinate
system, DeviceIntRec's last->{valuators,remainder} to just have one set
of doubles.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 Xi/xiwarppointer.c |    2 -
 dix/getevents.c    |   63 ++++++++++++++++++++++-----------------------------
 include/inputstr.h |    3 +-
 3 files changed, 28 insertions(+), 40 deletions(-)

diff --git a/Xi/xiwarppointer.c b/Xi/xiwarppointer.c
index a463ab9..a9e3442 100644
--- a/Xi/xiwarppointer.c
+++ b/Xi/xiwarppointer.c
@@ -192,8 +192,6 @@ ProcXIWarpPointer(ClientPtr client)
     /* if we don't update the device, we get a jump next time it moves */
     pDev->last.valuators[0] = x;
     pDev->last.valuators[1] = y;
-    pDev->last.remainder[0] = 0;
-    pDev->last.remainder[1] = 0;
     miPointerUpdateSprite(pDev);
 
     /* FIXME: XWarpPointer is supposed to generate an event. It doesn't do it
diff --git a/dix/getevents.c b/dix/getevents.c
index 6947846..7a47c49 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -303,15 +303,12 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
 {
     ScreenPtr scr = miPointerGetScreen(pDev);
     int i;
-    double val, ret;
     DeviceIntPtr lastSlave;
 
     /* master->last.valuators[0]/[1] is in screen coords and the actual
      * position of the pointer */
     pDev->last.valuators[0] = master->last.valuators[0];
     pDev->last.valuators[1] = master->last.valuators[1];
-    pDev->last.remainder[0] = master->last.remainder[0];
-    pDev->last.remainder[1] = master->last.remainder[1];
 
     if (!pDev->valuator)
         return;
@@ -319,19 +316,17 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
     /* scale back to device coordinates */
     if(pDev->valuator->numAxes > 0)
     {
-        val = pDev->last.valuators[0] + pDev->last.remainder[0];
-        ret = rescaleValuatorAxis(val, NULL, pDev->valuator->axes + 0,
-                                  scr->width);
-        pDev->last.valuators[0] = round_towards_zero(ret);
-        pDev->last.remainder[0] = ret - round_towards_zero(ret);
+        pDev->last.valuators[0] = rescaleValuatorAxis(pDev->last.valuators[0],
+                                                      NULL,
+                                                      pDev->valuator->axes + 0,
+                                                      scr->width);
     }
     if(pDev->valuator->numAxes > 1)
     {
-        val = pDev->last.valuators[1] + pDev->last.remainder[1];
-        ret = rescaleValuatorAxis(val, NULL, pDev->valuator->axes + 1,
-                                  scr->height);
-        pDev->last.valuators[1] = round_towards_zero(ret);
-        pDev->last.remainder[1] = ret - round_towards_zero(ret);
+        pDev->last.valuators[1] = rescaleValuatorAxis(pDev->last.valuators[1],
+                                                      NULL,
+                                                      pDev->valuator->axes + 1,
+                                                      scr->width);
     }
 
     /* calculate the other axis as well based on info from the old
@@ -343,15 +338,13 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev)
             if (i >= lastSlave->valuator->numAxes)
             {
                 pDev->last.valuators[i] = 0;
-                pDev->last.remainder[i] = 0;
             }
             else
             {
-                val = pDev->last.valuators[i] + pDev->last.remainder[i];
-                ret = rescaleValuatorAxis(val, lastSlave->valuator->axes + i,
+                double val = pDev->last.valuators[i];
+                val = rescaleValuatorAxis(val, lastSlave->valuator->axes + i,
                                           pDev->valuator->axes + i, 0);
-                pDev->last.valuators[i] = round_towards_zero(ret);
-                pDev->last.remainder[i] = ret - round_towards_zero(ret);
+                pDev->last.valuators[i] = val;
             }
         }
     }
@@ -543,7 +536,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
  */
 static void
 updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask,
-                    int *valuators)
+                    double *valuators)
 {
     char *buff = (char *) pDev->valuator->motion;
     ValuatorClassPtr v;
@@ -565,6 +558,7 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask,
 
         for (i = 0; i < v->numAxes; i++)
         {
+            int val;
             /* XI1 doesn't support mixed mode devices */
             if (valuator_get_mode(pDev, i) != valuator_get_mode(pDev, 0))
                 break;
@@ -577,7 +571,8 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask,
             buff += sizeof(INT32);
             memcpy(buff, &v->axes[i].max_value, sizeof(INT32));
             buff += sizeof(INT32);
-            memcpy(buff, &valuators[i], sizeof(INT32));
+            val = valuators[i];
+            memcpy(buff, &val, sizeof(INT32));
             buff += sizeof(INT32);
         }
     } else
@@ -593,12 +588,14 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask,
 
         for (i = 0; i < MAX_VALUATORS; i++)
         {
+            int val;
             if (valuator_mask_size(mask) <= i || !valuator_mask_isset(mask, i))
             {
                 buff += sizeof(INT32);
                 continue;
             }
-            memcpy(buff, &valuators[i], sizeof(INT32));
+            val = valuators[i];
+            memcpy(buff, &val, sizeof(INT32));
             buff += sizeof(INT32);
         }
     }
@@ -722,10 +719,9 @@ moveAbsolute(DeviceIntPtr dev, ValuatorMask *mask)
         if (valuator_mask_isset(mask, i))
             val = valuator_mask_get_double(mask, i);
         else
-            val = dev->last.valuators[i] + dev->last.remainder[i];
+            val = dev->last.valuators[i];
         clipAxis(dev, i, &val);
-        dev->last.valuators[i] = floor(val);
-        dev->last.remainder[i] = val - floor(val);
+        dev->last.valuators[i] = val;
         valuator_mask_set_double(mask, i, val);
     }
 }
@@ -747,7 +743,7 @@ moveRelative(DeviceIntPtr dev, ValuatorMask *mask)
     {
         if (valuator_mask_isset(mask, i))
         {
-            double val = dev->last.valuators[i] + dev->last.remainder[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. */
@@ -756,7 +752,6 @@ moveRelative(DeviceIntPtr dev, ValuatorMask *mask)
                 clipAxis(dev, i, &val);
             valuator_mask_set_double(mask, i, val);
             dev->last.valuators[i] = val;
-            dev->last.remainder[i] = val - round_towards_zero(val);
         }
     }
 }
@@ -806,11 +801,11 @@ positionSprite(DeviceIntPtr dev, int mode, ScreenPtr scr, ValuatorMask *mask,
     if (valuator_mask_isset(mask, 0))
         x = valuator_mask_get_double(mask, 0);
     else
-        x = dev->last.valuators[0] + dev->last.remainder[0];
+        x = dev->last.valuators[0];
     if (valuator_mask_isset(mask, 1))
         y = valuator_mask_get_double(mask, 1);
     else
-        y = dev->last.valuators[1] + dev->last.remainder[1];
+        y = dev->last.valuators[1];
 
     /* scale x&y to screen */
     *screenx = rescaleValuatorAxis(x, dev->valuator->axes + 0, NULL,
@@ -843,17 +838,13 @@ positionSprite(DeviceIntPtr dev, int mode, ScreenPtr scr, ValuatorMask *mask,
     if (!IsMaster(dev) || !IsFloating(dev))
     {
         DeviceIntPtr master = GetMaster(dev, MASTER_POINTER);
-        master->last.valuators[0] = round_towards_zero(*screenx);
-        master->last.remainder[0] = *screenx - round_towards_zero(*screenx);
-        master->last.valuators[1] = round_towards_zero(*screeny);
-        master->last.remainder[1] = *screeny - round_towards_zero(*screeny);
+        master->last.valuators[0] = *screenx;
+        master->last.valuators[1] = *screeny;
     }
 
     /* dropy x/y (device coordinates) back into valuators for next event */
-    dev->last.valuators[0] = round_towards_zero(x);
-    dev->last.valuators[1] = round_towards_zero(y);
-    dev->last.remainder[0] = x - round_towards_zero(x);
-    dev->last.remainder[1] = y - round_towards_zero(y);
+    dev->last.valuators[0] = x;
+    dev->last.valuators[1] = y;
 
     if (valuator_mask_isset(mask, 0))
         valuator_mask_set_double(mask, 0, x);
diff --git a/include/inputstr.h b/include/inputstr.h
index 00f72c2..11d69e7 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -518,8 +518,7 @@ typedef struct _DeviceIntRec {
      * remainder supports acceleration
      */
     struct {
-        int             valuators[MAX_VALUATORS];
-        float           remainder[MAX_VALUATORS];
+        double          valuators[MAX_VALUATORS];
         int             numValuators;
         DeviceIntPtr    slave;
     } last;
-- 
1.7.5.3



More information about the xorg-devel mailing list