Commit 11b6823d authored by Jim Grandpre's avatar Jim Grandpre

Bug fixes. Basic touch events (finger up, finger down, finger move) supported.

parent 72c5a40b
...@@ -301,11 +301,12 @@ SDL_DelFinger(SDL_Touch* touch,int fingerid) ...@@ -301,11 +301,12 @@ SDL_DelFinger(SDL_Touch* touch,int fingerid)
int int
SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressure) 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); SDL_Touch* touch = SDL_GetTouch(id);
if(down) { if(down) {
SDL_Finger nf; SDL_Finger nf;
nf.id = id; nf.id = fingerid;
nf.x = x; nf.x = x;
nf.y = y; nf.y = y;
nf.pressure = pressure; nf.pressure = pressure;
...@@ -324,13 +325,13 @@ SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressu ...@@ -324,13 +325,13 @@ SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressu
event.tfinger.y = y; event.tfinger.y = y;
event.tfinger.state = touch->buttonstate; event.tfinger.state = touch->buttonstate;
event.tfinger.windowID = touch->focus ? touch->focus->id : 0; event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
event.tfinger.fingerId = id; event.tfinger.fingerId = fingerid;
posted = (SDL_PushEvent(&event) > 0); posted = (SDL_PushEvent(&event) > 0);
} }
return posted; return posted;
} }
else { else {
SDL_DelFinger(touch,id); SDL_DelFinger(touch,fingerid);
posted = 0; posted = 0;
if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) { if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
SDL_Event event; SDL_Event event;
...@@ -338,7 +339,7 @@ SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressu ...@@ -338,7 +339,7 @@ SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressu
event.tfinger.touchId = (Uint8) id; event.tfinger.touchId = (Uint8) id;
event.tfinger.state = touch->buttonstate; event.tfinger.state = touch->buttonstate;
event.tfinger.windowID = touch->focus ? touch->focus->id : 0; event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
event.tfinger.fingerId = id; event.tfinger.fingerId = fingerid;
posted = (SDL_PushEvent(&event) > 0); posted = (SDL_PushEvent(&event) > 0);
} }
return posted; return posted;
...@@ -419,7 +420,8 @@ SDL_SendTouchMotion(int id, int fingerid, int relative, ...@@ -419,7 +420,8 @@ SDL_SendTouchMotion(int id, int fingerid, int relative,
if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) { if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
SDL_Event event; SDL_Event event;
event.tfinger.type = SDL_FINGERMOTION; 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.x = x;
event.tfinger.y = y; event.tfinger.y = y;
event.tfinger.state = touch->buttonstate; event.tfinger.state = touch->buttonstate;
......
...@@ -31,6 +31,7 @@ typedef struct EventTouchData ...@@ -31,6 +31,7 @@ typedef struct EventTouchData
{ {
int x,y,pressure,finger; //Temporary Variables until sync int x,y,pressure,finger; //Temporary Variables until sync
int eventStream; int eventStream;
SDL_bool up;
} EventTouchData; } EventTouchData;
#endif #endif
......
...@@ -419,7 +419,7 @@ X11_PumpEvents(_THIS) ...@@ -419,7 +419,7 @@ X11_PumpEvents(_THIS)
/* Process Touch events - TODO When X gets touch support, use that instead*/ /* Process Touch events - TODO When X gets touch support, use that instead*/
int i = 0,rd; int i = 0,rd;
char * name[256]; char name[256];
struct input_event ev[64]; struct input_event ev[64];
int size = sizeof (struct input_event); int size = sizeof (struct input_event);
static int initd = 0; //TODO - HACK! static int initd = 0; //TODO - HACK!
...@@ -431,7 +431,7 @@ X11_PumpEvents(_THIS) ...@@ -431,7 +431,7 @@ X11_PumpEvents(_THIS)
touch->driverdata = SDL_malloc(sizeof(EventTouchData)); touch->driverdata = SDL_malloc(sizeof(EventTouchData));
data = (EventTouchData*)(touch->driverdata); data = (EventTouchData*)(touch->driverdata);
printf("Openning device...\n"); printf("Openning device...\n");
data->eventStream = open("/dev/input/wacom-touch", data->eventStream = open("/dev/input/wacom",
O_RDONLY | O_NONBLOCK); O_RDONLY | O_NONBLOCK);
ioctl (data->eventStream, EVIOCGNAME (sizeof (name)), name); ioctl (data->eventStream, EVIOCGNAME (sizeof (name)), name);
printf ("Reading From : %s\n", name); printf ("Reading From : %s\n", name);
...@@ -452,24 +452,31 @@ X11_PumpEvents(_THIS) ...@@ -452,24 +452,31 @@ X11_PumpEvents(_THIS)
data->x = ev[i].value; data->x = ev[i].value;
else if (ev[i].code == ABS_Y) else if (ev[i].code == ABS_Y)
data->y = ev[i].value; data->y = ev[i].value;
else if (ev[i].code == ABS_MISC) {
data->up = SDL_TRUE;
data->finger = ev[i].value;
}
break; break;
case EV_MSC: case EV_MSC:
if(ev[i].code == MSC_SERIAL) if(ev[i].code == MSC_SERIAL)
data->finger = ev[i].value; data->finger = ev[i].value;
break; break;
case EV_SYN: case EV_SYN:
data->finger -= 1; /*Wacom indexes fingers from 1,
I index from 0*/
if(data->x >= 0 || data->y >= 0) if(data->x >= 0 || data->y >= 0)
SDL_SendTouchMotion(touch->id,data->finger, SDL_SendTouchMotion(touch->id,data->finger,
SDL_FALSE,data->x,data->y, SDL_FALSE,data->x,data->y,
data->pressure); 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", //printf("Synched: %i tx: %i, ty: %i\n",
// data->finger,data->x,data->y); // data->finger,data->x,data->y);
data->x = -1; data->x = -1;
data->y = -1; data->y = -1;
data->pressure = -1; data->pressure = -1;
data->finger = 0;
data->up = SDL_FALSE;
break; break;
} }
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#define BPP 4 #define BPP 4
#define DEPTH 32 #define DEPTH 32
#define MAXFINGERS 3
int mousx,mousy; int mousx,mousy;
int keystat[512]; int keystat[512];
int bstatus; int bstatus;
...@@ -20,6 +22,9 @@ typedef struct { ...@@ -20,6 +22,9 @@ typedef struct {
int x,y; int x,y;
} Point; } Point;
Point finger[MAXFINGERS];
void handler (int sig) void handler (int sig)
{ {
printf ("\nexiting...(%d)\n", sig); printf ("\nexiting...(%d)\n", sig);
...@@ -78,6 +83,10 @@ void DrawScreen(SDL_Surface* screen, int h) ...@@ -78,6 +83,10 @@ void DrawScreen(SDL_Surface* screen, int h)
} }
drawCircle(screen,mousx,mousy,30,0xFFFFFF); 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); if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
...@@ -144,14 +153,25 @@ int main(int argc, char* argv[]) ...@@ -144,14 +153,25 @@ int main(int argc, char* argv[])
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
bstatus &= ~(1<<(event.button.button-1)); bstatus &= ~(1<<(event.button.button-1));
break; break;
case SDL_FINGERMOTION: case SDL_FINGERMOTION:
i = 1;
//printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId, // event.tfinger.x,event.tfinger.y);
event.tfinger.x,event.tfinger.y); finger[event.tfinger.fingerId].x = event.tfinger.x;
finger[event.tfinger.fingerId].y = event.tfinger.y;
break; 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 //And draw
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment