From 85878d894ae944e9044c7f29b5285d96b19f5a1f Mon Sep 17 00:00:00 2001 From: grorp Date: Tue, 11 Jun 2024 22:37:57 +0200 Subject: [PATCH] Android: Fix back button sometimes not working as ESC (#14743) --- irr/src/CIrrDeviceSDL.cpp | 3 ++- src/client/inputhandler.cpp | 1 - src/client/inputhandler.h | 2 +- src/client/keycode.cpp | 1 - src/client/keycode.h | 1 - src/gui/guiFormSpecMenu.cpp | 4 ++-- src/gui/guiOpenURL.cpp | 4 +--- src/gui/guiPasswordChange.cpp | 4 +--- 8 files changed, 7 insertions(+), 13 deletions(-) diff --git a/irr/src/CIrrDeviceSDL.cpp b/irr/src/CIrrDeviceSDL.cpp index 81ff37511..f5859372e 100644 --- a/irr/src/CIrrDeviceSDL.cpp +++ b/irr/src/CIrrDeviceSDL.cpp @@ -1267,7 +1267,8 @@ void CIrrDeviceSDL::createKeyMap() // buttons missing - KeyMap.push_back(SKeyMap(SDLK_AC_BACK, KEY_CANCEL)); + // Android back button = ESC + KeyMap.push_back(SKeyMap(SDLK_AC_BACK, KEY_ESCAPE)); KeyMap.push_back(SKeyMap(SDLK_BACKSPACE, KEY_BACK)); KeyMap.push_back(SKeyMap(SDLK_TAB, KEY_TAB)); diff --git a/src/client/inputhandler.cpp b/src/client/inputhandler.cpp index 665d77dc5..ae994b8b5 100644 --- a/src/client/inputhandler.cpp +++ b/src/client/inputhandler.cpp @@ -94,7 +94,6 @@ void KeyCache::populate() handler->listenForKey(k); } handler->listenForKey(EscapeKey); - handler->listenForKey(CancelKey); } } diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h index 4c6db3618..400503a3d 100644 --- a/src/client/inputhandler.h +++ b/src/client/inputhandler.h @@ -309,7 +309,7 @@ class RealInputHandler : public InputHandler virtual bool cancelPressed() { - return wasKeyDown(KeyType::ESC) || m_receiver->WasKeyDown(CancelKey); + return wasKeyDown(KeyType::ESC); } virtual void clearWasKeyPressed() diff --git a/src/client/keycode.cpp b/src/client/keycode.cpp index ad7aaf776..19613229a 100644 --- a/src/client/keycode.cpp +++ b/src/client/keycode.cpp @@ -348,7 +348,6 @@ const char *KeyPress::name() const } const KeyPress EscapeKey("KEY_ESCAPE"); -const KeyPress CancelKey("KEY_CANCEL"); const KeyPress LMBKey("KEY_LBUTTON"); const KeyPress MMBKey("KEY_MBUTTON"); diff --git a/src/client/keycode.h b/src/client/keycode.h index 1adc98563..bb679391d 100644 --- a/src/client/keycode.h +++ b/src/client/keycode.h @@ -66,7 +66,6 @@ class KeyPress // Global defines for convenience extern const KeyPress EscapeKey; -extern const KeyPress CancelKey; extern const KeyPress LMBKey; extern const KeyPress MMBKey; // Middle Mouse Button diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 2e54b32dc..ca9401091 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -4105,7 +4105,7 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event) // Fix Esc/Return key being eaten by checkboxen and tables if (event.EventType == EET_KEY_INPUT_EVENT) { KeyPress kp(event.KeyInput); - if (kp == EscapeKey || kp == CancelKey + if (kp == EscapeKey || kp == getKeySetting("keymap_inventory") || event.KeyInput.Key==KEY_RETURN) { gui::IGUIElement *focused = Environment->getFocus(); @@ -4173,7 +4173,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) if (event.EventType==EET_KEY_INPUT_EVENT) { KeyPress kp(event.KeyInput); if (event.KeyInput.PressedDown && ( - (kp == EscapeKey) || (kp == CancelKey) || + (kp == EscapeKey) || ((m_client != NULL) && (kp == getKeySetting("keymap_inventory"))))) { tryClose(); return true; diff --git a/src/gui/guiOpenURL.cpp b/src/gui/guiOpenURL.cpp index f20d8ba7b..f91d31391 100644 --- a/src/gui/guiOpenURL.cpp +++ b/src/gui/guiOpenURL.cpp @@ -160,9 +160,7 @@ void GUIOpenURLMenu::drawMenu() bool GUIOpenURLMenu::OnEvent(const SEvent &event) { if (event.EventType == EET_KEY_INPUT_EVENT) { - if ((event.KeyInput.Key == KEY_ESCAPE || - event.KeyInput.Key == KEY_CANCEL) && - event.KeyInput.PressedDown) { + if (event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown) { quitMenu(); return true; } diff --git a/src/gui/guiPasswordChange.cpp b/src/gui/guiPasswordChange.cpp index d3c1867a8..414ff36a8 100644 --- a/src/gui/guiPasswordChange.cpp +++ b/src/gui/guiPasswordChange.cpp @@ -187,9 +187,7 @@ bool GUIPasswordChange::processInput() bool GUIPasswordChange::OnEvent(const SEvent &event) { if (event.EventType == EET_KEY_INPUT_EVENT) { - if ((event.KeyInput.Key == KEY_ESCAPE || - event.KeyInput.Key == KEY_CANCEL) && - event.KeyInput.PressedDown) { + if (event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown) { quitMenu(); return true; }