diff src/video/fbcon/SDL_fbevents.c @ 1201:718d00094f82

Date: Sat, 10 Dec 2005 18:29:41 +0100 From: Alberto Mardegan <mardy@users.sourceforge.net> To: sdl@libsdl.org Subject: [SDL] [PATCH] Touchscreen support to fbcon via tslib Hi all! I'm new to this list, I just subscribed. I've attached to this e-mail a patch I've written in order to add Touchscreen support to SDL's fbcon module via the tslib library. Since it introduces a new dependency, I've also edited the the configure.in file and added it as a compile-time option. This patch is especially useful for handhelds (I've tested it in my Zaurus). Please consider applying it. :-) -- Saluti, Mardy http://interlingua.altervista.org
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 12 Dec 2005 09:26:32 +0000
parents 3d4f1930ed02
children 4b2146866b82
line wrap: on
line diff
--- a/src/video/fbcon/SDL_fbevents.c	Mon Dec 12 09:22:36 2005 +0000
+++ b/src/video/fbcon/SDL_fbevents.c	Mon Dec 12 09:26:32 2005 +0000
@@ -317,11 +317,19 @@
 	MOUSE_MS,
 	MOUSE_BM,
 	MOUSE_ELO,
+	MOUSE_TSLIB,
 	NUM_MOUSE_DRVS
 } mouse_drv = MOUSE_NONE;
 
 void FB_CloseMouse(_THIS)
 {
+#ifdef HAVE_TSLIB
+	if (ts_dev != NULL) {
+		ts_close(ts_dev);
+		ts_dev = NULL;
+		mouse_fd = -1;
+	}
+#endif /* HAVE_TSLIB */
 	if ( mouse_fd > 0 ) {
 		close(mouse_fd);
 	}
@@ -500,6 +508,25 @@
 	mousedev = getenv("SDL_MOUSEDEV");
 	mouse_fd = -1;
 
+#ifdef HAVE_TSLIB
+	if ((mousedrv != NULL) && (strcmp(mousedrv, "TSLIB") == 0)) {
+		if (mousedev == NULL) mousedev = getenv("TSLIB_TSDEVICE");
+		if (mousedev != NULL) {
+			ts_dev = ts_open(mousedev, 1);
+			if ((ts_dev != NULL) && (ts_config(ts_dev) >= 0)) {
+#ifdef DEBUG_MOUSE
+				fprintf(stderr, "Using tslib touchscreen\n");
+#endif
+				mouse_drv = MOUSE_TSLIB;
+				mouse_fd = ts_fd(ts_dev);
+				return mouse_fd;
+			}
+		}
+		mouse_drv = MOUSE_NONE;
+		return mouse_fd;
+	}
+#endif /* HAVE_TSLIB */
+
 	/* ELO TOUCHSCREEN SUPPORT */
 
 	if( (mousedrv != NULL) && (strcmp(mousedrv, "ELO") == 0) ) {
@@ -642,6 +669,22 @@
 	}
 }
 
+/* Handle input from tslib */
+#ifdef HAVE_TSLIB
+static void handle_tslib(_THIS)
+{
+	struct ts_sample sample;
+	int button;
+
+	while (ts_read(ts_dev, &sample, 1) > 0) {
+		button = (sample.pressure > 0) ? 1 : 0;
+		button <<= 2;	/* must report it as button 3 */
+    	FB_vgamousecallback(button, 0, sample.x, sample.y);
+	}
+	return;
+}
+#endif /* HAVE_TSLIB */
+
 /* For now, use MSC, PS/2, and MS protocols
    Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.)
  */
@@ -678,6 +721,11 @@
 			packetsize = ELO_PACKET_SIZE;
 			relative = 0;
 			break;
+		case MOUSE_TSLIB:
+#ifdef HAVE_TSLIB
+			handle_tslib(this);
+#endif
+			return; /* nothing left to do */
 		case NUM_MOUSE_DRVS:
 			/* Uh oh.. */
 			packetsize = 0;