Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
119 lines (101 loc) · 2.96 KB

SDL_eventtouch.c

File metadata and controls

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