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

Latest commit

 

History

History
124 lines (103 loc) · 3.02 KB

SDL_x11touch.c

File metadata and controls

124 lines (103 loc) · 3.02 KB
 
May 31, 2010
May 31, 2010
1
/*
Apr 8, 2011
Apr 8, 2011
2
3
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
May 31, 2010
May 31, 2010
4
Apr 8, 2011
Apr 8, 2011
5
6
7
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
May 31, 2010
May 31, 2010
8
Apr 8, 2011
Apr 8, 2011
9
10
11
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
May 31, 2010
May 31, 2010
12
Apr 8, 2011
Apr 8, 2011
13
14
15
16
17
18
19
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
May 31, 2010
May 31, 2010
20
21
*/
#include "SDL_config.h"
Mar 12, 2011
Mar 12, 2011
22
23
24
#if SDL_VIDEO_DRIVER_X11
May 31, 2010
May 31, 2010
25
#include "SDL_x11video.h"
Dec 1, 2010
Dec 1, 2010
26
#include "SDL_x11touch.h"
May 31, 2010
May 31, 2010
27
28
#include "../../events/SDL_touch_c.h"
Aug 2, 2010
Aug 2, 2010
29
30
#ifdef SDL_INPUT_LINUXEV
May 31, 2010
May 31, 2010
31
32
#include <linux/input.h>
#include <fcntl.h>
Jul 22, 2010
Jul 22, 2010
33
#endif
May 31, 2010
May 31, 2010
34
35
36
37
void
X11_InitTouch(_THIS)
{
Aug 2, 2010
Aug 2, 2010
38
#ifdef SDL_INPUT_LINUXEV
May 31, 2010
May 31, 2010
39
40
41
42
43
44
45
46
47
48
49
50
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;
if(line[0] == '\n') {
if(vendor == 1386){
Jan 20, 2011
Jan 20, 2011
51
52
53
/*printf("Wacom... Assuming it is a touch device\n");*/
/*sprintf(tstr,"/dev/input/event%i",event);*/
/*printf("At location: %s\n",tstr);*/
May 31, 2010
May 31, 2010
54
55
56
57
58
59
60
61
62
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);
Aug 5, 2010
Aug 5, 2010
63
64
65
66
67
68
69
70
data->x = -1;
data->y = -1;
data->pressure = -1;
data->finger = 0;
data->up = SDL_FALSE;
May 31, 2010
May 31, 2010
71
72
73
data->eventStream = open(tstr,
O_RDONLY | O_NONBLOCK);
ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
Jun 1, 2010
Jun 1, 2010
74
75
76
77
78
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
79
touch.native_xres = touch.x_max - touch.x_min;
Jun 1, 2010
Jun 1, 2010
80
81
82
ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);
touch.y_min = abs[1];
touch.y_max = abs[2];
Jul 31, 2010
Jul 31, 2010
83
touch.native_yres = touch.y_max - touch.y_min;
Jun 1, 2010
Jun 1, 2010
84
85
86
ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);
touch.pressure_min = abs[1];
touch.pressure_max = abs[2];
Jul 31, 2010
Jul 31, 2010
87
touch.native_pressureres = touch.pressure_max - touch.pressure_min;
Jun 1, 2010
Jun 1, 2010
88
May 31, 2010
May 31, 2010
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
113
#endif
May 31, 2010
May 31, 2010
114
115
116
117
118
119
120
121
}
void
X11_QuitTouch(_THIS)
{
SDL_TouchQuit();
}
Mar 12, 2011
Mar 12, 2011
122
123
#endif /* SDL_VIDEO_DRIVER_X11 */
May 31, 2010
May 31, 2010
124
/* vi: set ts=4 sw=4 expandtab: */