[PATCH 21/27] Input: Modify mask in-place in positionSprite

Daniel Stone daniel at fooishbar.org
Fri Jun 3 07:59:57 PDT 2011


Instead of taking pointers to x and y values to modify in
positionSprite, just modify the mask (as well as dev->last) in place.

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

diff --git a/dix/getevents.c b/dix/getevents.c
index 1753616..de779b2 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -794,26 +794,34 @@ accelPointer(DeviceIntPtr dev, ValuatorMask* valuators, CARD32 ms)
  *
  * @param dev The device to be moved.
  * @param mode Movement mode (Absolute or Relative)
- * @param x Pointer to current x-axis value, may be modified.
- * @param y Pointer to current y-axis value, may be modified.
  * @param scr Screen the device's sprite is currently on.
+ * @param mask Mask of axis values for this event
  * @param screenx Screen x coordinate the sprite is on after the update.
  * @param screeny Screen y coordinate the sprite is on after the update.
  */
 static void
-positionSprite(DeviceIntPtr dev, int mode, double *x, double *y, ScreenPtr scr,
+positionSprite(DeviceIntPtr dev, int mode, ScreenPtr scr, ValuatorMask *mask,
                double *screenx, double *screeny)
 {
     int isx, isy; /* screen {x, y}, in int */
+    double x, y;
 
     if (!dev->valuator || dev->valuator->numAxes < 2)
         return;
 
+    if (valuator_mask_isset(mask, 0))
+        x = valuator_mask_get_double(mask, 0);
+    else
+        x = dev->last.valuators[0] + dev->last.remainder[0];
+    if (valuator_mask_isset(mask, 1))
+        y = valuator_mask_get_double(mask, 1);
+    else
+        y = dev->last.valuators[1] + dev->last.remainder[1];
+
     /* scale x&y to screen */
-    *screenx = rescaleValuatorAxis(*x, dev->valuator->axes + 0, NULL,
+    *screenx = rescaleValuatorAxis(x, dev->valuator->axes + 0, NULL,
                                    scr->width);
-
-    *screeny = rescaleValuatorAxis(*y, dev->valuator->axes + 1, NULL,
+    *screeny = rescaleValuatorAxis(y, dev->valuator->axes + 1, NULL,
                                    scr->height);
 
     /* miPointerSetPosition takes care of crossing screens for us, as well as
@@ -827,14 +835,14 @@ positionSprite(DeviceIntPtr dev, int mode, double *x, double *y, ScreenPtr scr,
     if (isx != round_towards_zero(*screenx))
     {
         *screenx -= round_towards_zero(*screenx) - isx;
-        *x = rescaleValuatorAxis(*screenx, NULL, dev->valuator->axes + 0,
-                                 scr->width);
+        x = rescaleValuatorAxis(*screenx, NULL, dev->valuator->axes + 0,
+                                scr->width);
     }
     if (isy != round_towards_zero(*screeny))
     {
         *screeny -= round_towards_zero(*screeny) - isy;
-        *y = rescaleValuatorAxis(*screeny, NULL, dev->valuator->axes + 1,
-                                 scr->height);
+        y = rescaleValuatorAxis(*screeny, NULL, dev->valuator->axes + 1,
+                                scr->height);
     }
 
     /* Update the MD's co-ordinates, which are always in screen space. */
@@ -848,10 +856,15 @@ positionSprite(DeviceIntPtr dev, int mode, double *x, double *y, ScreenPtr scr,
     }
 
     /* 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] = 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);
+
+    if (valuator_mask_isset(mask, 0))
+        valuator_mask_set_double(mask, 0, x);
+    if (valuator_mask_isset(mask, 1))
+        valuator_mask_set_double(mask, 1, y);
 }
 
 /**
@@ -1082,8 +1095,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
     CARD32 ms;
     DeviceEvent *event;
     RawDeviceEvent    *raw;
-    double x = 0.0, y = 0.0; /* device coords */
-    double screenx = 0.0, screeny = 0.0; /* screen coords */
+    double screenx = 0.0, screeny = 0.0;
     ScreenPtr scr = miPointerGetScreen(pDev);
     ValuatorMask mask;
 
@@ -1153,26 +1165,13 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
         moveRelative(pDev, &mask);
     }
 
-    x = pDev->last.valuators[0] + pDev->last.remainder[0];
-    y = pDev->last.valuators[1] + pDev->last.remainder[1];
-
     set_raw_valuators(raw, &mask, raw->valuators.data,
                       raw->valuators.data_frac);
 
-    positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative,
-                   &x, &y, scr, &screenx, &screeny);
-    if (valuator_mask_isset(&mask, 0))
-        valuator_mask_set_double(&mask, 0, x);
-    if (valuator_mask_isset(&mask, 1))
-        valuator_mask_set_double(&mask, 1, y);
+    positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative, scr,
+                   &mask, &screenx, &screeny);
     updateHistory(pDev, &mask, ms);
 
-    /* Update the valuators with the true value sent to the client*/
-    if (valuator_mask_isset(&mask, 0))
-        valuator_mask_set(&mask, 0, x);
-    if (valuator_mask_isset(&mask, 1))
-        valuator_mask_set(&mask, 1, y);
-
     clipValuators(pDev, &mask);
 
     event = &events->device_event;
-- 
1.7.5.3



More information about the xorg-devel mailing list