~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/dmx/input/dmxmotion.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86$ */
 
2
/*
 
3
 * Copyright 2002-2003 Red Hat Inc., Durham, North Carolina.
 
4
 *
 
5
 * All Rights Reserved.
 
6
 *
 
7
 * Permission is hereby granted, free of charge, to any person obtaining
 
8
 * a copy of this software and associated documentation files (the
 
9
 * "Software"), to deal in the Software without restriction, including
 
10
 * without limitation on the rights to use, copy, modify, merge,
 
11
 * publish, distribute, sublicense, and/or sell copies of the Software,
 
12
 * and to permit persons to whom the Software is furnished to do so,
 
13
 * subject to the following conditions:
 
14
 *
 
15
 * The above copyright notice and this permission notice (including the
 
16
 * next paragraph) shall be included in all copies or substantial
 
17
 * portions of the Software.
 
18
 *
 
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
20
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
21
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
22
 * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
 
23
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
24
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
25
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
26
 * SOFTWARE.
 
27
 */
 
28
 
 
29
/*
 
30
 * Authors:
 
31
 *   Rickard E. (Rik) Faith <faith@redhat.com>
 
32
 *
 
33
 */
 
34
 
 
35
/** \file
 
36
 * This file provides functions similar to miPointerGetMotionEvents and
 
37
 * miPointerPutMotionEvents, with the exception that devices with more
 
38
 * than two axes are fully supported.  These routines may be used only
 
39
 * for motion buffers for extension devices, and are \a not compatible
 
40
 * replacements for the mi routines.  */
 
41
 
 
42
#ifdef HAVE_DMX_CONFIG_H
 
43
#include <dmx-config.h>
 
44
#endif
 
45
 
 
46
#include "inputstr.h"
 
47
#include "dmxinputinit.h"
 
48
#include "dmxcommon.h"
 
49
#include "dmxmotion.h"
 
50
 
 
51
#define OFFSET(offset,element) ((offset) * (numAxes + 1) + (element))
 
52
 
 
53
/** Return size of motion buffer. \see DMX_MOTION_SIZE */
 
54
int 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 dmxPointerGetMotionEvents(DeviceIntPtr pDevice,
 
76
                              xTimecoord *coords,
 
77
                              unsigned long start,
 
78
                              unsigned long stop,
 
79
                              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) return 0;
 
88
    for (i = dmxLocal->head; i != dmxLocal->tail;) {
 
89
        if (dmxLocal->history[OFFSET(i,0)] >= stop) break;
 
90
        if (dmxLocal->history[OFFSET(i,0)] >= start) {
 
91
            for (j = 0; j < numAxes + 1; j++)
 
92
                c[OFFSET(count,j)] = dmxLocal->history[OFFSET(i,j)];
 
93
            ++count;
 
94
        }
 
95
        if (++i >= DMX_MOTION_SIZE) i = 0;
 
96
    }
 
97
    return count;
 
98
}
 
99
 
 
100
/** This routine adds an event to the motion history.  A similar
 
101
 * function is performed by miPointerMove for the mi versions of these
 
102
 * routines. */
 
103
void dmxPointerPutMotionEvent(DeviceIntPtr pDevice,
 
104
                              int firstAxis, int axesCount, int *v,
 
105
                              unsigned long time)
 
106
{
 
107
    GETDMXLOCALFROMPDEVICE;
 
108
    int           numAxes = pDevice->valuator->numAxes;
 
109
    int           i;
 
110
 
 
111
    if (!dmxLocal->history) {
 
112
        dmxLocal->history   = xalloc(sizeof(*dmxLocal->history)
 
113
                                     * (numAxes + 1)
 
114
                                     * DMX_MOTION_SIZE);
 
115
        dmxLocal->head      = 0;
 
116
        dmxLocal->tail      = 0;
 
117
        dmxLocal->valuators = xalloc(sizeof(*dmxLocal->valuators) * numAxes);
 
118
        memset(dmxLocal->valuators, 0, sizeof(*dmxLocal->valuators) * numAxes);
 
119
    } else {
 
120
        if (++dmxLocal->tail >= DMX_MOTION_SIZE) dmxLocal->tail = 0;
 
121
        if (dmxLocal->head == dmxLocal->tail)
 
122
            if (++dmxLocal->head >= DMX_MOTION_SIZE) dmxLocal->head = 0;
 
123
    }
 
124
 
 
125
    dmxLocal->history[OFFSET(dmxLocal->tail,0)] = time;
 
126
 
 
127
                                /* Initialize the data from the known
 
128
                                 * values (if Absolute) or to zero (if
 
129
                                 * Relative) */
 
130
    if (pDevice->valuator->mode == Absolute) {
 
131
        for (i = 0; i < numAxes; i++) 
 
132
            dmxLocal->history[OFFSET(dmxLocal->tail,i+1)]
 
133
                = dmxLocal->valuators[i];
 
134
    } else {
 
135
        for (i = 0; i < numAxes; i++) 
 
136
            dmxLocal->history[OFFSET(dmxLocal->tail,i+1)] = 0;
 
137
    }
 
138
    
 
139
    for (i = firstAxis; i < axesCount; i++) {
 
140
        dmxLocal->history[OFFSET(dmxLocal->tail,i+i)]
 
141
            = (unsigned long)v[i-firstAxis];
 
142
        dmxLocal->valuators[i] = v[i-firstAxis];
 
143
    }
 
144
}