From 9cf9b942eeec6913ccacc2f216072da02aa8b0e3 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 8 Apr 2024 22:07:52 +0200 Subject: [PATCH] (Android) Added a 'Back button/back swipe exits app' menu option --- es-app/src/guis/GuiMenu.cpp | 13 +++++++++++++ es-core/src/InputManager.cpp | 5 +++-- es-core/src/Settings.cpp | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 0d84bb77b..5503f468d 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -1790,6 +1790,19 @@ void GuiMenu::openOtherOptions() }); #endif +#if defined(__ANDROID__) + // Whether swiping or pressing back should exit the application. + auto backEventAppExit = std::make_shared(); + backEventAppExit->setState(Settings::getInstance()->getBool("BackEventAppExit")); + s->addWithLabel("BACK BUTTON/BACK SWIPE EXITS APP", backEventAppExit); + s->addSaveFunc([backEventAppExit, s] { + if (backEventAppExit->getState() != Settings::getInstance()->getBool("BackEventAppExit")) { + Settings::getInstance()->setBool("BackEventAppExit", backEventAppExit->getState()); + s->setNeedsSaving(); + } + }); +#endif + if (Settings::getInstance()->getBool("DebugFlag")) { // If the --debug command line option was passed then create a dummy entry. auto debugMode = std::make_shared(); diff --git a/es-core/src/InputManager.cpp b/es-core/src/InputManager.cpp index aca74d144..ed40c1fa2 100644 --- a/es-core/src/InputManager.cpp +++ b/es-core/src/InputManager.cpp @@ -477,8 +477,9 @@ bool InputManager::parseEvent(const SDL_Event& event) return false; #if defined(__ANDROID__) - // Quit application if the back button is pressed. - if (event.key.keysym.sym == SDLK_AC_BACK) { + // Quit application if the back button is pressed or if the back gesture is used. + if (event.key.keysym.sym == SDLK_AC_BACK && + Settings::getInstance()->getBool("BackEventAppExit")) { SDL_Event quit {}; quit.type = SDL_QUIT; SDL_PushEvent(&quit); diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index d17ce8335..58a423a46 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -303,6 +303,9 @@ void Settings::setDefaults() mBoolMap["MAMENameStripExtraInfo"] = {true, true}; #if defined(__unix__) && !defined(__ANDROID__) mBoolMap["DisableComposition"] = {false, false}; +#endif +#if defined(__ANDROID__) + mBoolMap["BackEventAppExit"] = {true, true}; #endif mBoolMap["DebugMode"] = {false, false}; mBoolMap["DisplayGPUStatistics"] = {false, false};