diff --git a/general.h b/general.h index cf6f77849a..c09b258eea 100644 --- a/general.h +++ b/general.h @@ -271,6 +271,7 @@ struct settings char joypad_driver[32]; char keyboard_layout[64]; + unsigned menu_remap_ids[MAX_USERS][RARCH_BIND_LIST_END]; unsigned remap_ids[MAX_USERS][RARCH_BIND_LIST_END]; struct retro_keybind binds[MAX_USERS][RARCH_BIND_LIST_END]; struct retro_keybind autoconf_binds[MAX_USERS][RARCH_BIND_LIST_END]; @@ -284,6 +285,7 @@ struct settings unsigned libretro_device[MAX_USERS]; unsigned analog_dpad_mode[MAX_USERS]; + bool menu_remap_binds_enable; bool remap_binds_enable; float axis_threshold; unsigned joypad_map[MAX_USERS]; diff --git a/input/input_remapping.c b/input/input_remapping.c index 3494527e1d..5bd3659765 100644 --- a/input/input_remapping.c +++ b/input/input_remapping.c @@ -118,3 +118,14 @@ void input_remapping_set_defaults(void) g_settings.input.remap_ids[i][j] = g_settings.input.binds[i][j].id; } } + +void input_menu_remapping_set_defaults(void) +{ + unsigned i, j; + + for (i = 0; i < MAX_USERS; i++) + { + for (j = 0; j < RARCH_BIND_LIST_END; j++) + g_settings.input.menu_remap_ids[i][j] = g_settings.input.binds[i][j].id; + } +} diff --git a/input/input_remapping.h b/input/input_remapping.h index 7a1ab57278..a202cc0a03 100644 --- a/input/input_remapping.h +++ b/input/input_remapping.h @@ -44,6 +44,8 @@ void input_remapping_save_file(const char *path); void input_remapping_set_defaults(void); +void input_menu_remapping_set_defaults(void); + #ifdef __cplusplus } #endif diff --git a/menu/menu_input.c b/menu/menu_input.c index 608ae5fe43..be35e23457 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -425,29 +425,68 @@ int menu_input_bind_iterate_keyboard(void *data) unsigned menu_input_frame(retro_input_t trigger_state) { + int16_t libretro_id = -1; + unsigned menu_id = 0; + if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_UP)) - return MENU_ACTION_UP; - if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN)) - return MENU_ACTION_DOWN; - if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT)) - return MENU_ACTION_LEFT; - if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT)) - return MENU_ACTION_RIGHT; - if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_L)) - return MENU_ACTION_SCROLL_UP; - if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_R)) - return MENU_ACTION_SCROLL_DOWN; - if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_B)) - return MENU_ACTION_CANCEL; - if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_A)) - return MENU_ACTION_OK; - if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_Y)) - return MENU_ACTION_Y; - if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_START)) - return MENU_ACTION_START; - if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT)) - return MENU_ACTION_SELECT; - if (trigger_state & (1ULL << RARCH_MENU_TOGGLE)) - return MENU_ACTION_TOGGLE; + libretro_id = RETRO_DEVICE_ID_JOYPAD_UP; + else if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN)) + libretro_id = RETRO_DEVICE_ID_JOYPAD_DOWN; + else if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT)) + libretro_id = RETRO_DEVICE_ID_JOYPAD_LEFT; + else if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT)) + libretro_id = RETRO_DEVICE_ID_JOYPAD_RIGHT; + else if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_L)) + libretro_id = RETRO_DEVICE_ID_JOYPAD_L; + else if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_R)) + libretro_id = RETRO_DEVICE_ID_JOYPAD_R; + else if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_B)) + libretro_id = RETRO_DEVICE_ID_JOYPAD_B; + else if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_A)) + libretro_id = RETRO_DEVICE_ID_JOYPAD_A; + else if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_Y)) + libretro_id = RETRO_DEVICE_ID_JOYPAD_Y; + else if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_START)) + libretro_id = MENU_ACTION_START; + else if (trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT)) + libretro_id = MENU_ACTION_SELECT; + else if (trigger_state & (1ULL << RARCH_MENU_TOGGLE)) + libretro_id = MENU_ACTION_TOGGLE; + + if (g_settings.input.menu_remap_binds_enable) + { + unsigned port = 0; + if (libretro_id != -1) + libretro_id = g_settings.input.menu_remap_ids[0][libretro_id]; + } + + switch (libretro_id) + { + case RETRO_DEVICE_ID_JOYPAD_UP: + return MENU_ACTION_UP; + case RETRO_DEVICE_ID_JOYPAD_DOWN: + return MENU_ACTION_DOWN; + case RETRO_DEVICE_ID_JOYPAD_LEFT: + return MENU_ACTION_LEFT; + case RETRO_DEVICE_ID_JOYPAD_RIGHT: + return MENU_ACTION_RIGHT; + case RETRO_DEVICE_ID_JOYPAD_L: + return MENU_ACTION_SCROLL_UP; + case RETRO_DEVICE_ID_JOYPAD_R: + return MENU_ACTION_SCROLL_DOWN; + case RETRO_DEVICE_ID_JOYPAD_B: + return MENU_ACTION_CANCEL; + case RETRO_DEVICE_ID_JOYPAD_A: + return MENU_ACTION_OK; + case RETRO_DEVICE_ID_JOYPAD_Y: + return MENU_ACTION_Y; + case RETRO_DEVICE_ID_JOYPAD_START: + return MENU_ACTION_START; + case RETRO_DEVICE_ID_JOYPAD_SELECT: + return MENU_ACTION_SELECT; + case RARCH_MENU_TOGGLE: + return MENU_ACTION_TOGGLE; + } + return MENU_ACTION_NOOP; } diff --git a/retroarch.cfg b/retroarch.cfg index d6aed9e2a2..f56d8c89b8 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -297,9 +297,6 @@ # Enable or disable the current overlay. # input_overlay_enable = true -# If enabled, overrides the input binds with the remapped binds set for the current core. -# input_remap_binds_enable = true - # Path to input overlay # input_overlay = @@ -311,6 +308,7 @@ #### Input + # Input driver. Depending on video driver, it might force a different input driver. # input_driver = sdl @@ -320,6 +318,12 @@ # Path to input remapping file. # input_remapping_path = +# If enabled, overrides the input binds with the remapped binds set for the current core. +# input_remap_binds_enable = true + +# If enabled, overrides the menu input binds with remapped binds. +# input_menu_remap_binds_enable = true + # Maximum amount of users supported by RetroArch. # input_max_users = 16 diff --git a/settings.c b/settings.c index ed4319c92b..b961417611 100644 --- a/settings.c +++ b/settings.c @@ -527,6 +527,7 @@ static void config_set_defaults(void) g_settings.input.input_descriptor_label_show = input_descriptor_label_show; g_settings.input.input_descriptor_hide_unbound = input_descriptor_hide_unbound; g_settings.input.remap_binds_enable = true; + g_settings.input.menu_remap_binds_enable = true; g_settings.input.max_users = MAX_USERS; rarch_assert(sizeof(g_settings.input.binds[0]) >= sizeof(retro_keybinds_1)); @@ -539,6 +540,7 @@ static void config_set_defaults(void) sizeof(retro_keybinds_rest)); input_remapping_set_defaults(); + input_menu_remapping_set_defaults(); for (i = 0; i < MAX_USERS; i++) { @@ -1211,6 +1213,8 @@ static bool config_load_file(const char *path, bool set_defaults) CONFIG_GET_BOOL(input.remap_binds_enable, "input_remap_binds_enable"); + CONFIG_GET_BOOL(input.menu_remap_binds_enable, + "menu_input_remap_binds_enable"); CONFIG_GET_FLOAT(input.axis_threshold, "input_axis_threshold"); CONFIG_GET_BOOL(input.netplay_client_swap_input, "netplay_client_swap_input"); @@ -1806,6 +1810,8 @@ bool config_save_file(const char *path) g_settings.input.axis_threshold); config_set_bool(conf, "input_remap_binds_enable", g_settings.input.remap_binds_enable); + config_set_bool(conf, "menu_input_remap_binds_enable", + g_settings.input.menu_remap_binds_enable); config_set_bool(conf, "netplay_client_swap_input", g_settings.input.netplay_client_swap_input); config_set_bool(conf, "input_descriptor_label_show", diff --git a/settings_data.c b/settings_data.c index 6eee664d15..caca8bb3d5 100644 --- a/settings_data.c +++ b/settings_data.c @@ -4802,6 +4802,18 @@ static bool setting_data_append_list_input_options( general_write_handler, general_read_handler); + CONFIG_BOOL( + g_settings.input.menu_remap_binds_enable, + "menu_input_remap_binds_enable", + "Menu Remap Binds Enable", + true, + "OFF", + "ON", + group_info.name, + subgroup_info.name, + general_write_handler, + general_read_handler); + CONFIG_BOOL( g_settings.input.autodetect_enable, "input_autodetect_enable",