Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | * Copyright 2002-2003 Red Hat Inc., Durham, North Carolina. | |
3 | * | |
4 | * All Rights Reserved. | |
5 | * | |
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: | |
13 | * | |
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. | |
17 | * | |
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 | |
25 | * SOFTWARE. | |
26 | */ | |
27 | ||
28 | /* | |
29 | * Authors: | |
30 | * Rickard E. (Rik) Faith <faith@redhat.com> | |
31 | * | |
32 | */ | |
33 | ||
34 | /** \file | |
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. */ | |
40 | ||
41 | #ifdef HAVE_DMX_CONFIG_H | |
42 | #include <dmx-config.h> | |
43 | #endif | |
44 | ||
45 | #include "inputstr.h" | |
46 | #include "dmxinputinit.h" | |
47 | #include "dmxcommon.h" | |
48 | #include "dmxmotion.h" | |
49 | ||
50 | #define OFFSET(offset,element) ((offset) * (numAxes + 1) + (element)) | |
51 | ||
52 | /** Return size of motion buffer. \see DMX_MOTION_SIZE */ | |
53 | int | |
54 | dmxPointerGetMotionBufferSize(void) | |
55 | { | |
56 | return DMX_MOTION_SIZE; | |
57 | } | |
58 | ||
59 | /** This routine performs the same function as \a miPointerGetMotionEvents: | |
60 | * the events in the motion history that are between the start and stop | |
61 | * times (in mS) are placed in the coords vector, and the count of the | |
62 | * number of items so placed is returned. This routine is called from | |
63 | * dix/devices.c so that coords can hold valuator->numMotionEvents | |
64 | * events. This routine is called from \a Xi/gtmotion.c with coords large | |
65 | * enough to hold the same number of events in a variable-length | |
66 | * extended \a xTimecoord structure. This provides sufficient data for the | |
67 | * \a XGetDeviceMotionEvents library call, and would be identical to | |
68 | * \a miPointerGetMotionEvents for devices with only 2 axes (i.e., core | |
69 | * pointers) if \a xTimecoord used 32bit integers. | |
70 | * | |
71 | * Because DMX uses the mi* routines for all core devices, this routine | |
72 | * only has to support extension devices using the polymorphic coords. | |
73 | * Because compatibility with miPointerGetMotionEvents is not possible, | |
74 | * it is not provided. */ | |
75 | int | |
76 | dmxPointerGetMotionEvents(DeviceIntPtr pDevice, | |
77 | xTimecoord * coords, | |
78 | unsigned long start, | |
79 | unsigned long stop, ScreenPtr pScreen) | |
80 | { | |
81 | GETDMXLOCALFROMPDEVICE; | |
82 | int numAxes = pDevice->valuator->numAxes; | |
83 | unsigned long *c = (unsigned long *) coords; | |
84 | int count = 0; | |
85 | int i, j; | |
86 | ||
87 | if (!dmxLocal->history) | |
88 | return 0; | |
89 | for (i = dmxLocal->head; i != dmxLocal->tail;) { | |
90 | if (dmxLocal->history[OFFSET(i, 0)] >= stop) | |
91 | break; | |
92 | if (dmxLocal->history[OFFSET(i, 0)] >= start) { | |
93 | for (j = 0; j < numAxes + 1; j++) | |
94 | c[OFFSET(count, j)] = dmxLocal->history[OFFSET(i, j)]; | |
95 | ++count; | |
96 | } | |
97 | if (++i >= DMX_MOTION_SIZE) | |
98 | i = 0; | |
99 | } | |
100 | return count; | |
101 | } | |
102 | ||
103 | /** This routine adds an event to the motion history. A similar | |
104 | * function is performed by miPointerMove for the mi versions of these | |
105 | * routines. */ | |
106 | void | |
107 | dmxPointerPutMotionEvent(DeviceIntPtr pDevice, | |
108 | int firstAxis, int axesCount, int *v, | |
109 | unsigned long time) | |
110 | { | |
111 | GETDMXLOCALFROMPDEVICE; | |
112 | int numAxes = pDevice->valuator->numAxes; | |
113 | int i; | |
114 | ||
115 | if (!dmxLocal->history) { | |
116 | dmxLocal->history = malloc(sizeof(*dmxLocal->history) | |
117 | * (numAxes + 1) | |
118 | * DMX_MOTION_SIZE); | |
119 | dmxLocal->head = 0; | |
120 | dmxLocal->tail = 0; | |
121 | dmxLocal->valuators = calloc(sizeof(*dmxLocal->valuators), numAxes); | |
122 | } | |
123 | else { | |
124 | if (++dmxLocal->tail >= DMX_MOTION_SIZE) | |
125 | dmxLocal->tail = 0; | |
126 | if (dmxLocal->head == dmxLocal->tail) | |
127 | if (++dmxLocal->head >= DMX_MOTION_SIZE) | |
128 | dmxLocal->head = 0; | |
129 | } | |
130 | ||
131 | dmxLocal->history[OFFSET(dmxLocal->tail, 0)] = time; | |
132 | ||
133 | /* Initialize the data from the known | |
134 | * values (if Absolute) or to zero (if | |
135 | * Relative) */ | |
136 | for (i = 0; i < numAxes; i++) { | |
137 | if (pDevice->valuator->axes[i].mode == Absolute) | |
138 | dmxLocal->history[OFFSET(dmxLocal->tail, i + 1)] | |
139 | = dmxLocal->valuators[i]; | |
140 | else | |
141 | dmxLocal->history[OFFSET(dmxLocal->tail, i + 1)] = 0; | |
142 | } | |
143 | ||
144 | for (i = firstAxis; i < axesCount; i++) { | |
145 | dmxLocal->history[OFFSET(dmxLocal->tail, i + i)] | |
146 | = (unsigned long) v[i - firstAxis]; | |
147 | dmxLocal->valuators[i] = v[i - firstAxis]; | |
148 | } | |
149 | } |