Magellan Linux

Contents of /trunk/xorg-old/patches-6.8.2-r10/9002_all_6.7.0-lnx-evdev-mouse.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 167 - (show annotations) (download)
Tue May 8 20:58:51 2007 UTC (17 years ago) by niro
File size: 8385 byte(s)
-import

1 diff -Nurd xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c xc-patched/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c
2 --- xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c 2003-10-10 07:06:39.000000000 -0400
3 +++ xc-patched/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c 2003-12-01 12:54:34.757487668 -0500
4 @@ -6,12 +6,21 @@
5
6 #include "X.h"
7 #include "xf86.h"
8 +#include "xf86Priv.h"
9 #include "xf86Xinput.h"
10 #include "xf86OSmouse.h"
11 #include "xf86_OSlib.h"
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
15 +#include "mipointer.h"
16 +#include "lnx_evdev.h"
17 +
18 +/* Names of protocols that are handled internally here. */
19 +static const char *internalNames[] = {
20 + "evdev",
21 + NULL
22 +};
23
24 static int
25 SupportedInterfaces(void)
26 @@ -185,6 +194,272 @@
27 return NULL;
28 }
29
30 +static const char **
31 +BuiltinNames(void)
32 +{
33 + return internalNames;
34 +}
35 +
36 +static Bool
37 +CheckProtocol(const char *protocol)
38 +{
39 + int i;
40 +
41 + for (i = 0; internalNames[i]; i++)
42 + if (xf86NameCmp(protocol, internalNames[i]) == 0)
43 + return TRUE;
44 + return FALSE;
45 +}
46 +
47 +typedef struct _evdevMseRec {
48 + int packetSize;
49 + int buttons;
50 + Bool sync;
51 + evdevDriver evdev;
52 +} evdevMseRec, *evdevMsePtr;
53 +
54 +static void
55 +evdevMouseReadInput(InputInfoPtr pInfo)
56 +{
57 + MouseDevPtr pMse;
58 + evdevMsePtr evdevMse;
59 + struct input_event *ev;
60 + int n, bit;
61 + int dx = 0, dy = 0, dz = 0, dw = 0;
62 +
63 + pMse = pInfo->private;
64 + ev = (struct input_event *) pMse->buffer;
65 + evdevMse = pMse->mousePriv;
66 +
67 + if (pInfo->fd == -1)
68 + return;
69 +
70 + do {
71 + n = read(pInfo->fd, pMse->buffer, sizeof(struct input_event));
72 + if (n == -1) {
73 + xf86Msg(X_ERROR, "%s: Error in reading! (%s) Disabiling.\n",
74 + pInfo->name, strerror(errno));
75 + RemoveEnabledDevice(pInfo->fd);
76 + xf86RemoveSIGIOHandler(pInfo->fd);
77 + close (pInfo->fd);
78 + pMse->device->public.on = FALSE;
79 + pInfo->fd = -1;
80 + pMse->PostEvent(pInfo, evdevMse->buttons, dx, dy, dz, dw);
81 + return;
82 + }
83 + if (n != sizeof(struct input_event)) {
84 + xf86Msg(X_WARNING, "%s: incomplete packet, size %d\n", pInfo->name, n);
85 + pMse->PostEvent(pInfo, evdevMse->buttons, dx, dy, dz, dw);
86 + return;
87 + }
88 +
89 + switch (ev->type) {
90 + case EV_REL:
91 + switch (ev->code) {
92 + case EV_REL_X:
93 + dx += ev->value;
94 + break;
95 + case EV_REL_Y:
96 + dy += ev->value;
97 + break;
98 + case EV_REL_Z:
99 + case EV_REL_WHEEL:
100 + dz -= ev->value;
101 + break;
102 + case EV_REL_HWHEEL:
103 + dw -= ev->value;
104 + break;
105 + }
106 + break;
107 + case EV_KEY:
108 + if ((ev->code < EV_BTN_MOUSE) || (ev->code >= EV_BTN_JOYSTICK))
109 + break;
110 + switch (ev->code) {
111 + case EV_BTN_RIGHT: bit = 1 << 0; break; /* 1 */
112 + case EV_BTN_MIDDLE: bit = 1 << 1; break; /* 2 */
113 + case EV_BTN_LEFT: bit = 1 << 2; break; /* 3 */
114 + default: bit = 1 << (ev->code - EV_BTN_MOUSE); break;
115 + }
116 + evdevMse->buttons &= ~bit;
117 + if (ev->value)
118 + evdevMse->buttons |= bit;
119 + break;
120 + case EV_SYN:
121 + switch (ev->code) {
122 + case EV_SYN_REPORT:
123 + pMse->PostEvent(pInfo,evdevMse->buttons,dx, dy, dz, dw);
124 + dx = dy = dz = dw = 0;
125 + break;
126 + }
127 + break;
128 + }
129 + if (!evdevMse->sync) {
130 + pMse->PostEvent(pInfo,evdevMse->buttons,dx, dy, dz, dw);
131 + dx = dy = dz = dw = 0;
132 + }
133 + } while (xf86WaitForInput(pInfo->fd, 0));
134 +
135 + pMse->PostEvent(pInfo, evdevMse->buttons, dx, dy, dz, dw);
136 +
137 + return;
138 +}
139 +
140 +static void
141 +evdevMouseSigioReadInput (int fd, void *closure)
142 +{
143 + evdevMouseReadInput ((InputInfoPtr) closure);
144 +}
145 +
146 +static int
147 +evdevMouseProc(DeviceIntPtr pPointer, int what)
148 +{
149 + InputInfoPtr pInfo;
150 + MouseDevPtr pMse;
151 + evdevMsePtr evdevMse;
152 + unsigned char map[MSE_MAXBUTTONS + 1];
153 + int i, j, blocked;
154 + unsigned long evtype_bits[NBITS(EV_MAX)];
155 + unsigned long evkey_bits[NBITS(EV_KEY_MAX)];
156 +
157 + pInfo = pPointer->public.devicePrivate;
158 + pMse = pInfo->private;
159 + pMse->device = pPointer;
160 + evdevMse = pMse->mousePriv;
161 +
162 + switch (what) {
163 + case DEVICE_INIT:
164 + pPointer->public.on = FALSE;
165 +
166 + evdevMse->evdev.name = xf86SetStrOption(pInfo->options,"Dev Name",NULL);
167 + evdevMse->evdev.phys = xf86SetStrOption(pInfo->options,"Dev Phys",NULL);
168 + evdevMse->evdev.cb_data = pInfo->dev;
169 + evdevMse->evdev.callback = evdevMouseProc;
170 + if (!evdevNewDriver (&evdevMse->evdev)) {
171 + xf86Msg(X_ERROR, "%s: cannot register with evdev brain\n", pInfo->name);
172 + return BadRequest;
173 + }
174 + if ((pInfo->fd = evdevGetFDForDriver (&evdevMse->evdev)) == -1) {
175 + xf86Msg(X_ERROR, "%s: cannot open input device\n", pInfo->name);
176 + return BadRequest;
177 + }
178 +
179 + ioctl(pInfo->fd, EVIOCGBIT(0, EV_MAX), evtype_bits);
180 + if (test_bit(EV_SYN, evtype_bits))
181 + evdevMse->sync = TRUE;
182 + else
183 + evdevMse->sync = FALSE;
184 +
185 + if (test_bit(EV_KEY, evtype_bits)) {
186 + ioctl(pInfo->fd, EVIOCGBIT(EV_KEY, EV_KEY_MAX), evkey_bits);
187 + i = EV_BTN_LEFT;
188 + for (i = EV_BTN_LEFT, j = 0; i <= EV_BTN_BACK; i++)
189 + if (test_bit(i, evkey_bits))
190 + j = i - EV_BTN_LEFT;
191 + if (++j > pMse->buttons) pMse->buttons = j;
192 + }
193 +
194 + close(pInfo->fd);
195 + pInfo->fd = -1;
196 +
197 + for (i = 0; i < MSE_MAXBUTTONS; ++i)
198 + map[i + 1] = i + 1;
199 +
200 + InitPointerDeviceStruct((DevicePtr)pPointer, map,
201 + min(pMse->buttons, MSE_MAXBUTTONS),
202 + miPointerGetMotionEvents, pMse->Ctrl,
203 + miPointerGetMotionBufferSize());
204 +
205 + /* X valuator */
206 + xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
207 + xf86InitValuatorDefaults(pPointer, 0);
208 + /* Y valuator */
209 + xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
210 + xf86InitValuatorDefaults(pPointer, 1);
211 + xf86MotionHistoryAllocate(pInfo);
212 + break;
213 +
214 + case DEVICE_ON:
215 + if (pPointer->public.on)
216 + break;
217 + if ((pInfo->fd = evdevGetFDForDriver (&evdevMse->evdev)) == -1) {
218 + xf86Msg(X_ERROR, "%s: cannot open input device (name: '%s', phys: '%s')\n", pInfo->name, evdevMse->evdev.name, evdevMse->evdev.phys);
219 + return BadRequest;
220 + }
221 +
222 + xf86FlushInput(pInfo->fd);
223 + if (!xf86InstallSIGIOHandler (pInfo->fd, evdevMouseSigioReadInput, pInfo))
224 + AddEnabledDevice(pInfo->fd);
225 + pMse->lastButtons = 0;
226 + pMse->emulateState = 0;
227 + evdevMse->buttons = 0;
228 + pPointer->public.on = TRUE;
229 + /*
230 + * send button up events for sanity. If no button down is pending
231 + * xf86PostButtonEvent() will discard them. So we are on the safe side.
232 + */
233 + blocked = xf86BlockSIGIO ();
234 + for (i = 1; i <= 5; i++)
235 + xf86PostButtonEvent(pPointer,0,i,0,0,0);
236 + xf86UnblockSIGIO (blocked);
237 + break;
238 +
239 + case DEVICE_OFF:
240 + case DEVICE_CLOSE:
241 + if (pInfo->fd != -1) {
242 + RemoveEnabledDevice(pInfo->fd);
243 + xf86RemoveSIGIOHandler(pInfo->fd);
244 + close (pInfo->fd);
245 + pInfo->fd = -1;
246 + }
247 + pPointer->public.on = FALSE;
248 + usleep(300000);
249 + break;
250 + }
251 + return Success;
252 +}
253 +
254 +
255 +/* This function is called when the protocol is "evdev". */
256 +static Bool
257 +evdevMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags)
258 +{
259 + MouseDevPtr pMse = pInfo->private;
260 + evdevMsePtr evdevMse;
261 +
262 + pMse->protocol = protocol;
263 + xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
264 +
265 + /* Collect the options, and process the common options. */
266 + xf86CollectInputOptions(pInfo, NULL, NULL);
267 + xf86ProcessCommonOptions(pInfo, pInfo->options);
268 +
269 + if (sizeof(struct input_event) <= sizeof(pMse->protoBuf))
270 + pMse->buffer = pMse->protoBuf;
271 + else
272 + pMse->buffer = xcalloc(sizeof(struct input_event),1);
273 + pMse->mousePriv = evdevMse = xcalloc(sizeof(evdevMseRec), 1);
274 + if ((pMse->buffer == NULL) || (pMse->mousePriv == NULL)) {
275 + xf86Msg(X_ERROR, "%s: cannot allocate buffer\n", pInfo->name);
276 + xfree(pMse);
277 + return FALSE;
278 + }
279 +
280 + if (!evdevStart (pInfo->drv)) {
281 + xf86Msg(X_ERROR, "%s: cannot start evdev brain\n", pInfo->name);
282 + return FALSE;
283 + }
284 +
285 + pMse->CommonOptions(pInfo);
286 +
287 + /* Setup the local procs. */
288 + pInfo->device_control = evdevMouseProc;
289 + pInfo->read_input = evdevMouseReadInput;
290 +
291 + pInfo->flags |= XI86_CONFIGURED;
292 +
293 + return TRUE;
294 +}
295 +
296 OSMouseInfoPtr
297 xf86OSMouseInit(int flags)
298 {
299 @@ -197,6 +472,8 @@
300 p->DefaultProtocol = DefaultProtocol;
301 p->FindDevice = FindDevice;
302 p->GuessProtocol = GuessProtocol;
303 + p->CheckProtocol = CheckProtocol;
304 + p->BuiltinNames = BuiltinNames;
305 + p->PreInit = evdevMousePreInit;
306 return p;
307 }
308 -