From f01a622eadebb66e2fe0da22e24e71679e20bcb5 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 10 Sep 2024 09:16:05 +0200 Subject: [PATCH] Enable joystick events in background Capture the gamepads even when the window is not focused. Note: In theory, with this flag set, we could capture gamepad events even without a window (--no-window). In practice, scrcpy still requires a window, because --no-window implies --no-control, and the input manager is owned by the sc_screen instance, which does not exist if there is no window. Supporting this use case would require a lot of refactors. Refs PR #5270 Suggested-by: Luiz Henrique Laurini --- app/src/scrcpy.c | 4 ++++ app/src/usb/scrcpy_otg.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 687a9f34..854657fb 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -136,6 +136,10 @@ sdl_set_hints(const char *render_driver) { if (!SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0")) { LOGW("Could not disable minimize on focus loss"); } + + if (!SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1")) { + LOGW("Could not allow joystick background events"); + } } static void diff --git a/app/src/usb/scrcpy_otg.c b/app/src/usb/scrcpy_otg.c index 47afd9d0..9595face 100644 --- a/app/src/usb/scrcpy_otg.c +++ b/app/src/usb/scrcpy_otg.c @@ -58,6 +58,10 @@ scrcpy_otg(struct scrcpy_options *options) { LOGW("Could not enable linear filtering"); } + if (!SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1")) { + LOGW("Could not allow joystick background events"); + } + // Minimal SDL initialization if (SDL_Init(SDL_INIT_EVENTS)) { LOGE("Could not initialize SDL: %s", SDL_GetError());