Bug # 10324: dix: Add scaling of X and Y on the reported pointer-events

Restore the rescaling code for x and y axis when generating
motion events.
This commit is contained in:
Magnus Vigerlöf 2008-02-02 22:57:32 +01:00
parent f04c083869
commit d9e23c4ff1

View File

@ -531,6 +531,7 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
DeviceIntPtr cp = inputInfo.pointer; DeviceIntPtr cp = inputInfo.pointer;
int x = 0, y = 0; int x = 0, y = 0;
Bool coreOnly = (pDev == inputInfo.pointer); Bool coreOnly = (pDev == inputInfo.pointer);
ScreenPtr scr = miPointerGetScreen(pDev);
/* Sanity checks. */ /* Sanity checks. */
if (type != MotionNotify && type != ButtonPress && type != ButtonRelease) if (type != MotionNotify && type != ButtonPress && type != ButtonRelease)
@ -574,20 +575,39 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
x = valuators[0]; x = valuators[0];
} }
else { else {
if (pDev->coreEvents) /* If we're sending core events but didn't provide a value,
x = cp->valuator->lastx; * translate the core value (but use the device coord if
else * it translates to the same coord to preserve sub-pixel
x = pDev->valuator->lastx; * coord information). If we're not sending core events use
* whatever value we have */
x = pDev->valuator->lastx;
if(pDev->coreEvents) {
int min = pDev->valuator->axes[0].min_value;
int max = pDev->valuator->axes[0].max_value;
if(min < max) {
if((int)((float)(x-min)*scr->width/(max-min+1)) != cp->valuator->lastx)
x = (int)((float)(cp->valuator->lastx)*(max-min+1)/scr->width)+min;
}
else
x = cp->valuator->lastx;
}
} }
if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) { if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) {
y = valuators[1 - first_valuator]; y = valuators[1 - first_valuator];
} }
else { else {
if (pDev->coreEvents) y = pDev->valuator->lasty;
y = cp->valuator->lasty; if(pDev->coreEvents) {
else int min = pDev->valuator->axes[1].min_value;
y = pDev->valuator->lasty; int max = pDev->valuator->axes[1].max_value;
if(min < max) {
if((int)((float)(y-min)*scr->height/(max-min+1)) != cp->valuator->lasty)
y = (int)((float)(cp->valuator->lasty)*(max-min+1)/scr->height)+min;
}
else
y = cp->valuator->lasty;
}
} }
} }
else { else {
@ -596,15 +616,35 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
valuators); valuators);
if (pDev->coreEvents) { if (pDev->coreEvents) {
if (first_valuator == 0 && num_valuators >= 1) /* Get and convert the core pointer coordinate space into
x = cp->valuator->lastx + valuators[0]; * device coordinates. Use the device coords if it translates
* into the same position as the core to preserve relative sub-
* pixel movements from the device. */
int min = pDev->valuator->axes[0].min_value;
int max = pDev->valuator->axes[0].max_value;
if(min < max) {
x = pDev->valuator->lastx;
if((int)((float)(x-min)*scr->width/(max-min+1)) != cp->valuator->lastx)
x = (int)((float)(cp->valuator->lastx)*(max-min+1)/scr->width)+min;
}
else else
x = cp->valuator->lastx; x = cp->valuator->lastx;
if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) min = pDev->valuator->axes[1].min_value;
y = cp->valuator->lasty + valuators[1 - first_valuator]; max = pDev->valuator->axes[1].max_value;
if(min < max) {
y = pDev->valuator->lasty;
if((int)((float)(y-min)*scr->height/(max-min+1)) != cp->valuator->lasty)
y = (int)((float)(cp->valuator->lasty)*(max-min+1)/scr->height)+min;
}
else else
y = cp->valuator->lasty; y = cp->valuator->lasty;
/* Add relative movement */
if (first_valuator == 0 && num_valuators >= 1)
x += valuators[0];
if (first_valuator <= 1 && num_valuators >= (2 - first_valuator))
y += valuators[1 - first_valuator];
} }
else { else {
if (first_valuator == 0 && num_valuators >= 1) if (first_valuator == 0 && num_valuators >= 1)
@ -623,11 +663,6 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
clipAxis(pDev, 0, &x); clipAxis(pDev, 0, &x);
clipAxis(pDev, 1, &y); clipAxis(pDev, 1, &y);
/* This takes care of crossing screens for us, as well as clipping
* to the current screen. Right now, we only have one history buffer,
* so we don't set this for both the device and core.*/
miPointerSetPosition(pDev, &x, &y, ms);
/* Drop x and y back into the valuators list, if they were originally /* Drop x and y back into the valuators list, if they were originally
* present. */ * present. */
if (first_valuator == 0 && num_valuators >= 1) if (first_valuator == 0 && num_valuators >= 1)
@ -637,12 +672,32 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
updateMotionHistory(pDev, ms, first_valuator, num_valuators, valuators); updateMotionHistory(pDev, ms, first_valuator, num_valuators, valuators);
pDev->valuator->lastx = x;
pDev->valuator->lasty = y;
/* Convert the dev coord back to screen coord if we're
* sending core events */
if (pDev->coreEvents) {
int min = pDev->valuator->axes[0].min_value;
int max = pDev->valuator->axes[0].max_value;
if(min < max)
x = (int)((float)(x-min)*scr->width/(max-min+1));
cp->valuator->lastx = x;
min = pDev->valuator->axes[1].min_value;
max = pDev->valuator->axes[1].max_value;
if(min < max)
y = (int)((float)(y-min)*scr->height/(max-min+1));
cp->valuator->lasty = y;
}
/* This takes care of crossing screens for us, as well as clipping
* to the current screen. Right now, we only have one history buffer,
* so we don't set this for both the device and core.*/
miPointerSetPosition(pDev, &x, &y, ms);
if (pDev->coreEvents) { if (pDev->coreEvents) {
cp->valuator->lastx = x; cp->valuator->lastx = x;
cp->valuator->lasty = y; cp->valuator->lasty = y;
} }
pDev->valuator->lastx = x;
pDev->valuator->lasty = y;
/* for some reason inputInfo.pointer does not have coreEvents set */ /* for some reason inputInfo.pointer does not have coreEvents set */
if (coreOnly || pDev->coreEvents) { if (coreOnly || pDev->coreEvents) {
@ -680,8 +735,8 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
kbp->detail = pDev->button->map[buttons]; kbp->detail = pDev->button->map[buttons];
} }
kbp->root_x = x; kbp->root_x = pDev->valuator->lastx;
kbp->root_y = y; kbp->root_y = pDev->valuator->lasty;
events++; events++;
if (num_valuators) { if (num_valuators) {