diff options
-rw-r--r-- | controller_info.c | 10 | ||||
-rw-r--r-- | nuklear_ui/blastem_nuklear.c | 12 |
2 files changed, 16 insertions, 6 deletions
diff --git a/controller_info.c b/controller_info.c index 12c90b3..c9ca1c7 100644 --- a/controller_info.c +++ b/controller_info.c @@ -2,6 +2,7 @@ #include "render_sdl.h" #include "controller_info.h" #include "config.h" +#include "util.h" typedef struct { char const *name; @@ -150,14 +151,19 @@ static void mappings_iter(char *key, tern_val val, uint8_t valtype, void *data) } char *mapping = tern_find_ptr(val.ptrval, "mapping"); if (mapping) { - SDL_GameControllerAddMapping(mapping); + const char *parts[] = {key, ",", mapping}; + char * full = alloc_concat_m(3, parts); + SDL_GameControllerAddMapping(full); + free(full); } } void controller_add_mappings(void) { load_ctype_config(); - tern_foreach(info_config, mappings_iter, NULL); + if (info_config) { + tern_foreach(info_config, mappings_iter, NULL); + } } void save_controller_info(int joystick, controller_info *info) diff --git a/nuklear_ui/blastem_nuklear.c b/nuklear_ui/blastem_nuklear.c index 683c95b..9830257 100644 --- a/nuklear_ui/blastem_nuklear.c +++ b/nuklear_ui/blastem_nuklear.c @@ -839,10 +839,14 @@ static void view_controller_variant(struct nk_context *context) const char *name = SDL_JoystickName(joy); size_t namesz = strlen(name); mapping_string = malloc(512 + namesz); - SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), mapping_string, 33); - mapping_string[32] = ','; - memcpy(mapping_string + 33, name, namesz); - mapping_pos = 33+namesz; + for (mapping_pos = 0; mapping_pos < namesz; mapping_pos++) + { + char c = name[mapping_pos]; + if (c == ',' || c == '\n' || c == '\r') { + c = ' '; + } + mapping_string[mapping_pos] = c; + } push_view(view_controller_mappings); } |