mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-03-06 14:27:43 +00:00
Changed the default quit shortcut to Alt + F4 and Command + Q.
Also renamed the setting 'Exit button combo' to 'Keyboard quit shortcut' and fixed an issue where the application sometimes quit when exiting an emulator using Alt + F4 while running in the background.
This commit is contained in:
parent
fdbe826b53
commit
765aaeb2df
|
@ -1059,24 +1059,31 @@ void GuiMenu::openOtherOptions()
|
|||
}
|
||||
});
|
||||
|
||||
// Exit button configuration.
|
||||
auto exit_button_config = std::make_shared<OptionListComponent<std::string>>(
|
||||
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");
|
||||
// Keyboard quit shortcut.
|
||||
auto keyboardQuitShortcut = std::make_shared<OptionListComponent<std::string>>(
|
||||
getHelpStyle(), "KEYBOARD QUIT SHORTCUT", false);
|
||||
std::string selectedShortcut {Settings::getInstance()->getString("KeyboardQuitShortcut")};
|
||||
#if defined(_WIN64) || defined(__unix__)
|
||||
exit_button_config->add("Alt + Q", "AltQ", selectedExitButtonCombo == "AltQ");
|
||||
keyboardQuitShortcut->add("Alt + F4", "AltF4", selectedShortcut == "AltF4");
|
||||
keyboardQuitShortcut->add("Ctrl + Q", "CtrlQ", selectedShortcut == "CtrlQ");
|
||||
keyboardQuitShortcut->add("Alt + Q", "AltQ", selectedShortcut == "AltQ");
|
||||
#endif
|
||||
#if defined(__APPLE__)
|
||||
exit_button_config->add("\u2318 + Q", "CmdQ", selectedExitButtonCombo == "CmdQ");
|
||||
keyboardQuitShortcut->add("\u2318 + Q", "CmdQ", selectedShortcut == "CmdQ");
|
||||
keyboardQuitShortcut->add("Ctrl + Q", "CtrlQ", selectedShortcut == "CtrlQ");
|
||||
keyboardQuitShortcut->add("Alt + Q", "AltQ", selectedShortcut == "AltQ");
|
||||
#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());
|
||||
keyboardQuitShortcut->add("F4", "F4", selectedShortcut == "F4");
|
||||
// If there are no objects returned, then there must be a manually modified entry in the
|
||||
// configuration file. Simply set the keyboard quit shortcut to the first entry in this case.
|
||||
if (keyboardQuitShortcut->getSelectedObjects().size() == 0)
|
||||
keyboardQuitShortcut->selectEntry(0);
|
||||
s->addWithLabel("KEYBOARD QUIT SHORTCUT", keyboardQuitShortcut);
|
||||
s->addSaveFunc([keyboardQuitShortcut, s] {
|
||||
if (keyboardQuitShortcut->getSelected() !=
|
||||
Settings::getInstance()->getString("KeyboardQuitShortcut")) {
|
||||
Settings::getInstance()->setString("KeyboardQuitShortcut",
|
||||
keyboardQuitShortcut->getSelected());
|
||||
s->setNeedsSaving();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
#define KEYBOARD_GUID_STRING "-1"
|
||||
#define CEC_GUID_STRING "-2"
|
||||
|
||||
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 sAltDown {false};
|
||||
static bool sLguiDown {false};
|
||||
namespace
|
||||
{
|
||||
int SDL_USER_CECBUTTONDOWN {-1};
|
||||
int SDL_USER_CECBUTTONUP {-1};
|
||||
} // namespace
|
||||
|
||||
InputManager::InputManager() noexcept
|
||||
: mWindow {Window::getInstance()}
|
||||
|
@ -334,8 +333,8 @@ InputConfig* InputManager::getInputConfigByDevice(int device)
|
|||
|
||||
bool InputManager::parseEvent(const SDL_Event& event)
|
||||
{
|
||||
bool causedEvent = false;
|
||||
int32_t axisValue;
|
||||
bool causedEvent {false};
|
||||
int32_t axisValue {0};
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_CONTROLLERAXISMOTION: {
|
||||
|
@ -418,35 +417,37 @@ bool InputManager::parseEvent(const SDL_Event& event)
|
|||
return true;
|
||||
}
|
||||
case SDL_KEYDOWN: {
|
||||
|
||||
// Save button states for alt and command.
|
||||
if (event.key.keysym.sym == SDLK_LALT)
|
||||
sAltDown = true;
|
||||
if (event.key.keysym.sym == SDLK_LGUI)
|
||||
sLguiDown = true;
|
||||
|
||||
if (event.key.keysym.sym == SDLK_BACKSPACE && SDL_IsTextInputActive())
|
||||
mWindow->textInput("\b");
|
||||
|
||||
if (event.key.repeat)
|
||||
return false;
|
||||
|
||||
// Handle application exit.
|
||||
bool exitState;
|
||||
std::string exitOption = Settings::getInstance()->getString("ExitButtonCombo");
|
||||
if (exitOption == "AltF4")
|
||||
exitState = event.key.keysym.sym == SDLK_F4 && sAltDown;
|
||||
else if (exitOption == "CmdQ")
|
||||
exitState = event.key.keysym.sym == SDLK_q && sLguiDown;
|
||||
else if (exitOption == "AltQ")
|
||||
exitState = event.key.keysym.sym == SDLK_q && sAltDown;
|
||||
else
|
||||
exitState = event.key.keysym.sym == SDLK_F4;
|
||||
if (exitState) {
|
||||
SDL_Event quit;
|
||||
quit.type = SDL_QUIT;
|
||||
SDL_PushEvent(&quit);
|
||||
return false;
|
||||
// There is no need to handle the OS-default quit shortcut (Alt + F4 on Windows and
|
||||
// Linux and Command + Q on macOS) as that's taken care of by the window manager.
|
||||
std::string quitShortcut {Settings::getInstance()->getString("KeyboardQuitShortcut")};
|
||||
#if defined(__APPLE__)
|
||||
if (quitShortcut != "CmdQ") {
|
||||
#else
|
||||
if (quitShortcut != "AltF4") {
|
||||
#endif
|
||||
bool quitES {false};
|
||||
if (quitShortcut == "F4" && event.key.keysym.sym == SDLK_F4 &&
|
||||
!(event.key.keysym.mod & KMOD_LALT))
|
||||
quitES = true;
|
||||
else if (quitShortcut == "CtrlQ" && event.key.keysym.sym == SDLK_q &&
|
||||
event.key.keysym.mod & KMOD_CTRL)
|
||||
quitES = true;
|
||||
else if (quitShortcut == "AltQ" && event.key.keysym.sym == SDLK_q &&
|
||||
event.key.keysym.mod & KMOD_LALT)
|
||||
quitES = true;
|
||||
|
||||
if (quitES) {
|
||||
SDL_Event quit;
|
||||
quit.type = SDL_QUIT;
|
||||
SDL_PushEvent(&quit);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
mWindow->input(getInputConfigByDevice(DEVICE_KEYBOARD),
|
||||
|
@ -454,13 +455,6 @@ bool InputManager::parseEvent(const SDL_Event& event)
|
|||
return true;
|
||||
}
|
||||
case SDL_KEYUP: {
|
||||
|
||||
// Release button states.
|
||||
if (event.key.keysym.sym == SDLK_LALT)
|
||||
sAltDown = false;
|
||||
if (event.key.keysym.sym == SDLK_LGUI)
|
||||
sLguiDown = false;
|
||||
|
||||
mWindow->input(getInputConfigByDevice(DEVICE_KEYBOARD),
|
||||
Input(DEVICE_KEYBOARD, TYPE_KEY, event.key.keysym.sym, 0, false));
|
||||
return true;
|
||||
|
|
|
@ -223,7 +223,11 @@ void Settings::setDefaults()
|
|||
mIntMap["MaxVRAM"] = {256, 256};
|
||||
#endif
|
||||
mIntMap["DisplayIndex"] = {1, 1};
|
||||
mStringMap["ExitButtonCombo"] = {"F4", "F4"};
|
||||
#if defined(__APPLE__)
|
||||
mStringMap["KeyboardQuitShortcut"] = {"CmdQ", "CmdQ"};
|
||||
#else
|
||||
mStringMap["KeyboardQuitShortcut"] = {"AltF4", "AltF4"};
|
||||
#endif
|
||||
mStringMap["SaveGamelistsMode"] = {"always", "always"};
|
||||
#if defined(_WIN64)
|
||||
mBoolMap["HideTaskbar"] = {false, false};
|
||||
|
|
Loading…
Reference in a new issue