Lines 6-17
Link Here
|
6 |
|
6 |
|
7 |
#include "X.h" |
7 |
#include "X.h" |
8 |
#include "xf86.h" |
8 |
#include "xf86.h" |
|
|
9 |
#include "xf86Priv.h" |
9 |
#include "xf86Xinput.h" |
10 |
#include "xf86Xinput.h" |
10 |
#include "xf86OSmouse.h" |
11 |
#include "xf86OSmouse.h" |
11 |
#include "xf86_OSlib.h" |
12 |
#include "xf86_OSlib.h" |
12 |
#include <sys/types.h> |
13 |
#include <sys/types.h> |
13 |
#include <sys/stat.h> |
14 |
#include <sys/stat.h> |
14 |
#include <unistd.h> |
15 |
#include <unistd.h> |
|
|
16 |
#include "mipointer.h" |
17 |
#include "lnx_evdev.h" |
18 |
|
19 |
/* Names of protocols that are handled internally here. */ |
20 |
static const char *internalNames[] = { |
21 |
"evdev", |
22 |
NULL |
23 |
}; |
15 |
|
24 |
|
16 |
static int |
25 |
static int |
17 |
SupportedInterfaces(void) |
26 |
SupportedInterfaces(void) |
Lines 185-190
Link Here
|
185 |
return NULL; |
194 |
return NULL; |
186 |
} |
195 |
} |
187 |
|
196 |
|
|
|
197 |
static const char ** |
198 |
BuiltinNames(void) |
199 |
{ |
200 |
return internalNames; |
201 |
} |
202 |
|
203 |
static Bool |
204 |
CheckProtocol(const char *protocol) |
205 |
{ |
206 |
int i; |
207 |
|
208 |
for (i = 0; internalNames[i]; i++) |
209 |
if (xf86NameCmp(protocol, internalNames[i]) == 0) |
210 |
return TRUE; |
211 |
return FALSE; |
212 |
} |
213 |
|
214 |
typedef struct _evdevMseRec { |
215 |
int packetSize; |
216 |
int buttons; |
217 |
Bool sync; |
218 |
evdevDriver evdev; |
219 |
} evdevMseRec, *evdevMsePtr; |
220 |
|
221 |
static void |
222 |
evdevMouseReadInput(InputInfoPtr pInfo) |
223 |
{ |
224 |
MouseDevPtr pMse; |
225 |
evdevMsePtr evdevMse; |
226 |
struct input_event *ev; |
227 |
int n, bit; |
228 |
int dx = 0, dy = 0, dz = 0, dw = 0; |
229 |
|
230 |
pMse = pInfo->private; |
231 |
ev = (struct input_event *) pMse->buffer; |
232 |
evdevMse = pMse->mousePriv; |
233 |
|
234 |
if (pInfo->fd == -1) |
235 |
return; |
236 |
|
237 |
do { |
238 |
n = read(pInfo->fd, pMse->buffer, sizeof(struct input_event)); |
239 |
if (n == -1) { |
240 |
xf86Msg(X_ERROR, "%s: Error in reading! (%s) Disabiling.\n", |
241 |
pInfo->name, strerror(errno)); |
242 |
RemoveEnabledDevice(pInfo->fd); |
243 |
xf86RemoveSIGIOHandler(pInfo->fd); |
244 |
close (pInfo->fd); |
245 |
pMse->device->public.on = FALSE; |
246 |
pInfo->fd = -1; |
247 |
pMse->PostEvent(pInfo, evdevMse->buttons, dx, dy, dz, dw); |
248 |
return; |
249 |
} |
250 |
if (n != sizeof(struct input_event)) { |
251 |
xf86Msg(X_WARNING, "%s: incomplete packet, size %d\n", pInfo->name, n); |
252 |
pMse->PostEvent(pInfo, evdevMse->buttons, dx, dy, dz, dw); |
253 |
return; |
254 |
} |
255 |
|
256 |
switch (ev->type) { |
257 |
case EV_REL: |
258 |
switch (ev->code) { |
259 |
case EV_REL_X: |
260 |
dx += ev->value; |
261 |
break; |
262 |
case EV_REL_Y: |
263 |
dy += ev->value; |
264 |
break; |
265 |
case EV_REL_Z: |
266 |
case EV_REL_WHEEL: |
267 |
dz -= ev->value; |
268 |
break; |
269 |
case EV_REL_HWHEEL: |
270 |
dw -= ev->value; |
271 |
break; |
272 |
} |
273 |
break; |
274 |
case EV_KEY: |
275 |
if ((ev->code < EV_BTN_MOUSE) || (ev->code >= EV_BTN_JOYSTICK)) |
276 |
break; |
277 |
switch (ev->code) { |
278 |
case EV_BTN_RIGHT: bit = 1 << 0; break; /* 1 */ |
279 |
case EV_BTN_MIDDLE: bit = 1 << 1; break; /* 2 */ |
280 |
case EV_BTN_LEFT: bit = 1 << 2; break; /* 3 */ |
281 |
default: bit = 1 << (ev->code - EV_BTN_MOUSE); break; |
282 |
} |
283 |
evdevMse->buttons &= ~bit; |
284 |
if (ev->value) |
285 |
evdevMse->buttons |= bit; |
286 |
break; |
287 |
case EV_SYN: |
288 |
switch (ev->code) { |
289 |
case EV_SYN_REPORT: |
290 |
pMse->PostEvent(pInfo,evdevMse->buttons,dx, dy, dz, dw); |
291 |
dx = dy = dz = dw = 0; |
292 |
break; |
293 |
} |
294 |
break; |
295 |
} |
296 |
if (!evdevMse->sync) { |
297 |
pMse->PostEvent(pInfo,evdevMse->buttons,dx, dy, dz, dw); |
298 |
dx = dy = dz = dw = 0; |
299 |
} |
300 |
} while (xf86WaitForInput(pInfo->fd, 0)); |
301 |
|
302 |
pMse->PostEvent(pInfo, evdevMse->buttons, dx, dy, dz, dw); |
303 |
|
304 |
return; |
305 |
} |
306 |
|
307 |
static void |
308 |
evdevMouseSigioReadInput (int fd, void *closure) |
309 |
{ |
310 |
evdevMouseReadInput ((InputInfoPtr) closure); |
311 |
} |
312 |
|
313 |
static int |
314 |
evdevMouseProc(DeviceIntPtr pPointer, int what) |
315 |
{ |
316 |
InputInfoPtr pInfo; |
317 |
MouseDevPtr pMse; |
318 |
evdevMsePtr evdevMse; |
319 |
unsigned char map[MSE_MAXBUTTONS + 1]; |
320 |
int i, j, blocked; |
321 |
unsigned long evtype_bits[NBITS(EV_MAX)]; |
322 |
unsigned long evkey_bits[NBITS(EV_KEY_MAX)]; |
323 |
|
324 |
pInfo = pPointer->public.devicePrivate; |
325 |
pMse = pInfo->private; |
326 |
pMse->device = pPointer; |
327 |
evdevMse = pMse->mousePriv; |
328 |
|
329 |
switch (what) { |
330 |
case DEVICE_INIT: |
331 |
pPointer->public.on = FALSE; |
332 |
|
333 |
evdevMse->evdev.name = xf86SetStrOption(pInfo->options,"Dev Name",NULL); |
334 |
evdevMse->evdev.phys = xf86SetStrOption(pInfo->options,"Dev Phys",NULL); |
335 |
evdevMse->evdev.cb_data = pInfo->dev; |
336 |
evdevMse->evdev.callback = evdevMouseProc; |
337 |
if (!evdevNewDriver (&evdevMse->evdev)) { |
338 |
xf86Msg(X_ERROR, "%s: cannot register with evdev brain\n", pInfo->name); |
339 |
return BadRequest; |
340 |
} |
341 |
if ((pInfo->fd = evdevGetFDForDriver (&evdevMse->evdev)) == -1) { |
342 |
xf86Msg(X_ERROR, "%s: cannot open input device\n", pInfo->name); |
343 |
return BadRequest; |
344 |
} |
345 |
|
346 |
ioctl(pInfo->fd, EVIOCGBIT(0, EV_MAX), evtype_bits); |
347 |
if (test_bit(EV_SYN, evtype_bits)) |
348 |
evdevMse->sync = TRUE; |
349 |
else |
350 |
evdevMse->sync = FALSE; |
351 |
|
352 |
if (test_bit(EV_KEY, evtype_bits)) { |
353 |
ioctl(pInfo->fd, EVIOCGBIT(EV_KEY, EV_KEY_MAX), evkey_bits); |
354 |
i = EV_BTN_LEFT; |
355 |
for (i = EV_BTN_LEFT, j = 0; i <= EV_BTN_BACK; i++) |
356 |
if (test_bit(i, evkey_bits)) |
357 |
j = i - EV_BTN_LEFT; |
358 |
if (++j > pMse->buttons) pMse->buttons = j; |
359 |
} |
360 |
|
361 |
close(pInfo->fd); |
362 |
pInfo->fd = -1; |
363 |
|
364 |
for (i = 0; i < MSE_MAXBUTTONS; ++i) |
365 |
map[i + 1] = i + 1; |
366 |
|
367 |
InitPointerDeviceStruct((DevicePtr)pPointer, map, |
368 |
min(pMse->buttons, MSE_MAXBUTTONS), |
369 |
miPointerGetMotionEvents, pMse->Ctrl, |
370 |
miPointerGetMotionBufferSize()); |
371 |
|
372 |
/* X valuator */ |
373 |
xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1); |
374 |
xf86InitValuatorDefaults(pPointer, 0); |
375 |
/* Y valuator */ |
376 |
xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1); |
377 |
xf86InitValuatorDefaults(pPointer, 1); |
378 |
xf86MotionHistoryAllocate(pInfo); |
379 |
break; |
380 |
|
381 |
case DEVICE_ON: |
382 |
if (pPointer->public.on) |
383 |
break; |
384 |
if ((pInfo->fd = evdevGetFDForDriver (&evdevMse->evdev)) == -1) { |
385 |
xf86Msg(X_ERROR, "%s: cannot open input device (name: '%s', phys: '%s')\n", pInfo->name, evdevMse->evdev.name, evdevMse->evdev.phys); |
386 |
return BadRequest; |
387 |
} |
388 |
|
389 |
xf86FlushInput(pInfo->fd); |
390 |
if (!xf86InstallSIGIOHandler (pInfo->fd, evdevMouseSigioReadInput, pInfo)) |
391 |
AddEnabledDevice(pInfo->fd); |
392 |
pMse->lastButtons = 0; |
393 |
pMse->emulateState = 0; |
394 |
evdevMse->buttons = 0; |
395 |
pPointer->public.on = TRUE; |
396 |
/* |
397 |
* send button up events for sanity. If no button down is pending |
398 |
* xf86PostButtonEvent() will discard them. So we are on the safe side. |
399 |
*/ |
400 |
blocked = xf86BlockSIGIO (); |
401 |
for (i = 1; i <= 5; i++) |
402 |
xf86PostButtonEvent(pPointer,0,i,0,0,0); |
403 |
xf86UnblockSIGIO (blocked); |
404 |
break; |
405 |
|
406 |
case DEVICE_OFF: |
407 |
case DEVICE_CLOSE: |
408 |
if (pInfo->fd != -1) { |
409 |
RemoveEnabledDevice(pInfo->fd); |
410 |
xf86RemoveSIGIOHandler(pInfo->fd); |
411 |
close (pInfo->fd); |
412 |
pInfo->fd = -1; |
413 |
} |
414 |
pPointer->public.on = FALSE; |
415 |
usleep(300000); |
416 |
break; |
417 |
} |
418 |
return Success; |
419 |
} |
420 |
|
421 |
|
422 |
/* This function is called when the protocol is "evdev". */ |
423 |
static Bool |
424 |
evdevMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags) |
425 |
{ |
426 |
MouseDevPtr pMse = pInfo->private; |
427 |
evdevMsePtr evdevMse; |
428 |
|
429 |
pMse->protocol = protocol; |
430 |
xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol); |
431 |
|
432 |
/* Collect the options, and process the common options. */ |
433 |
xf86CollectInputOptions(pInfo, NULL, NULL); |
434 |
xf86ProcessCommonOptions(pInfo, pInfo->options); |
435 |
|
436 |
if (sizeof(struct input_event) <= sizeof(pMse->protoBuf)) |
437 |
pMse->buffer = pMse->protoBuf; |
438 |
else |
439 |
pMse->buffer = xcalloc(sizeof(struct input_event),1); |
440 |
pMse->mousePriv = evdevMse = xcalloc(sizeof(evdevMseRec), 1); |
441 |
if ((pMse->buffer == NULL) || (pMse->mousePriv == NULL)) { |
442 |
xf86Msg(X_ERROR, "%s: cannot allocate buffer\n", pInfo->name); |
443 |
xfree(pMse); |
444 |
return FALSE; |
445 |
} |
446 |
|
447 |
if (!evdevStart (pInfo->drv)) { |
448 |
xf86Msg(X_ERROR, "%s: cannot start evdev brain\n", pInfo->name); |
449 |
return FALSE; |
450 |
} |
451 |
|
452 |
pMse->CommonOptions(pInfo); |
453 |
|
454 |
/* Setup the local procs. */ |
455 |
pInfo->device_control = evdevMouseProc; |
456 |
pInfo->read_input = evdevMouseReadInput; |
457 |
|
458 |
pInfo->flags |= XI86_CONFIGURED; |
459 |
|
460 |
return TRUE; |
461 |
} |
462 |
|
188 |
OSMouseInfoPtr |
463 |
OSMouseInfoPtr |
189 |
xf86OSMouseInit(int flags) |
464 |
xf86OSMouseInit(int flags) |
190 |
{ |
465 |
{ |
Lines 197-202
Link Here
|
197 |
p->DefaultProtocol = DefaultProtocol; |
472 |
p->DefaultProtocol = DefaultProtocol; |
198 |
p->FindDevice = FindDevice; |
473 |
p->FindDevice = FindDevice; |
199 |
p->GuessProtocol = GuessProtocol; |
474 |
p->GuessProtocol = GuessProtocol; |
|
|
475 |
p->CheckProtocol = CheckProtocol; |
476 |
p->BuiltinNames = BuiltinNames; |
477 |
p->PreInit = evdevMousePreInit; |
200 |
return p; |
478 |
return p; |
201 |
} |
479 |
} |
202 |
|
|
|