Add connected gamepads on start
Trigger SDL_CONTROLLERDEVICEADDED for all gamepads already connected when scrcpy starts. We want to handle both the gamepads initially connected and the gamepads connected while scrcpy is running. It is a bit racy, because a device may be added after the controller subsystem initialization, but before the call to list the joysticks. In that case, a single device may in theory be detected as added twice. This should be harmless though (the second initialization will just fail without major impact).
This commit is contained in:
parent
2d929fa4e5
commit
07d5a6ca80
@ -337,6 +337,21 @@ scrcpy_generate_scid(void) {
|
||||
return sc_rand_u32(&rand) & 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
static void
|
||||
init_sdl_gamepads(void) {
|
||||
// Trigger a SDL_CONTROLLERDEVICEADDED event for all gamepads already
|
||||
// connected
|
||||
int num_joysticks = SDL_NumJoysticks();
|
||||
for (int i = 0; i < num_joysticks; ++i) {
|
||||
if (SDL_IsGameController(i)) {
|
||||
SDL_Event event;
|
||||
event.cdevice.type = SDL_CONTROLLERDEVICEADDED;
|
||||
event.cdevice.which = i;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum scrcpy_exit_code
|
||||
scrcpy(struct scrcpy_options *options) {
|
||||
static struct scrcpy scrcpy;
|
||||
@ -851,6 +866,11 @@ aoa_complete:
|
||||
timeout_started = true;
|
||||
}
|
||||
|
||||
bool use_gamepads = true;
|
||||
if (use_gamepads) {
|
||||
init_sdl_gamepads();
|
||||
}
|
||||
|
||||
ret = event_loop(s);
|
||||
terminate_event_loop();
|
||||
LOGD("quit...");
|
||||
|
Loading…
x
Reference in New Issue
Block a user