Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
authorJim Grandpre
Sat, 29 May 2010 01:47:19 -0400
changeset 46438806b78988f7
parent 4642 057e8762d2a1
child 4644 fb500b3e1717
Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
src/events/SDL_touch.c
src/video/x11/SDL_eventtouch.h
src/video/x11/SDL_x11events.c
touchTest/touchTest.c
     1.1 --- a/src/events/SDL_touch.c	Fri May 28 01:26:52 2010 -0400
     1.2 +++ b/src/events/SDL_touch.c	Sat May 29 01:47:19 2010 -0400
     1.3 @@ -301,11 +301,12 @@
     1.4  int
     1.5  SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressure)
     1.6  {
     1.7 -  int posted;
     1.8 +    int posted;
     1.9      SDL_Touch* touch = SDL_GetTouch(id);
    1.10 +
    1.11      if(down) {
    1.12  	SDL_Finger nf;
    1.13 -	nf.id = id;
    1.14 +	nf.id = fingerid;
    1.15  	nf.x = x;
    1.16  	nf.y = y;
    1.17  	nf.pressure = pressure;
    1.18 @@ -324,13 +325,13 @@
    1.19  	    event.tfinger.y = y;
    1.20  	    event.tfinger.state = touch->buttonstate;
    1.21  	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
    1.22 -	    event.tfinger.fingerId = id;
    1.23 +	    event.tfinger.fingerId = fingerid;
    1.24  	    posted = (SDL_PushEvent(&event) > 0);
    1.25  	}
    1.26  	return posted;
    1.27      }
    1.28      else {
    1.29 -	SDL_DelFinger(touch,id);
    1.30 +	SDL_DelFinger(touch,fingerid);
    1.31  	posted = 0;
    1.32  	if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
    1.33  	    SDL_Event event;
    1.34 @@ -338,7 +339,7 @@
    1.35  	    event.tfinger.touchId = (Uint8) id;
    1.36  	    event.tfinger.state = touch->buttonstate;
    1.37  	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
    1.38 -	    event.tfinger.fingerId = id;
    1.39 +	    event.tfinger.fingerId = fingerid;
    1.40  	    posted = (SDL_PushEvent(&event) > 0);
    1.41  	}
    1.42  	return posted;
    1.43 @@ -419,7 +420,8 @@
    1.44  	if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
    1.45  	    SDL_Event event;
    1.46  	    event.tfinger.type = SDL_FINGERMOTION;
    1.47 -	    event.tfinger.touchId = (Uint8) index;
    1.48 +	    event.tfinger.touchId = (Uint8) id;
    1.49 +	    event.tfinger.fingerId = (Uint8) fingerid;
    1.50  	    event.tfinger.x = x;
    1.51  	    event.tfinger.y = y;
    1.52  	    event.tfinger.state = touch->buttonstate;
     2.1 --- a/src/video/x11/SDL_eventtouch.h	Fri May 28 01:26:52 2010 -0400
     2.2 +++ b/src/video/x11/SDL_eventtouch.h	Sat May 29 01:47:19 2010 -0400
     2.3 @@ -31,6 +31,7 @@
     2.4  {
     2.5      int x,y,pressure,finger; //Temporary Variables until sync
     2.6      int eventStream;
     2.7 +    SDL_bool up;
     2.8  } EventTouchData;
     2.9  #endif
    2.10  
     3.1 --- a/src/video/x11/SDL_x11events.c	Fri May 28 01:26:52 2010 -0400
     3.2 +++ b/src/video/x11/SDL_x11events.c	Sat May 29 01:47:19 2010 -0400
     3.3 @@ -419,7 +419,7 @@
     3.4  
     3.5      /* Process Touch events - TODO When X gets touch support, use that instead*/
     3.6      int i = 0,rd;
     3.7 -    char * name[256];
     3.8 +    char name[256];
     3.9      struct input_event ev[64];
    3.10      int size = sizeof (struct input_event);
    3.11      static int initd = 0; //TODO - HACK!
    3.12 @@ -431,7 +431,7 @@
    3.13  	    touch->driverdata = SDL_malloc(sizeof(EventTouchData));
    3.14  	    data = (EventTouchData*)(touch->driverdata);
    3.15  	    printf("Openning device...\n");
    3.16 -	    data->eventStream = open("/dev/input/wacom-touch", 
    3.17 +	    data->eventStream = open("/dev/input/wacom", 
    3.18  				     O_RDONLY | O_NONBLOCK);
    3.19  	    ioctl (data->eventStream, EVIOCGNAME (sizeof (name)), name);
    3.20  	    printf ("Reading From : %s\n", name);
    3.21 @@ -452,24 +452,31 @@
    3.22  			data->x = ev[i].value;
    3.23  		    else if (ev[i].code == ABS_Y)
    3.24  			data->y = ev[i].value;
    3.25 +		    else if (ev[i].code == ABS_MISC) {
    3.26 +			data->up = SDL_TRUE;
    3.27 +			data->finger = ev[i].value;
    3.28 +		    }
    3.29  		    break;
    3.30  		case EV_MSC:
    3.31  		    if(ev[i].code == MSC_SERIAL)
    3.32  			data->finger = ev[i].value;
    3.33  		    break;
    3.34  		case EV_SYN:
    3.35 -		    data->finger -= 1; /*Wacom indexes fingers from 1, 
    3.36 -					 I index from 0*/		  
    3.37  		    if(data->x >= 0 || data->y >= 0)
    3.38  			SDL_SendTouchMotion(touch->id,data->finger, 
    3.39  					    SDL_FALSE,data->x,data->y,
    3.40  					    data->pressure);
    3.41 -		    
    3.42 +		    if(data->up) 
    3.43 +			SDL_SendFingerDown(touch->id,data->finger,
    3.44 +					   SDL_FALSE,data->x,data->y,
    3.45 +					   data->pressure);
    3.46  		    //printf("Synched: %i tx: %i, ty: %i\n",
    3.47  		    //	   data->finger,data->x,data->y);
    3.48  		    data->x = -1;
    3.49  		    data->y = -1;
    3.50  		    data->pressure = -1;
    3.51 +		    data->finger = 0;
    3.52 +		    data->up = SDL_FALSE;
    3.53  		    
    3.54  		    break;		
    3.55  		}
     4.1 --- a/touchTest/touchTest.c	Fri May 28 01:26:52 2010 -0400
     4.2 +++ b/touchTest/touchTest.c	Sat May 29 01:47:19 2010 -0400
     4.3 @@ -9,6 +9,8 @@
     4.4  #define BPP 4
     4.5  #define DEPTH 32
     4.6  
     4.7 +#define MAXFINGERS 3
     4.8 +
     4.9  int mousx,mousy;
    4.10  int keystat[512];
    4.11  int bstatus;
    4.12 @@ -20,6 +22,9 @@
    4.13    int x,y;
    4.14  } Point;
    4.15  
    4.16 +
    4.17 +Point finger[MAXFINGERS];
    4.18 +
    4.19  void handler (int sig)
    4.20  {
    4.21    printf ("\nexiting...(%d)\n", sig);
    4.22 @@ -78,6 +83,10 @@
    4.23      }
    4.24    drawCircle(screen,mousx,mousy,30,0xFFFFFF);
    4.25    
    4.26 +  int i;
    4.27 +  for(i=0;i<MAXFINGERS;i++)
    4.28 +    if(finger[i].x >= 0 && finger[i].y >= 0)
    4.29 +      drawCircle(screen,finger[i].x,finger[i].y,20,0xFF6600);
    4.30    
    4.31    if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
    4.32    
    4.33 @@ -144,14 +153,25 @@
    4.34  	  case SDL_MOUSEBUTTONUP:
    4.35  	    bstatus &= ~(1<<(event.button.button-1));
    4.36  	    break;
    4.37 -	  case SDL_FINGERMOTION:
    4.38 -	    i = 1;
    4.39 -	    
    4.40 +	  case SDL_FINGERMOTION:    
    4.41  	    
    4.42 -	    printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
    4.43 +	    //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
    4.44 +	    //	   event.tfinger.x,event.tfinger.y);
    4.45 +	    finger[event.tfinger.fingerId].x = event.tfinger.x;
    4.46 +	    finger[event.tfinger.fingerId].y = event.tfinger.y;
    4.47 +	    break;	    
    4.48 +	  case SDL_FINGERDOWN:
    4.49 +	    printf("Figner: %i down - x: %i, y: %i\n",event.tfinger.fingerId,
    4.50  		   event.tfinger.x,event.tfinger.y);
    4.51 -		
    4.52 -	    break;	    
    4.53 +	    finger[event.tfinger.fingerId].x = event.tfinger.x;
    4.54 +	    finger[event.tfinger.fingerId].y = event.tfinger.y;
    4.55 +	    break;
    4.56 +	  case SDL_FINGERUP:
    4.57 +	    printf("Figner: %i up - x: %i, y: %i\n",event.tfinger.fingerId,
    4.58 +		   event.tfinger.x,event.tfinger.y);
    4.59 +	    finger[event.tfinger.fingerId].x = -1;
    4.60 +	    finger[event.tfinger.fingerId].y = -1;
    4.61 +	    break;
    4.62  	  }
    4.63        }
    4.64      //And draw