X11 touch handling fixed for one device (LPC32xx Touchscreen).
authorRyan C. Gordon <icculus@icculus.org>
Fri, 05 Aug 2011 00:55:29 -0400
changeset 5603 e1ca92e7f2ff
parent 5602 a712b965fbb6
child 5604 e2ad06c52c65
X11 touch handling fixed for one device (LPC32xx Touchscreen).
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11touch.c
--- a/src/video/x11/SDL_x11events.c	Fri Aug 05 00:49:31 2011 -0400
+++ b/src/video/x11/SDL_x11events.c	Fri Aug 05 00:55:29 2011 -0400
@@ -549,6 +549,7 @@
     struct input_event ev[64];
     int size = sizeof (struct input_event);
 
+/* !!! FIXME: clean the tabstops out of here. */
     for(i = 0;i < SDL_GetNumTouch();++i) {
 	SDL_Touch* touch = SDL_GetTouchIndex(i);
 	if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch());
@@ -561,12 +562,10 @@
 	if(data->eventStream <= 0) 
 	    printf("Error: Couldn't open stream\n");
 	rd = read(data->eventStream, ev, size * 64);
-	//printf("Got %i/%i bytes\n",rd,size);
 	if(rd >= size) {
 	    for (i = 0; i < rd / sizeof(struct input_event); i++) {
 		switch (ev[i].type) {
 		case EV_ABS:
-		    //printf("Got position x: %i!\n",data->x);
 		    switch (ev[i].code) {
 			case ABS_X:
 			    data->x = ev[i].value;
@@ -585,29 +584,37 @@
 			}
 		    break;
 		case EV_MSC:
-		    if(ev[i].code == MSC_SERIAL)
-			data->finger = ev[i].value;
-		    break;
+			if(ev[i].code == MSC_SERIAL)
+				data->finger = ev[i].value;
+			break;
+		case EV_KEY:
+			if(ev[i].code == BTN_TOUCH)
+			    if(ev[i].value == 0)
+			        data->up = SDL_TRUE;
+			break;
 		case EV_SYN:
-		  //printf("Id: %i\n",touch->id); 
-		  if(data->up) {
+		  if(!data->down) {
+		      data->down = SDL_TRUE;
 		      SDL_SendFingerDown(touch->id,data->finger,
-			  	       SDL_FALSE,data->x,data->y,
-				       data->pressure);		    
+		    		  data->down, data->x, data->y,
+		    		  data->pressure);
 		  }
-		  else if(data->x >= 0 || data->y >= 0)
+		  else if(!data->up)
 		    SDL_SendTouchMotion(touch->id,data->finger, 
-					SDL_FALSE,data->x,data->y,
+					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;
-		    
+		  else
+		  {
+		      data->down = SDL_FALSE;
+			  SDL_SendFingerDown(touch->id,data->finger,
+					  data->down, data->x,data->y,
+					  data->pressure);
+			  data->x = -1;
+			  data->y = -1;
+			  data->pressure = -1;
+			  data->finger = 0;
+			  data->up = SDL_FALSE;
+		  }
 		  break;		
 		}
 	    }
--- a/src/video/x11/SDL_x11touch.c	Fri Aug 05 00:49:31 2011 -0400
+++ b/src/video/x11/SDL_x11touch.c	Fri Aug 05 00:55:29 2011 -0400
@@ -47,10 +47,9 @@
   while(!feof(fd)) {
     if(fgets(line,256,fd) <=0) continue;
     if(line[0] == '\n') {
-      if(vendor == 1386){
-	/*printf("Wacom... Assuming it is a touch device\n");*/
-	/*sprintf(tstr,"/dev/input/event%i",event);*/
-	/*printf("At location: %s\n",tstr);*/
+    if(vendor == 1386 || vendor==1){
+
+	sprintf(tstr,"/dev/input/event%i",event);
 
 	SDL_Touch touch;
 	touch.pressure_max = 0;
@@ -66,6 +65,7 @@
 	data->pressure = -1;
 	data->finger = 0;
 	data->up = SDL_FALSE;
+    data->down = SDL_FALSE;
 	
 
 	data->eventStream = open(tstr,