Added the hint SDL_HINT_GAMECONTROLLERCONFIG_FILE to specify a file to load at initialization containing SDL game controller mappings
authorSam Lantinga <slouken@libsdl.org>
Fri, 07 Dec 2018 12:02:08 -0800
changeset 124672d7891d05d8d
parent 12466 b442834306a8
child 12468 209066a82aef
Added the hint SDL_HINT_GAMECONTROLLERCONFIG_FILE to specify a file to load at initialization containing SDL game controller mappings
include/SDL_hints.h
src/joystick/SDL_gamecontroller.c
     1.1 --- a/include/SDL_hints.h	Thu Dec 06 09:09:05 2018 -0800
     1.2 +++ b/include/SDL_hints.h	Fri Dec 07 12:02:08 2018 -0800
     1.3 @@ -437,6 +437,16 @@
     1.4  #define SDL_HINT_GAMECONTROLLERCONFIG "SDL_GAMECONTROLLERCONFIG"
     1.5  
     1.6  /**
     1.7 + *  \brief  A variable that lets you provide a file with extra gamecontroller db entries.
     1.8 + *
     1.9 + *  The file should contain lines of gamecontroller config data, see SDL_gamecontroller.h
    1.10 + *
    1.11 + *  This hint must be set before calling SDL_Init(SDL_INIT_GAMECONTROLLER)
    1.12 + *  You can update mappings after the system is initialized with SDL_GameControllerMappingForGUID() and SDL_GameControllerAddMapping()
    1.13 + */
    1.14 +#define SDL_HINT_GAMECONTROLLERCONFIG_FILE "SDL_GAMECONTROLLERCONFIG_FILE"
    1.15 +
    1.16 +/**
    1.17   *  \brief  A variable containing a list of devices to skip when scanning for game controllers.
    1.18   *
    1.19   *  The format of the string is a comma separated list of USB VID/PID pairs
     2.1 --- a/src/joystick/SDL_gamecontroller.c	Thu Dec 06 09:09:05 2018 -0800
     2.2 +++ b/src/joystick/SDL_gamecontroller.c	Fri Dec 07 12:02:08 2018 -0800
     2.3 @@ -1308,15 +1308,17 @@
     2.4  
     2.5  /*
     2.6   * Fill the given buffer with the expected controller mapping filepath. 
     2.7 - * Usually this will just be CONTROLLER_MAPPING_FILE, but for Android,
     2.8 - * we want to get the internal storage path.
     2.9 + * Usually this will just be SDL_HINT_GAMECONTROLLERCONFIG_FILE, but for
    2.10 + * Android, we want to get the internal storage path.
    2.11   */
    2.12  static SDL_bool SDL_GetControllerMappingFilePath(char *path, size_t size)
    2.13  {
    2.14 -#ifdef CONTROLLER_MAPPING_FILE
    2.15 -#define STRING(X) SDL_STRINGIFY_ARG(X)
    2.16 -    return SDL_strlcpy(path, STRING(CONTROLLER_MAPPING_FILE), size) < size;
    2.17 -#elif defined(__ANDROID__)
    2.18 +    const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG_FILE);
    2.19 +    if (hint && *hint) {
    2.20 +        return SDL_strlcpy(path, hint, size) < size;
    2.21 +    }
    2.22 +
    2.23 +#if defined(__ANDROID__)
    2.24      return SDL_snprintf(path, size, "%s/controller_map.txt", SDL_AndroidGetInternalStoragePath()) < size;
    2.25  #else
    2.26      return SDL_FALSE;