summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter@cs.unisa.edu.au>2008-05-26 16:35:23 +0930
committerPeter Hutterer <peter@cs.unisa.edu.au>2008-05-26 17:22:25 +0930
commit1883485edd7eb90c0b76bca41c71e26ae2c0b91a (patch)
tree177b0cdb290d3bd647768f0d6f559ad741928e1e
parent0b88510069bdf6d020d73b424f62c2923c0db4a4 (diff)
If core motion history is required, scale back to screen coords and INT16.
-rw-r--r--Xi/gtmotion.c2
-rw-r--r--dix/devices.c9
-rw-r--r--dix/getevents.c46
-rw-r--r--hw/xfree86/common/xf86Helper.c4
-rw-r--r--hw/xfree86/common/xf86Xinput.h2
-rw-r--r--include/input.h3
6 files changed, 51 insertions, 15 deletions
diff --git a/Xi/gtmotion.c b/Xi/gtmotion.c
index 8b59d67ec..7cc5c2670 100644
--- a/Xi/gtmotion.c
+++ b/Xi/gtmotion.c
@@ -135,7 +135,7 @@ ProcXGetDeviceMotionEvents(ClientPtr client)
size = sizeof(Time) + (axes * sizeof(INT32));
rep.nEvents = GetMotionHistory(dev, (xTimecoord **) &coords,/* XXX */
start.milliseconds, stop.milliseconds,
- (ScreenPtr) NULL);
+ (ScreenPtr) NULL, FALSE);
}
if (rep.nEvents > 0) {
length = (rep.nEvents * size + 3) >> 2;
diff --git a/dix/devices.c b/dix/devices.c
index 9db276b16..60d48b25e 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2308,12 +2308,9 @@ ProcGetMotionEvents(ClientPtr client)
{
if (CompareTimeStamps(stop, currentTime) == LATER)
stop = currentTime;
- coords = (xTimecoord *)xalloc(mouse->valuator->numMotionEvents
- * sizeof(xTimecoord));
- if (!coords)
- return BadAlloc;
- count = GetMotionHistory(mouse, coords, start.milliseconds,
- stop.milliseconds, pWin->drawable.pScreen);
+ count = GetMotionHistory(mouse, &coords, start.milliseconds,
+ stop.milliseconds, pWin->drawable.pScreen,
+ TRUE);
xmin = pWin->drawable.x - wBorderWidth (pWin);
xmax = pWin->drawable.x + (int)pWin->drawable.width +
wBorderWidth (pWin);
diff --git a/dix/getevents.c b/dix/getevents.c
index 349823dc8..643e97763 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -258,15 +258,16 @@ AllocateMotionHistory(DeviceIntPtr pDev)
pDev->name, size * pDev->valuator->numMotionEvents);
}
-
/**
* Dump the motion history between start and stop into the supplied buffer.
* Only records the event for a given screen in theory, but in practice, we
* sort of ignore this.
+ *
+ * If core is set, we only generate x/y, in INT16, scaled to screen coords.
*/
_X_EXPORT int
GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
- unsigned long stop, ScreenPtr pScreen)
+ unsigned long stop, ScreenPtr pScreen, BOOL core)
{
char *ibuff = NULL, *obuff;
int i = 0, ret = 0;
@@ -277,10 +278,15 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
int dflt;
AxisInfo from, *to; /* for scaling */
CARD32 *ocbuf, *icbuf; /* pointer to coordinates for copying */
+ INT16 *corebuf;
+ AxisInfo core_axis = {0};
if (!pDev->valuator || !pDev->valuator->numMotionEvents)
return 0;
+ if (core && !pScreen)
+ return 0;
+
if (pDev->isMaster)
size = (sizeof(INT32) * 3 * MAX_VALUATORS) + sizeof(Time);
else
@@ -304,7 +310,36 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
return ret;
}
else if (current >= start) {
- if (pDev->isMaster)
+ if (core)
+ {
+ memcpy(obuff, ibuff, sizeof(Time)); /* copy timestamp */
+
+ icbuf = (INT32*)(ibuff + sizeof(Time));
+ corebuf = (INT16*)(obuff + sizeof(Time));
+
+ /* fetch x coordinate + range */
+ memcpy(&from.min_value, icbuf++, sizeof(INT32));
+ memcpy(&from.max_value, icbuf++, sizeof(INT32));
+ memcpy(&coord, icbuf++, sizeof(INT32));
+
+ /* scale to screen coords */
+ to = &core_axis;
+ to->max_value = pScreen->width;
+ coord = rescaleValuatorAxis(coord, &from, to, pScreen->width);
+
+ memcpy(corebuf, &coord, sizeof(INT16));
+ corebuf++;
+
+ /* fetch y coordinate + range */
+ memcpy(&from.min_value, icbuf++, sizeof(INT32));
+ memcpy(&from.max_value, icbuf++, sizeof(INT32));
+ memcpy(&coord, icbuf++, sizeof(INT32));
+
+ to->max_value = pScreen->height;
+ coord = rescaleValuatorAxis(coord, &from, to, pScreen->height);
+ memcpy(corebuf, &coord, sizeof(INT16));
+
+ } else if (pDev->isMaster)
{
memcpy(obuff, ibuff, sizeof(Time)); /* copy timestamp */
@@ -345,7 +380,10 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start,
/* don't advance by size here. size may be different to the
* actually written size if the MD has less valuators than MAX */
- obuff += (sizeof(INT32) * pDev->valuator->numAxes) + sizeof(Time);
+ if (core)
+ obuff += sizeof(INT32) + sizeof(Time);
+ else
+ obuff += (sizeof(INT32) * pDev->valuator->numAxes) + sizeof(Time);
ret++;
}
}
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 1dd0bbc0d..eaa6c76fb 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -2933,9 +2933,9 @@ xf86MotionHistoryAllocate(LocalDevicePtr local)
_X_EXPORT int
xf86GetMotionEvents(DeviceIntPtr pDev, xTimecoord *buff, unsigned long start,
- unsigned long stop, ScreenPtr pScreen)
+ unsigned long stop, ScreenPtr pScreen, BOOL core)
{
- return GetMotionHistory(pDev, buff, start, stop, pScreen);
+ return GetMotionHistory(pDev, buff, start, stop, pScreen, core);
}
_X_EXPORT void
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index dd72ec733..02f657de3 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -197,7 +197,7 @@ void xf86DeleteInput(InputInfoPtr pInp, int flags);
void xf86MotionHistoryAllocate(LocalDevicePtr local);
int xf86GetMotionEvents(DeviceIntPtr dev, xTimecoord *buff,
unsigned long start, unsigned long stop,
- ScreenPtr pScreen);
+ ScreenPtr pScreen, BOOL core);
/* xf86Option.c */
void xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts,
diff --git a/include/input.h b/include/input.h
index 3071d75de..a816385a5 100644
--- a/include/input.h
+++ b/include/input.h
@@ -486,7 +486,8 @@ extern int GetMotionHistory(
xTimecoord **buff,
unsigned long start,
unsigned long stop,
- ScreenPtr pScreen);
+ ScreenPtr pScreen,
+ BOOL core);
extern void SwitchCorePointer(DeviceIntPtr pDev);