From 37f9f118c40e770bdeb5988a112b4dd224decf8d Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 13 Jan 2021 18:54:37 +1000 Subject: [PATCH] Android: Add 'Open Pause Menu' hotkey --- android/app/src/cpp/android_host_interface.cpp | 16 ++++++++++++++++ android/app/src/cpp/android_host_interface.h | 1 + .../stenzek/duckstation/EmulationActivity.java | 6 ++++++ src/frontend-common/common_host_interface.cpp | 13 +++++++++---- src/frontend-common/common_host_interface.h | 3 +++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/android/app/src/cpp/android_host_interface.cpp b/android/app/src/cpp/android_host_interface.cpp index 1875ff21d..04f690c47 100644 --- a/android/app/src/cpp/android_host_interface.cpp +++ b/android/app/src/cpp/android_host_interface.cpp @@ -45,6 +45,7 @@ static jmethodID s_EmulationActivity_method_onEmulationStopped; static jmethodID s_EmulationActivity_method_onGameTitleChanged; static jmethodID s_EmulationActivity_method_setVibration; static jmethodID s_EmulationActivity_method_getRefreshRate; +static jmethodID s_EmulationActivity_method_openPauseMenu; static jclass s_PatchCode_class; static jmethodID s_PatchCode_constructor; static jclass s_GameListEntry_class; @@ -224,6 +225,19 @@ std::unique_ptr AndroidHostInterface::OpenPackageFile(const char* pa return ret; } +void AndroidHostInterface::RegisterHotkeys() +{ + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("OpenPauseMenu"), + StaticString(TRANSLATABLE("Hotkeys", "Open Pause Menu")), [this](bool pressed) { + if (pressed) { + AndroidHelpers::GetJNIEnv()->CallVoidMethod(m_emulation_activity_object, + s_EmulationActivity_method_openPauseMenu); + } + }); + + CommonHostInterface::RegisterHotkeys(); +} + bool AndroidHostInterface::GetMainDisplayRefreshRate(float* refresh_rate) { if (!m_emulation_activity_object) @@ -898,6 +912,8 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) nullptr || (s_EmulationActivity_method_getRefreshRate = env->GetMethodID(emulation_activity_class, "getRefreshRate", "()F")) == nullptr || + (s_EmulationActivity_method_openPauseMenu = + env->GetMethodID(emulation_activity_class, "openPauseMenu", "()V")) == nullptr || (s_PatchCode_constructor = env->GetMethodID(s_PatchCode_class, "", "(ILjava/lang/String;Z)V")) == nullptr || (s_GameListEntry_constructor = env->GetMethodID( s_GameListEntry_class, "", diff --git a/android/app/src/cpp/android_host_interface.h b/android/app/src/cpp/android_host_interface.h index 5586c6415..b4a79677d 100644 --- a/android/app/src/cpp/android_host_interface.h +++ b/android/app/src/cpp/android_host_interface.h @@ -72,6 +72,7 @@ protected: void SetUserDirectory() override; void LoadSettings() override; void UpdateInputMap() override; + void RegisterHotkeys() override; bool AcquireHostDisplay() override; void ReleaseHostDisplay() override; diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java b/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java index 832262e8b..53f9169c7 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java @@ -154,6 +154,12 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde return display.getRefreshRate(); } + public void openPauseMenu() { + runOnUiThread(() -> { + showMenu(); + }); + } + private void doApplySettings() { AndroidHostInterface.getInstance().applySettings(); updateRequestedOrientation(); diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 2940566f4..54c630c5e 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -77,10 +77,7 @@ bool CommonHostInterface::Initialize() m_save_state_selector_ui = std::make_unique(this); - RegisterGeneralHotkeys(); - RegisterGraphicsHotkeys(); - RegisterSaveStateHotkeys(); - RegisterAudioHotkeys(); + RegisterHotkeys(); UpdateControllerInterface(); return true; @@ -1462,6 +1459,14 @@ bool CommonHostInterface::AddRumbleToInputMap(const std::string& binding, u32 co return false; } +void CommonHostInterface::RegisterHotkeys() +{ + RegisterGeneralHotkeys(); + RegisterGraphicsHotkeys(); + RegisterSaveStateHotkeys(); + RegisterAudioHotkeys(); +} + void CommonHostInterface::RegisterGeneralHotkeys() { RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("FastForward"), diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index 671b3cb7e..a33a882e9 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -225,6 +225,9 @@ protected: /// Request the frontend to exit. virtual void RequestExit() = 0; + /// Registers frontend-specific hotkeys. + virtual void RegisterHotkeys(); + /// Executes per-frame tasks such as controller polling. virtual void PollAndUpdate();