src/video/x11/SDL_x11touch.c
author Sam Lantinga
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 5481 22dfc3958dc3
child 5603 e1ca92e7f2ff
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
jim@4645
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@5535
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
jim@4645
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
jim@4645
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
jim@4645
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
jim@4645
    20
*/
jim@4645
    21
#include "SDL_config.h"
slouken@5481
    22
slouken@5481
    23
#if SDL_VIDEO_DRIVER_X11
slouken@5481
    24
jim@4645
    25
#include "SDL_x11video.h"
slouken@4923
    26
#include "SDL_x11touch.h"
jim@4645
    27
#include "../../events/SDL_touch_c.h"
jim@4645
    28
jim@4681
    29
jim@4681
    30
#ifdef SDL_INPUT_LINUXEV
jim@4645
    31
#include <linux/input.h>
jim@4645
    32
#include <fcntl.h>
jimtla@4669
    33
#endif
jim@4645
    34
jim@4645
    35
void
jim@4645
    36
X11_InitTouch(_THIS)
jim@4645
    37
{
jim@4681
    38
#ifdef SDL_INPUT_LINUXEV
jim@4645
    39
  FILE *fd;
jim@4645
    40
  fd = fopen("/proc/bus/input/devices","r");
jim@4645
    41
  
jim@4645
    42
  char c;
jim@4645
    43
  int i = 0;
jim@4645
    44
  char line[256];
jim@4645
    45
  char tstr[256];
jim@4645
    46
  int vendor = -1,product = -1,event = -1;
jim@4645
    47
  while(!feof(fd)) {
jim@4645
    48
    if(fgets(line,256,fd) <=0) continue;
jim@4645
    49
    if(line[0] == '\n') {
jim@4645
    50
      if(vendor == 1386){
slouken@5044
    51
	/*printf("Wacom... Assuming it is a touch device\n");*/
slouken@5044
    52
	/*sprintf(tstr,"/dev/input/event%i",event);*/
slouken@5044
    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@4645
    59
	
jim@4645
    60
jim@4645
    61
	touch.driverdata = SDL_malloc(sizeof(EventTouchData));
jim@4645
    62
	EventTouchData* data = (EventTouchData*)(touch.driverdata);
jim@4683
    63
jim@4683
    64
	data->x = -1;
jim@4683
    65
	data->y = -1;
jim@4683
    66
	data->pressure = -1;
jim@4683
    67
	data->finger = 0;
jim@4683
    68
	data->up = SDL_FALSE;
jim@4683
    69
	
jim@4683
    70
jim@4645
    71
	data->eventStream = open(tstr, 
jim@4645
    72
				 O_RDONLY | O_NONBLOCK);
jim@4645
    73
	ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
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];
jimtla@4678
    79
	touch.native_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];
jimtla@4678
    83
	touch.native_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];
jimtla@4678
    87
	touch.native_pressureres = touch.pressure_max - touch.pressure_min;
jim@4646
    88
jim@4645
    89
	SDL_AddTouch(&touch, tstr);
jim@4645
    90
      }
jim@4645
    91
      vendor = -1;
jim@4645
    92
      product = -1;
jim@4645
    93
      event = -1;      
jim@4645
    94
    }
jim@4645
    95
    else if(line[0] == 'I') {
jim@4645
    96
      i = 1;
jim@4645
    97
      while(line[i]) {
jim@4645
    98
	sscanf(&line[i],"Vendor=%x",&vendor);
jim@4645
    99
	sscanf(&line[i],"Product=%x",&product);
jim@4645
   100
	i++;
jim@4645
   101
      }
jim@4645
   102
    }
jim@4645
   103
    else if(line[0] == 'H') {
jim@4645
   104
      i = 1;
jim@4645
   105
      while(line[i]) {
jim@4645
   106
	sscanf(&line[i],"event%d",&event);
jim@4645
   107
	i++;
jim@4645
   108
      }
jim@4645
   109
    }
jim@4645
   110
  }
jim@4645
   111
  
jim@4645
   112
  close(fd);
jimtla@4669
   113
#endif
jim@4645
   114
}
jim@4645
   115
jim@4645
   116
void
jim@4645
   117
X11_QuitTouch(_THIS)
jim@4645
   118
{
jim@4645
   119
    SDL_TouchQuit();
jim@4645
   120
}
jim@4645
   121
slouken@5481
   122
#endif /* SDL_VIDEO_DRIVER_X11 */
slouken@5481
   123
jim@4645
   124
/* vi: set ts=4 sw=4 expandtab: */