Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | * Copyright 2002 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 | * | |
36 | * This code implements a low-level device driver for a USB mouse. */ | |
37 | ||
38 | #ifdef HAVE_DMX_CONFIG_H | |
39 | #include <dmx-config.h> | |
40 | #endif | |
41 | ||
42 | #include "usb-private.h" | |
43 | ||
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" | |
49 | ||
50 | #define GETPRIV myPrivate *priv \ | |
51 | = ((DMXLocalInputInfoPtr)(pDev->devicePrivate))->private | |
52 | ||
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 | |
64 | ||
65 | /* End of interface definitions. */ | |
66 | /*****************************************************************************/ | |
67 | ||
68 | /** Read the USB device using #usbRead. */ | |
69 | void | |
70 | mouUSBRead(DevicePtr pDev, | |
71 | MOTIONPROC motion, | |
72 | ENQUEUEPROC enqueue, CHECKPROC checkspecial, BLOCK block) | |
73 | { | |
74 | usbRead(pDev, motion, enqueue, BTN_MISC, block); | |
75 | } | |
76 | ||
77 | /** Initialize \a pDev using #usbInit. */ | |
78 | void | |
79 | mouUSBInit(DevicePtr pDev) | |
80 | { | |
81 | usbInit(pDev, usbMouse); | |
82 | } | |
83 | ||
84 | /** Turn \a pDev on (i.e., take input from \a pDev). */ | |
85 | int | |
86 | mouUSBOn(DevicePtr pDev) | |
87 | { | |
88 | GETPRIV; | |
89 | ||
90 | if (priv->fd < 0) | |
91 | mouUSBInit(pDev); | |
92 | return priv->fd; | |
93 | } | |
94 | ||
95 | static void | |
96 | mouUSBGetMap(DevicePtr pDev, unsigned char *map, int *nButtons) | |
97 | { | |
98 | int i; | |
99 | ||
100 | if (nButtons) | |
101 | *nButtons = 5; | |
102 | if (map) | |
103 | for (i = 0; i <= *nButtons; i++) | |
104 | map[i] = i; | |
105 | } | |
106 | ||
107 | /** Fill the \a info structure with information needed to initialize \a | |
108 | * pDev. */ | |
109 | void | |
110 | mouUSBGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info) | |
111 | { | |
112 | static KeySym keyboard_mapping = NoSymbol; | |
113 | ||
114 | info->buttonClass = 1; | |
115 | mouUSBGetMap(pDev, info->map, &info->numButtons); | |
116 | info->valuatorClass = 1; | |
117 | info->numRelAxes = 2; | |
118 | info->minval[0] = 0; | |
119 | info->maxval[0] = 0; | |
120 | info->res[0] = 1; | |
121 | info->minres[0] = 0; | |
122 | info->maxres[0] = 1; | |
123 | info->ptrFeedbackClass = 1; | |
124 | ||
125 | /* Some USB mice devices return key | |
126 | * events from their pair'd | |
127 | * keyboard... */ | |
128 | info->keyClass = 1; | |
129 | info->keySyms.minKeyCode = 8; | |
130 | info->keySyms.maxKeyCode = 8; | |
131 | info->keySyms.mapWidth = 1; | |
132 | info->keySyms.map = &keyboard_mapping; | |
133 | } |