From 70ce0f2e064ccf3dc5779df289e0a07cbbacff52 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 7 Dec 2018 12:02:08 -0800 Subject: [PATCH] Added the hint SDL_HINT_GAMECONTROLLERCONFIG_FILE to specify a file to load at initialization containing SDL game controller mappings --- include/SDL_hints.h | 10 ++++++++++ src/joystick/SDL_gamecontroller.c | 14 ++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/include/SDL_hints.h b/include/SDL_hints.h index b000ee90c3a78..5638b5cfb72c2 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -436,6 +436,16 @@ extern "C" { */ #define SDL_HINT_GAMECONTROLLERCONFIG "SDL_GAMECONTROLLERCONFIG" +/** + * \brief A variable that lets you provide a file with extra gamecontroller db entries. + * + * The file should contain lines of gamecontroller config data, see SDL_gamecontroller.h + * + * This hint must be set before calling SDL_Init(SDL_INIT_GAMECONTROLLER) + * You can update mappings after the system is initialized with SDL_GameControllerMappingForGUID() and SDL_GameControllerAddMapping() + */ +#define SDL_HINT_GAMECONTROLLERCONFIG_FILE "SDL_GAMECONTROLLERCONFIG_FILE" + /** * \brief A variable containing a list of devices to skip when scanning for game controllers. * diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index ae549425acb7e..c028716bb1dfc 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -1308,15 +1308,17 @@ SDL_GameControllerLoadHints() /* * Fill the given buffer with the expected controller mapping filepath. - * Usually this will just be CONTROLLER_MAPPING_FILE, but for Android, - * we want to get the internal storage path. + * Usually this will just be SDL_HINT_GAMECONTROLLERCONFIG_FILE, but for + * Android, we want to get the internal storage path. */ static SDL_bool SDL_GetControllerMappingFilePath(char *path, size_t size) { -#ifdef CONTROLLER_MAPPING_FILE -#define STRING(X) SDL_STRINGIFY_ARG(X) - return SDL_strlcpy(path, STRING(CONTROLLER_MAPPING_FILE), size) < size; -#elif defined(__ANDROID__) + const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG_FILE); + if (hint && *hint) { + return SDL_strlcpy(path, hint, size) < size; + } + +#if defined(__ANDROID__) return SDL_snprintf(path, size, "%s/controller_map.txt", SDL_AndroidGetInternalStoragePath()) < size; #else return SDL_FALSE;