mi: switch miPointerSetPosition to take doubles
Don't switch between doubles and ints in the caller, instead take doubles in miPointerSetPosition and do the conversion there. For full feature we should change everything down from here for doubles too. Functional change: previously we'd restore the remainder regardless of screen switching/confinement (despite what the comment said). Now, screen changing or cursor constraints will cause the remainder be clipped off. This should happen for cursor constraints but arguably not for screen crossing. This also corrects a currently wrong comment about miPointerSetPosition's input coordinates. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
parent
81cfe44b1e
commit
3b36fd1b49
|
@ -805,8 +805,8 @@ static ScreenPtr
|
||||||
positionSprite(DeviceIntPtr dev, int mode, ValuatorMask *mask,
|
positionSprite(DeviceIntPtr dev, int mode, ValuatorMask *mask,
|
||||||
double *screenx, double *screeny)
|
double *screenx, double *screeny)
|
||||||
{
|
{
|
||||||
int isx, isy; /* screen {x, y}, in int */
|
|
||||||
double x, y;
|
double x, y;
|
||||||
|
double tmpx, tmpy;
|
||||||
ScreenPtr scr = miPointerGetScreen(dev);
|
ScreenPtr scr = miPointerGetScreen(dev);
|
||||||
|
|
||||||
if (!dev->valuator || dev->valuator->numAxes < 2)
|
if (!dev->valuator || dev->valuator->numAxes < 2)
|
||||||
|
@ -827,25 +827,22 @@ positionSprite(DeviceIntPtr dev, int mode, ValuatorMask *mask,
|
||||||
*screeny = rescaleValuatorAxis(y, dev->valuator->axes + 1, NULL,
|
*screeny = rescaleValuatorAxis(y, dev->valuator->axes + 1, NULL,
|
||||||
scr->height);
|
scr->height);
|
||||||
|
|
||||||
|
tmpx = *screenx;
|
||||||
|
tmpy = *screeny;
|
||||||
/* miPointerSetPosition takes care of crossing screens for us, as well as
|
/* miPointerSetPosition takes care of crossing screens for us, as well as
|
||||||
* clipping to the current screen. In the event we actually change screen,
|
* clipping to the current screen. */
|
||||||
* we just drop the float component on the floor, then convert from
|
scr = miPointerSetPosition(dev, mode, screenx, screeny);
|
||||||
* screenx back into device co-ordinates. */
|
|
||||||
isx = trunc(*screenx);
|
/* If we were constrained, rescale x/y from the screen coordinates so
|
||||||
isy = trunc(*screeny);
|
* the device valuators reflect the correct position. For screen
|
||||||
scr = miPointerSetPosition(dev, mode, &isx, &isy);
|
* crossing this doesn't matter much, the coords would be 0 or max.
|
||||||
if (isx != trunc(*screenx))
|
*/
|
||||||
{
|
if (tmpx != *screenx)
|
||||||
*screenx -= trunc(*screenx) - isx;
|
|
||||||
x = rescaleValuatorAxis(*screenx, NULL, dev->valuator->axes + 0,
|
x = rescaleValuatorAxis(*screenx, NULL, dev->valuator->axes + 0,
|
||||||
scr->width);
|
scr->width);
|
||||||
}
|
if (tmpy != *screeny)
|
||||||
if (isy != trunc(*screeny))
|
|
||||||
{
|
|
||||||
*screeny -= trunc(*screeny) - isy;
|
|
||||||
y = rescaleValuatorAxis(*screeny, NULL, dev->valuator->axes + 1,
|
y = rescaleValuatorAxis(*screeny, NULL, dev->valuator->axes + 1,
|
||||||
scr->height);
|
scr->height);
|
||||||
}
|
|
||||||
|
|
||||||
/* Update the MD's co-ordinates, which are always in screen space. */
|
/* Update the MD's co-ordinates, which are always in screen space. */
|
||||||
if (!IsMaster(dev) || !IsFloating(dev)) {
|
if (!IsMaster(dev) || !IsFloating(dev)) {
|
||||||
|
|
|
@ -569,17 +569,16 @@ miPointerMoveNoEvent (DeviceIntPtr pDev, ScreenPtr pScreen,
|
||||||
*
|
*
|
||||||
* @param pDev The device to move
|
* @param pDev The device to move
|
||||||
* @param mode Movement mode (Absolute or Relative)
|
* @param mode Movement mode (Absolute or Relative)
|
||||||
* @param[in,out] x The x coordinate in screen coordinates (in regards to total
|
* @param[in,out] screenx The x coordinate in screen coordinates
|
||||||
* desktop size)
|
* @param[in,out] screeny The y coordinate in screen coordinates
|
||||||
* @param[in,out] y The y coordinate in screen coordinates (in regards to total
|
|
||||||
* desktop size)
|
|
||||||
*/
|
*/
|
||||||
ScreenPtr
|
ScreenPtr
|
||||||
miPointerSetPosition(DeviceIntPtr pDev, int mode, int *x, int *y)
|
miPointerSetPosition(DeviceIntPtr pDev, int mode, double *screenx, double *screeny)
|
||||||
{
|
{
|
||||||
miPointerScreenPtr pScreenPriv;
|
miPointerScreenPtr pScreenPriv;
|
||||||
ScreenPtr pScreen;
|
ScreenPtr pScreen;
|
||||||
ScreenPtr newScreen;
|
ScreenPtr newScreen;
|
||||||
|
int x, y;
|
||||||
|
|
||||||
miPointerPtr pPointer;
|
miPointerPtr pPointer;
|
||||||
|
|
||||||
|
@ -591,13 +590,16 @@ miPointerSetPosition(DeviceIntPtr pDev, int mode, int *x, int *y)
|
||||||
if (!pScreen)
|
if (!pScreen)
|
||||||
return NULL; /* called before ready */
|
return NULL; /* called before ready */
|
||||||
|
|
||||||
if (*x < 0 || *x >= pScreen->width || *y < 0 || *y >= pScreen->height)
|
x = trunc(*screenx);
|
||||||
|
y = trunc(*screeny);
|
||||||
|
|
||||||
|
if (x < 0 || x >= pScreen->width || y < 0 || y >= pScreen->height)
|
||||||
{
|
{
|
||||||
pScreenPriv = GetScreenPrivate (pScreen);
|
pScreenPriv = GetScreenPrivate (pScreen);
|
||||||
if (!pPointer->confined)
|
if (!pPointer->confined)
|
||||||
{
|
{
|
||||||
newScreen = pScreen;
|
newScreen = pScreen;
|
||||||
(*pScreenPriv->screenFuncs->CursorOffScreen) (&newScreen, x, y);
|
(*pScreenPriv->screenFuncs->CursorOffScreen) (&newScreen, &x, &y);
|
||||||
if (newScreen != pScreen)
|
if (newScreen != pScreen)
|
||||||
{
|
{
|
||||||
pScreen = newScreen;
|
pScreen = newScreen;
|
||||||
|
@ -610,21 +612,30 @@ miPointerSetPosition(DeviceIntPtr pDev, int mode, int *x, int *y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Constrain the sprite to the current limits. */
|
/* Constrain the sprite to the current limits. */
|
||||||
if (*x < pPointer->limits.x1)
|
if (x < pPointer->limits.x1)
|
||||||
*x = pPointer->limits.x1;
|
x = pPointer->limits.x1;
|
||||||
if (*x >= pPointer->limits.x2)
|
if (x >= pPointer->limits.x2)
|
||||||
*x = pPointer->limits.x2 - 1;
|
x = pPointer->limits.x2 - 1;
|
||||||
if (*y < pPointer->limits.y1)
|
if (y < pPointer->limits.y1)
|
||||||
*y = pPointer->limits.y1;
|
y = pPointer->limits.y1;
|
||||||
if (*y >= pPointer->limits.y2)
|
if (y >= pPointer->limits.y2)
|
||||||
*y = pPointer->limits.y2 - 1;
|
y = pPointer->limits.y2 - 1;
|
||||||
|
|
||||||
if (pScreen->ConstrainCursorHarder)
|
if (pScreen->ConstrainCursorHarder)
|
||||||
pScreen->ConstrainCursorHarder(pDev, pScreen, mode, x, y);
|
pScreen->ConstrainCursorHarder(pDev, pScreen, mode, &x, &y);
|
||||||
|
|
||||||
if (pPointer->x != *x || pPointer->y != *y ||
|
if (pPointer->x != x || pPointer->y != y ||
|
||||||
pPointer->pScreen != pScreen)
|
pPointer->pScreen != pScreen)
|
||||||
miPointerMoveNoEvent(pDev, pScreen, *x, *y);
|
miPointerMoveNoEvent(pDev, pScreen, x, y);
|
||||||
|
|
||||||
|
/* In the event we actually change screen or we get confined, we just
|
||||||
|
* drop the float component on the floor
|
||||||
|
* FIXME: only drop remainder for ConstrainCursorHarder, not for screen
|
||||||
|
* crossings */
|
||||||
|
if (x != trunc(*screenx))
|
||||||
|
*screenx = x;
|
||||||
|
if (y != trunc(*screeny))
|
||||||
|
*screeny = y;
|
||||||
|
|
||||||
return pScreen;
|
return pScreen;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,8 +134,8 @@ extern _X_EXPORT void miPointerGetPosition(
|
||||||
extern _X_EXPORT ScreenPtr miPointerSetPosition(
|
extern _X_EXPORT ScreenPtr miPointerSetPosition(
|
||||||
DeviceIntPtr pDev,
|
DeviceIntPtr pDev,
|
||||||
int mode,
|
int mode,
|
||||||
int *x,
|
double *x,
|
||||||
int *y);
|
double *y);
|
||||||
|
|
||||||
extern _X_EXPORT void miPointerUpdateSprite(
|
extern _X_EXPORT void miPointerUpdateSprite(
|
||||||
DeviceIntPtr pDev);
|
DeviceIntPtr pDev);
|
||||||
|
|
Loading…
Reference in New Issue