Merge pull request #11307 from sonninnos/close-content-hotkey

Hotkey for Close Content / Unload Core
This commit is contained in:
Autechre 2020-09-09 06:26:49 +02:00 committed by GitHub
commit 8f60e63527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 81 additions and 2 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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"

View File

@ -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"

View File

@ -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
@ -1565,6 +1566,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);

View File

@ -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,

View File

@ -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;
@ -39309,6 +39345,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 */