X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fsdl.c;h=ee43dc05b0c1b1795328b129d1ca0a563f0398e2;hp=5586628b40dabf1385a5ae09472828f079e5501b;hb=aa77ac7ad31e0a9ab20bb85b51e429cd45f12455;hpb=cad3c0cde6926a8a379725b1ffc6fc657272a76d diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 5586628b..ee43dc05 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -2734,6 +2734,22 @@ void HandleJoystickEvent(Event *event) switch(event->type) { #if defined(TARGET_SDL2) + case SDL_CONTROLLERDEVICEADDED: +#if 1 + Error(ERR_DEBUG, "SDL_CONTROLLERDEVICEADDED: device %d added", + event->cdevice.which); +#endif + InitJoysticks(); + break; + + case SDL_CONTROLLERDEVICEREMOVED: +#if 1 + Error(ERR_DEBUG, "SDL_CONTROLLERDEVICEREMOVED: device %d removed", + event->cdevice.which); +#endif + InitJoysticks(); + break; + case SDL_CONTROLLERAXISMOTION: #if 1 Error(ERR_DEBUG, "SDL_CONTROLLERAXISMOTION: device %d, axis %d: %d", @@ -2817,7 +2833,10 @@ void SDLInitJoysticks() static boolean sdl_joystick_subsystem_initialized = FALSE; boolean print_warning = !sdl_joystick_subsystem_initialized; #if defined(TARGET_SDL2) - char *mappings_file = "gamecontrollerdb.txt"; + char *mappings_file_base = getPath2(options.ro_base_directory, + GAMECONTROLLER_BASENAME); + char *mappings_file_user = getPath2(getUserGameDataDir(), + GAMECONTROLLER_BASENAME); int num_mappings; #endif int i; @@ -2839,15 +2858,25 @@ void SDLInitJoysticks() } #if defined(TARGET_SDL2) - num_mappings = SDL_GameControllerAddMappingsFromFile(mappings_file); + num_mappings = SDL_GameControllerAddMappingsFromFile(mappings_file_base); + + if (num_mappings != -1) + Error(ERR_INFO, "%d game controller base mapping(s) added", num_mappings); + else + Error(ERR_WARN, "no game controller base mappings found"); + + num_mappings = SDL_GameControllerAddMappingsFromFile(mappings_file_user); if (num_mappings != -1) - Error(ERR_INFO, "%d game controller mapping(s) added", num_mappings); + Error(ERR_INFO, "%d game controller user mapping(s) added", num_mappings); else - Error(ERR_WARN, "no game controller mappings found"); + Error(ERR_WARN, "no game controller user mappings found"); Error(ERR_INFO, "%d joystick(s) found:", SDL_NumJoysticks()); + checked_free(mappings_file_base); + checked_free(mappings_file_user); + for (i = 0; i < SDL_NumJoysticks(); i++) { const char *name, *type;