From 53f29a2cb582761f955951284d2c5a47a11d3eb7 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 12 Dec 2005 09:26:32 +0000 Subject: [PATCH] Date: Sat, 10 Dec 2005 18:29:41 +0100 From: Alberto Mardegan 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 --HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401204 --- configure.in | 24 +++++++++++++++++ src/video/fbcon/SDL_fbevents.c | 48 ++++++++++++++++++++++++++++++++++ src/video/fbcon/SDL_fbvideo.h | 9 +++++++ 3 files changed, 81 insertions(+) diff --git a/configure.in b/configure.in index 3b03ee68d..4a6096c9f 100644 --- a/configure.in +++ b/configure.in @@ -1233,6 +1233,29 @@ CheckInputEvents() fi } +dnl See if we can use the Touchscreen input library +CheckTslib() +{ + AC_ARG_ENABLE(input-tslib, +[ --enable-input-tslib use the Touchscreen library for input [default=yes]], + , enable_input_tslib=yes) + if test x$enable_input_tslib = xyes; then + AC_MSG_CHECKING(for Touchscreen library support) + enable_input_tslib=no + AC_TRY_COMPILE([ + #include "tslib.h" + ],[ + ],[ + enable_input_tslib=yes + ]) + AC_MSG_RESULT($enable_input_tslib) + if test x$enable_input_tslib = xyes; then + CFLAGS="$CFLAGS -DHAVE_TSLIB" + SYSTEM_LIBS="$SYSTEM_LIBS -lts" + fi + fi +} + dnl See if we can use GNU pth library for threads CheckPTH() { @@ -2078,6 +2101,7 @@ case "$target" in CheckPicoGUI CheckOpenGLX11 CheckInputEvents + CheckTslib CheckPTHREAD CheckSIGACTION CheckAltivec diff --git a/src/video/fbcon/SDL_fbevents.c b/src/video/fbcon/SDL_fbevents.c index a20e7e26e..69d85067d 100644 --- a/src/video/fbcon/SDL_fbevents.c +++ b/src/video/fbcon/SDL_fbevents.c @@ -317,11 +317,19 @@ static enum { 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 @@ int FB_OpenMouse(_THIS) 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 @@ void FB_vgamousecallback(int button, int relative, int dx, int dy) } } +/* 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 @@ static void handle_mouse(_THIS) 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; diff --git a/src/video/fbcon/SDL_fbvideo.h b/src/video/fbcon/SDL_fbvideo.h index d24faaeb6..0af9409ef 100644 --- a/src/video/fbcon/SDL_fbvideo.h +++ b/src/video/fbcon/SDL_fbvideo.h @@ -35,6 +35,9 @@ static char rcsid = #include "SDL_mouse.h" #include "SDL_mutex.h" #include "SDL_sysvideo.h" +#ifdef HAVE_TSLIB +#include "tslib.h" +#endif /* Hidden "this" pointer for the video functions */ #define _THIS SDL_VideoDevice *this @@ -65,6 +68,9 @@ struct SDL_PrivateVideoData { struct termios saved_kbd_termios; int mouse_fd; +#ifdef HAVE_TSLIB + struct tsdev *ts_dev; +#endif char *mapped_mem; int mapped_memlen; @@ -95,6 +101,9 @@ struct SDL_PrivateVideoData { #define saved_kbd_mode (this->hidden->saved_kbd_mode) #define saved_kbd_termios (this->hidden->saved_kbd_termios) #define mouse_fd (this->hidden->mouse_fd) +#ifdef HAVE_TSLIB +#define ts_dev (this->hidden->ts_dev) +#endif /* HAVE_TSLIB */ #define cache_vinfo (this->hidden->cache_vinfo) #define saved_vinfo (this->hidden->saved_vinfo) #define saved_cmaplen (this->hidden->saved_cmaplen)