Skip to content

Commit 8c0f968

Browse files
Mapping of descriptor binds?
1 parent b150feb commit 8c0f968

File tree

2 files changed

+61
-21
lines changed

2 files changed

+61
-21
lines changed

configuration.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6089,6 +6089,10 @@ void config_save_file_salamander(void)
60896089

60906090
bool input_config_bind_map_get_valid(unsigned bind_index)
60916091
{
6092+
/* Binds for extra keys are always valid. */
6093+
if (bind_index >= RARCH_BIND_ID_EXTRA_BUTTON_START && bind_index <= RARCH_BIND_ID_EXTRA_BUTTON_END)
6094+
return true;
6095+
60926096
const struct input_bind_map *keybind =
60936097
(const struct input_bind_map*)INPUT_CONFIG_BIND_MAP_GET(bind_index);
60946098
if (!keybind)
@@ -6111,7 +6115,11 @@ unsigned input_config_bind_map_get_meta(unsigned bind_index)
61116115

61126116
const char *input_config_bind_map_get_base(unsigned bind_index)
61136117
{
6114-
const struct input_bind_map *keybind =
6118+
/* Binds for extra keys are never mappable in any way. */
6119+
if (bind_index >= RARCH_BIND_ID_EXTRA_BUTTON_START && bind_index <= RARCH_BIND_ID_EXTRA_BUTTON_END)
6120+
return 0;
6121+
6122+
const struct input_bind_map *keybind =
61156123
(const struct input_bind_map*)INPUT_CONFIG_BIND_MAP_GET(bind_index);
61166124
if (!keybind)
61176125
return NULL;
@@ -6120,7 +6128,11 @@ const char *input_config_bind_map_get_base(unsigned bind_index)
61206128

61216129
const char *input_config_bind_map_get_desc(unsigned bind_index)
61226130
{
6123-
const struct input_bind_map *keybind =
6131+
/* Binds for extra keys are never mappable in any way. */
6132+
if (bind_index >= RARCH_BIND_ID_EXTRA_BUTTON_START && bind_index <= RARCH_BIND_ID_EXTRA_BUTTON_END)
6133+
return NULL;
6134+
6135+
const struct input_bind_map *keybind =
61246136
(const struct input_bind_map*)INPUT_CONFIG_BIND_MAP_GET(bind_index);
61256137
if (!keybind)
61266138
return NULL;
@@ -6129,7 +6141,15 @@ const char *input_config_bind_map_get_desc(unsigned bind_index)
61296141

61306142
uint8_t input_config_bind_map_get_retro_key(unsigned bind_index)
61316143
{
6132-
const struct input_bind_map *keybind =
6144+
/* Extra binds are very special keys. */
6145+
if (bind_index >= RARCH_BIND_ID_EXTRA_BUTTON_START && bind_index <= RARCH_BIND_ID_EXTRA_BUTTON_END)
6146+
{
6147+
RARCH_LOG("TODO: Handle extra key in input_config_bind_map_get_retro_key(%d)\n",
6148+
bind_index);
6149+
return 0;
6150+
}
6151+
6152+
const struct input_bind_map *keybind =
61336153
(const struct input_bind_map*)INPUT_CONFIG_BIND_MAP_GET(bind_index);
61346154
if (!keybind)
61356155
return 0;

menu/menu_setting.c

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9021,7 +9021,7 @@ static bool setting_append_list_input_player_options(
90219021
*/
90229022
static char buffer[MAX_USERS][13+2+1];
90239023
static char group_label[MAX_USERS][255];
9024-
unsigned bindIndex, j;
9024+
unsigned logicalIndex, bindIndex;
90259025
rarch_setting_group_info_t group_info;
90269026
rarch_setting_group_info_t subgroup_info;
90279027
settings_t *settings = config_get_ptr();
@@ -9254,18 +9254,18 @@ static bool setting_append_list_input_player_options(
92549254
{
92559255
const char *value_na =
92569256
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE);
9257-
for (j = 0; j < RARCH_BIND_LIST_END; j++)
9257+
for (bindIndex = 0; bindIndex < RARCH_BIND_LIST_END; bindIndex++)
92589258
{
92599259
char label[NAME_MAX_LENGTH];
92609260
char name[NAME_MAX_LENGTH];
9261-
bool isExtraKey = (j >= RARCH_BIND_ID_EXTRA_BUTTON_START && j < RARCH_BIND_ID_EXTRA_BUTTON_END);
9261+
bool isExtraKey = (bindIndex >= RARCH_BIND_ID_EXTRA_BUTTON_START && bindIndex <= RARCH_BIND_ID_EXTRA_BUTTON_END);
92629262
size_t _len = 0;
92639263

9264-
bindIndex = (j < RARCH_ANALOG_BIND_LIST_END)
9265-
? input_config_bind_order[j]
9266-
: j;
9264+
logicalIndex = (bindIndex < RARCH_ANALOG_BIND_LIST_END)
9265+
? input_config_bind_order[bindIndex]
9266+
: bindIndex;
92679267

9268-
if (!isExtraKey && input_config_bind_map_get_meta(bindIndex))
9268+
if (!isExtraKey && input_config_bind_map_get_meta(logicalIndex))
92699269
continue;
92709270

92719271
name[0] = '\0';
@@ -9281,44 +9281,64 @@ static bool setting_append_list_input_player_options(
92819281

92829282
if (
92839283
settings->bools.input_descriptor_label_show
9284-
&& (bindIndex < RARCH_FIRST_META_KEY)
9284+
&& (isExtraKey || logicalIndex < RARCH_FIRST_META_KEY)
92859285
&& core_has_set_input_descriptor()
9286-
&& (bindIndex != RARCH_TURBO_ENABLE)
9286+
&& (logicalIndex != RARCH_TURBO_ENABLE)
92879287
)
92889288
{
9289-
if (sys_info->input_desc_btn[user][bindIndex])
9289+
/* Remap the binding key to extra key accordingly. */
9290+
if (isExtraKey)
9291+
{
9292+
logicalIndex = RETRO_DEVICE_ID_JOYPAD_MAX_BUTTONS + (bindIndex - RARCH_BIND_ID_EXTRA_BUTTON_START);
9293+
9294+
/* Debug. */
9295+
RARCH_LOG("Reassigned bindIndex %d to logicalIndex %d\n",
9296+
bindIndex, logicalIndex);
9297+
}
9298+
9299+
/* Debug. */
9300+
if (sys_info->input_desc_btn[user][logicalIndex])
9301+
RARCH_LOG("Desc of bind %d/logical %d is %s\n",
9302+
bindIndex, logicalIndex,
9303+
sys_info->input_desc_btn[user][logicalIndex]);
9304+
9305+
if (sys_info->input_desc_btn[user][logicalIndex])
92909306
strlcpy(label + _len,
9291-
sys_info->input_desc_btn[user][bindIndex],
9307+
sys_info->input_desc_btn[user][logicalIndex],
92929308
sizeof(label) - _len);
92939309
else
92949310
{
92959311
snprintf(label, sizeof(label), "%s (%s)",
9296-
input_config_bind_map_get_desc(bindIndex),
9312+
input_config_bind_map_get_desc(logicalIndex),
92979313
value_na);
92989314

92999315
if (settings->bools.input_descriptor_hide_unbound)
93009316
continue;
93019317
}
93029318
}
9303-
else
9319+
else if (!isExtraKey)
93049320
strlcpy(label + _len,
9305-
input_config_bind_map_get_desc(bindIndex),
9321+
input_config_bind_map_get_desc(logicalIndex),
93069322
sizeof(label) - _len);
93079323

9308-
snprintf(name, sizeof(name), "p%u_%s", user + 1, input_config_bind_map_get_base(bindIndex));
9324+
/* Not a valid controller key. */
9325+
else
9326+
continue;
9327+
9328+
snprintf(name, sizeof(name), "p%u_%s", user + 1, input_config_bind_map_get_base(logicalIndex));
93099329

93109330
CONFIG_BIND_ALT(
93119331
list, list_info,
9312-
&input_config_binds[user][bindIndex],
9332+
&input_config_binds[user][logicalIndex],
93139333
user + 1,
93149334
user,
93159335
strdup(name),
93169336
strdup(label),
9317-
&defaults[bindIndex],
9337+
&defaults[logicalIndex],
93189338
&group_info,
93199339
&subgroup_info,
93209340
parent_group);
9321-
(*list)[list_info->index - 1].bind_type = bindIndex + MENU_SETTINGS_BIND_BEGIN;
9341+
(*list)[list_info->index - 1].bind_type = logicalIndex + MENU_SETTINGS_BIND_BEGIN;
93229342
}
93239343
}
93249344

0 commit comments

Comments
 (0)