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