src/video/x11/SDL_eventtouch.c
author jimtla
Thu, 22 Jul 2010 08:12:28 +0400
changeset 4669 62e6a6e9720b
parent 4646 eea1bf53effa
child 4678 f8431f66613d
permissions -rw-r--r--
Fixed x11 compile bugs.
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"
jim@4645
    24
#include "SDL_eventtouch.h"
jim@4645
    25
#include "../../events/SDL_touch_c.h"
jim@4645
    26
jimtla@4669
    27
#ifdef HAVE_LINUX_INPUT_H
jim@4645
    28
#include <linux/input.h>
jim@4645
    29
#include <fcntl.h>
jimtla@4669
    30
#endif
jim@4645
    31
jim@4645
    32
void
jim@4645
    33
X11_InitTouch(_THIS)
jim@4645
    34
{
jimtla@4669
    35
#ifdef HAVE_LINUX_INPUT_H
jim@4645
    36
  printf("Initializing touch...\n");
jim@4645
    37
jim@4645
    38
  FILE *fd;
jim@4645
    39
  fd = fopen("/proc/bus/input/devices","r");
jim@4645
    40
  
jim@4645
    41
  char c;
jim@4645
    42
  int i = 0;
jim@4645
    43
  char line[256];
jim@4645
    44
  char tstr[256];
jim@4645
    45
  int vendor = -1,product = -1,event = -1;
jim@4645
    46
  while(!feof(fd)) {
jim@4645
    47
    if(fgets(line,256,fd) <=0) continue;
jim@4645
    48
    //printf("%s",line);
jim@4645
    49
    if(line[0] == '\n') {
jim@4645
    50
      if(vendor == 1386){
jim@4645
    51
	printf("Wacom... Assuming it is a touch device\n");
jim@4645
    52
	sprintf(tstr,"/dev/input/event%i",event);
jim@4645
    53
	printf("At location: %s\n",tstr);
jim@4645
    54
jim@4645
    55
	SDL_Touch touch;
jim@4645
    56
	touch.pressure_max = 0;
jim@4645
    57
	touch.pressure_min = 0;
jim@4645
    58
	touch.id = event; 
jim@4646
    59
jim@4646
    60
	
jim@4646
    61
jim@4645
    62
	
jim@4645
    63
jim@4645
    64
	touch.driverdata = SDL_malloc(sizeof(EventTouchData));
jim@4645
    65
	EventTouchData* data = (EventTouchData*)(touch.driverdata);
jim@4645
    66
	printf("Opening device...\n");
jim@4645
    67
	//printf("New Touch - DataPtr: %i\n",data);
jim@4645
    68
	data->eventStream = open(tstr, 
jim@4645
    69
				 O_RDONLY | O_NONBLOCK);
jim@4645
    70
	ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
jim@4645
    71
	printf ("Reading From : %s\n", tstr);
jim@4646
    72
jim@4646
    73
jim@4646
    74
jim@4646
    75
	int abs[5];
jim@4646
    76
	ioctl(data->eventStream,EVIOCGABS(0),abs);	
jim@4646
    77
	touch.x_min = abs[1];
jim@4646
    78
	touch.x_max = abs[2];
jim@4646
    79
	touch.xres = touch.x_max - touch.x_min;
jim@4646
    80
	ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
jim@4646
    81
	touch.y_min = abs[1];
jim@4646
    82
	touch.y_max = abs[2];
jim@4646
    83
	touch.yres = touch.y_max - touch.y_min;
jim@4646
    84
	ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
jim@4646
    85
	touch.pressure_min = abs[1];
jim@4646
    86
	touch.pressure_max = abs[2];
jim@4646
    87
	touch.pressureres = touch.pressure_max - touch.pressure_min;
jim@4646
    88
jim@4646
    89
jim@4645
    90
	SDL_AddTouch(&touch, tstr);
jim@4645
    91
jim@4645
    92
      }
jim@4645
    93
      vendor = -1;
jim@4645
    94
      product = -1;
jim@4645
    95
      event = -1;      
jim@4645
    96
    }
jim@4645
    97
    else if(line[0] == 'I') {
jim@4645
    98
      i = 1;
jim@4645
    99
      while(line[i]) {
jim@4645
   100
	sscanf(&line[i],"Vendor=%x",&vendor);
jim@4645
   101
	sscanf(&line[i],"Product=%x",&product);
jim@4645
   102
	i++;
jim@4645
   103
      }
jim@4645
   104
    }
jim@4645
   105
    else if(line[0] == 'H') {
jim@4645
   106
      i = 1;
jim@4645
   107
      while(line[i]) {
jim@4645
   108
	sscanf(&line[i],"event%d",&event);
jim@4645
   109
	i++;
jim@4645
   110
      }
jim@4645
   111
    }
jim@4645
   112
  }
jim@4645
   113
  
jim@4645
   114
  close(fd);
jimtla@4669
   115
#endif
jim@4645
   116
}
jim@4645
   117
jim@4645
   118
void
jim@4645
   119
X11_QuitTouch(_THIS)
jim@4645
   120
{
jim@4645
   121
    SDL_TouchQuit();
jim@4645
   122
}
jim@4645
   123
jim@4645
   124
/* vi: set ts=4 sw=4 expandtab: */