From eb5e5b546ccdb43a8e812fa73b215eca99b121d5 Mon Sep 17 00:00:00 2001 From: Tony Jansson Date: Thu, 3 Sep 2020 19:40:07 +0300 Subject: [PATCH] Hotkey for Close Content --- command.h | 1 + config.def.keybinds.h | 21 ++++++++++++++++++ input/input_defines.h | 1 + intl/msg_hash_us.c | 4 ++++ intl/msg_hash_us.h | 8 +++++++ menu/cbs/menu_cbs_sublabel.c | 4 ++++ msg_hash.h | 2 ++ retroarch.c | 42 ++++++++++++++++++++++++++++++++++-- 8 files changed, 81 insertions(+), 2 deletions(-) diff --git a/command.h b/command.h index 9116c1f24a..4595ffb31e 100644 --- a/command.h +++ b/command.h @@ -40,6 +40,7 @@ enum event_command CMD_EVENT_LOAD_CORE, CMD_EVENT_LOAD_CORE_PERSIST, CMD_EVENT_UNLOAD_CORE, + CMD_EVENT_CLOSE_CONTENT, CMD_EVENT_LOAD_STATE, /* Swaps the current state with what's on the undo load buffer */ CMD_EVENT_UNDO_LOAD_STATE, diff --git a/config.def.keybinds.h b/config.def.keybinds.h index bc16570bc6..e71d1b5095 100644 --- a/config.def.keybinds.h +++ b/config.def.keybinds.h @@ -325,6 +325,13 @@ static const struct retro_keybind retro_keybinds_1[] = { RARCH_FULLSCREEN_TOGGLE_KEY, NO_BTN, NO_BTN, 0, true }, + { + NULL, NULL, + AXIS_NONE, AXIS_NONE, AXIS_NONE, + MENU_ENUM_LABEL_VALUE_INPUT_META_CLOSE_CONTENT_KEY, RETROK_UNKNOWN, + RARCH_CLOSE_CONTENT_KEY, NO_BTN, NO_BTN, 0, + true + }, { NULL, NULL, AXIS_NONE, AXIS_NONE, AXIS_NONE, @@ -865,6 +872,13 @@ static const struct retro_keybind retro_keybinds_1[] = { RARCH_FULLSCREEN_TOGGLE_KEY, NO_BTN, NO_BTN, 0, true }, + { + NULL, NULL, + AXIS_NONE, AXIS_NONE, AXIS_NONE, + MENU_ENUM_LABEL_VALUE_INPUT_META_CLOSE_CONTENT_KEY, RETROK_UNKNOWN, + RARCH_CLOSE_CONTENT_KEY, NO_BTN, NO_BTN, 0, + true + }, { NULL, NULL, AXIS_NONE, AXIS_NONE, AXIS_NONE, @@ -1405,6 +1419,13 @@ static const struct retro_keybind retro_keybinds_1[] = { RARCH_FULLSCREEN_TOGGLE_KEY, NO_BTN, NO_BTN, 0, true }, + { + NULL, NULL, + AXIS_NONE, AXIS_NONE, AXIS_NONE, + MENU_ENUM_LABEL_VALUE_INPUT_META_CLOSE_CONTENT_KEY, RETROK_UNKNOWN, + RARCH_CLOSE_CONTENT_KEY, NO_BTN, NO_BTN, 0, + true + }, #ifdef HAVE_LAKKA { NULL, NULL, diff --git a/input/input_defines.h b/input/input_defines.h index edd95037bd..8146a24ece 100644 --- a/input/input_defines.h +++ b/input/input_defines.h @@ -81,6 +81,7 @@ enum RARCH_LOAD_STATE_KEY, RARCH_SAVE_STATE_KEY, RARCH_FULLSCREEN_TOGGLE_KEY, + RARCH_CLOSE_CONTENT_KEY, RARCH_QUIT_KEY, RARCH_STATE_SLOT_PLUS, RARCH_STATE_SLOT_MINUS, diff --git a/intl/msg_hash_us.c b/intl/msg_hash_us.c index dd3895d9c4..8a4d3e0d3f 100644 --- a/intl/msg_hash_us.c +++ b/intl/msg_hash_us.c @@ -184,6 +184,10 @@ int msg_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len) snprintf(s, len, "Toggles fullscreen."); break; + case RARCH_CLOSE_CONTENT_KEY: + snprintf(s, len, + "Closes content."); + break; case RARCH_QUIT_KEY: snprintf(s, len, "Key to exit RetroArch cleanly. \n" diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 63d8f808c1..8f17c01924 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -2227,6 +2227,14 @@ MSG_HASH( MENU_ENUM_SUBLABEL_INPUT_META_FULLSCREEN_TOGGLE_KEY, "Switches between fullscreen and windowed display modes." ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_INPUT_META_CLOSE_CONTENT_KEY, + "Close Content" + ) +MSG_HASH( + MENU_ENUM_SUBLABEL_INPUT_META_CLOSE_CONTENT_KEY, + "Closes the current content. Any unsaved changes might be lost." + ) MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_META_QUIT_KEY, "Quit RetroArch" diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index a531962166..5176d4b1d7 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -229,6 +229,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_slowmotion_hold_key, ME DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_load_state_key, MENU_ENUM_SUBLABEL_INPUT_META_LOAD_STATE_KEY) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_save_state_key, MENU_ENUM_SUBLABEL_INPUT_META_SAVE_STATE_KEY) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_fullscreen_toggle_key, MENU_ENUM_SUBLABEL_INPUT_META_FULLSCREEN_TOGGLE_KEY) +DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_close_content_key, MENU_ENUM_SUBLABEL_INPUT_META_CLOSE_CONTENT_KEY) #ifdef HAVE_LAKKA DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_restart_key, MENU_ENUM_SUBLABEL_INPUT_META_RESTART_KEY) #else @@ -1557,6 +1558,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case RARCH_FULLSCREEN_TOGGLE_KEY: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_meta_fullscreen_toggle_key); return 0; + case RARCH_CLOSE_CONTENT_KEY: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_meta_close_content_key); + return 0; case RARCH_QUIT_KEY: #ifdef HAVE_LAKKA BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_meta_restart_key); diff --git a/msg_hash.h b/msg_hash.h index 1fc1822a7a..6a0aec2521 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -814,6 +814,7 @@ enum msg_hash_enums MENU_ENUM_LABEL_VALUE_INPUT_META_LOAD_STATE_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_SAVE_STATE_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_FULLSCREEN_TOGGLE_KEY, + MENU_ENUM_LABEL_VALUE_INPUT_META_CLOSE_CONTENT_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_QUIT_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_RESTART_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_STATE_SLOT_PLUS, @@ -864,6 +865,7 @@ enum msg_hash_enums MENU_ENUM_SUBLABEL_INPUT_META_LOAD_STATE_KEY, MENU_ENUM_SUBLABEL_INPUT_META_SAVE_STATE_KEY, MENU_ENUM_SUBLABEL_INPUT_META_FULLSCREEN_TOGGLE_KEY, + MENU_ENUM_SUBLABEL_INPUT_META_CLOSE_CONTENT_KEY, MENU_ENUM_SUBLABEL_INPUT_META_QUIT_KEY, MENU_ENUM_SUBLABEL_INPUT_META_RESTART_KEY, MENU_ENUM_SUBLABEL_INPUT_META_STATE_SLOT_PLUS, diff --git a/retroarch.c b/retroarch.c index ef374be29d..7772a7e468 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1843,6 +1843,8 @@ struct menu_state /* Flagged when menu entries need to be refreshed */ bool entries_need_refresh; bool entries_nonblocking_refresh; + /* 'Close Content'-hotkey menu resetting */ + bool pending_close_content; }; struct menu_bind_state_port @@ -2674,6 +2676,7 @@ static const struct input_bind_map input_config_bind_map[RARCH_BIND_LIST_END_NUL DECLARE_META_BIND(1, load_state, RARCH_LOAD_STATE_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_LOAD_STATE_KEY), DECLARE_META_BIND(1, save_state, RARCH_SAVE_STATE_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_SAVE_STATE_KEY), DECLARE_META_BIND(2, toggle_fullscreen, RARCH_FULLSCREEN_TOGGLE_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_FULLSCREEN_TOGGLE_KEY), + DECLARE_META_BIND(2, close_content, RARCH_CLOSE_CONTENT_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_CLOSE_CONTENT_KEY), #ifdef HAVE_LAKKA DECLARE_META_BIND(2, exit_emulator, RARCH_QUIT_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_RESTART_KEY), #else @@ -4741,9 +4744,7 @@ int generic_menu_entry_action( void *userdata, menu_entry_t *entry, size_t i, enum menu_action action) { int ret = 0; -#ifdef HAVE_ACCESSIBILITY struct rarch_state *p_rarch = &rarch_st; -#endif file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); menu_file_list_cbs_t *cbs = selection_buf ? (menu_file_list_cbs_t*)selection_buf->list[i].actiondata : NULL; @@ -4898,6 +4899,26 @@ int generic_menu_entry_action( speak_string, 10); } #endif + if (p_rarch->menu_driver_state.pending_close_content) + { + menu_handle_t *menu = menu_driver_get_ptr(); + const char *content_path = path_get(RARCH_PATH_CONTENT); + const char *menu_flush_to = msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU); + + /* Flush to playlist entry menu if launched via playlist */ + if (menu && + !string_is_empty(menu->deferred_path) && + !string_is_empty(content_path) && + string_is_equal(menu->deferred_path, content_path)) + menu_flush_to = msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_RPL_ENTRY_ACTIONS); + + command_event(CMD_EVENT_UNLOAD_CORE, 0); + menu_entries_flush_stack(menu_flush_to, 0); + menu_driver_ctl(RARCH_MENU_CTL_UNSET_PREVENT_POPULATE, NULL); + menu_navigation_set_selection(0); + + p_rarch->menu_driver_state.pending_close_content = false; + } return ret; } @@ -12660,6 +12681,7 @@ static const struct cmd_map map[] = { { "LOAD_STATE", RARCH_LOAD_STATE_KEY }, { "SAVE_STATE", RARCH_SAVE_STATE_KEY }, { "FULLSCREEN_TOGGLE", RARCH_FULLSCREEN_TOGGLE_KEY }, + { "CLOSE_CONTENT", RARCH_CLOSE_CONTENT_KEY }, { "QUIT", RARCH_QUIT_KEY }, { "STATE_SLOT_PLUS", RARCH_STATE_SLOT_PLUS }, { "STATE_SLOT_MINUS", RARCH_STATE_SLOT_MINUS }, @@ -16039,6 +16061,20 @@ bool command_event(enum event_command cmd, void *data) } } break; + case CMD_EVENT_CLOSE_CONTENT: +#ifdef HAVE_MENU + /* Closing content via hotkey requires toggling menu + * and resetting the position later on to prevent + * going to empty Quick Menu */ + if (!p_rarch->menu_driver_alive) + { + p_rarch->menu_driver_state.pending_close_content = true; + command_event(CMD_EVENT_MENU_TOGGLE, 0); + } +#else + command_event(CMD_EVENT_QUIT, 0); +#endif + break; case CMD_EVENT_QUIT: if (!retroarch_main_quit()) return false; @@ -39198,6 +39234,8 @@ static enum runloop_state runloop_check_state( HOTKEY_CHECK(RARCH_GAME_FOCUS_TOGGLE, CMD_EVENT_GAME_FOCUS_TOGGLE, true, NULL); /* Check if we have pressed the UI companion toggle button */ HOTKEY_CHECK(RARCH_UI_COMPANION_TOGGLE, CMD_EVENT_UI_COMPANION_TOGGLE, true, NULL); + /* Check close content key */ + HOTKEY_CHECK(RARCH_CLOSE_CONTENT_KEY, CMD_EVENT_CLOSE_CONTENT, true, NULL); #ifdef HAVE_MENU /* Check if we have pressed the menu toggle button */