From 37ebdcdec774a730f08062b3c6f9bcb38bf70e97 Mon Sep 17 00:00:00 2001 From: pinumbernumber <1337rz@gmail.com> Date: Wed, 28 Aug 2013 21:16:27 +0100 Subject: [PATCH] Add correct joypad name reporting to RGUI (for xi and di), also cleanup dinput name variables --- input/dinput.c | 32 ++++++++++++++++---------------- input/winxinput_joypad.c | 5 +++++ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/input/dinput.c b/input/dinput.c index 9971f5bd93..0f787633a0 100644 --- a/input/dinput.c +++ b/input/dinput.c @@ -49,6 +49,7 @@ struct dinput_joypad { LPDIRECTINPUTDEVICE8 joypad; DIJOYSTATE2 joy_state; + char* joy_name; }; static unsigned g_joypad_cnt; @@ -350,9 +351,6 @@ const input_driver_t input_dinput = { // -1 = not xbox pad, otherwise 0..3 int g_xbox_pad_indexes[MAX_PLAYERS]; -// TODO: Move the name string to struct dinput_joypad -static char *g_pad_names[MAX_PLAYERS]; - static void dinput_joypad_destroy(void) { for (unsigned i = 0; i < MAX_PLAYERS; i++) @@ -362,16 +360,17 @@ static void dinput_joypad_destroy(void) IDirectInputDevice8_Unacquire(g_pads[i].joypad); IDirectInputDevice8_Release(g_pads[i].joypad); } + + if (g_pads[i].joy_name) + { + free(g_pads[i].joy_name); + g_pads[i].joy_name = NULL; + } + } g_joypad_cnt = 0; memset(g_pads, 0, sizeof(g_pads)); - - for (unsigned i = 0; i < MAX_PLAYERS; i++) - { - free (g_pad_names[i]); - g_pad_names[i] = NULL; - } // Can be blocked by global Dinput context. dinput_destroy_context(); @@ -443,8 +442,8 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) return DIENUM_CONTINUE; size_t name_len = strlen(inst->tszProductName) + 1; - g_pad_names[g_joypad_cnt] = (char*)malloc(name_len); - strncpy(g_pad_names[g_joypad_cnt], inst->tszProductName, name_len); + g_pads[g_joypad_cnt].joy_name = (char*)malloc(name_len); + strncpy(g_pads[g_joypad_cnt].joy_name, inst->tszProductName, name_len); #ifdef HAVE_WINXINPUT int last_xbox_pad_index = 0; @@ -473,7 +472,7 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) if (1) #endif { - + strlcpy(g_settings.input.device_names[g_joypad_cnt], dinput_joypad_name(g_joypad_cnt), sizeof(g_settings.input.device_names[g_joypad_cnt])); input_config_autoconfigure_joypad(g_joypad_cnt, dinput_joypad_name(g_joypad_cnt), dinput_joypad.ident); } @@ -488,9 +487,10 @@ static bool dinput_joypad_init(void) return false; for (unsigned i = 0; i < MAX_PLAYERS; ++i) + { g_xbox_pad_indexes[i] = -1; - - memset(&g_pad_names, 0, sizeof(g_pad_names)); + g_pads[i].joy_name = NULL; + } RARCH_LOG("Enumerating DInput joypads ...\n"); IDirectInput8_EnumDevices(g_ctx, DI8DEVCLASS_GAMECTRL, @@ -633,8 +633,8 @@ static bool dinput_joypad_query_pad(unsigned pad) static const char *dinput_joypad_name(unsigned pad) { - if ((pad < MAX_PLAYERS) && (g_pad_names[pad])) - return g_pad_names[pad]; + if (pad < MAX_PLAYERS) + return g_pads[pad].joy_name; return NULL; } diff --git a/input/winxinput_joypad.c b/input/winxinput_joypad.c index abf7ec9fb7..535e8b62ea 100644 --- a/input/winxinput_joypad.c +++ b/input/winxinput_joypad.c @@ -208,8 +208,13 @@ static bool winxinput_joypad_init(void) return false; for (unsigned autoconf_pad = 0; autoconf_pad < MAX_PLAYERS; autoconf_pad++) + { if (pad_index_to_xplayer_index(autoconf_pad) > -1) + { + strlcpy(g_settings.input.device_names[autoconf_pad], winxinput_joypad_name(autoconf_pad), sizeof(g_settings.input.device_names[autoconf_pad])); input_config_autoconfigure_joypad(autoconf_pad, winxinput_joypad_name(autoconf_pad), winxinput_joypad.ident); + } + } return true;