src/video/x11/SDL_eventtouch.c
author Jim Grandpre
Mon, 31 May 2010 00:24:37 -0400
changeset 4645 0375d020e7e3
child 4646 eea1bf53effa
permissions -rw-r--r--
Auto-detects Wacom touch devices.
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
jim@4645
    27
#include <linux/input.h>
jim@4645
    28
#include <fcntl.h>
jim@4645
    29
jim@4645
    30
void
jim@4645
    31
X11_InitTouch(_THIS)
jim@4645
    32
{
jim@4645
    33
  printf("Initializing touch...\n");
jim@4645
    34
jim@4645
    35
  FILE *fd;
jim@4645
    36
  fd = fopen("/proc/bus/input/devices","r");
jim@4645
    37
  
jim@4645
    38
  char c;
jim@4645
    39
  int i = 0;
jim@4645
    40
  char line[256];
jim@4645
    41
  char tstr[256];
jim@4645
    42
  int vendor = -1,product = -1,event = -1;
jim@4645
    43
  while(!feof(fd)) {
jim@4645
    44
    if(fgets(line,256,fd) <=0) continue;
jim@4645
    45
    //printf("%s",line);
jim@4645
    46
    if(line[0] == '\n') {
jim@4645
    47
      if(vendor == 1386){
jim@4645
    48
	printf("Wacom... Assuming it is a touch device\n");
jim@4645
    49
	sprintf(tstr,"/dev/input/event%i",event);
jim@4645
    50
	printf("At location: %s\n",tstr);
jim@4645
    51
jim@4645
    52
	SDL_Touch touch;
jim@4645
    53
	touch.pressure_max = 0;
jim@4645
    54
	touch.pressure_min = 0;
jim@4645
    55
	touch.id = event; 
jim@4645
    56
    
jim@4645
    57
	
jim@4645
    58
jim@4645
    59
	touch.driverdata = SDL_malloc(sizeof(EventTouchData));
jim@4645
    60
	EventTouchData* data = (EventTouchData*)(touch.driverdata);
jim@4645
    61
	printf("Opening device...\n");
jim@4645
    62
	//printf("New Touch - DataPtr: %i\n",data);
jim@4645
    63
	data->eventStream = open(tstr, 
jim@4645
    64
				 O_RDONLY | O_NONBLOCK);
jim@4645
    65
	ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
jim@4645
    66
	printf ("Reading From : %s\n", tstr);
jim@4645
    67
	SDL_AddTouch(&touch, tstr);
jim@4645
    68
jim@4645
    69
      }
jim@4645
    70
      vendor = -1;
jim@4645
    71
      product = -1;
jim@4645
    72
      event = -1;      
jim@4645
    73
    }
jim@4645
    74
    else if(line[0] == 'I') {
jim@4645
    75
      i = 1;
jim@4645
    76
      while(line[i]) {
jim@4645
    77
	sscanf(&line[i],"Vendor=%x",&vendor);
jim@4645
    78
	sscanf(&line[i],"Product=%x",&product);
jim@4645
    79
	i++;
jim@4645
    80
      }
jim@4645
    81
    }
jim@4645
    82
    else if(line[0] == 'H') {
jim@4645
    83
      i = 1;
jim@4645
    84
      while(line[i]) {
jim@4645
    85
	sscanf(&line[i],"event%d",&event);
jim@4645
    86
	i++;
jim@4645
    87
      }
jim@4645
    88
    }
jim@4645
    89
  }
jim@4645
    90
  
jim@4645
    91
  close(fd);
jim@4645
    92
}
jim@4645
    93
jim@4645
    94
void
jim@4645
    95
X11_QuitTouch(_THIS)
jim@4645
    96
{
jim@4645
    97
    SDL_TouchQuit();
jim@4645
    98
}
jim@4645
    99
jim@4645
   100
/* vi: set ts=4 sw=4 expandtab: */