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

Latest commit

 

History

History
executable file
·
132 lines (113 loc) · 3.94 KB

SDL_x11touch.c

File metadata and controls

executable file
·
132 lines (113 loc) · 3.94 KB
 
Oct 12, 2011
Oct 12, 2011
1
2
/*
Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
Oct 12, 2011
Oct 12, 2011
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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.
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:
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.
*/
#include "SDL_config.h"
#if SDL_VIDEO_DRIVER_X11
#include "SDL_x11video.h"
#include "SDL_x11touch.h"
May 31, 2012
May 31, 2012
27
#include "SDL_x11xinput2.h"
Oct 12, 2011
Oct 12, 2011
28
29
30
31
32
33
34
35
36
37
38
#include "../../events/SDL_touch_c.h"
#ifdef SDL_INPUT_LINUXEV
#include <linux/input.h>
#include <fcntl.h>
#endif
void
X11_InitTouch(_THIS)
{
May 31, 2012
May 31, 2012
39
40
41
42
43
44
/*Initilized Xinput2 multitouch
* and return in order to not initialize
* evtouch also*/
if(X11_Xinput2IsMutitouchSupported()) {
X11_InitXinput2Multitouch(_this);
return;
Oct 12, 2011
Oct 12, 2011
45
}
May 31, 2012
May 31, 2012
46
47
48
#ifdef SDL_INPUT_LINUXEV
FILE *fd;
fd = fopen("/proc/bus/input/devices","r");
Jul 2, 2012
Jul 2, 2012
49
if (!fd) return;
May 31, 2012
May 31, 2012
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
int i = 0;
int tsfd;
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 || vendor==1) {
sprintf(tstr,"/dev/input/event%i",event);
tsfd = open( tstr, O_RDONLY | O_NONBLOCK );
if ( tsfd == -1 )
continue; /* Maybe not enough permissions ? */
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);
data->x = -1;
data->y = -1;
data->pressure = -1;
data->finger = 0;
data->up = SDL_FALSE;
data->down = SDL_FALSE;
data->eventStream = tsfd;
ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
int abs[5];
ioctl(data->eventStream,EVIOCGABS(0),abs);
touch.x_min = abs[1];
touch.x_max = abs[2];
touch.native_xres = touch.x_max - touch.x_min;
ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);
touch.y_min = abs[1];
touch.y_max = abs[2];
touch.native_yres = touch.y_max - touch.y_min;
ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);
touch.pressure_min = abs[1];
touch.pressure_max = abs[2];
touch.native_pressureres = touch.pressure_max - touch.pressure_min;
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++;
}
}
Oct 12, 2011
Oct 12, 2011
119
}
May 31, 2012
May 31, 2012
120
fclose(fd);
Oct 12, 2011
Oct 12, 2011
121
122
123
124
125
126
127
128
129
130
131
132
#endif
}
void
X11_QuitTouch(_THIS)
{
SDL_TouchQuit();
}
#endif /* SDL_VIDEO_DRIVER_X11 */
/* vi: set ts=4 sw=4 expandtab: */