Commit 27ad25a0 authored by Jim Grandpre's avatar Jim Grandpre

Added SDL_touch.c/SDL_touch_c.h as slightly modifeind SDL_mouse*. Made reads...

Added SDL_touch.c/SDL_touch_c.h as slightly modifeind SDL_mouse*. Made reads in touchSimp non-blocking.
parent bc2e106a
......@@ -26,6 +26,7 @@
#include "SDL_thread.h"
#include "SDL_mouse_c.h"
#include "SDL_keyboard_c.h"
#include "SDL_touch_c.h"
#include "SDL_windowevents_c.h"
/* Start and stop the event processing loop */
......
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2010 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifndef _SDL_touch_c_h
#define _SDL_touch_c_h
typedef struct SDL_Touch SDL_Touch;
struct SDL_Touch
{
/* Warp the touch to (x,y) */
void (*WarpTouch) (SDL_Touch * touch, SDL_Window * window, int x,
int y);
/* Free the touch when it's time */
void (*FreeTouch) (SDL_Touch * touch);
/* data common for tablets */
int pressure;
int pressure_max;
int pressure_min;
int tilt; /* for future use */
int rotation; /* for future use */
int total_ends;
int current_end;
/* Data common to all touch */
int id;
SDL_Window *focus;
int which;
int x;
int y;
int z; /* for future use */
int xdelta;
int ydelta;
int last_x, last_y; /* the last reported x and y coordinates */
char *name;
Uint8 buttonstate;
SDL_bool relative_mode;
SDL_bool proximity;
SDL_bool flush_motion;
SDL_Cursor *cursors;
SDL_Cursor *def_cursor;
SDL_Cursor *cur_cursor;
SDL_bool cursor_shown;
void *driverdata;
};
/* Initialize the touch subsystem */
extern int SDL_TouchInit(void);
/* Get the touch at an index */
extern SDL_Touch *SDL_GetTouch(int index);
/* Add a touch, possibly reattaching at a particular index (or -1),
returning the index of the touch, or -1 if there was an error.
*/
extern int SDL_AddTouch(const SDL_Touch * touch, char *name,
int pressure_max, int pressure_min, int ends);
/* Remove a touch at an index, clearing the slot for later */
extern void SDL_DelTouch(int index);
/* Clear the button state of a touch at an index */
extern void SDL_ResetTouch(int index);
/* Set the touch focus window */
extern void SDL_SetTouchFocus(int id, SDL_Window * window);
/* Send a touch motion event for a touch */
extern int SDL_SendTouchMotion(int id, int relative, int x, int y, int z);
/* Send a touch button event for a touch */
extern int SDL_SendTouchButton(int id, Uint8 state, Uint8 button);
/* Send a touch wheel event for a touch */
extern int SDL_SendTouchWheel(int id, int x, int y);
/* Send a proximity event for a touch */
extern int SDL_SendProximity(int id, int x, int y, int type);
/* Shutdown the touch subsystem */
extern void SDL_TouchQuit(void);
/* FIXME: Where do these functions go in this header? */
extern void SDL_ChangeEnd(int id, int end);
#endif /* _SDL_touch_c_h */
/* vi: set ts=4 sw=4 expandtab: */
......@@ -408,6 +408,10 @@ X11_PumpEvents(_THIS)
while (X11_Pending(data->display)) {
X11_DispatchEvent(_this);
}
/* Process Touch events - TODO When X gets touch support, REMOVE THIS*/
}
/* This is so wrong it hurts */
......
No preview for this file type
......@@ -20,6 +20,7 @@ int bstatus;
typedef struct {
int x,y;
} Point;
......@@ -120,7 +121,7 @@ int main(int argc, char* argv[])
device = argv[1];
//Open Device
if ((fd = open (device, O_RDONLY)) == -1)
if ((fd = open (device, O_RDONLY | O_NONBLOCK)) == -1)
printf ("%s is not a vaild device.\n", device);
//Print Device Name
......@@ -189,50 +190,53 @@ int main(int argc, char* argv[])
}
//poll for Touch <- Goal: make this a case:
if ((rd = read (fd, ev, size * 64)) < size)
perror_exit ("read()");
/*if ((rd = read (fd, ev, size * 64)) < size)
perror_exit ("read()"); */
//printf("time: %i\n type: %X\n code: %X\n value: %i\n ",
// ev->time,ev->type,ev->code,ev->value);
for (i = 0; i < rd / sizeof(struct input_event); i++)
switch (ev[i].type)
{
case EV_ABS:
if(ev[i].code == ABS_X)
tx = ev[i].value;
else if (ev[i].code == ABS_Y)
ty = ev[i].value;
else if (ev[i].code == ABS_MISC)
{
//printf("Misc:type: %X\n code: %X\n value: %i\n ",
// ev[i].type,ev[i].code,ev[i].value);
}
break;
case EV_MSC:
if(ev[i].code == MSC_SERIAL)
curf = ev[i].value;
break;
case EV_SYN:
curf -= 1;
if(tx >= 0)
finger[curf].x = tx;
if(ty >= 0)
finger[curf].y = ty;
//printf("Synched: %i tx: %i, ty: %i\n",curf,finger[curf].x,finger[curf].y);
tx = -1;
ty = -1;
break;
}
//And draw
DrawScreen(screen,h);
/*
for(i=0;i<512;i++)
if(keystat[i]) printf("%i\n",i);
printf("Buttons:%i\n",bstatus);
*/
}
SDL_Quit();
if((rd = read (fd, ev, size * 64)) >= size)
for (i = 0; i < rd / sizeof(struct input_event); i++)
switch (ev[i].type)
{
case EV_ABS:
if(ev[i].code == ABS_X)
tx = ev[i].value;
else if (ev[i].code == ABS_Y)
ty = ev[i].value;
else if (ev[i].code == ABS_MISC)
{
//printf("Misc:type: %X\n code: %X\n value: %i\n ",
// ev[i].type,ev[i].code,ev[i].value);
}
break;
case EV_MSC:
if(ev[i].code == MSC_SERIAL)
curf = ev[i].value;
break;
case EV_SYN:
curf -= 1;
if(tx >= 0)
finger[curf].x = tx;
if(ty >= 0)
finger[curf].y = ty;
//printf("Synched: %i tx: %i, ty: %i\n",curf,finger[curf].x,finger[curf].y);
tx = -1;
ty = -1;
break;
}
//And draw
DrawScreen(screen,h);
/*
for(i=0;i<512;i++)
if(keystat[i]) printf("%i\n",i);
printf("Buttons:%i\n",bstatus);
*/
}
SDL_Quit();
return 0;
}
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