From 6b6f9ae678b3feaf238b7558fb68008d871e89cd Mon Sep 17 00:00:00 2001 From: natinusala Date: Mon, 25 Feb 2019 19:12:50 +0100 Subject: [PATCH] menu: add press quit twice setting --- config.def.h | 2 ++ configuration.c | 2 ++ configuration.h | 2 ++ intl/msg_hash_lbl.h | 2 ++ intl/msg_hash_us.h | 12 +++++++++ menu/cbs/menu_cbs_sublabel.c | 4 +++ menu/menu_defines.h | 3 +-- menu/menu_displaylist.c | 3 +++ menu/menu_input.c | 3 --- menu/menu_setting.c | 16 ++++++++++++ msg_hash.h | 3 +++ retroarch.c | 49 ++++++++++++++++++++++-------------- 12 files changed, 77 insertions(+), 24 deletions(-) diff --git a/config.def.h b/config.def.h index e1c5e15638..c8c7f19b16 100644 --- a/config.def.h +++ b/config.def.h @@ -432,6 +432,8 @@ static bool menu_swap_ok_cancel_buttons = true; static bool menu_swap_ok_cancel_buttons = false; #endif +static bool quit_press_twice = false; + /* Crop overscanned frames. */ static const bool crop_overscan = true; diff --git a/configuration.c b/configuration.c index 9327732352..11e9bd712f 100644 --- a/configuration.c +++ b/configuration.c @@ -1579,6 +1579,8 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings, SETTING_BOOL("playlist_show_core_name", &settings->bools.playlist_show_core_name, true, playlist_show_core_name, false); SETTING_BOOL("playlist_sort_alphabetical", &settings->bools.playlist_sort_alphabetical, true, playlist_sort_alphabetical, false); + SETTING_BOOL("quit_press_twice", &settings->bools.quit_press_twice, true, quit_press_twice, false); + *size = count; return tmp; diff --git a/configuration.h b/configuration.h index 3b55f2cffc..79f64ef833 100644 --- a/configuration.h +++ b/configuration.h @@ -313,6 +313,8 @@ typedef struct settings bool playlist_show_core_name; bool playlist_sort_alphabetical; bool playlist_show_sublabels; + + bool quit_press_twice; } bools; struct diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index 31fba11c18..7fe4bdbf9c 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -1445,6 +1445,8 @@ MSG_HASH(MENU_ENUM_LABEL_SHADER_PIPELINE_SNOW, "shader_pipeline_snow") MSG_HASH(MENU_ENUM_LABEL_INPUT_UNIFIED_MENU_CONTROLS, "unified_menu_controls") +MSG_HASH(MENU_ENUM_LABEL_QUIT_PRESS_TWICE, + "quit_press_twice") MSG_HASH(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR, "detect_core_list_push_dir") MSG_HASH(MENU_ENUM_LABEL_BATTERY_LEVEL_ENABLE, diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 6efa6135b8..0ae886806a 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -4794,6 +4794,10 @@ MSG_HASH( MSG_SCREENSHOT_SAVED, "Screenshot saved" ) +MSG_HASH( + MSG_PRESS_AGAIN_TO_QUIT, + "Press again to quit..." + ) MSG_HASH( MSG_TO, "to" @@ -5087,6 +5091,14 @@ MSG_HASH( MENU_ENUM_SUBLABEL_INPUT_UNIFIED_MENU_CONTROLS, "Use the same controls for both the menu and the game. Applies to the keyboard." ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_QUIT_PRESS_TWICE, + "Press quit twice" + ) +MSG_HASH( + MENU_ENUM_SUBLABEL_QUIT_PRESS_TWICE, + "Press the quit hotkey twice to exit RetroArch." + ) MSG_HASH( MENU_ENUM_SUBLABEL_VIDEO_FONT_ENABLE, "Show onscreen messages." diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index bb979f7d82..151c823fe9 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -185,6 +185,7 @@ default_sublabel_macro(action_bind_sublabel_video_smooth, MENU_ default_sublabel_macro(action_bind_sublabel_history_list_enable, MENU_ENUM_SUBLABEL_HISTORY_LIST_ENABLE) default_sublabel_macro(action_bind_sublabel_content_history_size, MENU_ENUM_SUBLABEL_CONTENT_HISTORY_SIZE) default_sublabel_macro(action_bind_sublabel_menu_input_unified_controls, MENU_ENUM_SUBLABEL_INPUT_UNIFIED_MENU_CONTROLS) +default_sublabel_macro(action_bind_sublabel_quit_press_twice, MENU_ENUM_SUBLABEL_QUIT_PRESS_TWICE) default_sublabel_macro(action_bind_sublabel_onscreen_notifications_enable, MENU_ENUM_SUBLABEL_VIDEO_FONT_ENABLE) default_sublabel_macro(action_bind_sublabel_video_crop_overscan, MENU_ENUM_SUBLABEL_VIDEO_CROP_OVERSCAN) default_sublabel_macro(action_bind_sublabel_video_filter, MENU_ENUM_SUBLABEL_VIDEO_FILTER) @@ -1938,6 +1939,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_INPUT_UNIFIED_MENU_CONTROLS: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_menu_input_unified_controls); break; + case MENU_ENUM_LABEL_QUIT_PRESS_TWICE: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_quit_press_twice); + break; case MENU_ENUM_LABEL_AUDIO_MAX_TIMING_SKEW: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_audio_max_timing_skew); break; diff --git a/menu/menu_defines.h b/menu/menu_defines.h index e1e9323626..411a3f7d04 100644 --- a/menu/menu_defines.h +++ b/menu/menu_defines.h @@ -266,8 +266,7 @@ enum menu_action MENU_ACTION_SCROLL_UP, MENU_ACTION_TOGGLE, MENU_ACTION_POINTER_MOVED, - MENU_ACTION_POINTER_PRESSED, - MENU_ACTION_QUIT + MENU_ACTION_POINTER_PRESSED }; enum menu_input_pointer_state diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index bf0e23e054..dfa7a46402 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -7075,6 +7075,9 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist ret = menu_displaylist_parse_settings_enum(menu, info, MENU_ENUM_LABEL_INPUT_UNIFIED_MENU_CONTROLS, PARSE_ONLY_BOOL, false); + ret = menu_displaylist_parse_settings_enum(menu, info, + MENU_ENUM_LABEL_QUIT_PRESS_TWICE, + PARSE_ONLY_BOOL, false); if (menu_displaylist_parse_settings_enum(menu, info, MENU_ENUM_LABEL_INPUT_POLL_TYPE_BEHAVIOR, PARSE_ONLY_UINT, false) == 0) diff --git a/menu/menu_input.c b/menu/menu_input.c index 2ce35f2ada..e95b24541d 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -336,9 +336,6 @@ unsigned menu_event(input_bits_t *p_input, input_bits_t *p_trigger_input) menu_event_kb_set_internal(RETROK_F11, 0); } - if (BIT256_GET_PTR(p_trigger_input, RARCH_QUIT_KEY)) - return MENU_ACTION_QUIT; - mouse_enabled = settings->bools.menu_mouse_enable; #ifdef HAVE_OVERLAY if (!mouse_enabled) diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 2386ec0611..c3af7fe2ca 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -6858,6 +6858,22 @@ static bool setting_append_list( ); settings_data_list_current_add_flags(list, list_info, SD_FLAG_LAKKA_ADVANCED); + CONFIG_BOOL( + list, list_info, + &settings->bools.quit_press_twice, + MENU_ENUM_LABEL_QUIT_PRESS_TWICE, + MENU_ENUM_LABEL_VALUE_QUIT_PRESS_TWICE, + false, + MENU_ENUM_LABEL_VALUE_OFF, + MENU_ENUM_LABEL_VALUE_ON, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler, + SD_FLAG_NONE + ); + CONFIG_UINT( list, list_info, &settings->uints.input_poll_type_behavior, diff --git a/msg_hash.h b/msg_hash.h index 444be356c0..fb033dc476 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -347,6 +347,7 @@ enum msg_hash_enums MSG_MOVIE_PLAYBACK_ENDED, MSG_TAKING_SCREENSHOT, MSG_SCREENSHOT_SAVED, + MSG_PRESS_AGAIN_TO_QUIT, MSG_WIFI_SCAN_COMPLETE, MSG_SCANNING_WIRELESS_NETWORKS, MSG_FAILED_TO_TAKE_SCREENSHOT, @@ -765,6 +766,8 @@ enum msg_hash_enums MENU_LABEL(INPUT_POLL_TYPE_BEHAVIOR), MENU_LABEL(INPUT_UNIFIED_MENU_CONTROLS), + MENU_LABEL(QUIT_PRESS_TWICE), + /* Video */ MENU_LABEL(CRT_SWITCH_RESOLUTION), MENU_LABEL(CRT_SWITCH_RESOLUTION_SUPER), diff --git a/retroarch.c b/retroarch.c index 152b4d071e..ccd60681e8 100644 --- a/retroarch.c +++ b/retroarch.c @@ -147,6 +147,8 @@ #define SHADER_FILE_WATCH_DELAY_MSEC 500 #define HOLD_START_DELAY_SEC 2 +#define QUIT_DELAY_USEC 3 * 1000000 /* 3 seconds */ + /* Descriptive names for options without short variant. * * Please keep the name in sync with the option name. @@ -2743,24 +2745,25 @@ static enum runloop_state runloop_check_state( #ifdef HAVE_MENU static input_bits_t last_input = {{0}}; #endif - static bool old_quit_key = false; - static bool quit_key = false; - static bool trig_quit_key = false; - static bool runloop_exec = false; - static bool old_focus = true; - bool is_focused = false; - bool is_alive = false; - uint64_t frame_count = 0; - bool focused = true; - bool pause_nonactive = settings->bools.pause_nonactive; - bool rarch_is_initialized = rarch_ctl(RARCH_CTL_IS_INITED, NULL); - bool fs_toggle_triggered = false; + static bool old_quit_key = false; + static bool quit_key = false; + static bool trig_quit_key = false; + static retro_time_t quit_key_time = 0; + static bool runloop_exec = false; + static bool old_focus = true; + bool is_focused = false; + bool is_alive = false; + uint64_t frame_count = 0; + bool focused = true; + bool pause_nonactive = settings->bools.pause_nonactive; + bool rarch_is_initialized = rarch_ctl(RARCH_CTL_IS_INITED, NULL); + bool fs_toggle_triggered = false; #ifdef HAVE_MENU - bool menu_driver_binding_state = menu_driver_is_binding_state(); - bool menu_is_alive = menu_driver_is_alive(); - unsigned menu_toggle_gamepad_combo = settings->uints.input_menu_toggle_gamepad_combo; + bool menu_driver_binding_state = menu_driver_is_binding_state(); + bool menu_is_alive = menu_driver_is_alive(); + unsigned menu_toggle_gamepad_combo = settings->uints.input_menu_toggle_gamepad_combo; #ifdef HAVE_EASTEREGG - static uint64_t seq = 0; + static uint64_t seq = 0; #endif #endif @@ -2889,6 +2892,17 @@ static enum runloop_state runloop_check_state( trig_quit_key = quit_key && !old_quit_key; old_quit_key = quit_key; + /* Check double press if enabled */ + if (trig_quit_key && settings->bools.quit_press_twice) + { + retro_time_t cur_time = cpu_features_get_time_usec(); + trig_quit_key = trig_quit_key && (cur_time - quit_key_time < QUIT_DELAY_USEC); + quit_key_time = cur_time; + + if (!trig_quit_key) + runloop_msg_queue_push(msg_hash_to_str(MSG_PRESS_AGAIN_TO_QUIT), 1, QUIT_DELAY_USEC * 60 / 1000000, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); + } + if (time_to_exit(trig_quit_key)) { if ((runloop_max_frames != 0) && (frame_count >= runloop_max_frames)) @@ -3063,9 +3077,6 @@ static enum runloop_state runloop_check_state( if (!focused) return RUNLOOP_STATE_POLLED_AND_SLEEP; - if (action == MENU_ACTION_QUIT && !menu_driver_binding_state) - return RUNLOOP_STATE_QUIT; - if (runloop_idle) return RUNLOOP_STATE_POLLED_AND_SLEEP; }