Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
authorJim Grandpre <jim.tla@gmail.com>
Sat, 29 May 2010 01:47:19 -0400
changeset 4643 8806b78988f7
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
--- a/src/events/SDL_touch.c	Fri May 28 01:26:52 2010 -0400
+++ b/src/events/SDL_touch.c	Sat May 29 01:47:19 2010 -0400
@@ -301,11 +301,12 @@
 int
 SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressure)
 {
-  int posted;
+    int posted;
     SDL_Touch* touch = SDL_GetTouch(id);
+
     if(down) {
 	SDL_Finger nf;
-	nf.id = id;
+	nf.id = fingerid;
 	nf.x = x;
 	nf.y = y;
 	nf.pressure = pressure;
@@ -324,13 +325,13 @@
 	    event.tfinger.y = y;
 	    event.tfinger.state = touch->buttonstate;
 	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
-	    event.tfinger.fingerId = id;
+	    event.tfinger.fingerId = fingerid;
 	    posted = (SDL_PushEvent(&event) > 0);
 	}
 	return posted;
     }
     else {
-	SDL_DelFinger(touch,id);
+	SDL_DelFinger(touch,fingerid);
 	posted = 0;
 	if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
 	    SDL_Event event;
@@ -338,7 +339,7 @@
 	    event.tfinger.touchId = (Uint8) id;
 	    event.tfinger.state = touch->buttonstate;
 	    event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
-	    event.tfinger.fingerId = id;
+	    event.tfinger.fingerId = fingerid;
 	    posted = (SDL_PushEvent(&event) > 0);
 	}
 	return posted;
@@ -419,7 +420,8 @@
 	if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
 	    SDL_Event event;
 	    event.tfinger.type = SDL_FINGERMOTION;
-	    event.tfinger.touchId = (Uint8) index;
+	    event.tfinger.touchId = (Uint8) id;
+	    event.tfinger.fingerId = (Uint8) fingerid;
 	    event.tfinger.x = x;
 	    event.tfinger.y = y;
 	    event.tfinger.state = touch->buttonstate;
--- a/src/video/x11/SDL_eventtouch.h	Fri May 28 01:26:52 2010 -0400
+++ b/src/video/x11/SDL_eventtouch.h	Sat May 29 01:47:19 2010 -0400
@@ -31,6 +31,7 @@
 {
     int x,y,pressure,finger; //Temporary Variables until sync
     int eventStream;
+    SDL_bool up;
 } EventTouchData;
 #endif
 
--- a/src/video/x11/SDL_x11events.c	Fri May 28 01:26:52 2010 -0400
+++ b/src/video/x11/SDL_x11events.c	Sat May 29 01:47:19 2010 -0400
@@ -419,7 +419,7 @@
 
     /* Process Touch events - TODO When X gets touch support, use that instead*/
     int i = 0,rd;
-    char * name[256];
+    char name[256];
     struct input_event ev[64];
     int size = sizeof (struct input_event);
     static int initd = 0; //TODO - HACK!
@@ -431,7 +431,7 @@
 	    touch->driverdata = SDL_malloc(sizeof(EventTouchData));
 	    data = (EventTouchData*)(touch->driverdata);
 	    printf("Openning device...\n");
-	    data->eventStream = open("/dev/input/wacom-touch", 
+	    data->eventStream = open("/dev/input/wacom", 
 				     O_RDONLY | O_NONBLOCK);
 	    ioctl (data->eventStream, EVIOCGNAME (sizeof (name)), name);
 	    printf ("Reading From : %s\n", name);
@@ -452,24 +452,31 @@
 			data->x = ev[i].value;
 		    else if (ev[i].code == ABS_Y)
 			data->y = ev[i].value;
+		    else if (ev[i].code == ABS_MISC) {
+			data->up = SDL_TRUE;
+			data->finger = ev[i].value;
+		    }
 		    break;
 		case EV_MSC:
 		    if(ev[i].code == MSC_SERIAL)
 			data->finger = ev[i].value;
 		    break;
 		case EV_SYN:
-		    data->finger -= 1; /*Wacom indexes fingers from 1, 
-					 I index from 0*/		  
 		    if(data->x >= 0 || data->y >= 0)
 			SDL_SendTouchMotion(touch->id,data->finger, 
 					    SDL_FALSE,data->x,data->y,
 					    data->pressure);
-		    
+		    if(data->up) 
+			SDL_SendFingerDown(touch->id,data->finger,
+					   SDL_FALSE,data->x,data->y,
+					   data->pressure);
 		    //printf("Synched: %i tx: %i, ty: %i\n",
 		    //	   data->finger,data->x,data->y);
 		    data->x = -1;
 		    data->y = -1;
 		    data->pressure = -1;
+		    data->finger = 0;
+		    data->up = SDL_FALSE;
 		    
 		    break;		
 		}
--- a/touchTest/touchTest.c	Fri May 28 01:26:52 2010 -0400
+++ b/touchTest/touchTest.c	Sat May 29 01:47:19 2010 -0400
@@ -9,6 +9,8 @@
 #define BPP 4
 #define DEPTH 32
 
+#define MAXFINGERS 3
+
 int mousx,mousy;
 int keystat[512];
 int bstatus;
@@ -20,6 +22,9 @@
   int x,y;
 } Point;
 
+
+Point finger[MAXFINGERS];
+
 void handler (int sig)
 {
   printf ("\nexiting...(%d)\n", sig);
@@ -78,6 +83,10 @@
     }
   drawCircle(screen,mousx,mousy,30,0xFFFFFF);
   
+  int i;
+  for(i=0;i<MAXFINGERS;i++)
+    if(finger[i].x >= 0 && finger[i].y >= 0)
+      drawCircle(screen,finger[i].x,finger[i].y,20,0xFF6600);
   
   if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
   
@@ -144,14 +153,25 @@
 	  case SDL_MOUSEBUTTONUP:
 	    bstatus &= ~(1<<(event.button.button-1));
 	    break;
-	  case SDL_FINGERMOTION:
-	    i = 1;
-	    
+	  case SDL_FINGERMOTION:    
 	    
-	    printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
+	    //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
+	    //	   event.tfinger.x,event.tfinger.y);
+	    finger[event.tfinger.fingerId].x = event.tfinger.x;
+	    finger[event.tfinger.fingerId].y = event.tfinger.y;
+	    break;	    
+	  case SDL_FINGERDOWN:
+	    printf("Figner: %i down - x: %i, y: %i\n",event.tfinger.fingerId,
 		   event.tfinger.x,event.tfinger.y);
-		
-	    break;	    
+	    finger[event.tfinger.fingerId].x = event.tfinger.x;
+	    finger[event.tfinger.fingerId].y = event.tfinger.y;
+	    break;
+	  case SDL_FINGERUP:
+	    printf("Figner: %i up - x: %i, y: %i\n",event.tfinger.fingerId,
+		   event.tfinger.x,event.tfinger.y);
+	    finger[event.tfinger.fingerId].x = -1;
+	    finger[event.tfinger.fingerId].y = -1;
+	    break;
 	  }
       }
     //And draw