Date: Sat, 10 Dec 2005 18:29:41 +0100
authorRyan C. Gordon <icculus@icculus.org>
Mon, 12 Dec 2005 09:26:32 +0000
changeset 1201718d00094f82
parent 1200 8f418dce02b2
child 1202 0748fbb272e7
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
configure.in
src/video/fbcon/SDL_fbevents.c
src/video/fbcon/SDL_fbvideo.h
     1.1 --- a/configure.in	Mon Dec 12 09:22:36 2005 +0000
     1.2 +++ b/configure.in	Mon Dec 12 09:26:32 2005 +0000
     1.3 @@ -1233,6 +1233,29 @@
     1.4      fi
     1.5  }
     1.6  
     1.7 +dnl See if we can use the Touchscreen input library
     1.8 +CheckTslib()
     1.9 +{
    1.10 +    AC_ARG_ENABLE(input-tslib,
    1.11 +[  --enable-input-tslib    use the Touchscreen library for input [default=yes]],
    1.12 +                  , enable_input_tslib=yes)
    1.13 +    if test x$enable_input_tslib = xyes; then
    1.14 +        AC_MSG_CHECKING(for Touchscreen library support)
    1.15 +        enable_input_tslib=no
    1.16 +        AC_TRY_COMPILE([
    1.17 +          #include "tslib.h"
    1.18 +        ],[
    1.19 +        ],[
    1.20 +        enable_input_tslib=yes
    1.21 +        ])
    1.22 +        AC_MSG_RESULT($enable_input_tslib)
    1.23 +        if test x$enable_input_tslib = xyes; then
    1.24 +            CFLAGS="$CFLAGS -DHAVE_TSLIB"
    1.25 +            SYSTEM_LIBS="$SYSTEM_LIBS -lts"
    1.26 +        fi
    1.27 +    fi
    1.28 +}
    1.29 +
    1.30  dnl See if we can use GNU pth library for threads
    1.31  CheckPTH()
    1.32  {
    1.33 @@ -2078,6 +2101,7 @@
    1.34          CheckPicoGUI
    1.35          CheckOpenGLX11
    1.36          CheckInputEvents
    1.37 +        CheckTslib
    1.38          CheckPTHREAD
    1.39          CheckSIGACTION
    1.40          CheckAltivec
     2.1 --- a/src/video/fbcon/SDL_fbevents.c	Mon Dec 12 09:22:36 2005 +0000
     2.2 +++ b/src/video/fbcon/SDL_fbevents.c	Mon Dec 12 09:26:32 2005 +0000
     2.3 @@ -317,11 +317,19 @@
     2.4  	MOUSE_MS,
     2.5  	MOUSE_BM,
     2.6  	MOUSE_ELO,
     2.7 +	MOUSE_TSLIB,
     2.8  	NUM_MOUSE_DRVS
     2.9  } mouse_drv = MOUSE_NONE;
    2.10  
    2.11  void FB_CloseMouse(_THIS)
    2.12  {
    2.13 +#ifdef HAVE_TSLIB
    2.14 +	if (ts_dev != NULL) {
    2.15 +		ts_close(ts_dev);
    2.16 +		ts_dev = NULL;
    2.17 +		mouse_fd = -1;
    2.18 +	}
    2.19 +#endif /* HAVE_TSLIB */
    2.20  	if ( mouse_fd > 0 ) {
    2.21  		close(mouse_fd);
    2.22  	}
    2.23 @@ -500,6 +508,25 @@
    2.24  	mousedev = getenv("SDL_MOUSEDEV");
    2.25  	mouse_fd = -1;
    2.26  
    2.27 +#ifdef HAVE_TSLIB
    2.28 +	if ((mousedrv != NULL) && (strcmp(mousedrv, "TSLIB") == 0)) {
    2.29 +		if (mousedev == NULL) mousedev = getenv("TSLIB_TSDEVICE");
    2.30 +		if (mousedev != NULL) {
    2.31 +			ts_dev = ts_open(mousedev, 1);
    2.32 +			if ((ts_dev != NULL) && (ts_config(ts_dev) >= 0)) {
    2.33 +#ifdef DEBUG_MOUSE
    2.34 +				fprintf(stderr, "Using tslib touchscreen\n");
    2.35 +#endif
    2.36 +				mouse_drv = MOUSE_TSLIB;
    2.37 +				mouse_fd = ts_fd(ts_dev);
    2.38 +				return mouse_fd;
    2.39 +			}
    2.40 +		}
    2.41 +		mouse_drv = MOUSE_NONE;
    2.42 +		return mouse_fd;
    2.43 +	}
    2.44 +#endif /* HAVE_TSLIB */
    2.45 +
    2.46  	/* ELO TOUCHSCREEN SUPPORT */
    2.47  
    2.48  	if( (mousedrv != NULL) && (strcmp(mousedrv, "ELO") == 0) ) {
    2.49 @@ -642,6 +669,22 @@
    2.50  	}
    2.51  }
    2.52  
    2.53 +/* Handle input from tslib */
    2.54 +#ifdef HAVE_TSLIB
    2.55 +static void handle_tslib(_THIS)
    2.56 +{
    2.57 +	struct ts_sample sample;
    2.58 +	int button;
    2.59 +
    2.60 +	while (ts_read(ts_dev, &sample, 1) > 0) {
    2.61 +		button = (sample.pressure > 0) ? 1 : 0;
    2.62 +		button <<= 2;	/* must report it as button 3 */
    2.63 +    	FB_vgamousecallback(button, 0, sample.x, sample.y);
    2.64 +	}
    2.65 +	return;
    2.66 +}
    2.67 +#endif /* HAVE_TSLIB */
    2.68 +
    2.69  /* For now, use MSC, PS/2, and MS protocols
    2.70     Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.)
    2.71   */
    2.72 @@ -678,6 +721,11 @@
    2.73  			packetsize = ELO_PACKET_SIZE;
    2.74  			relative = 0;
    2.75  			break;
    2.76 +		case MOUSE_TSLIB:
    2.77 +#ifdef HAVE_TSLIB
    2.78 +			handle_tslib(this);
    2.79 +#endif
    2.80 +			return; /* nothing left to do */
    2.81  		case NUM_MOUSE_DRVS:
    2.82  			/* Uh oh.. */
    2.83  			packetsize = 0;
     3.1 --- a/src/video/fbcon/SDL_fbvideo.h	Mon Dec 12 09:22:36 2005 +0000
     3.2 +++ b/src/video/fbcon/SDL_fbvideo.h	Mon Dec 12 09:26:32 2005 +0000
     3.3 @@ -35,6 +35,9 @@
     3.4  #include "SDL_mouse.h"
     3.5  #include "SDL_mutex.h"
     3.6  #include "SDL_sysvideo.h"
     3.7 +#ifdef HAVE_TSLIB
     3.8 +#include "tslib.h"
     3.9 +#endif
    3.10  
    3.11  /* Hidden "this" pointer for the video functions */
    3.12  #define _THIS	SDL_VideoDevice *this
    3.13 @@ -65,6 +68,9 @@
    3.14  	struct termios saved_kbd_termios;
    3.15  
    3.16  	int mouse_fd;
    3.17 +#ifdef HAVE_TSLIB
    3.18 +	struct tsdev *ts_dev;
    3.19 +#endif
    3.20  
    3.21  	char *mapped_mem;
    3.22  	int mapped_memlen;
    3.23 @@ -95,6 +101,9 @@
    3.24  #define saved_kbd_mode		(this->hidden->saved_kbd_mode)
    3.25  #define saved_kbd_termios	(this->hidden->saved_kbd_termios)
    3.26  #define mouse_fd		(this->hidden->mouse_fd)
    3.27 +#ifdef HAVE_TSLIB
    3.28 +#define ts_dev			(this->hidden->ts_dev)
    3.29 +#endif /* HAVE_TSLIB */
    3.30  #define cache_vinfo		(this->hidden->cache_vinfo)
    3.31  #define saved_vinfo		(this->hidden->saved_vinfo)
    3.32  #define saved_cmaplen		(this->hidden->saved_cmaplen)