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 <https://github.com/Genymobile/scrcpy/pull/5270#issuecomment-2339360460>
PR #5270 <https://github.com/Genymobile/scrcpy/pull/5270>

Suggested-by: Luiz Henrique Laurini <luizhenriquelaurini@gmail.com>
This commit is contained in:
Romain Vimont 2024-09-10 09:16:05 +02:00
parent 0ba430a462
commit f01a622ead
2 changed files with 8 additions and 0 deletions

View File

@ -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

View File

@ -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());