src/video/x11/SDL_x11touch.c
author Sam Lantinga
Tue, 08 Feb 2011 16:50:51 -0800
changeset 5229 c015d3e63631
parent 5044 4913042e8572
child 5262 b530ef003506
permissions -rw-r--r--
Fixed setting the texture unit, still doesn't work.
jim@4645
     1
/*
jim@4645
     2
    SDL - Simple DirectMedia Layer
jim@4645
     3
    Copyright (C) 1997-2010 Sam Lantinga
jim@4645
     4
jim@4645
     5
    This library is free software; you can redistribute it and/or
jim@4645
     6
    modify it under the terms of the GNU Lesser General Public
jim@4645
     7
    License as published by the Free Software Foundation; either
jim@4645
     8
    version 2.1 of the License, or (at your option) any later version.
jim@4645
     9
jim@4645
    10
    This library is distributed in the hope that it will be useful,
jim@4645
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
jim@4645
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
jim@4645
    13
    Lesser General Public License for more details.
jim@4645
    14
jim@4645
    15
    You should have received a copy of the GNU Lesser General Public
jim@4645
    16
    License along with this library; if not, write to the Free Software
jim@4645
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
jim@4645
    18
jim@4645
    19
    Sam Lantinga
jim@4645
    20
    slouken@libsdl.org
jim@4645
    21
*/
jim@4645
    22
#include "SDL_config.h"
jim@4645
    23
#include "SDL_x11video.h"
slouken@4923
    24
#include "SDL_x11touch.h"
jim@4645
    25
#include "../../events/SDL_touch_c.h"
jim@4645
    26
jim@4681
    27
jim@4681
    28
#ifdef SDL_INPUT_LINUXEV
jim@4645
    29
#include <linux/input.h>
jim@4645
    30
#include <fcntl.h>
jimtla@4669
    31
#endif
jim@4645
    32
jim@4645
    33
void
jim@4645
    34
X11_InitTouch(_THIS)
jim@4645
    35
{
jim@4681
    36
#ifdef SDL_INPUT_LINUXEV
jim@4645
    37
  FILE *fd;
jim@4645
    38
  fd = fopen("/proc/bus/input/devices","r");
jim@4645
    39
  
jim@4645
    40
  char c;
jim@4645
    41
  int i = 0;
jim@4645
    42
  char line[256];
jim@4645
    43
  char tstr[256];
jim@4645
    44
  int vendor = -1,product = -1,event = -1;
jim@4645
    45
  while(!feof(fd)) {
jim@4645
    46
    if(fgets(line,256,fd) <=0) continue;
jim@4645
    47
    if(line[0] == '\n') {
jim@4645
    48
      if(vendor == 1386){
slouken@5044
    49
	/*printf("Wacom... Assuming it is a touch device\n");*/
slouken@5044
    50
	/*sprintf(tstr,"/dev/input/event%i",event);*/
slouken@5044
    51
	/*printf("At location: %s\n",tstr);*/
jim@4645
    52
jim@4645
    53
	SDL_Touch touch;
jim@4645
    54
	touch.pressure_max = 0;
jim@4645
    55
	touch.pressure_min = 0;
jim@4645
    56
	touch.id = event; 
jim@4645
    57
	
jim@4645
    58
jim@4645
    59
	touch.driverdata = SDL_malloc(sizeof(EventTouchData));
jim@4645
    60
	EventTouchData* data = (EventTouchData*)(touch.driverdata);
jim@4683
    61
jim@4683
    62
	data->x = -1;
jim@4683
    63
	data->y = -1;
jim@4683
    64
	data->pressure = -1;
jim@4683
    65
	data->finger = 0;
jim@4683
    66
	data->up = SDL_FALSE;
jim@4683
    67
	
jim@4683
    68
jim@4645
    69
	data->eventStream = open(tstr, 
jim@4645
    70
				 O_RDONLY | O_NONBLOCK);
jim@4645
    71
	ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
jim@4646
    72
jim@4646
    73
	int abs[5];
jim@4646
    74
	ioctl(data->eventStream,EVIOCGABS(0),abs);	
jim@4646
    75
	touch.x_min = abs[1];
jim@4646
    76
	touch.x_max = abs[2];
jimtla@4678
    77
	touch.native_xres = touch.x_max - touch.x_min;
jim@4646
    78
	ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
jim@4646
    79
	touch.y_min = abs[1];
jim@4646
    80
	touch.y_max = abs[2];
jimtla@4678
    81
	touch.native_yres = touch.y_max - touch.y_min;
jim@4646
    82
	ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
jim@4646
    83
	touch.pressure_min = abs[1];
jim@4646
    84
	touch.pressure_max = abs[2];
jimtla@4678
    85
	touch.native_pressureres = touch.pressure_max - touch.pressure_min;
jim@4646
    86
jim@4645
    87
	SDL_AddTouch(&touch, tstr);
jim@4645
    88
      }
jim@4645
    89
      vendor = -1;
jim@4645
    90
      product = -1;
jim@4645
    91
      event = -1;      
jim@4645
    92
    }
jim@4645
    93
    else if(line[0] == 'I') {
jim@4645
    94
      i = 1;
jim@4645
    95
      while(line[i]) {
jim@4645
    96
	sscanf(&line[i],"Vendor=%x",&vendor);
jim@4645
    97
	sscanf(&line[i],"Product=%x",&product);
jim@4645
    98
	i++;
jim@4645
    99
      }
jim@4645
   100
    }
jim@4645
   101
    else if(line[0] == 'H') {
jim@4645
   102
      i = 1;
jim@4645
   103
      while(line[i]) {
jim@4645
   104
	sscanf(&line[i],"event%d",&event);
jim@4645
   105
	i++;
jim@4645
   106
      }
jim@4645
   107
    }
jim@4645
   108
  }
jim@4645
   109
  
jim@4645
   110
  close(fd);
jimtla@4669
   111
#endif
jim@4645
   112
}
jim@4645
   113
jim@4645
   114
void
jim@4645
   115
X11_QuitTouch(_THIS)
jim@4645
   116
{
jim@4645
   117
    SDL_TouchQuit();
jim@4645
   118
}
jim@4645
   119
jim@4645
   120
/* vi: set ts=4 sw=4 expandtab: */