Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
f75117cf
Commit
f75117cf
authored
May 31, 2010
by
Jim Grandpre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto-detects Wacom touch devices.
parent
3dcae434
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
182 additions
and
24 deletions
+182
-24
SDL_touch.c
src/events/SDL_touch.c
+18
-9
SDL_touch_c.h
src/events/SDL_touch_c.h
+1
-0
SDL_eventtouch.c
src/video/x11/SDL_eventtouch.c
+100
-0
SDL_eventtouch.h
src/video/x11/SDL_eventtouch.h
+2
-2
SDL_x11events.c
src/video/x11/SDL_x11events.c
+6
-13
SDL_x11video.c
src/video/x11/SDL_x11video.c
+3
-0
makefile
touchTest/makefile
+2
-0
parseDevicesTest.c
touchTest/parseDevicesTest.c
+50
-0
No files found.
src/events/SDL_touch.c
View file @
f75117cf
...
@@ -36,12 +36,7 @@ static SDL_Touch **SDL_touchPads = NULL;
...
@@ -36,12 +36,7 @@ static SDL_Touch **SDL_touchPads = NULL;
int
int
SDL_TouchInit
(
void
)
SDL_TouchInit
(
void
)
{
{
SDL_Touch
touch
;
touch
.
pressure_max
=
0
;
touch
.
pressure_min
=
0
;
touch
.
id
=
0
;
//Should be function?
SDL_AddTouch
(
&
touch
,
"Touch1"
);
return
(
0
);
return
(
0
);
}
}
...
@@ -138,6 +133,9 @@ SDL_AddTouch(const SDL_Touch * touch, char *name)
...
@@ -138,6 +133,9 @@ SDL_AddTouch(const SDL_Touch * touch, char *name)
SDL_strlcpy
(
SDL_touchPads
[
index
]
->
name
,
name
,
length
+
1
);
SDL_strlcpy
(
SDL_touchPads
[
index
]
->
name
,
name
,
length
+
1
);
SDL_touchPads
[
index
]
->
num_fingers
=
0
;
SDL_touchPads
[
index
]
->
num_fingers
=
0
;
SDL_touchPads
[
index
]
->
max_fingers
=
0
;
SDL_touchPads
[
index
]
->
fingers
=
NULL
;
SDL_touchPads
[
index
]
->
buttonstate
=
0
;
SDL_touchPads
[
index
]
->
buttonstate
=
0
;
SDL_touchPads
[
index
]
->
relative_mode
=
SDL_FALSE
;
SDL_touchPads
[
index
]
->
relative_mode
=
SDL_FALSE
;
SDL_touchPads
[
index
]
->
flush_motion
=
SDL_FALSE
;
SDL_touchPads
[
index
]
->
flush_motion
=
SDL_FALSE
;
...
@@ -261,16 +259,27 @@ SDL_AddFinger(SDL_Touch* touch,SDL_Finger* finger)
...
@@ -261,16 +259,27 @@ SDL_AddFinger(SDL_Touch* touch,SDL_Finger* finger)
}
}
/* Add the touch to the list of touch */
/* Add the touch to the list of touch */
if
(
touch
->
num_fingers
>=
touch
->
max_fingers
){
if
(
fingers
==
NULL
)
{
touch
->
max_fingers
=
1
;
fingers
=
(
SDL_Finger
**
)
SDL_malloc
(
sizeof
(
finger
));
}
else
{
fingers
=
(
SDL_Finger
**
)
SDL_realloc
(
touch
->
fingers
,
fingers
=
(
SDL_Finger
**
)
SDL_realloc
(
touch
->
fingers
,
(
touch
->
num_fingers
+
1
)
*
sizeof
(
*
touch
));
(
touch
->
num_fingers
+
1
)
*
sizeof
(
finger
));
touch
->
max_fingers
=
touch
->
num_fingers
+
1
;
}
}
if
(
!
fingers
)
{
if
(
!
fingers
)
{
SDL_OutOfMemory
();
SDL_OutOfMemory
();
return
-
1
;
return
-
1
;
}
}
touch
->
fingers
=
fingers
;
touch
->
fingers
=
fingers
;
index
=
touch
->
num_fingers
++
;
index
=
touch
->
num_fingers
;
touch
->
num_fingers
++
;
touch
->
fingers
[
index
]
=
(
SDL_Finger
*
)
SDL_malloc
(
sizeof
(
*
(
touch
->
fingers
[
index
])));
touch
->
fingers
[
index
]
=
(
SDL_Finger
*
)
SDL_malloc
(
sizeof
(
*
(
touch
->
fingers
[
index
])));
if
(
!
touch
->
fingers
[
index
])
{
if
(
!
touch
->
fingers
[
index
])
{
SDL_OutOfMemory
();
SDL_OutOfMemory
();
...
...
src/events/SDL_touch_c.h
View file @
f75117cf
...
@@ -61,6 +61,7 @@ struct SDL_Touch
...
@@ -61,6 +61,7 @@ struct SDL_Touch
SDL_bool
flush_motion
;
SDL_bool
flush_motion
;
int
num_fingers
;
int
num_fingers
;
int
max_fingers
;
SDL_Finger
**
fingers
;
SDL_Finger
**
fingers
;
void
*
driverdata
;
void
*
driverdata
;
...
...
src/video/x11/SDL_eventtouch.c
0 → 100644
View file @
f75117cf
/*
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"
#include <linux/input.h>
#include <fcntl.h>
void
X11_InitTouch
(
_THIS
)
{
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
);
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
);
}
void
X11_QuitTouch
(
_THIS
)
{
SDL_TouchQuit
();
}
/* vi: set ts=4 sw=4 expandtab: */
src/video/x11/SDL_eventtouch.h
View file @
f75117cf
...
@@ -35,8 +35,8 @@ typedef struct EventTouchData
...
@@ -35,8 +35,8 @@ typedef struct EventTouchData
}
EventTouchData
;
}
EventTouchData
;
#endif
#endif
//extern void X11_InitMouse
(_THIS);
extern
void
X11_InitTouch
(
_THIS
);
//extern void X11_QuitMouse
(_THIS);
extern
void
X11_QuitTouch
(
_THIS
);
#endif
/* _SDL_eventtouch_h */
#endif
/* _SDL_eventtouch_h */
...
...
src/video/x11/SDL_x11events.c
View file @
f75117cf
...
@@ -109,7 +109,6 @@ X11_DispatchEvent(_THIS)
...
@@ -109,7 +109,6 @@ X11_DispatchEvent(_THIS)
#endif
#endif
}
}
break
;
break
;
/* Losing mouse coverage? */
/* Losing mouse coverage? */
case
LeaveNotify
:{
case
LeaveNotify
:{
#ifdef DEBUG_XEVENTS
#ifdef DEBUG_XEVENTS
...
@@ -422,23 +421,16 @@ X11_PumpEvents(_THIS)
...
@@ -422,23 +421,16 @@ X11_PumpEvents(_THIS)
char
name
[
256
];
char
name
[
256
];
struct
input_event
ev
[
64
];
struct
input_event
ev
[
64
];
int
size
=
sizeof
(
struct
input_event
);
int
size
=
sizeof
(
struct
input_event
);
static
int
initd
=
0
;
//TODO - HACK!
for
(
i
=
0
;
i
<
SDL_GetNumTouch
();
++
i
)
{
for
(
i
=
0
;
i
<
SDL_GetNumTouch
();
++
i
)
{
SDL_Touch
*
touch
=
SDL_GetTouchIndex
(
i
);
SDL_Touch
*
touch
=
SDL_GetTouchIndex
(
i
);
if
(
!
touch
)
printf
(
"Touch %i/%i DNE
\n
"
,
i
,
SDL_GetNumTouch
());
if
(
!
touch
)
printf
(
"Touch %i/%i DNE
\n
"
,
i
,
SDL_GetNumTouch
());
EventTouchData
*
data
;
EventTouchData
*
data
;
if
(
!
initd
){
//data->eventStream <= 0) {
touch
->
driverdata
=
SDL_malloc
(
sizeof
(
EventTouchData
));
data
=
(
EventTouchData
*
)(
touch
->
driverdata
);
printf
(
"Openning device...
\n
"
);
data
->
eventStream
=
open
(
"/dev/input/wacom"
,
O_RDONLY
|
O_NONBLOCK
);
ioctl
(
data
->
eventStream
,
EVIOCGNAME
(
sizeof
(
name
)),
name
);
printf
(
"Reading From : %s
\n
"
,
name
);
initd
=
1
;
}
else
data
=
(
EventTouchData
*
)(
touch
->
driverdata
);
data
=
(
EventTouchData
*
)(
touch
->
driverdata
);
if
(
data
==
NULL
)
{
printf
(
"No driver data
\n
"
);
continue
;
}
if
(
data
->
eventStream
<=
0
)
if
(
data
->
eventStream
<=
0
)
printf
(
"Error: Couldn't open stream
\n
"
);
printf
(
"Error: Couldn't open stream
\n
"
);
rd
=
read
(
data
->
eventStream
,
ev
,
size
*
64
);
rd
=
read
(
data
->
eventStream
,
ev
,
size
*
64
);
...
@@ -469,6 +461,7 @@ X11_PumpEvents(_THIS)
...
@@ -469,6 +461,7 @@ X11_PumpEvents(_THIS)
data
->
finger
=
ev
[
i
].
value
;
data
->
finger
=
ev
[
i
].
value
;
break
;
break
;
case
EV_SYN
:
case
EV_SYN
:
printf
(
"Id: %i
\n
"
,
touch
->
id
);
if
(
data
->
x
>=
0
||
data
->
y
>=
0
)
if
(
data
->
x
>=
0
||
data
->
y
>=
0
)
SDL_SendTouchMotion
(
touch
->
id
,
data
->
finger
,
SDL_SendTouchMotion
(
touch
->
id
,
data
->
finger
,
SDL_FALSE
,
data
->
x
,
data
->
y
,
SDL_FALSE
,
data
->
x
,
data
->
y
,
...
...
src/video/x11/SDL_x11video.c
View file @
f75117cf
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#include "SDL_video.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_mouse.h"
#include "SDL_eventtouch.h"
#include "../SDL_sysvideo.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../SDL_pixels_c.h"
...
@@ -269,6 +270,7 @@ X11_VideoInit(_THIS)
...
@@ -269,6 +270,7 @@ X11_VideoInit(_THIS)
}
}
X11_InitMouse
(
_this
);
X11_InitMouse
(
_this
);
X11_InitTouch
(
_this
);
return
0
;
return
0
;
}
}
...
@@ -289,6 +291,7 @@ X11_VideoQuit(_THIS)
...
@@ -289,6 +291,7 @@ X11_VideoQuit(_THIS)
X11_QuitModes
(
_this
);
X11_QuitModes
(
_this
);
X11_QuitKeyboard
(
_this
);
X11_QuitKeyboard
(
_this
);
X11_QuitMouse
(
_this
);
X11_QuitMouse
(
_this
);
X11_QuitTouch
(
_this
);
}
}
SDL_bool
SDL_bool
...
...
touchTest/makefile
View file @
f75117cf
...
@@ -2,4 +2,6 @@ SDLTest : touchSimp.c touchPong.c
...
@@ -2,4 +2,6 @@ SDLTest : touchSimp.c touchPong.c
gcc touchTest.c
-o
touchTest
`
sdl-config
--cflags
--libs
`
-g
gcc touchTest.c
-o
touchTest
`
sdl-config
--cflags
--libs
`
-g
gcc touchSimp.c
-o
touchSimp
`
sdl-config
--cflags
--libs
`
-g
gcc touchSimp.c
-o
touchSimp
`
sdl-config
--cflags
--libs
`
-g
gcc touchPong.c
-o
touchPong
`
sdl-config
--cflags
--libs
`
-g
gcc touchPong.c
-o
touchPong
`
sdl-config
--cflags
--libs
`
-g
gcc parseDevicesTest.c
-o
parseDevicesTest
-g
touchTest/parseDevicesTest.c
0 → 100644
View file @
f75117cf
#include <stdio.h>
#include <stdlib.h>
#include <linux/input.h>
int
main
(
int
agrc
,
char
**
argv
)
{
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
))
{
fgets
(
line
,
256
,
fd
);
//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
);
}
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
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment