Skip to content

Commit

Permalink
Automatically switch to testing a new controller when it's plugged in
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 25, 2020
1 parent 46a8447 commit e16afa7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions test/testgamecontroller.c
Expand Up @@ -165,15 +165,17 @@ loop(void *arg)
switch (event.type) {
case SDL_CONTROLLERDEVICEADDED:
SDL_Log("Game controller device %d added.\n", (int) event.cdevice.which);
if (!gamecontroller) {
gamecontroller = SDL_GameControllerOpen(event.cdevice.which);
if (gamecontroller) {
InitGameController();
} else {
SDL_Log("Couldn't open controller: %s\n", SDL_GetError());
}
UpdateWindowTitle();
if (gamecontroller) {
SDL_GameControllerClose(gamecontroller);
}

gamecontroller = SDL_GameControllerOpen(event.cdevice.which);
if (gamecontroller) {
InitGameController();
} else {
SDL_Log("Couldn't open controller: %s\n", SDL_GetError());
}
UpdateWindowTitle();
break;

case SDL_CONTROLLERDEVICEREMOVED:
Expand Down

0 comments on commit e16afa7

Please sign in to comment.