============================================================
authorSam Lantinga <slouken@libsdl.org>
Tue, 27 Sep 2011 23:14:16 -0400
changeset 59662edecf22a2e7
parent 5965 dd0c84d3d846
child 5967 ae97a61f002f
============================================================
src/video/x11/SDL_x11touch.c
     1.1 --- a/src/video/x11/SDL_x11touch.c	Wed Sep 21 03:08:00 2011 -0400
     1.2 +++ b/src/video/x11/SDL_x11touch.c	Tue Sep 27 23:14:16 2011 -0400
     1.3 @@ -38,7 +38,7 @@
     1.4  #ifdef SDL_INPUT_LINUXEV
     1.5    FILE *fd;
     1.6    fd = fopen("/proc/bus/input/devices","r");
     1.7 -  
     1.8 +
     1.9    char c;
    1.10    int i = 0;
    1.11    char line[256];
    1.12 @@ -47,46 +47,44 @@
    1.13    while(!feof(fd)) {
    1.14      if(fgets(line,256,fd) <=0) continue;
    1.15      if(line[0] == '\n') {
    1.16 -    if(vendor == 1386 || vendor==1){
    1.17 +      if(vendor == 1386 || vendor==1) {
    1.18 +
    1.19 +        sprintf(tstr,"/dev/input/event%i",event);
    1.20  
    1.21 -	sprintf(tstr,"/dev/input/event%i",event);
    1.22 +        SDL_Touch touch;
    1.23 +        touch.pressure_max = 0;
    1.24 +        touch.pressure_min = 0;
    1.25 +        touch.id = event; 
    1.26  
    1.27 -	SDL_Touch touch;
    1.28 -	touch.pressure_max = 0;
    1.29 -	touch.pressure_min = 0;
    1.30 -	touch.id = event; 
    1.31 -	
    1.32 +        touch.driverdata = SDL_malloc(sizeof(EventTouchData));
    1.33 +        EventTouchData* data = (EventTouchData*)(touch.driverdata);
    1.34  
    1.35 -	touch.driverdata = SDL_malloc(sizeof(EventTouchData));
    1.36 -	EventTouchData* data = (EventTouchData*)(touch.driverdata);
    1.37 +        data->x = -1;
    1.38 +        data->y = -1;
    1.39 +        data->pressure = -1;
    1.40 +        data->finger = 0;
    1.41 +        data->up = SDL_FALSE;
    1.42 +        data->down = SDL_FALSE;
    1.43  
    1.44 -	data->x = -1;
    1.45 -	data->y = -1;
    1.46 -	data->pressure = -1;
    1.47 -	data->finger = 0;
    1.48 -	data->up = SDL_FALSE;
    1.49 -    data->down = SDL_FALSE;
    1.50 -	
    1.51 -
    1.52 -	data->eventStream = open(tstr, 
    1.53 -				 O_RDONLY | O_NONBLOCK);
    1.54 -	ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
    1.55 +        data->eventStream = open(tstr, 
    1.56 +                    O_RDONLY | O_NONBLOCK);
    1.57 +        ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
    1.58  
    1.59 -	int abs[5];
    1.60 -	ioctl(data->eventStream,EVIOCGABS(0),abs);	
    1.61 -	touch.x_min = abs[1];
    1.62 -	touch.x_max = abs[2];
    1.63 -	touch.native_xres = touch.x_max - touch.x_min;
    1.64 -	ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
    1.65 -	touch.y_min = abs[1];
    1.66 -	touch.y_max = abs[2];
    1.67 -	touch.native_yres = touch.y_max - touch.y_min;
    1.68 -	ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
    1.69 -	touch.pressure_min = abs[1];
    1.70 -	touch.pressure_max = abs[2];
    1.71 -	touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    1.72 +        int abs[5];
    1.73 +        ioctl(data->eventStream,EVIOCGABS(0),abs);	
    1.74 +        touch.x_min = abs[1];
    1.75 +        touch.x_max = abs[2];
    1.76 +        touch.native_xres = touch.x_max - touch.x_min;
    1.77 +        ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
    1.78 +        touch.y_min = abs[1];
    1.79 +        touch.y_max = abs[2];
    1.80 +        touch.native_yres = touch.y_max - touch.y_min;
    1.81 +        ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
    1.82 +        touch.pressure_min = abs[1];
    1.83 +        touch.pressure_max = abs[2];
    1.84 +        touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    1.85  
    1.86 -	SDL_AddTouch(&touch, tstr);
    1.87 +        SDL_AddTouch(&touch, tstr);
    1.88        }
    1.89        vendor = -1;
    1.90        product = -1;
    1.91 @@ -95,20 +93,20 @@
    1.92      else if(line[0] == 'I') {
    1.93        i = 1;
    1.94        while(line[i]) {
    1.95 -	sscanf(&line[i],"Vendor=%x",&vendor);
    1.96 -	sscanf(&line[i],"Product=%x",&product);
    1.97 -	i++;
    1.98 +        sscanf(&line[i],"Vendor=%x",&vendor);
    1.99 +        sscanf(&line[i],"Product=%x",&product);
   1.100 +        i++;
   1.101        }
   1.102      }
   1.103      else if(line[0] == 'H') {
   1.104        i = 1;
   1.105        while(line[i]) {
   1.106 -	sscanf(&line[i],"event%d",&event);
   1.107 -	i++;
   1.108 +        sscanf(&line[i],"event%d",&event);
   1.109 +        i++;
   1.110        }
   1.111      }
   1.112    }
   1.113 -  
   1.114 +
   1.115    close(fd);
   1.116  #endif
   1.117  }