Automatically switch to testing a new controller when it's plugged in

This commit is contained in:
Sam Lantinga 2020-11-24 16:38:49 -08:00
parent 46a844786b
commit e16afa792f

View File

@ -165,15 +165,17 @@ loop(void *arg)
switch (event.type) { switch (event.type) {
case SDL_CONTROLLERDEVICEADDED: case SDL_CONTROLLERDEVICEADDED:
SDL_Log("Game controller device %d added.\n", (int) event.cdevice.which); SDL_Log("Game controller device %d added.\n", (int) event.cdevice.which);
if (!gamecontroller) { if (gamecontroller) {
gamecontroller = SDL_GameControllerOpen(event.cdevice.which); SDL_GameControllerClose(gamecontroller);
if (gamecontroller) {
InitGameController();
} else {
SDL_Log("Couldn't open controller: %s\n", SDL_GetError());
}
UpdateWindowTitle();
} }
gamecontroller = SDL_GameControllerOpen(event.cdevice.which);
if (gamecontroller) {
InitGameController();
} else {
SDL_Log("Couldn't open controller: %s\n", SDL_GetError());
}
UpdateWindowTitle();
break; break;
case SDL_CONTROLLERDEVICEREMOVED: case SDL_CONTROLLERDEVICEREMOVED: