Fix SDL game controller init timing

This commit is contained in:
Simon Chan 2023-02-07 16:41:39 +08:00
parent 8df26fef2b
commit 88b8f1c6d7
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD

View file

@ -367,11 +367,6 @@ scrcpy(struct scrcpy_options *options) {
sdl_configure(options->display, options->disable_screensaver);
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)) {
LOGE("Could not initialize SDL: %s", SDL_GetError());
return false;
}
// Await for server without blocking Ctrl+C handling
bool connected;
if (!await_for_server(&connected)) {
@ -384,6 +379,14 @@ scrcpy(struct scrcpy_options *options) {
goto end;
}
// Initialize GAMECONTROLLER subsystem after server connected
// Otherwise the initial CONTROLLERDEVICEADDED event might
// be handled by `await_for_server`
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)) {
LOGE("Could not initialize SDL: %s", SDL_GetError());
return false;
}
// It is necessarily initialized here, since the device is connected
struct sc_server_info *info = &s->server.info;