Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Bug fixes. Basic touch events (finger up, finger down, finger move) s…
Browse files Browse the repository at this point in the history
…upported.
  • Loading branch information
jimtla committed May 29, 2010
1 parent edc9cef commit 632271c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
14 changes: 8 additions & 6 deletions src/events/SDL_touch.c
Expand Up @@ -301,11 +301,12 @@ SDL_DelFinger(SDL_Touch* touch,int fingerid)
int
SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressure)
{
int posted;
int posted;
SDL_Touch* touch = SDL_GetTouch(id);

if(down) {
SDL_Finger nf;
nf.id = id;
nf.id = fingerid;
nf.x = x;
nf.y = y;
nf.pressure = pressure;
Expand All @@ -324,21 +325,21 @@ SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressu
event.tfinger.y = y;
event.tfinger.state = touch->buttonstate;
event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
event.tfinger.fingerId = id;
event.tfinger.fingerId = fingerid;
posted = (SDL_PushEvent(&event) > 0);
}
return posted;
}
else {
SDL_DelFinger(touch,id);
SDL_DelFinger(touch,fingerid);
posted = 0;
if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
SDL_Event event;
event.tfinger.type = SDL_FINGERUP;
event.tfinger.touchId = (Uint8) id;
event.tfinger.state = touch->buttonstate;
event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
event.tfinger.fingerId = id;
event.tfinger.fingerId = fingerid;
posted = (SDL_PushEvent(&event) > 0);
}
return posted;
Expand Down Expand Up @@ -419,7 +420,8 @@ SDL_SendTouchMotion(int id, int fingerid, int relative,
if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
SDL_Event event;
event.tfinger.type = SDL_FINGERMOTION;
event.tfinger.touchId = (Uint8) index;
event.tfinger.touchId = (Uint8) id;
event.tfinger.fingerId = (Uint8) fingerid;
event.tfinger.x = x;
event.tfinger.y = y;
event.tfinger.state = touch->buttonstate;
Expand Down
1 change: 1 addition & 0 deletions src/video/x11/SDL_eventtouch.h
Expand Up @@ -31,6 +31,7 @@ typedef struct EventTouchData
{
int x,y,pressure,finger; //Temporary Variables until sync
int eventStream;
SDL_bool up;
} EventTouchData;
#endif

Expand Down
17 changes: 12 additions & 5 deletions src/video/x11/SDL_x11events.c
Expand Up @@ -419,7 +419,7 @@ X11_PumpEvents(_THIS)

/* Process Touch events - TODO When X gets touch support, use that instead*/
int i = 0,rd;
char * name[256];
char name[256];
struct input_event ev[64];
int size = sizeof (struct input_event);
static int initd = 0; //TODO - HACK!
Expand All @@ -431,7 +431,7 @@ X11_PumpEvents(_THIS)
touch->driverdata = SDL_malloc(sizeof(EventTouchData));
data = (EventTouchData*)(touch->driverdata);
printf("Openning device...\n");
data->eventStream = open("/dev/input/wacom-touch",
data->eventStream = open("/dev/input/wacom",
O_RDONLY | O_NONBLOCK);
ioctl (data->eventStream, EVIOCGNAME (sizeof (name)), name);
printf ("Reading From : %s\n", name);
Expand All @@ -452,24 +452,31 @@ X11_PumpEvents(_THIS)
data->x = ev[i].value;
else if (ev[i].code == ABS_Y)
data->y = ev[i].value;
else if (ev[i].code == ABS_MISC) {
data->up = SDL_TRUE;
data->finger = ev[i].value;
}
break;
case EV_MSC:
if(ev[i].code == MSC_SERIAL)
data->finger = ev[i].value;
break;
case EV_SYN:
data->finger -= 1; /*Wacom indexes fingers from 1,
I index from 0*/
if(data->x >= 0 || data->y >= 0)
SDL_SendTouchMotion(touch->id,data->finger,
SDL_FALSE,data->x,data->y,
data->pressure);

if(data->up)
SDL_SendFingerDown(touch->id,data->finger,
SDL_FALSE,data->x,data->y,
data->pressure);
//printf("Synched: %i tx: %i, ty: %i\n",
// data->finger,data->x,data->y);
data->x = -1;
data->y = -1;
data->pressure = -1;
data->finger = 0;
data->up = SDL_FALSE;

break;
}
Expand Down
32 changes: 26 additions & 6 deletions touchTest/touchTest.c
Expand Up @@ -9,6 +9,8 @@
#define BPP 4
#define DEPTH 32

#define MAXFINGERS 3

int mousx,mousy;
int keystat[512];
int bstatus;
Expand All @@ -20,6 +22,9 @@ typedef struct {
int x,y;
} Point;


Point finger[MAXFINGERS];

void handler (int sig)
{
printf ("\nexiting...(%d)\n", sig);
Expand Down Expand Up @@ -78,6 +83,10 @@ void DrawScreen(SDL_Surface* screen, int h)
}
drawCircle(screen,mousx,mousy,30,0xFFFFFF);

int i;
for(i=0;i<MAXFINGERS;i++)
if(finger[i].x >= 0 && finger[i].y >= 0)
drawCircle(screen,finger[i].x,finger[i].y,20,0xFF6600);

if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);

Expand Down Expand Up @@ -144,14 +153,25 @@ int main(int argc, char* argv[])
case SDL_MOUSEBUTTONUP:
bstatus &= ~(1<<(event.button.button-1));
break;
case SDL_FINGERMOTION:
i = 1;
case SDL_FINGERMOTION:


printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
event.tfinger.x,event.tfinger.y);
//printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
// event.tfinger.x,event.tfinger.y);
finger[event.tfinger.fingerId].x = event.tfinger.x;
finger[event.tfinger.fingerId].y = event.tfinger.y;
break;
case SDL_FINGERDOWN:
printf("Figner: %i down - x: %i, y: %i\n",event.tfinger.fingerId,
event.tfinger.x,event.tfinger.y);
finger[event.tfinger.fingerId].x = event.tfinger.x;
finger[event.tfinger.fingerId].y = event.tfinger.y;
break;
case SDL_FINGERUP:
printf("Figner: %i up - x: %i, y: %i\n",event.tfinger.fingerId,
event.tfinger.x,event.tfinger.y);
finger[event.tfinger.fingerId].x = -1;
finger[event.tfinger.fingerId].y = -1;
break;
}
}
//And draw
Expand Down

0 comments on commit 632271c

Please sign in to comment.