scrcpy icon indicating copy to clipboard operation
scrcpy copied to clipboard

GamePad support

Open BinaryQuantumSoul opened this issue 1 year ago • 7 comments

Based on yumechan's game-controller branch from which I resolved all the merge conflicts. Made sure it compiles and actually works.

Some conflicts may still remain as some things are done in an older scrcpy, but I hope not a lot ?

Demo video: https://www.reddit.com/r/OdinHandheld/comments/1e1e4ud/three_layers_of_odin_2_gamepad_control/

BinaryQuantumSoul avatar Jul 12 '24 03:07 BinaryQuantumSoul

@rom1v thoughts ?

BinaryQuantumSoul avatar Jul 21 '24 08:07 BinaryQuantumSoul

Hi,

Thank you for your work.

I'm in holidays so I cannot check now.

But IIRC this branch used a native library as dependency, and we wanted to avoid that. I think there was a solution for this without adding such a dependency, but could not find the issue/comment right now from my phone.

Also, it seems this branch is not a proper set of individual self-contained patches (without commits fixing previous commits, etc.).

Regards

rom1v avatar Jul 21 '24 12:07 rom1v

Hi, Thanks. No worries, you can tell me the specifics after your holidays. It would be hard for it to be "individual self-contained patches" since I had to deal with merge conflicts everywhere Regards.

BinaryQuantumSoul avatar Jul 21 '24 12:07 BinaryQuantumSoul

Hey, do you mind posting a prebuilt scrcpy on your fork or here? i cant for the love of god figure out how to build it (im on windows), i tried a lotta things on mingw64 but ended up with a build where everything but the controller worked..

ghoste0001 avatar Aug 01 '24 22:08 ghoste0001

Hey, do you mind posting a prebuilt scrcpy on your fork or here? i cant for the love of god figure out how to build it (im on windows), i tried a lotta things on mingw64 but ended up with a build where everything but the controller worked..

Hello, to be honest I only tried it on linux so far. Did you follow build instructions from this repo ? I'm reading "cross"compiling the windows version from linux is the preferred method. I could do it for you but I don't have access to my computer right now. Maybe try building it inside WSL ?

BinaryQuantumSoul avatar Aug 03 '24 12:08 BinaryQuantumSoul

Hey, do you mind posting a prebuilt scrcpy on your fork or here? i cant for the love of god figure out how to build it (im on windows), i tried a lotta things on mingw64 but ended up with a build where everything but the controller worked..

Hello, to be honest I only tried it on linux so far. Did you follow build instructions from this repo ? I'm reading "cross"compiling the windows version from linux is the preferred method. I could do it for you but I don't have access to my computer right now. Maybe try building it inside WSL ?

I tried to build it on WSL, i followed the instructions and now i got this:

ghost@GHOST-PC:~/scrcpy-gamepad$ ./release.sh
./gradlew clean

BUILD SUCCESSFUL in 6s
1 actionable task: 1 up-to-date
rm -rf "dist" "build-test" "build-server" \
        "build-win32" "build-win64"
[ -d "build-test" ] || ( mkdir "build-test" && \
        meson setup "build-test" -Db_sanitize=address )
The Meson build system
Version: 0.61.2
Source dir: /home/ghost/scrcpy-gamepad
Build dir: /home/ghost/scrcpy-gamepad/build-test
Build type: native build
Project name: scrcpy
Project version: 2.5
C compiler for the host machine: cc (gcc 11.4.0 "cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0")
C linker for the host machine: cc ld.bfd 2.38
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: /usr/bin/pkg-config (0.29.2)
Run-time dependency libavformat found: YES 58.76.100
Run-time dependency libavcodec found: YES 58.134.100
Run-time dependency libavutil found: YES 56.70.100
Run-time dependency libswresample found: YES 3.9.100
Run-time dependency sdl2 found: YES 2.0.20
Run-time dependency libavdevice found: YES 58.13.100
Run-time dependency libusb-1.0 found: YES 1.0.25
Checking for function "strdup" : YES
Checking for function "asprintf" : YES
Checking for function "vasprintf" : YES
Checking for function "nrand48" : YES
Checking for function "jrand48" : YES
Checking for function "reallocarray" : YES
Header <sys/socket.h> has symbol "SOCK_CLOEXEC" : YES
Configuring config.h using configuration
Program ./scripts/build-wrapper.sh found: YES (/home/ghost/scrcpy-gamepad/server/./scripts/build-wrapper.sh)
Build targets in project: 13

scrcpy 2.5

  User defined options
    b_sanitize: address

