comparison src/video/x11/SDL_x11touch.c @ 4923:1002d074d459

Renamed X11 touch files for consistency
author Sam Lantinga <slouken@libsdl.org>
date Wed, 01 Dec 2010 12:17:12 -0800
parents src/video/x11/SDL_eventtouch.c@15dfe42edbfd
children 4913042e8572
comparison
equal deleted inserted replaced
4922:ba79f17d68c1 4923:1002d074d459
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_x11touch.h"
25 #include "../../events/SDL_touch_c.h"
26
27
28 #ifdef SDL_INPUT_LINUXEV
29 #include <linux/input.h>
30 #include <fcntl.h>
31 #endif
32
33 void
34 X11_InitTouch(_THIS)
35 {
36 #ifdef SDL_INPUT_LINUXEV
37 printf("Initializing touch...\n");
38
39 FILE *fd;
40 fd = fopen("/proc/bus/input/devices","r");
41
42 char c;
43 int i = 0;
44 char line[256];
45 char tstr[256];
46 int vendor = -1,product = -1,event = -1;
47 while(!feof(fd)) {
48 if(fgets(line,256,fd) <=0) continue;
49 //printf("%s",line);
50 if(line[0] == '\n') {
51 if(vendor == 1386){
52 printf("Wacom... Assuming it is a touch device\n");
53 sprintf(tstr,"/dev/input/event%i",event);
54 printf("At location: %s\n",tstr);
55
56 SDL_Touch touch;
57 touch.pressure_max = 0;
58 touch.pressure_min = 0;
59 touch.id = event;
60
61
62 touch.driverdata = SDL_malloc(sizeof(EventTouchData));
63 EventTouchData* data = (EventTouchData*)(touch.driverdata);
64
65 data->x = -1;
66 data->y = -1;
67 data->pressure = -1;
68 data->finger = 0;
69 data->up = SDL_FALSE;
70
71
72 printf("Opening device...\n");
73 //printf("New Touch - DataPtr: %i\n",data);
74 data->eventStream = open(tstr,
75 O_RDONLY | O_NONBLOCK);
76 ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
77 printf ("Reading From : %s\n", tstr);
78
79
80
81 int abs[5];
82 ioctl(data->eventStream,EVIOCGABS(0),abs);
83 touch.x_min = abs[1];
84 touch.x_max = abs[2];
85 touch.native_xres = touch.x_max - touch.x_min;
86 ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);
87 touch.y_min = abs[1];
88 touch.y_max = abs[2];
89 touch.native_yres = touch.y_max - touch.y_min;
90 ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);
91 touch.pressure_min = abs[1];
92 touch.pressure_max = abs[2];
93 touch.native_pressureres = touch.pressure_max - touch.pressure_min;
94
95 SDL_AddTouch(&touch, tstr);
96 }
97 vendor = -1;
98 product = -1;
99 event = -1;
100 }
101 else if(line[0] == 'I') {
102 i = 1;
103 while(line[i]) {
104 sscanf(&line[i],"Vendor=%x",&vendor);
105 sscanf(&line[i],"Product=%x",&product);
106 i++;
107 }
108 }
109 else if(line[0] == 'H') {
110 i = 1;
111 while(line[i]) {
112 sscanf(&line[i],"event%d",&event);
113 i++;
114 }
115 }
116 }
117
118 close(fd);
119 #endif
120 }
121
122 void
123 X11_QuitTouch(_THIS)
124 {
125 SDL_TouchQuit();
126 }
127
128 /* vi: set ts=4 sw=4 expandtab: */