summaryrefslogtreecommitdiff
path: root/test/testgamecontroller.c
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2020-11-24 16:38:49 -0800
committerSam Lantinga <slouken@libsdl.org>2020-11-24 16:38:49 -0800
commitf5baf1d383e6094b0a0ef0b71ad0653b878a0718 (patch)
tree79e197e1254c3a15dd429c9fffc952d3577ab60b /test/testgamecontroller.c
parent6c128b9d261f0af4e809b6f6bcc90e6cd5b53021 (diff)
downloadsdl-f5baf1d383e6094b0a0ef0b71ad0653b878a0718.tar.gz
Automatically switch to testing a new controller when it's plugged in
Diffstat (limited to 'test/testgamecontroller.c')
-rw-r--r--test/testgamecontroller.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c
index 7f3af1e29..d32148040 100644
--- a/test/testgamecontroller.c
+++ b/test/testgamecontroller.c
@@ -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: