Skip to content

Commit fbc49d4

Browse files
committed
joystick interposer support for evdev and SDL
1 parent d967fe8 commit fbc49d4

File tree

6 files changed

+555
-180
lines changed

6 files changed

+555
-180
lines changed

addons/js-interposer/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*.so
1+
*.so
2+
sdl_joystick_reader

addons/js-interposer/Makefile

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
PREFIX ?= /usr
22

3-
all:
3+
all: build build32
4+
5+
deps:
6+
@sudo apt-get update
7+
@sudo apt-get install -y build-essential evtest strace joystick libsdl2-dev gcc-multilib libevdev-dev
8+
9+
build:
410
gcc -shared -fPIC -o selkies_joystick_interposer.so joystick_interposer.c -ldl
511

6-
install: all
12+
build32:
13+
gcc -m32 -shared -fPIC -o selkies_joystick_interposer_i386.so joystick_interposer.c -ldl
14+
15+
install: build
716
mkdir -p $(PREFIX)/lib/$(gcc -print-multiarch | sed -e 's/i.*86/i386/')
817
cp *.so $(PREFIX)/lib/$(gcc -print-multiarch | sed -e 's/i.*86/i386/')/
918
clean:
10-
rm -f *.so
19+
rm -f *.so
20+
sudo rm -f /dev/input/js0 /dev/input/event1000
21+
22+
fake-devices:
23+
@sudo touch /dev/input/js0 && sudo chmod 777 /dev/input/js0
24+
@sudo touch /dev/input/event1000 && sudo chmod 777 /dev/input/event1000
25+
26+
py-js-test:
27+
python3 js-interposer-test.py /tmp/selkies_js0.sock
28+
29+
py-ev-test:
30+
python3 js-interposer-test.py /tmp/selkies_event1000.sock
31+
32+
jstest: build
33+
LD_PRELOAD=$(PWD)/selkies_joystick_interposer.so jstest /dev/input/js0
34+
35+
evtest: build fake-devices
36+
LD_PRELOAD=$(PWD)/selkies_joystick_interposer.so evtest /dev/input/event1000
37+
38+
sdltest: build fake-devices
39+
gcc -o sdl_joystick_reader sdl-js-test.c -lSDL2
40+
LD_PRELOAD=$(PWD)/selkies_joystick_interposer.so ./sdl_joystick_reader
41+
42+
winetest: build build32 fake-devices
43+
LD_PRELOAD=$(PWD)/selkies_joystick_interposer.so wine control

addons/js-interposer/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,21 @@ If using Wine with `x86_64`, both `/usr/lib/x86_64-linux-gnu/selkies_joystick_in
2323
```bash
2424
sudo mkdir -pm1777 /dev/input
2525
sudo touch /dev/input/js0 /dev/input/js1 /dev/input/js2 /dev/input/js3
26-
sudo chmod 777 /dev/input/js*
26+
sudo touch /dev/input/event1000 /dev/input/event1001 /dev/input/event1002 /dev/input/event1003
27+
sudo chmod 777 /dev/input/js* /dev/input/event*
2728
```
2829

2930
3. Use the below command before running your target application as well as Selkies-GStreamer for the interposer library to intercept joystick/gamepad events (the single quotes are required in the first line).
3031

3132
```bash
3233
export SELKIES_INTERPOSER='/usr/$LIB/selkies_joystick_interposer.so'
3334
export LD_PRELOAD="${SELKIES_INTERPOSER}${LD_PRELOAD:+:${LD_PRELOAD}}"
34-
export SDL_JOYSTICK_DEVICE=/dev/input/js0
3535
```
3636

3737
Otherwise, if you only need one architecture, the below is an equivalent command.
3838

3939
```bash
4040
export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/selkies_joystick_interposer.so${LD_PRELOAD:+:${LD_PRELOAD}}"
41-
export SDL_JOYSTICK_DEVICE=/dev/input/js0
4241
```
4342

4443
You can replace `/usr/$LIB/selkies_joystick_interposer.so` with any non-root path of your choice if using the `.tar.gz` tarball. Make sure the correct `selkies_joystick_interposer.so` is installed in that path.

0 commit comments

Comments
 (0)