From 31ad9351f5030a10f14c55b0725b4f96ba57e84d Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 27 Nov 2023 01:20:09 +0100 Subject: [PATCH] port: load gamecontrollerdb if available --- port/src/input.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/port/src/input.c b/port/src/input.c index da383f156..e1af7e079 100644 --- a/port/src/input.c +++ b/port/src/input.c @@ -10,6 +10,9 @@ #include "config.h" #include "utils.h" #include "system.h" +#include "fs.h" + +#define CONTROLLERDB_FNAME "gamecontrollerdb.txt" #define MAX_BIND_STR 256 @@ -637,6 +640,15 @@ s32 inputInit(void) SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC); } + // try to load controller db from an external file in the save folder + if (fsFileSize("$S/" CONTROLLERDB_FNAME)) { + const char *dbpath = fsFullPath("$S/" CONTROLLERDB_FNAME); + const s32 dbcount = SDL_GameControllerAddMappingsFromFile(dbpath); + if (dbcount >= 0) { + sysLogPrintf(LOG_NOTE, "input: added %d controller mappings from %s", dbcount, dbpath); + } + } + inputInitAllControllers(); // since the main event loop is elsewhere, we can receive some events we need using a watcher