mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-31 04:25:40 +00:00
Merge branch 'quit-button-config' into '517-make-the-application-quit-shortcut-configurable-e-g-f4-alt-f4-alt-q-command-q'
Added a menu option in 'other options' for setting the exit button combo. See merge request leonstyhre/emulationstation-de!3
This commit is contained in:
commit
7a072674d3
|
@ -1184,6 +1184,33 @@ void GuiMenu::openOtherOptions()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Exit button configuration.
|
||||||
|
auto exit_button_config = std::make_shared<OptionListComponent<std::string>>
|
||||||
|
(mWindow, getHelpStyle(), "CHOOSE EXIT BUTTON COMBO", false);
|
||||||
|
std::vector<std::string> 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
|
// 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.
|
// sense to enable this setting and menu entry for that operating system.
|
||||||
#if !defined(__APPLE__)
|
#if !defined(__APPLE__)
|
||||||
|
|
|
@ -28,6 +28,11 @@
|
||||||
int SDL_USER_CECBUTTONDOWN = -1;
|
int SDL_USER_CECBUTTONDOWN = -1;
|
||||||
int SDL_USER_CECBUTTONUP = -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::sInstance = nullptr;
|
||||||
|
|
||||||
InputManager::InputManager() : mKeyboardInputConfig(nullptr)
|
InputManager::InputManager() : mKeyboardInputConfig(nullptr)
|
||||||
|
@ -431,13 +436,42 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case SDL_KEYDOWN: {
|
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())
|
if (event.key.keysym.sym == SDLK_BACKSPACE && SDL_IsTextInputActive())
|
||||||
window->textInput("\b");
|
window->textInput("\b");
|
||||||
|
|
||||||
if (event.key.repeat)
|
if (event.key.repeat)
|
||||||
return false;
|
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;
|
SDL_Event quit;
|
||||||
quit.type = SDL_QUIT;
|
quit.type = SDL_QUIT;
|
||||||
SDL_PushEvent(&quit);
|
SDL_PushEvent(&quit);
|
||||||
|
@ -449,6 +483,21 @@ bool InputManager::parseEvent(const SDL_Event& event, Window* window)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case SDL_KEYUP: {
|
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,
|
window->input(getInputConfigByDevice(DEVICE_KEYBOARD), Input(DEVICE_KEYBOARD,
|
||||||
TYPE_KEY, event.key.keysym.sym, 0, false));
|
TYPE_KEY, event.key.keysym.sym, 0, false));
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -260,6 +260,7 @@ void Settings::setDefaults()
|
||||||
mBoolMap["DisableComposition"] = { true, true };
|
mBoolMap["DisableComposition"] = { true, true };
|
||||||
#endif
|
#endif
|
||||||
mBoolMap["DisplayGPUStatistics"] = { false, false };
|
mBoolMap["DisplayGPUStatistics"] = { false, false };
|
||||||
|
mStringMap["ExitButtonCombo"] = { "F4", "F4" };
|
||||||
// macOS requires root privileges to reboot and power off so it doesn't make much
|
// 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.
|
// sense to enable this setting and menu entry for that operating system.
|
||||||
#if !defined(__APPLE__)
|
#if !defined(__APPLE__)
|
||||||
|
|
Loading…
Reference in a new issue