src/video/x11/SDL_x11touch.c
changeset 6316 a89c79a3f0cd
parent 6138 4c64952a58fb
child 6348 049721824c2e
equal deleted inserted replaced
6315:ad9087c284e9 6316:a89c79a3f0cd
    22 
    22 
    23 #if SDL_VIDEO_DRIVER_X11
    23 #if SDL_VIDEO_DRIVER_X11
    24 
    24 
    25 #include "SDL_x11video.h"
    25 #include "SDL_x11video.h"
    26 #include "SDL_x11touch.h"
    26 #include "SDL_x11touch.h"
       
    27 #include "SDL_x11xinput2.h"
    27 #include "../../events/SDL_touch_c.h"
    28 #include "../../events/SDL_touch_c.h"
    28 
    29 
    29 
    30 
    30 #ifdef SDL_INPUT_LINUXEV
    31 #ifdef SDL_INPUT_LINUXEV
    31 #include <linux/input.h>
    32 #include <linux/input.h>
    33 #endif
    34 #endif
    34 
    35 
    35 void
    36 void
    36 X11_InitTouch(_THIS)
    37 X11_InitTouch(_THIS)
    37 {
    38 {
       
    39     /*Initilized Xinput2 multitouch 
       
    40     * and return in order to not initialize
       
    41     * evtouch also*/
       
    42     if(X11_Xinput2IsMutitouchSupported()) {
       
    43         X11_InitXinput2Multitouch(_this);
       
    44         return;
       
    45     }
    38 #ifdef SDL_INPUT_LINUXEV
    46 #ifdef SDL_INPUT_LINUXEV
    39   FILE *fd;
    47     FILE *fd;
    40   fd = fopen("/proc/bus/input/devices","r");
    48     fd = fopen("/proc/bus/input/devices","r");
    41 
    49 
    42   int i = 0;
    50     int i = 0;
    43   int tsfd;
    51     int tsfd;
    44   char line[256];
    52     char line[256];
    45   char tstr[256];
    53     char tstr[256];
    46   int vendor = -1,product = -1,event = -1;
    54     int vendor = -1,product = -1,event = -1;
    47   while(!feof(fd)) {
    55     while(!feof(fd)) {
    48     if(fgets(line,256,fd) <=0) continue;
    56         if(fgets(line,256,fd) <=0) continue;
    49     if(line[0] == '\n') {
    57         if(line[0] == '\n') {
    50       if(vendor == 1386 || vendor==1) {
    58             if(vendor == 1386 || vendor==1) {
       
    59                 sprintf(tstr,"/dev/input/event%i",event);
    51 
    60 
    52         sprintf(tstr,"/dev/input/event%i",event);
    61                 tsfd = open( tstr, O_RDONLY | O_NONBLOCK );
       
    62                 if ( tsfd == -1 )
       
    63                     continue;   /* Maybe not enough permissions ? */
    53 
    64 
    54         tsfd = open( tstr, O_RDONLY | O_NONBLOCK );
    65                 SDL_Touch touch;
    55         if ( tsfd == -1 )
    66                 touch.pressure_max = 0;
    56             continue;   /* Maybe not enough permissions ? */
    67                 touch.pressure_min = 0;
       
    68                 touch.id = event; 
    57 
    69 
    58         SDL_Touch touch;
    70                 touch.driverdata = SDL_malloc(sizeof(EventTouchData));
    59         touch.pressure_max = 0;
    71                 EventTouchData* data = (EventTouchData*)(touch.driverdata);
    60         touch.pressure_min = 0;
       
    61         touch.id = event; 
       
    62 
    72 
    63         touch.driverdata = SDL_malloc(sizeof(EventTouchData));
    73                 data->x = -1;
    64         EventTouchData* data = (EventTouchData*)(touch.driverdata);
    74                 data->y = -1;
       
    75                 data->pressure = -1;
       
    76                 data->finger = 0;
       
    77                 data->up = SDL_FALSE;
       
    78                 data->down = SDL_FALSE;
    65 
    79 
    66         data->x = -1;
    80                 data->eventStream = tsfd;
    67         data->y = -1;
    81                 ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
    68         data->pressure = -1;
       
    69         data->finger = 0;
       
    70         data->up = SDL_FALSE;
       
    71         data->down = SDL_FALSE;
       
    72 
    82 
    73         data->eventStream = tsfd;
    83                 int abs[5];
    74         ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
    84                 ioctl(data->eventStream,EVIOCGABS(0),abs);	
       
    85                 touch.x_min = abs[1];
       
    86                 touch.x_max = abs[2];
       
    87                 touch.native_xres = touch.x_max - touch.x_min;
       
    88                 ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
       
    89                 touch.y_min = abs[1];
       
    90                 touch.y_max = abs[2];
       
    91                 touch.native_yres = touch.y_max - touch.y_min;
       
    92                 ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
       
    93                 touch.pressure_min = abs[1];
       
    94                 touch.pressure_max = abs[2];
       
    95                 touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    75 
    96 
    76         int abs[5];
    97                 SDL_AddTouch(&touch, tstr);
    77         ioctl(data->eventStream,EVIOCGABS(0),abs);	
    98             }
    78         touch.x_min = abs[1];
    99             vendor = -1;
    79         touch.x_max = abs[2];
   100             product = -1;
    80         touch.native_xres = touch.x_max - touch.x_min;
   101             event = -1;      
    81         ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
   102         }
    82         touch.y_min = abs[1];
   103         else if(line[0] == 'I') {
    83         touch.y_max = abs[2];
   104             i = 1;
    84         touch.native_yres = touch.y_max - touch.y_min;
   105             while(line[i]) {
    85         ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
   106                 sscanf(&line[i],"Vendor=%x",&vendor);
    86         touch.pressure_min = abs[1];
   107                 sscanf(&line[i],"Product=%x",&product);
    87         touch.pressure_max = abs[2];
   108                 i++;
    88         touch.native_pressureres = touch.pressure_max - touch.pressure_min;
   109             }
    89 
   110         }
    90         SDL_AddTouch(&touch, tstr);
   111         else if(line[0] == 'H') {
    91       }
   112             i = 1;
    92       vendor = -1;
   113             while(line[i]) {
    93       product = -1;
   114                 sscanf(&line[i],"event%d",&event);
    94       event = -1;      
   115                 i++;
       
   116             }
       
   117         }
    95     }
   118     }
    96     else if(line[0] == 'I') {
   119     fclose(fd);
    97       i = 1;
       
    98       while(line[i]) {
       
    99         sscanf(&line[i],"Vendor=%x",&vendor);
       
   100         sscanf(&line[i],"Product=%x",&product);
       
   101         i++;
       
   102       }
       
   103     }
       
   104     else if(line[0] == 'H') {
       
   105       i = 1;
       
   106       while(line[i]) {
       
   107         sscanf(&line[i],"event%d",&event);
       
   108         i++;
       
   109       }
       
   110     }
       
   111   }
       
   112 
       
   113   fclose(fd);
       
   114 #endif
   120 #endif
   115 }
   121 }
   116 
   122 
   117 void
   123 void
   118 X11_QuitTouch(_THIS)
   124 X11_QuitTouch(_THIS)