From 2ecb105c5c262ded05266b612f7e9797ba7820e6 Mon Sep 17 00:00:00 2001 From: SophiaHadash <=> Date: Thu, 1 Jul 2021 17:46:03 +0200 Subject: [PATCH 1/7] Added a menu option in 'other options' for setting the exit button combo. Added 4 button combos including Apple and Windows key combos. --- es-app/src/guis/GuiMenu.cpp | 27 +++++++++++++++++++ es-core/src/InputManager.cpp | 51 +++++++++++++++++++++++++++++++++++- es-core/src/Settings.cpp | 1 + 3 files changed, 78 insertions(+), 1 deletion(-) 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 688fb0dbf..9f314e7f0 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) @@ -424,13 +429,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); @@ -442,6 +476,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__) From 17d28ea88b098293073f722491c50538f179480b Mon Sep 17 00:00:00 2001 From: SophiaHadash <=> Date: Wed, 7 Jul 2021 14:13:46 +0200 Subject: [PATCH 2/7] remove exit combo ESC, add combo Alt+Q --- es-app/src/guis/GuiMenu.cpp | 7 +++---- es-core/src/InputManager.cpp | 25 +++++++------------------ 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index ca478c2da..f2a7d93d0 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -1190,13 +1190,12 @@ void GuiMenu::openOtherOptions() std::vector exitButtonCombos; exitButtonCombos.push_back("F4"); exitButtonCombos.push_back("Alt + F4"); - exitButtonCombos.push_back("Escape"); + #if defined(_WIN64) || defined(__unix__) + exitButtonCombos.push_back("Alt + Q"); + #endif #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); diff --git a/es-core/src/InputManager.cpp b/es-core/src/InputManager.cpp index 3cbe01d76..53c28cea8 100644 --- a/es-core/src/InputManager.cpp +++ b/es-core/src/InputManager.cpp @@ -30,7 +30,6 @@ 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; @@ -442,10 +441,6 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window) { altDown = true; } - if (event.key.keysym.sym == SDLK_LCTRL) - { - ctrlDown = true; - } if (event.key.keysym.sym == SDLK_LGUI) { lguiDown = true; @@ -458,18 +453,16 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window) return false; // handle application exit - bool exitState = false; + bool exitState; std::string exitOption = Settings::getInstance()->getString("ExitButtonCombo"); - if (exitOption == "F4"){ - exitState = event.key.keysym.sym == SDLK_F4; - }else if (exitOption == "Alt + F4"){ + 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; + exitState = event.key.keysym.sym == SDLK_q && lguiDown; + }else if (exitOption == "Alt + Q"){ + exitState = event.key.keysym.sym == SDLK_q && altDown; + }else{ + exitState = event.key.keysym.sym == SDLK_F4; } if (exitState) { SDL_Event quit; @@ -489,10 +482,6 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window) { altDown = false; } - if (event.key.keysym.sym == SDLK_LCTRL) - { - ctrlDown = false; - } if (event.key.keysym.sym == SDLK_LGUI) { lguiDown = false; From 8f1b6296cdfc56b2e189acda16fa49ca4349c1ed Mon Sep 17 00:00:00 2001 From: SophiaHadash <=> Date: Wed, 7 Jul 2021 14:16:20 +0200 Subject: [PATCH 3/7] remove word 'choose' from menu --- es-app/src/guis/GuiMenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index f2a7d93d0..4eb4a80a4 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -1186,7 +1186,7 @@ void GuiMenu::openOtherOptions() // Exit button configuration. auto exit_button_config = std::make_shared> - (mWindow, getHelpStyle(), "CHOOSE EXIT BUTTON COMBO", false); + (mWindow, getHelpStyle(), "EXIT BUTTON COMBO", false); std::vector exitButtonCombos; exitButtonCombos.push_back("F4"); exitButtonCombos.push_back("Alt + F4"); From ba2ef814de8be96c80a2504ec390fd48d4c2cb8f Mon Sep 17 00:00:00 2001 From: SophiaHadash <=> Date: Wed, 7 Jul 2021 14:24:15 +0200 Subject: [PATCH 4/7] code-words for options --- es-app/src/guis/GuiMenu.cpp | 16 ++++++---------- es-core/src/InputManager.cpp | 6 +++--- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 4eb4a80a4..038ad5c4f 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -1187,20 +1187,16 @@ void GuiMenu::openOtherOptions() // Exit button configuration. auto exit_button_config = std::make_shared> (mWindow, getHelpStyle(), "EXIT BUTTON COMBO", false); - std::vector exitButtonCombos; - exitButtonCombos.push_back("F4"); - exitButtonCombos.push_back("Alt + F4"); + std::string selectedExitButtonCombo = Settings::getInstance()->getString("ExitButtonCombo"); + exit_button_config->add("F4", "F4", selectedExitButtonCombo == "F4"); + exit_button_config->add("Alt + F4", "AltF4", selectedExitButtonCombo == "AltF4"); #if defined(_WIN64) || defined(__unix__) - exitButtonCombos.push_back("Alt + Q"); + exit_button_config->add("Alt + Q", "AltQ", selectedExitButtonCombo == "AltQ"); #endif #if defined(__APPLE__) - exitButtonCombos.push_back("\u2318 + Q"); + exit_button_config->add("\u2318 + Q", "CmdQ", selectedExitButtonCombo == "CmdQ"); #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->addWithLabel("EXIT BUTTON COMBO", exit_button_config); s->addSaveFunc([exit_button_config, s] { if (exit_button_config->getSelected() != Settings::getInstance()->getString("ExitButtonCombo")) { diff --git a/es-core/src/InputManager.cpp b/es-core/src/InputManager.cpp index 53c28cea8..d2868289f 100644 --- a/es-core/src/InputManager.cpp +++ b/es-core/src/InputManager.cpp @@ -455,11 +455,11 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window) // handle application exit bool exitState; std::string exitOption = Settings::getInstance()->getString("ExitButtonCombo"); - if (exitOption == "Alt + F4"){ + if (exitOption == "AltF4"){ exitState = event.key.keysym.sym == SDLK_F4 && altDown; - }else if (exitOption == "\u2318 + Q"){ + }else if (exitOption == "CmdQ"){ exitState = event.key.keysym.sym == SDLK_q && lguiDown; - }else if (exitOption == "Alt + Q"){ + }else if (exitOption == "AltQ"){ exitState = event.key.keysym.sym == SDLK_q && altDown; }else{ exitState = event.key.keysym.sym == SDLK_F4; From 6c165a4ca098365d572f03ddab41e3e8123744cd Mon Sep 17 00:00:00 2001 From: SophiaHadash <=> Date: Wed, 7 Jul 2021 14:28:09 +0200 Subject: [PATCH 5/7] move option up --- es-app/src/guis/GuiMenu.cpp | 44 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 038ad5c4f..4ceea6a1b 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -948,6 +948,28 @@ void GuiMenu::openOtherOptions() }); #endif + // Exit button configuration. + auto exit_button_config = std::make_shared> + (mWindow, getHelpStyle(), "EXIT BUTTON COMBO", false); + std::string selectedExitButtonCombo = Settings::getInstance()->getString("ExitButtonCombo"); + exit_button_config->add("F4", "F4", selectedExitButtonCombo == "F4"); + exit_button_config->add("Alt + F4", "AltF4", selectedExitButtonCombo == "AltF4"); + #if defined(_WIN64) || defined(__unix__) + exit_button_config->add("Alt + Q", "AltQ", selectedExitButtonCombo == "AltQ"); + #endif + #if defined(__APPLE__) + exit_button_config->add("\u2318 + Q", "CmdQ", selectedExitButtonCombo == "CmdQ"); + #endif + s->addWithLabel("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(); + } + }); + // When to save game metadata. auto save_gamelist_mode = std::make_shared> (mWindow, getHelpStyle(), "WHEN TO SAVE METADATA", false); @@ -1184,28 +1206,6 @@ void GuiMenu::openOtherOptions() } }); - // Exit button configuration. - auto exit_button_config = std::make_shared> - (mWindow, getHelpStyle(), "EXIT BUTTON COMBO", false); - std::string selectedExitButtonCombo = Settings::getInstance()->getString("ExitButtonCombo"); - exit_button_config->add("F4", "F4", selectedExitButtonCombo == "F4"); - exit_button_config->add("Alt + F4", "AltF4", selectedExitButtonCombo == "AltF4"); - #if defined(_WIN64) || defined(__unix__) - exit_button_config->add("Alt + Q", "AltQ", selectedExitButtonCombo == "AltQ"); - #endif - #if defined(__APPLE__) - exit_button_config->add("\u2318 + Q", "CmdQ", selectedExitButtonCombo == "CmdQ"); - #endif - s->addWithLabel("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__) From e24c92effe2b2770118715e5adacbd20e9a00e77 Mon Sep 17 00:00:00 2001 From: SophiaHadash <=> Date: Wed, 7 Jul 2021 14:31:32 +0200 Subject: [PATCH 6/7] code style and comments style --- es-core/src/InputManager.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/es-core/src/InputManager.cpp b/es-core/src/InputManager.cpp index d2868289f..274a73bc4 100644 --- a/es-core/src/InputManager.cpp +++ b/es-core/src/InputManager.cpp @@ -28,7 +28,7 @@ int SDL_USER_CECBUTTONDOWN = -1; int SDL_USER_CECBUTTONUP = -1; -// save button states for combo-button exit support and predefine exit option-function map +// Save button states for combo-button exit support and predefine exit option-function map. static bool altDown = false; static bool lguiDown = false; @@ -436,15 +436,11 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window) } case SDL_KEYDOWN: { - // save button states for alt and command + // Save button states for alt and command. if (event.key.keysym.sym == SDLK_LALT) - { altDown = true; - } if (event.key.keysym.sym == SDLK_LGUI) - { lguiDown = true; - } if (event.key.keysym.sym == SDLK_BACKSPACE && SDL_IsTextInputActive()) window->textInput("\b"); @@ -452,18 +448,17 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window) if (event.key.repeat) return false; - // handle application exit + // Handle application exit. bool exitState; std::string exitOption = Settings::getInstance()->getString("ExitButtonCombo"); - if (exitOption == "AltF4"){ + if (exitOption == "AltF4") exitState = event.key.keysym.sym == SDLK_F4 && altDown; - }else if (exitOption == "CmdQ"){ + else if (exitOption == "CmdQ") exitState = event.key.keysym.sym == SDLK_q && lguiDown; - }else if (exitOption == "AltQ"){ + else if (exitOption == "AltQ") exitState = event.key.keysym.sym == SDLK_q && altDown; - }else{ + else exitState = event.key.keysym.sym == SDLK_F4; - } if (exitState) { SDL_Event quit; quit.type = SDL_QUIT; @@ -477,15 +472,11 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window) } case SDL_KEYUP: { - // release button states + // Release button states. if (event.key.keysym.sym == SDLK_LALT) - { altDown = 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)); From 5f23074f725e93005c39ee6d3a11d2137c563aa6 Mon Sep 17 00:00:00 2001 From: SophiaHadash <=> Date: Wed, 7 Jul 2021 14:35:42 +0200 Subject: [PATCH 7/7] indentation of multi-line statements --- es-app/src/guis/GuiMenu.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 4ceea6a1b..3b0d47ffe 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -950,7 +950,7 @@ void GuiMenu::openOtherOptions() // Exit button configuration. auto exit_button_config = std::make_shared> - (mWindow, getHelpStyle(), "EXIT BUTTON COMBO", false); + (mWindow, getHelpStyle(), "EXIT BUTTON COMBO", false); std::string selectedExitButtonCombo = Settings::getInstance()->getString("ExitButtonCombo"); exit_button_config->add("F4", "F4", selectedExitButtonCombo == "F4"); exit_button_config->add("Alt + F4", "AltF4", selectedExitButtonCombo == "AltF4"); @@ -965,7 +965,7 @@ void GuiMenu::openOtherOptions() if (exit_button_config->getSelected() != Settings::getInstance()->getString("ExitButtonCombo")) { Settings::getInstance()->setString("ExitButtonCombo", - exit_button_config->getSelected()); + exit_button_config->getSelected()); s->setNeedsSaving(); } });