1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2002-2003 Red Hat Inc., Durham, North Carolina.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * All Rights Reserved.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining
7*4882a593Smuzhiyun * a copy of this software and associated documentation files (the
8*4882a593Smuzhiyun * "Software"), to deal in the Software without restriction, including
9*4882a593Smuzhiyun * without limitation on the rights to use, copy, modify, merge,
10*4882a593Smuzhiyun * publish, distribute, sublicense, and/or sell copies of the Software,
11*4882a593Smuzhiyun * and to permit persons to whom the Software is furnished to do so,
12*4882a593Smuzhiyun * subject to the following conditions:
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * The above copyright notice and this permission notice (including the
15*4882a593Smuzhiyun * next paragraph) shall be included in all copies or substantial
16*4882a593Smuzhiyun * portions of the Software.
17*4882a593Smuzhiyun *
18*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19*4882a593Smuzhiyun * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20*4882a593Smuzhiyun * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21*4882a593Smuzhiyun * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22*4882a593Smuzhiyun * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23*4882a593Smuzhiyun * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24*4882a593Smuzhiyun * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25*4882a593Smuzhiyun * SOFTWARE.
26*4882a593Smuzhiyun */
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun * Authors:
30*4882a593Smuzhiyun * Rickard E. (Rik) Faith <faith@redhat.com>
31*4882a593Smuzhiyun *
32*4882a593Smuzhiyun */
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun /** \file
35*4882a593Smuzhiyun * This file provides functions similar to miPointerGetMotionEvents and
36*4882a593Smuzhiyun * miPointerPutMotionEvents, with the exception that devices with more
37*4882a593Smuzhiyun * than two axes are fully supported. These routines may be used only
38*4882a593Smuzhiyun * for motion buffers for extension devices, and are \a not compatible
39*4882a593Smuzhiyun * replacements for the mi routines. */
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun #ifdef HAVE_DMX_CONFIG_H
42*4882a593Smuzhiyun #include <dmx-config.h>
43*4882a593Smuzhiyun #endif
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun #include "inputstr.h"
46*4882a593Smuzhiyun #include "dmxinputinit.h"
47*4882a593Smuzhiyun #include "dmxcommon.h"
48*4882a593Smuzhiyun #include "dmxmotion.h"
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun #define OFFSET(offset,element) ((offset) * (numAxes + 1) + (element))
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun /** Return size of motion buffer. \see DMX_MOTION_SIZE */
53*4882a593Smuzhiyun int
dmxPointerGetMotionBufferSize(void)54*4882a593Smuzhiyun dmxPointerGetMotionBufferSize(void)
55*4882a593Smuzhiyun {
56*4882a593Smuzhiyun return DMX_MOTION_SIZE;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /** This routine performs the same function as \a miPointerGetMotionEvents:
60*4882a593Smuzhiyun * the events in the motion history that are between the start and stop
61*4882a593Smuzhiyun * times (in mS) are placed in the coords vector, and the count of the
62*4882a593Smuzhiyun * number of items so placed is returned. This routine is called from
63*4882a593Smuzhiyun * dix/devices.c so that coords can hold valuator->numMotionEvents
64*4882a593Smuzhiyun * events. This routine is called from \a Xi/gtmotion.c with coords large
65*4882a593Smuzhiyun * enough to hold the same number of events in a variable-length
66*4882a593Smuzhiyun * extended \a xTimecoord structure. This provides sufficient data for the
67*4882a593Smuzhiyun * \a XGetDeviceMotionEvents library call, and would be identical to
68*4882a593Smuzhiyun * \a miPointerGetMotionEvents for devices with only 2 axes (i.e., core
69*4882a593Smuzhiyun * pointers) if \a xTimecoord used 32bit integers.
70*4882a593Smuzhiyun *
71*4882a593Smuzhiyun * Because DMX uses the mi* routines for all core devices, this routine
72*4882a593Smuzhiyun * only has to support extension devices using the polymorphic coords.
73*4882a593Smuzhiyun * Because compatibility with miPointerGetMotionEvents is not possible,
74*4882a593Smuzhiyun * it is not provided. */
75*4882a593Smuzhiyun int
dmxPointerGetMotionEvents(DeviceIntPtr pDevice,xTimecoord * coords,unsigned long start,unsigned long stop,ScreenPtr pScreen)76*4882a593Smuzhiyun dmxPointerGetMotionEvents(DeviceIntPtr pDevice,
77*4882a593Smuzhiyun xTimecoord * coords,
78*4882a593Smuzhiyun unsigned long start,
79*4882a593Smuzhiyun unsigned long stop, ScreenPtr pScreen)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun GETDMXLOCALFROMPDEVICE;
82*4882a593Smuzhiyun int numAxes = pDevice->valuator->numAxes;
83*4882a593Smuzhiyun unsigned long *c = (unsigned long *) coords;
84*4882a593Smuzhiyun int count = 0;
85*4882a593Smuzhiyun int i, j;
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun if (!dmxLocal->history)
88*4882a593Smuzhiyun return 0;
89*4882a593Smuzhiyun for (i = dmxLocal->head; i != dmxLocal->tail;) {
90*4882a593Smuzhiyun if (dmxLocal->history[OFFSET(i, 0)] >= stop)
91*4882a593Smuzhiyun break;
92*4882a593Smuzhiyun if (dmxLocal->history[OFFSET(i, 0)] >= start) {
93*4882a593Smuzhiyun for (j = 0; j < numAxes + 1; j++)
94*4882a593Smuzhiyun c[OFFSET(count, j)] = dmxLocal->history[OFFSET(i, j)];
95*4882a593Smuzhiyun ++count;
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun if (++i >= DMX_MOTION_SIZE)
98*4882a593Smuzhiyun i = 0;
99*4882a593Smuzhiyun }
100*4882a593Smuzhiyun return count;
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /** This routine adds an event to the motion history. A similar
104*4882a593Smuzhiyun * function is performed by miPointerMove for the mi versions of these
105*4882a593Smuzhiyun * routines. */
106*4882a593Smuzhiyun void
dmxPointerPutMotionEvent(DeviceIntPtr pDevice,int firstAxis,int axesCount,int * v,unsigned long time)107*4882a593Smuzhiyun dmxPointerPutMotionEvent(DeviceIntPtr pDevice,
108*4882a593Smuzhiyun int firstAxis, int axesCount, int *v,
109*4882a593Smuzhiyun unsigned long time)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun GETDMXLOCALFROMPDEVICE;
112*4882a593Smuzhiyun int numAxes = pDevice->valuator->numAxes;
113*4882a593Smuzhiyun int i;
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun if (!dmxLocal->history) {
116*4882a593Smuzhiyun dmxLocal->history = xallocarray(numAxes + 1,
117*4882a593Smuzhiyun sizeof(*dmxLocal->history) * DMX_MOTION_SIZE);
118*4882a593Smuzhiyun dmxLocal->head = 0;
119*4882a593Smuzhiyun dmxLocal->tail = 0;
120*4882a593Smuzhiyun dmxLocal->valuators = calloc(sizeof(*dmxLocal->valuators), numAxes);
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun else {
123*4882a593Smuzhiyun if (++dmxLocal->tail >= DMX_MOTION_SIZE)
124*4882a593Smuzhiyun dmxLocal->tail = 0;
125*4882a593Smuzhiyun if (dmxLocal->head == dmxLocal->tail)
126*4882a593Smuzhiyun if (++dmxLocal->head >= DMX_MOTION_SIZE)
127*4882a593Smuzhiyun dmxLocal->head = 0;
128*4882a593Smuzhiyun }
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun dmxLocal->history[OFFSET(dmxLocal->tail, 0)] = time;
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun /* Initialize the data from the known
133*4882a593Smuzhiyun * values (if Absolute) or to zero (if
134*4882a593Smuzhiyun * Relative) */
135*4882a593Smuzhiyun for (i = 0; i < numAxes; i++) {
136*4882a593Smuzhiyun if (pDevice->valuator->axes[i].mode == Absolute)
137*4882a593Smuzhiyun dmxLocal->history[OFFSET(dmxLocal->tail, i + 1)]
138*4882a593Smuzhiyun = dmxLocal->valuators[i];
139*4882a593Smuzhiyun else
140*4882a593Smuzhiyun dmxLocal->history[OFFSET(dmxLocal->tail, i + 1)] = 0;
141*4882a593Smuzhiyun }
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun for (i = firstAxis; i < axesCount; i++) {
144*4882a593Smuzhiyun dmxLocal->history[OFFSET(dmxLocal->tail, i + i)]
145*4882a593Smuzhiyun = (unsigned long) v[i - firstAxis];
146*4882a593Smuzhiyun dmxLocal->valuators[i] = v[i - firstAxis];
147*4882a593Smuzhiyun }
148*4882a593Smuzhiyun }
149