[PATCH 20/28] Input: Modify mask in-place in positionSprite
Daniel Stone
daniel at fooishbar.org
Thu Jun 9 10:17:28 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>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
---
dix/getevents.c | 67 ++++++++++++++++++++++++------------------------------
1 files changed, 30 insertions(+), 37 deletions(-)
diff --git a/dix/getevents.c b/dix/getevents.c
index 3328511..9eecfdd 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -793,26 +793,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
@@ -826,14 +834,14 @@ positionSprite(DeviceIntPtr dev, int mode, double *x, double *y, ScreenPtr scr,
if (isx != trunc(*screenx))
{
*screenx -= trunc(*screenx) - isx;
- *x = rescaleValuatorAxis(*screenx, NULL, dev->valuator->axes + 0,
- scr->width);
+ x = rescaleValuatorAxis(*screenx, NULL, dev->valuator->axes + 0,
+ scr->width);
}
if (isy != trunc(*screeny))
{
*screeny -= trunc(*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. */
@@ -846,10 +854,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] = trunc(*x);
- dev->last.valuators[1] = trunc(*y);
- dev->last.remainder[0] = *x - trunc(*x);
- dev->last.remainder[1] = *y - trunc(*y);
+ dev->last.valuators[0] = trunc(x);
+ dev->last.valuators[1] = trunc(y);
+ dev->last.remainder[0] = x - trunc(x);
+ dev->last.remainder[1] = y - trunc(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);
}
/**
@@ -1095,8 +1108,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;
@@ -1166,32 +1178,13 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
moveRelative(pDev, &mask);
}
- if (valuator_mask_isset(&mask, 0))
- x = valuator_mask_get_double(&mask, 0);
- else
- x = pDev->last.valuators[0] + pDev->last.remainder[0];
- if (valuator_mask_isset(&mask, 1))
- y = valuator_mask_get_double(&mask, 1);
- else
- 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