From aa3daca293656784636ff7ff8e35802afcc7d473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 11 Aug 2021 23:26:39 +0200 Subject: [PATCH] If it's a TV and VIRTKEY_PAUSE is not mapped to a pad control, pause on app switch. --- Core/KeyMap.cpp | 11 +++++++++++ Core/KeyMap.h | 2 ++ UI/EmuScreen.cpp | 10 +++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Core/KeyMap.cpp b/Core/KeyMap.cpp index 46d39dd51a..2015a4c941 100644 --- a/Core/KeyMap.cpp +++ b/Core/KeyMap.cpp @@ -905,6 +905,17 @@ void RemoveButtonMapping(int btn) { } } +bool IsKeyMapped(int device, int key) { + for (auto &iter : g_controllerMap) { + for (auto &mappedKey : iter.second) { + if (mappedKey == KeyDef(device, key)) { + return true; + } + } + } + return false; +} + void SetKeyMapping(int btn, KeyDef key, bool replace) { if (key.keyCode < 0) return; diff --git a/Core/KeyMap.h b/Core/KeyMap.h index f6918ec71b..d8b7a8a710 100644 --- a/Core/KeyMap.h +++ b/Core/KeyMap.h @@ -163,4 +163,6 @@ namespace KeyMap { const std::set &GetSeenPads(); void AutoConfForPad(const std::string &name); + + bool IsKeyMapped(int device, int key); } diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 858f73f5a0..2490c6abce 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -506,10 +506,14 @@ void EmuScreen::sendMessage(const char *message, const char *value) { } #endif } else if (!strcmp(message, "app_resumed") && screenManager()->topScreen() == this) { - // If there's no back button mapped, use this as the way to get into the menu. + if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_TV) { + if (!KeyMap::IsKeyMapped(DEVICE_ID_PAD_0, VIRTKEY_PAUSE) || !KeyMap::IsKeyMapped(DEVICE_ID_PAD_1, VIRTKEY_PAUSE)) { + // If it's a TV (so no built-in back button), and there's no back button mapped to a pad, + // use this as the fallback way to get into the menu. - // TODO: Check mappings. - screenManager()->push(new GamePauseScreen(gamePath_)); + screenManager()->push(new GamePauseScreen(gamePath_)); + } + } } }