@@ -44,7 +44,9 @@ static _THIS = NULL;
4444#include <linux/kd.h>
4545#include <linux/keyboard.h>
4646#endif
47-
47+ #ifdef SDL_INPUT_TSLIB
48+ #include <tslib.h>
49+ #endif
4850
4951/* We need this to prevent keystrokes from appear in the console */
5052#ifndef KDSKBMUTE
@@ -452,14 +454,60 @@ int
452454SDL_EVDEV_Init (void )
453455{
454456 int retval = 0 ;
457+ #ifdef SDL_INPUT_TSLIB
458+ const char * mousedev ;
459+ const char * mousedrv ;
460+ int ts_mouse_fd = -1 ;
461+ struct tsdev * ts_dev ;
455462
463+ mousedrv = SDL_getenv ("SDL_MOUSEDRV" );
464+ mousedev = SDL_getenv ("SDL_MOUSEDEV" );
465+ #endif
466+
456467 if (_this == NULL ) {
457468
458469 _this = (SDL_EVDEV_PrivateData * ) SDL_calloc (1 , sizeof (* _this ));
459470 if (_this == NULL ) {
460471 return SDL_OutOfMemory ();
461472 }
462473
474+ #ifdef SDL_INPUT_TSLIB
475+ if ( mousedrv && (SDL_strcmp (mousedrv , "TSLIB" ) == 0 ) ) {
476+ if (mousedev == NULL ) mousedev = SDL_getenv ("TSLIB_TSDEVICE" );
477+ if (mousedev != NULL ) {
478+ ts_dev = ts_open (mousedev , 1 );
479+ if ((ts_dev != NULL ) && (ts_config (ts_dev ) >= 0 )) {
480+ ts_mouse_fd = ts_fd (ts_dev );
481+ }
482+ }
483+ }
484+
485+ if (ts_mouse_fd != -1 ){
486+ SDL_evdevlist_item * item ;
487+ item = (SDL_evdevlist_item * ) SDL_calloc (1 , sizeof (SDL_evdevlist_item ));
488+ if (item == NULL ) {
489+ return SDL_OutOfMemory ();
490+ }
491+
492+ item -> fd = ts_mouse_fd ;
493+ item -> ts_dev = ts_dev ;
494+ item -> path = SDL_strdup (mousedev );
495+ if (item -> path == NULL ) {
496+ close (item -> fd );
497+ SDL_free (item );
498+ return SDL_OutOfMemory ();
499+ }
500+
501+ if (_this -> last == NULL ) {
502+ _this -> first = _this -> last = item ;
503+ } else {
504+ _this -> last -> next = item ;
505+ _this -> last = item ;
506+ }
507+ SDL_EVDEV_sync_device (item );
508+ }
509+ #endif
510+
463511#if SDL_USE_LIBUDEV
464512 if (SDL_UDEV_Init () < 0 ) {
465513 SDL_free (_this );
@@ -594,6 +642,24 @@ SDL_EVDEV_Poll(void)
594642 mouse = SDL_GetMouse ();
595643
596644 for (item = _this -> first ; item != NULL ; item = item -> next ) {
645+ #ifdef SDL_INPUT_TSLIB
646+ if (item -> ts_dev ){
647+ SDL_Mouse * mouse = SDL_GetMouse ();
648+ struct ts_sample sample ;
649+
650+ while (ts_read (item -> ts_dev , & sample , 1 ) > 0 ) {
651+ int button = (sample .pressure > 0 ) ? 1 : 0 ;
652+ int old_mouse_state = (mouse -> buttonstate & SDL_BUTTON_LEFT ) > 0 ? 1 : 0 ;
653+
654+ if ( old_mouse_state != button ){
655+ SDL_SendMouseButton (mouse -> focus , mouse -> mouseID , button ? SDL_PRESSED : SDL_RELEASED , SDL_BUTTON_LEFT );
656+ }
657+
658+ SDL_SendMouseMotion (mouse -> focus , mouse -> mouseID , SDL_FALSE , sample .x , sample .y );
659+ }
660+ continue ;
661+ }
662+ #endif
597663 while ((len = read (item -> fd , events , (sizeof events ))) > 0 ) {
598664 len /= sizeof (events [0 ]);
599665 for (i = 0 ; i < len ; ++ i ) {
@@ -806,3 +872,4 @@ SDL_EVDEV_device_removed(const char *devpath)
806872
807873/* vi: set ts=4 sw=4 expandtab: */
808874
875+
0 commit comments