Input: Convert positionSprite and GetPointerEvents to double
Use doubles internally in both of these functions, eliminating most of the remaining int co-ordinate usage. Signed-off-by: Daniel Stone <daniel@fooishbar.org> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
51437995a5
commit
629a575261
144
dix/getevents.c
144
dix/getevents.c
|
@ -776,91 +776,61 @@ accelPointer(DeviceIntPtr dev, ValuatorMask* valuators, CARD32 ms)
|
||||||
* @param mode Movement mode (Absolute or Relative)
|
* @param mode Movement mode (Absolute or Relative)
|
||||||
* @param x Pointer to current x-axis value, may be modified.
|
* @param x Pointer to current x-axis value, may be modified.
|
||||||
* @param y Pointer to current y-axis value, may be modified.
|
* @param y Pointer to current y-axis value, may be modified.
|
||||||
* @param x_frac Fractional part of current x-axis value, may be modified.
|
|
||||||
* @param y_frac Fractional part of current y-axis value, may be modified.
|
|
||||||
* @param scr Screen the device's sprite is currently on.
|
* @param scr Screen the device's sprite is currently on.
|
||||||
* @param screenx Screen x coordinate the sprite is on after the update.
|
* @param screenx Screen x coordinate the sprite is on after the update.
|
||||||
* @param screeny Screen y coordinate the sprite is on after the update.
|
* @param screeny Screen y coordinate the sprite is on after the update.
|
||||||
* @param screenx_frac Fractional part of screen x coordinate, as above.
|
|
||||||
* @param screeny_frac Fractional part of screen y coordinate, as above.
|
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
positionSprite(DeviceIntPtr dev, int mode,
|
positionSprite(DeviceIntPtr dev, int mode, double *x, double *y, ScreenPtr scr,
|
||||||
int *x, int *y, float x_frac, float y_frac,
|
double *screenx, double *screeny)
|
||||||
ScreenPtr scr, int *screenx, int *screeny, float *screenx_frac, float *screeny_frac)
|
|
||||||
{
|
{
|
||||||
int old_screenx, old_screeny;
|
int isx, isy; /* screen {x, y}, in int */
|
||||||
double val, ret;
|
|
||||||
|
|
||||||
if (!dev->valuator || dev->valuator->numAxes < 2)
|
if (!dev->valuator || dev->valuator->numAxes < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* scale x&y to screen */
|
/* scale x&y to screen */
|
||||||
val = *x + x_frac;
|
*screenx = rescaleValuatorAxis(*x, dev->valuator->axes + 0, NULL,
|
||||||
ret = rescaleValuatorAxis(val, dev->valuator->axes + 0, NULL, scr->width);
|
scr->width);
|
||||||
*screenx = trunc(ret);
|
|
||||||
*screenx_frac = ret - trunc(ret);
|
|
||||||
|
|
||||||
val = *y + y_frac;
|
*screeny = rescaleValuatorAxis(*y, dev->valuator->axes + 1, NULL,
|
||||||
ret = rescaleValuatorAxis(val, dev->valuator->axes + 1, NULL, scr->height);
|
scr->height);
|
||||||
*screeny = trunc(ret);
|
|
||||||
*screeny_frac = ret - trunc(ret);
|
|
||||||
|
|
||||||
/* Hit the left screen edge? */
|
/* miPointerSetPosition takes care of crossing screens for us, as well as
|
||||||
if (*screenx <= 0 && *screenx_frac < 0.0f)
|
* clipping to the current screen. In the event we actually change screen,
|
||||||
|
* we just drop the float component on the floor, then convert from
|
||||||
|
* screenx back into device co-ordinates. */
|
||||||
|
isx = trunc(*screenx);
|
||||||
|
isy = trunc(*screeny);
|
||||||
|
miPointerSetPosition(dev, mode, &isx, &isy);
|
||||||
|
scr = miPointerGetScreen(dev);
|
||||||
|
if (isx != trunc(*screenx))
|
||||||
{
|
{
|
||||||
*screenx_frac = 0.0f;
|
*screenx -= trunc(*screenx) - isx;
|
||||||
x_frac = 0.0f;
|
*x = rescaleValuatorAxis(*screenx, NULL, dev->valuator->axes + 0,
|
||||||
|
scr->width);
|
||||||
}
|
}
|
||||||
if (*screeny <= 0 && *screeny_frac < 0.0f)
|
if (isy != trunc(*screeny))
|
||||||
{
|
{
|
||||||
*screeny_frac = 0.0f;
|
*screeny -= trunc(*screeny) - isy;
|
||||||
y_frac = 0.0f;
|
*y = rescaleValuatorAxis(*screeny, NULL, dev->valuator->axes + 1,
|
||||||
|
scr->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update the MD's co-ordinates, which are always in screen space. */
|
||||||
old_screenx = *screenx;
|
if (!IsMaster(dev) || !IsFloating(dev)) {
|
||||||
old_screeny = *screeny;
|
|
||||||
/* This takes care of crossing screens for us, as well as clipping
|
|
||||||
* to the current screen. */
|
|
||||||
miPointerSetPosition(dev, mode, screenx, screeny);
|
|
||||||
|
|
||||||
if(!IsMaster(dev) && !IsFloating(dev)) {
|
|
||||||
DeviceIntPtr master = GetMaster(dev, MASTER_POINTER);
|
DeviceIntPtr master = GetMaster(dev, MASTER_POINTER);
|
||||||
master->last.valuators[0] = *screenx;
|
master->last.valuators[0] = trunc(*screenx);
|
||||||
master->last.valuators[1] = *screeny;
|
master->last.remainder[0] = *screenx - trunc(*screenx);
|
||||||
master->last.remainder[0] = *screenx_frac;
|
master->last.valuators[1] = trunc(*screeny);
|
||||||
master->last.remainder[1] = *screeny_frac;
|
master->last.remainder[1] = *screeny - trunc(*screeny);
|
||||||
}
|
|
||||||
|
|
||||||
if (dev->valuator)
|
|
||||||
{
|
|
||||||
/* Crossed screen? Scale back to device coordiantes */
|
|
||||||
if(*screenx != old_screenx)
|
|
||||||
{
|
|
||||||
scr = miPointerGetScreen(dev);
|
|
||||||
val = *screenx + *screenx_frac;
|
|
||||||
ret = rescaleValuatorAxis(val, NULL, dev->valuator->axes + 0,
|
|
||||||
scr->width);
|
|
||||||
*x = trunc(ret);
|
|
||||||
x_frac = ret - trunc(ret);
|
|
||||||
}
|
|
||||||
if(*screeny != old_screeny)
|
|
||||||
{
|
|
||||||
scr = miPointerGetScreen(dev);
|
|
||||||
val = *screeny + *screeny_frac;
|
|
||||||
ret = rescaleValuatorAxis(val, NULL, dev->valuator->axes + 1,
|
|
||||||
scr->height);
|
|
||||||
*y = trunc(ret);
|
|
||||||
y_frac = ret - trunc(ret);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* dropy x/y (device coordinates) back into valuators for next event */
|
/* dropy x/y (device coordinates) back into valuators for next event */
|
||||||
dev->last.valuators[0] = *x;
|
dev->last.valuators[0] = trunc(*x);
|
||||||
dev->last.valuators[1] = *y;
|
dev->last.valuators[1] = trunc(*y);
|
||||||
dev->last.remainder[0] = x_frac;
|
dev->last.remainder[0] = *x - trunc(*x);
|
||||||
dev->last.remainder[1] = y_frac;
|
dev->last.remainder[1] = *y - trunc(*y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1106,9 +1076,8 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
|
||||||
CARD32 ms;
|
CARD32 ms;
|
||||||
DeviceEvent *event;
|
DeviceEvent *event;
|
||||||
RawDeviceEvent *raw;
|
RawDeviceEvent *raw;
|
||||||
int x = 0, y = 0, /* device coords */
|
double x = 0.0, y = 0.0; /* device coords */
|
||||||
cx, cy; /* only screen coordinates */
|
double screenx = 0.0, screeny = 0.0; /* screen coords */
|
||||||
float x_frac = 0.0, y_frac = 0.0, cx_frac, cy_frac;
|
|
||||||
ScreenPtr scr = miPointerGetScreen(pDev);
|
ScreenPtr scr = miPointerGetScreen(pDev);
|
||||||
ValuatorMask mask;
|
ValuatorMask mask;
|
||||||
|
|
||||||
|
@ -1155,7 +1124,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
|
||||||
{
|
{
|
||||||
if (flags & POINTER_SCREEN) /* valuators are in screen coords */
|
if (flags & POINTER_SCREEN) /* valuators are in screen coords */
|
||||||
{
|
{
|
||||||
int scaled;
|
double scaled;
|
||||||
|
|
||||||
if (valuator_mask_isset(&mask, 0))
|
if (valuator_mask_isset(&mask, 0))
|
||||||
{
|
{
|
||||||
|
@ -1185,27 +1154,21 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
|
||||||
set_raw_valuators(raw, &mask, raw->valuators.data,
|
set_raw_valuators(raw, &mask, raw->valuators.data,
|
||||||
raw->valuators.data_frac);
|
raw->valuators.data_frac);
|
||||||
|
|
||||||
if (valuator_mask_isset(&mask, 0)) {
|
if (valuator_mask_isset(&mask, 0))
|
||||||
double tmp = valuator_mask_get_double(&mask, 0);
|
x = valuator_mask_get_double(&mask, 0);
|
||||||
x = trunc(tmp);
|
else
|
||||||
x_frac = tmp - x;
|
x = pDev->last.valuators[0] + pDev->last.remainder[0];
|
||||||
}
|
if (valuator_mask_isset(&mask, 1))
|
||||||
else {
|
y = valuator_mask_get_double(&mask, 1);
|
||||||
x = pDev->last.valuators[0];
|
else
|
||||||
x_frac = pDev->last.remainder[0];
|
y = pDev->last.valuators[1] + pDev->last.remainder[1];
|
||||||
}
|
|
||||||
if (valuator_mask_isset(&mask, 1)) {
|
|
||||||
double tmp = valuator_mask_get_double(&mask, 1);
|
|
||||||
y = trunc(tmp);
|
|
||||||
y_frac = tmp - y;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
y = pDev->last.valuators[1];
|
|
||||||
y_frac = pDev->last.remainder[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative,
|
positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative,
|
||||||
&x, &y, x_frac, y_frac, scr, &cx, &cy, &cx_frac, &cy_frac);
|
&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);
|
||||||
updateHistory(pDev, &mask, ms);
|
updateHistory(pDev, &mask, ms);
|
||||||
|
|
||||||
/* Update the valuators with the true value sent to the client*/
|
/* Update the valuators with the true value sent to the client*/
|
||||||
|
@ -1235,10 +1198,11 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
|
||||||
event->detail.button = buttons;
|
event->detail.button = buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
event->root_x = cx; /* root_x/y always in screen coords */
|
/* root_x and root_y must be in screen co-ordinates */
|
||||||
event->root_y = cy;
|
event->root_x = trunc(screenx);
|
||||||
event->root_x_frac = cx_frac;
|
event->root_y = trunc(screeny);
|
||||||
event->root_y_frac = cy_frac;
|
event->root_x_frac = screenx - trunc(screenx);
|
||||||
|
event->root_y_frac = screeny - trunc(screeny);
|
||||||
|
|
||||||
set_valuators(pDev, event, &mask);
|
set_valuators(pDev, event, &mask);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue