Skip to content

Commit 8def902

Browse files
author
Cedric PAILLE
committed
Added tslib support
1 parent 8320a2e commit 8def902

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

configure.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2838,7 +2838,7 @@ dnl Set up the configuration based on the host platform!
28382838
case "$host" in
28392839
*-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*)
28402840
case "$host" in
2841-
*-raspberry-linux*)
2841+
*-raspberry-linux*|*-openbricks-linux*)
28422842
# Raspberry Pi
28432843
ARCH=linux
28442844
RPI_CFLAGS="-I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux"
@@ -3674,6 +3674,11 @@ if test x$enable_libudev = xyes; then
36743674
else
36753675
SUMMARY="${SUMMARY}Using libudev : NO\n"
36763676
fi
3677+
if test x$enable_input_tslib = xyes; then
3678+
SUMMARY="${SUMMARY}Using libts : YES\n"
3679+
else
3680+
SUMMARY="${SUMMARY}Using libts : NO\n"
3681+
fi
36773682
if test x$have_dbus_dbus_h_hdr = xyes; then
36783683
SUMMARY="${SUMMARY}Using dbus : YES\n"
36793684
else

src/core/linux/SDL_evdev.c

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
452454
SDL_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+

src/core/linux/SDL_evdev.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@
2929
#include "SDL_events.h"
3030
#include <sys/stat.h>
3131

32+
struct tsdev;
33+
3234
typedef struct SDL_evdevlist_item
3335
{
3436
char *path;
3537
int fd;
38+
#ifdef SDL_INPUT_TSLIB
39+
struct tsdev* ts_dev;
40+
#endif
3641
struct SDL_evdevlist_item *next;
3742
} SDL_evdevlist_item;
3843

@@ -57,3 +62,4 @@ extern void SDL_EVDEV_Poll(void);
5762
#endif /* _SDL_evdev_h */
5863

5964
/* vi: set ts=4 sw=4 expandtab: */
65+

0 commit comments

Comments
 (0)