2 * Copyright 2002 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>
36 * This code implements a low-level device driver for a USB mouse. */
38 #ifdef HAVE_DMX_CONFIG_H
39 #include <dmx-config.h>
42 #include "usb-private.h"
44 /*****************************************************************************/
45 /* Define some macros to make it easier to move this file to another
46 * part of the Xserver tree. All calls to the dmx* layer are #defined
47 * here for the .c file. The .h file will also have to be edited. */
48 #include "usb-mouse.h"
50 #define GETPRIV myPrivate *priv \
51 = ((DMXLocalInputInfoPtr)(pDev->devicePrivate))->private
53 #define LOG0(f) dmxLog(dmxDebug,f)
54 #define LOG1(f,a) dmxLog(dmxDebug,f,a)
55 #define LOG2(f,a,b) dmxLog(dmxDebug,f,a,b)
56 #define LOG3(f,a,b,c) dmxLog(dmxDebug,f,a,b,c)
57 #define FATAL0(f) dmxLog(dmxFatal,f)
58 #define FATAL1(f,a) dmxLog(dmxFatal,f,a)
59 #define FATAL2(f,a,b) dmxLog(dmxFatal,f,a,b)
60 #define MOTIONPROC dmxMotionProcPtr
61 #define ENQUEUEPROC dmxEnqueueProcPtr
62 #define CHECKPROC dmxCheckSpecialProcPtr
63 #define BLOCK DMXBlockType
65 /* End of interface definitions. */
66 /*****************************************************************************/
68 /** Read the USB device using #usbRead. */
69 void mouUSBRead(DevicePtr pDev
,
72 CHECKPROC checkspecial
,
75 usbRead(pDev
, motion
, enqueue
, BTN_MISC
, block
);
78 /** Initialize \a pDev using #usbInit. */
79 void mouUSBInit(DevicePtr pDev
)
81 usbInit(pDev
, usbMouse
);
84 /** Turn \a pDev on (i.e., take input from \a pDev). */
85 int mouUSBOn(DevicePtr pDev
)
89 if (priv
->fd
< 0) mouUSBInit(pDev
);
93 static void mouUSBGetMap(DevicePtr pDev
, unsigned char *map
, int *nButtons
)
97 if (nButtons
) *nButtons
= 5;
98 if (map
) for (i
= 0; i
<= *nButtons
; i
++) map
[i
] = i
;
101 /** Fill the \a info structure with information needed to initialize \a
103 void mouUSBGetInfo(DevicePtr pDev
, DMXLocalInitInfoPtr info
)
105 static KeySym keyboard_mapping
= NoSymbol
;
107 info
->buttonClass
= 1;
108 mouUSBGetMap(pDev
, info
->map
, &info
->numButtons
);
109 info
->valuatorClass
= 1;
110 info
->numRelAxes
= 2;
116 info
->ptrFeedbackClass
= 1;
118 /* Some USB mice devices return key
119 * events from their pair'd
122 info
->keySyms
.minKeyCode
= 8;
123 info
->keySyms
.maxKeyCode
= 8;
124 info
->keySyms
.mapWidth
= 1;
125 info
->keySyms
.map
= &keyboard_mapping
;