comparison src/video/x11/SDL_eventtouch.c @ 4645:0375d020e7e3

Auto-detects Wacom touch devices.
author Jim Grandpre <jim.tla@gmail.com>
date Mon, 31 May 2010 00:24:37 -0400
parents
children eea1bf53effa
comparison
equal deleted inserted replaced
4644:fb500b3e1717 4645:0375d020e7e3
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2010 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22 #include "SDL_config.h"
23 #include "SDL_x11video.h"
24 #include "SDL_eventtouch.h"
25 #include "../../events/SDL_touch_c.h"
26
27 #include <linux/input.h>
28 #include <fcntl.h>
29
30 void
31 X11_InitTouch(_THIS)
32 {
33 printf("Initializing touch...\n");
34
35 FILE *fd;
36 fd = fopen("/proc/bus/input/devices","r");
37
38 char c;
39 int i = 0;
40 char line[256];
41 char tstr[256];
42 int vendor = -1,product = -1,event = -1;
43 while(!feof(fd)) {
44 if(fgets(line,256,fd) <=0) continue;
45 //printf("%s",line);
46 if(line[0] == '\n') {
47 if(vendor == 1386){
48 printf("Wacom... Assuming it is a touch device\n");
49 sprintf(tstr,"/dev/input/event%i",event);
50 printf("At location: %s\n",tstr);
51
52 SDL_Touch touch;
53 touch.pressure_max = 0;
54 touch.pressure_min = 0;
55 touch.id = event;
56
57
58
59 touch.driverdata = SDL_malloc(sizeof(EventTouchData));
60 EventTouchData* data = (EventTouchData*)(touch.driverdata);
61 printf("Opening device...\n");
62 //printf("New Touch - DataPtr: %i\n",data);
63 data->eventStream = open(tstr,
64 O_RDONLY | O_NONBLOCK);
65 ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
66 printf ("Reading From : %s\n", tstr);
67 SDL_AddTouch(&touch, tstr);
68
69 }
70 vendor = -1;
71 product = -1;
72 event = -1;
73 }
74 else if(line[0] == 'I') {
75 i = 1;
76 while(line[i]) {
77 sscanf(&line[i],"Vendor=%x",&vendor);
78 sscanf(&line[i],"Product=%x",&product);
79 i++;
80 }
81 }
82 else if(line[0] == 'H') {
83 i = 1;
84 while(line[i]) {
85 sscanf(&line[i],"event%d",&event);
86 i++;
87 }
88 }
89 }
90
91 close(fd);
92 }
93
94 void
95 X11_QuitTouch(_THIS)
96 {
97 SDL_TouchQuit();
98 }
99
100 /* vi: set ts=4 sw=4 expandtab: */