Found ninja-1.10.1 at /usr/bin/ninja
ninja -C "build-test"
ninja: Entering directory `build-test'
[94/124] Compiling C object app/test_control_msg_serialize.p/tests_test_control_msg_serialize.c.o
FAILED: app/test_control_msg_serialize.p/tests_test_control_msg_serialize.c.o
cc -Iapp/test_control_msg_serialize.p -Iapp -I../app -I../app/src -I/usr/include/x86_64-linux-gnu -I/usr/include/SDL2 -I/usr/include/libusb-1.0 -fdiagnostics-color=always -fsanitize=address -fno-omit-frame-pointer -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=c11 -g -Wmissing-prototypes -D_REENTRANT -DSDL_MAIN_HANDLED -DSC_TEST -MD -MQ app/test_control_msg_serialize.p/tests_test_control_msg_serialize.c.o -MF app/test_control_msg_serialize.p/tests_test_control_msg_serialize.c.o.d -o app/test_control_msg_serialize.p/tests_test_control_msg_serialize.c.o -c ../app/tests/test_control_msg_serialize.c
../app/tests/test_control_msg_serialize.c: In function ‘test_serialize_inject_game_controller_axis’:
../app/tests/test_control_msg_serialize.c:353:12: error: variable ‘msg’ has initializer but incomplete type
  353 |     struct control_msg msg = {
      |            ^~~~~~~~~~~
../app/tests/test_control_msg_serialize.c:354:10: error: ‘struct control_msg’ has no member named ‘type’
  354 |         .type = CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_AXIS,
      |          ^~~~
../app/tests/test_control_msg_serialize.c:354:17: error: ‘CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_AXIS’ undeclared (first use in this function); did you mean ‘SC_CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_AXIS’?
  354 |         .type = CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_AXIS,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                 SC_CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_AXIS
../app/tests/test_control_msg_serialize.c:354:17: note: each undeclared identifier is reported only once for each function it appears in
../app/tests/test_control_msg_serialize.c:354:17: warning: excess elements in struct initializer
../app/tests/test_control_msg_serialize.c:354:17: note: (near initialization for ‘msg’)
../app/tests/test_control_msg_serialize.c:355:10: error: ‘struct control_msg’ has no member named ‘inject_game_controller_axis’
  355 |         .inject_game_controller_axis = {
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../app/tests/test_control_msg_serialize.c:355:40: error: extra brace group at end of initializer
  355 |         .inject_game_controller_axis = {
      |                                        ^
../app/tests/test_control_msg_serialize.c:355:40: note: (near initialization for ‘msg’)
../app/tests/test_control_msg_serialize.c:355:40: warning: excess elements in struct initializer
../app/tests/test_control_msg_serialize.c:355:40: note: (near initialization for ‘msg’)
../app/tests/test_control_msg_serialize.c:353:24: error: storage size of ‘msg’ isn’t known
  353 |     struct control_msg msg = {
      |                        ^~~
../app/tests/test_control_msg_serialize.c:362:23: error: ‘CONTROL_MSG_MAX_SIZE’ undeclared (first use in this function); did you mean ‘SC_CONTROL_MSG_MAX_SIZE’?
  362 |     unsigned char buf[CONTROL_MSG_MAX_SIZE];
      |                       ^~~~~~~~~~~~~~~~~~~~
      |                       SC_CONTROL_MSG_MAX_SIZE
../app/tests/test_control_msg_serialize.c:363:19: warning: implicit declaration of function ‘control_msg_serialize’; did you mean ‘sc_control_msg_serialize’? [-Wimplicit-function-declaration]
  363 |     size_t size = control_msg_serialize(&msg, buf);
      |                   ^~~~~~~~~~~~~~~~~~~~~
      |                   sc_control_msg_serialize
../app/tests/test_control_msg_serialize.c:362:19: warning: unused variable ‘buf’ [-Wunused-variable]
  362 |     unsigned char buf[CONTROL_MSG_MAX_SIZE];
      |                   ^~~
../app/tests/test_control_msg_serialize.c:353:24: warning: unused variable ‘msg’ [-Wunused-variable]
  353 |     struct control_msg msg = {
      |                        ^~~
../app/tests/test_control_msg_serialize.c: In function ‘test_serialize_inject_game_controller_button’:
../app/tests/test_control_msg_serialize.c:399:12: error: variable ‘msg’ has initializer but incomplete type
  399 |     struct control_msg msg = {
      |            ^~~~~~~~~~~
../app/tests/test_control_msg_serialize.c:400:10: error: ‘struct control_msg’ has no member named ‘type’
  400 |         .type = CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_BUTTON,
      |          ^~~~
../app/tests/test_control_msg_serialize.c:400:17: error: ‘CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_BUTTON’ undeclared (first use in this function); did you mean ‘SC_CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_BUTTON’?
  400 |         .type = CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_BUTTON,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                 SC_CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_BUTTON
../app/tests/test_control_msg_serialize.c:400:17: warning: excess elements in struct initializer
../app/tests/test_control_msg_serialize.c:400:17: note: (near initialization for ‘msg’)
../app/tests/test_control_msg_serialize.c:401:10: error: ‘struct control_msg’ has no member named ‘inject_game_controller_button’
  401 |         .inject_game_controller_button = {
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../app/tests/test_control_msg_serialize.c:401:42: error: extra brace group at end of initializer
  401 |         .inject_game_controller_button = {
      |                                          ^
../app/tests/test_control_msg_serialize.c:401:42: note: (near initialization for ‘msg’)
../app/tests/test_control_msg_serialize.c:401:42: warning: excess elements in struct initializer
../app/tests/test_control_msg_serialize.c:401:42: note: (near initialization for ‘msg’)
../app/tests/test_control_msg_serialize.c:399:24: error: storage size of ‘msg’ isn’t known
  399 |     struct control_msg msg = {
      |                        ^~~
../app/tests/test_control_msg_serialize.c:408:23: error: ‘CONTROL_MSG_MAX_SIZE’ undeclared (first use in this function); did you mean ‘SC_CONTROL_MSG_MAX_SIZE’?
  408 |     unsigned char buf[CONTROL_MSG_MAX_SIZE];
      |                       ^~~~~~~~~~~~~~~~~~~~
      |                       SC_CONTROL_MSG_MAX_SIZE
../app/tests/test_control_msg_serialize.c:408:19: warning: unused variable ‘buf’ [-Wunused-variable]
  408 |     unsigned char buf[CONTROL_MSG_MAX_SIZE];
      |                   ^~~
../app/tests/test_control_msg_serialize.c:399:24: warning: unused variable ‘msg’ [-Wunused-variable]
  399 |     struct control_msg msg = {
      |                        ^~~
../app/tests/test_control_msg_serialize.c: In function ‘test_serialize_inject_game_controller_device’:
../app/tests/test_control_msg_serialize.c:437:12: error: variable ‘msg’ has initializer but incomplete type
  437 |     struct control_msg msg = {
      |            ^~~~~~~~~~~
../app/tests/test_control_msg_serialize.c:438:10: error: ‘struct control_msg’ has no member named ‘type’
  438 |         .type = CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_DEVICE,
      |          ^~~~
../app/tests/test_control_msg_serialize.c:438:17: error: ‘CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_DEVICE’ undeclared (first use in this function); did you mean ‘SC_CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_DEVICE’?
  438 |         .type = CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_DEVICE,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                 SC_CONTROL_MSG_TYPE_INJECT_GAME_CONTROLLER_DEVICE
../app/tests/test_control_msg_serialize.c:438:17: warning: excess elements in struct initializer
../app/tests/test_control_msg_serialize.c:438:17: note: (near initialization for ‘msg’)
../app/tests/test_control_msg_serialize.c:439:10: error: ‘struct control_msg’ has no member named ‘inject_game_controller_device’
  439 |         .inject_game_controller_device = {
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../app/tests/test_control_msg_serialize.c:439:42: error: extra brace group at end of initializer
  439 |         .inject_game_controller_device = {
      |                                          ^
../app/tests/test_control_msg_serialize.c:439:42: note: (near initialization for ‘msg’)
../app/tests/test_control_msg_serialize.c:439:42: warning: excess elements in struct initializer
../app/tests/test_control_msg_serialize.c:439:42: note: (near initialization for ‘msg’)
../app/tests/test_control_msg_serialize.c:437:24: error: storage size of ‘msg’ isn’t known
  437 |     struct control_msg msg = {
      |                        ^~~
../app/tests/test_control_msg_serialize.c:445:23: error: ‘CONTROL_MSG_MAX_SIZE’ undeclared (first use in this function); did you mean ‘SC_CONTROL_MSG_MAX_SIZE’?
  445 |     unsigned char buf[CONTROL_MSG_MAX_SIZE];
      |                       ^~~~~~~~~~~~~~~~~~~~
      |                       SC_CONTROL_MSG_MAX_SIZE
../app/tests/test_control_msg_serialize.c:445:19: warning: unused variable ‘buf’ [-Wunused-variable]
  445 |     unsigned char buf[CONTROL_MSG_MAX_SIZE];
      |                   ^~~
../app/tests/test_control_msg_serialize.c:437:24: warning: unused variable ‘msg’ [-Wunused-variable]
  437 |     struct control_msg msg = {
      |                        ^~~
[96/124] Linking target app/test_cli
ninja: build stopped: subcommand failed.
make: *** [release.mk:56: test] Error 1

I cloned your fork and ran "./release.sh", did i do sumn wrong?

ghoste0001 avatar Aug 09 '24 06:08 ghoste0001

Looks like I messed up somewhere. I only built partially with ./install_release.sh and it worked flawlessly. I did not see the release.sh errors. In the meantime, try ./install_release and run it from wsl

BinaryQuantumSoul avatar Aug 13 '24 14:08 BinaryQuantumSoul

#5270 released in scrcpy 2.7 :rocket:

rom1v avatar Sep 15 '24 19:09 rom1v