Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11events.c @ 4642:057e8762d2a1
Added reading of event* for touch events.
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Fri, 28 May 2010 01:26:52 -0400 |
parents | f068a6dfc858 |
children | 8806b78988f7 |
comparison
equal
deleted
inserted
replaced
4641:49a97daea6ec | 4642:057e8762d2a1 |
---|---|
26 #include <unistd.h> | 26 #include <unistd.h> |
27 | 27 |
28 #include "SDL_x11video.h" | 28 #include "SDL_x11video.h" |
29 #include "../../events/SDL_events_c.h" | 29 #include "../../events/SDL_events_c.h" |
30 #include "../../events/SDL_mouse_c.h" | 30 #include "../../events/SDL_mouse_c.h" |
31 #include "../../events/SDL_touch_c.h" | |
31 | 32 |
32 #include "SDL_syswm.h" | 33 #include "SDL_syswm.h" |
34 | |
35 #include <stdio.h> | |
36 | |
37 //Touch Input/event* includes | |
38 #include <linux/input.h> | |
39 #include <fcntl.h> | |
33 | 40 |
34 static void | 41 static void |
35 X11_DispatchEvent(_THIS) | 42 X11_DispatchEvent(_THIS) |
36 { | 43 { |
37 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; | 44 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; |
408 while (X11_Pending(data->display)) { | 415 while (X11_Pending(data->display)) { |
409 X11_DispatchEvent(_this); | 416 X11_DispatchEvent(_this); |
410 } | 417 } |
411 | 418 |
412 | 419 |
413 /* Process Touch events - TODO When X gets touch support, REMOVE THIS*/ | 420 /* Process Touch events - TODO When X gets touch support, use that instead*/ |
414 | 421 int i = 0,rd; |
422 char * name[256]; | |
423 struct input_event ev[64]; | |
424 int size = sizeof (struct input_event); | |
425 static int initd = 0; //TODO - HACK! | |
426 for(i = 0;i < SDL_GetNumTouch();++i) { | |
427 SDL_Touch* touch = SDL_GetTouchIndex(i); | |
428 if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch()); | |
429 EventTouchData* data; | |
430 if(!initd){//data->eventStream <= 0) { | |
431 touch->driverdata = SDL_malloc(sizeof(EventTouchData)); | |
432 data = (EventTouchData*)(touch->driverdata); | |
433 printf("Openning device...\n"); | |
434 data->eventStream = open("/dev/input/wacom-touch", | |
435 O_RDONLY | O_NONBLOCK); | |
436 ioctl (data->eventStream, EVIOCGNAME (sizeof (name)), name); | |
437 printf ("Reading From : %s\n", name); | |
438 initd = 1; | |
439 } | |
440 else | |
441 data = (EventTouchData*)(touch->driverdata); | |
442 if(data->eventStream <= 0) | |
443 printf("Error: Couldn't open stream\n"); | |
444 rd = read(data->eventStream, ev, size * 64); | |
445 //printf("Got %i/%i bytes\n",rd,size); | |
446 if(rd >= size) { | |
447 for (i = 0; i < rd / sizeof(struct input_event); i++) { | |
448 switch (ev[i].type) { | |
449 case EV_ABS: | |
450 //printf("Got position x: %i!\n",data->x); | |
451 if(ev[i].code == ABS_X) | |
452 data->x = ev[i].value; | |
453 else if (ev[i].code == ABS_Y) | |
454 data->y = ev[i].value; | |
455 break; | |
456 case EV_MSC: | |
457 if(ev[i].code == MSC_SERIAL) | |
458 data->finger = ev[i].value; | |
459 break; | |
460 case EV_SYN: | |
461 data->finger -= 1; /*Wacom indexes fingers from 1, | |
462 I index from 0*/ | |
463 if(data->x >= 0 || data->y >= 0) | |
464 SDL_SendTouchMotion(touch->id,data->finger, | |
465 SDL_FALSE,data->x,data->y, | |
466 data->pressure); | |
467 | |
468 //printf("Synched: %i tx: %i, ty: %i\n", | |
469 // data->finger,data->x,data->y); | |
470 data->x = -1; | |
471 data->y = -1; | |
472 data->pressure = -1; | |
473 | |
474 break; | |
475 } | |
476 } | |
477 } | |
478 } | |
415 } | 479 } |
416 | 480 |
417 /* This is so wrong it hurts */ | 481 /* This is so wrong it hurts */ |
418 #define GNOME_SCREENSAVER_HACK | 482 #define GNOME_SCREENSAVER_HACK |
419 #ifdef GNOME_SCREENSAVER_HACK | 483 #ifdef GNOME_SCREENSAVER_HACK |