diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index acd194935..ca478c2da 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -1184,6 +1184,33 @@ void GuiMenu::openOtherOptions() } }); + // Exit button configuration. + auto exit_button_config = std::make_shared> + (mWindow, getHelpStyle(), "CHOOSE EXIT BUTTON COMBO", false); + std::vector exitButtonCombos; + exitButtonCombos.push_back("F4"); + exitButtonCombos.push_back("Alt + F4"); + exitButtonCombos.push_back("Escape"); + #if defined(__APPLE__) + exitButtonCombos.push_back("\u2318 + Q"); + #endif + #if defined(_WIN64) + exitButtonCombos.push_back("Ctrl + F4"); + #endif + for (auto it = exitButtonCombos.cbegin(); it != exitButtonCombos.cend(); it++) { + exit_button_config->add(*it, *it, Settings::getInstance()-> + getString("ExitButtonCombo") == *it); + } + s->addWithLabel("CHOOSE EXIT BUTTON COMBO", exit_button_config); + s->addSaveFunc([exit_button_config, s] { + if (exit_button_config->getSelected() != + Settings::getInstance()->getString("ExitButtonCombo")) { + Settings::getInstance()->setString("ExitButtonCombo", + exit_button_config->getSelected()); + s->setNeedsSaving(); + } + }); + // macOS requires root privileges to reboot and power off so it doesn't make much // sense to enable this setting and menu entry for that operating system. #if !defined(__APPLE__) diff --git a/es-core/src/InputManager.cpp b/es-core/src/InputManager.cpp index b7c5e7d49..3cbe01d76 100644 --- a/es-core/src/InputManager.cpp +++ b/es-core/src/InputManager.cpp @@ -28,6 +28,11 @@ int SDL_USER_CECBUTTONDOWN = -1; int SDL_USER_CECBUTTONUP = -1; +// save button states for combo-button exit support and predefine exit option-function map +static bool altDown = false; +static bool ctrlDown = false; +static bool lguiDown = false; + InputManager* InputManager::sInstance = nullptr; InputManager::InputManager() : mKeyboardInputConfig(nullptr) @@ -431,13 +436,42 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window) return true; } case SDL_KEYDOWN: { + + // save button states for alt and command + if (event.key.keysym.sym == SDLK_LALT) + { + altDown = true; + } + if (event.key.keysym.sym == SDLK_LCTRL) + { + ctrlDown = true; + } + if (event.key.keysym.sym == SDLK_LGUI) + { + lguiDown = true; + } + if (event.key.keysym.sym == SDLK_BACKSPACE && SDL_IsTextInputActive()) window->textInput("\b"); if (event.key.repeat) return false; - if (event.key.keysym.sym == SDLK_F4) { + // handle application exit + bool exitState = false; + std::string exitOption = Settings::getInstance()->getString("ExitButtonCombo"); + if (exitOption == "F4"){ + exitState = event.key.keysym.sym == SDLK_F4; + }else if (exitOption == "Alt + F4"){ + exitState = event.key.keysym.sym == SDLK_F4 && altDown; + }else if (exitOption == "\u2318 + Q"){ + exitState = event.key.keysym.sym == SDLK_F4 && lguiDown; + }else if (exitOption == "Ctrl + F4"){ + exitState = event.key.keysym.sym == SDLK_F4 && ctrlDown; + }else if (exitOption == "Escape"){ + exitState = event.key.keysym.sym == SDLK_ESCAPE; + } + if (exitState) { SDL_Event quit; quit.type = SDL_QUIT; SDL_PushEvent(&quit); @@ -449,6 +483,21 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window) return true; } case SDL_KEYUP: { + + // release button states + if (event.key.keysym.sym == SDLK_LALT) + { + altDown = false; + } + if (event.key.keysym.sym == SDLK_LCTRL) + { + ctrlDown = false; + } + if (event.key.keysym.sym == SDLK_LGUI) + { + lguiDown = false; + } + window->input(getInputConfigByDevice(DEVICE_KEYBOARD), Input(DEVICE_KEYBOARD, TYPE_KEY, event.key.keysym.sym, 0, false)); return true; diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 4625f1c05..cbd80098b 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -260,6 +260,7 @@ void Settings::setDefaults() mBoolMap["DisableComposition"] = { true, true }; #endif mBoolMap["DisplayGPUStatistics"] = { false, false }; + mStringMap["ExitButtonCombo"] = { "F4", "F4" }; // macOS requires root privileges to reboot and power off so it doesn't make much // sense to enable this setting and menu entry for that operating system. #if !defined(__APPLE__)