src/video/x11/SDL_x11touch.c
author Sam Lantinga
Sat, 12 Mar 2011 13:21:57 -0800
changeset 5481 22dfc3958dc3
parent 5262 b530ef003506
child 5535 96594ac5fd1a
permissions -rw-r--r--
Fixed so code will compile with SDL_config_minimal.h
jim@4645
     1
/*
jim@4645
     2
    SDL - Simple DirectMedia Layer
slouken@5262
     3
    Copyright (C) 1997-2011 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"
slouken@5481
    23
slouken@5481
    24
#if SDL_VIDEO_DRIVER_X11
slouken@5481
    25
jim@4645
    26
#include "SDL_x11video.h"
slouken@4923
    27
#include "SDL_x11touch.h"
jim@4645
    28
#include "../../events/SDL_touch_c.h"
jim@4645
    29
jim@4681
    30
jim@4681
    31
#ifdef SDL_INPUT_LINUXEV
jim@4645
    32
#include <linux/input.h>
jim@4645
    33
#include <fcntl.h>
jimtla@4669
    34
#endif
jim@4645
    35
jim@4645
    36
void
jim@4645
    37
X11_InitTouch(_THIS)
jim@4645
    38
{
jim@4681
    39
#ifdef SDL_INPUT_LINUXEV
jim@4645
    40
  FILE *fd;
jim@4645
    41
  fd = fopen("/proc/bus/input/devices","r");
jim@4645
    42
  
jim@4645
    43
  char c;
jim@4645
    44
  int i = 0;
jim@4645
    45
  char line[256];
jim@4645
    46
  char tstr[256];
jim@4645
    47
  int vendor = -1,product = -1,event = -1;
jim@4645
    48
  while(!feof(fd)) {
jim@4645
    49
    if(fgets(line,256,fd) <=0) continue;
jim@4645
    50
    if(line[0] == '\n') {
jim@4645
    51
      if(vendor == 1386){
slouken@5044
    52
	/*printf("Wacom... Assuming it is a touch device\n");*/
slouken@5044
    53
	/*sprintf(tstr,"/dev/input/event%i",event);*/
slouken@5044
    54
	/*printf("At location: %s\n",tstr);*/
jim@4645
    55
jim@4645
    56
	SDL_Touch touch;
jim@4645
    57
	touch.pressure_max = 0;
jim@4645
    58
	touch.pressure_min = 0;
jim@4645
    59
	touch.id = event; 
jim@4645
    60
	
jim@4645
    61
jim@4645
    62
	touch.driverdata = SDL_malloc(sizeof(EventTouchData));
jim@4645
    63
	EventTouchData* data = (EventTouchData*)(touch.driverdata);
jim@4683
    64
jim@4683
    65
	data->x = -1;
jim@4683
    66
	data->y = -1;
jim@4683
    67
	data->pressure = -1;
jim@4683
    68
	data->finger = 0;
jim@4683
    69
	data->up = SDL_FALSE;
jim@4683
    70
	
jim@4683
    71
jim@4645
    72
	data->eventStream = open(tstr, 
jim@4645
    73
				 O_RDONLY | O_NONBLOCK);
jim@4645
    74
	ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
jim@4646
    75
jim@4646
    76
	int abs[5];
jim@4646
    77
	ioctl(data->eventStream,EVIOCGABS(0),abs);	
jim@4646
    78
	touch.x_min = abs[1];
jim@4646
    79
	touch.x_max = abs[2];
jimtla@4678
    80
	touch.native_xres = touch.x_max - touch.x_min;
jim@4646
    81
	ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
jim@4646
    82
	touch.y_min = abs[1];
jim@4646
    83
	touch.y_max = abs[2];
jimtla@4678
    84
	touch.native_yres = touch.y_max - touch.y_min;
jim@4646
    85
	ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
jim@4646
    86
	touch.pressure_min = abs[1];
jim@4646
    87
	touch.pressure_max = abs[2];
jimtla@4678
    88
	touch.native_pressureres = touch.pressure_max - touch.pressure_min;
jim@4646
    89
jim@4645
    90
	SDL_AddTouch(&touch, tstr);
jim@4645
    91
      }
jim@4645
    92
      vendor = -1;
jim@4645
    93
      product = -1;
jim@4645
    94
      event = -1;      
jim@4645
    95
    }
jim@4645
    96
    else if(line[0] == 'I') {
jim@4645
    97
      i = 1;
jim@4645
    98
      while(line[i]) {
jim@4645
    99
	sscanf(&line[i],"Vendor=%x",&vendor);
jim@4645
   100
	sscanf(&line[i],"Product=%x",&product);
jim@4645
   101
	i++;
jim@4645
   102
      }
jim@4645
   103
    }
jim@4645
   104
    else if(line[0] == 'H') {
jim@4645
   105
      i = 1;
jim@4645
   106
      while(line[i]) {
jim@4645
   107
	sscanf(&line[i],"event%d",&event);
jim@4645
   108
	i++;
jim@4645
   109
      }
jim@4645
   110
    }
jim@4645
   111
  }
jim@4645
   112
  
jim@4645
   113
  close(fd);
jimtla@4669
   114
#endif
jim@4645
   115
}
jim@4645
   116
jim@4645
   117
void
jim@4645
   118
X11_QuitTouch(_THIS)
jim@4645
   119
{
jim@4645
   120
    SDL_TouchQuit();
jim@4645
   121
}
jim@4645
   122
slouken@5481
   123
#endif /* SDL_VIDEO_DRIVER_X11 */
slouken@5481
   124
jim@4645
   125
/* vi: set ts=4 sw=4 expandtab: */