From a917a0fd015daf39214b59d996aeb52ae577093e Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Mon, 12 Aug 2024 19:22:36 -0700 Subject: [PATCH] Enable `BUTTON_FORWARD` and `BUTTON_BACK` mouse buttons on Android --- editor/plugins/script_editor_plugin.cpp | 11 +++++++++++ .../java/lib/src/org/godotengine/godot/Godot.kt | 9 ++------- .../godotengine/godot/input/GodotInputHandler.java | 11 ----------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index d7de5a722305..dd5e208c3d72 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -3270,6 +3270,17 @@ void ScriptEditor::input(const Ref &p_event) { } } } + + const Ref key = p_event; + if (key.is_valid() && key->is_pressed() && is_visible_in_tree()) { + if (key->get_keycode() == Key::BACK) { + _history_back(); + } + + if (key->get_keycode() == Key::FORWARD) { + _history_forward(); + } + } } void ScriptEditor::shortcut_input(const Ref &p_event) { diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt index 38bd336e2d96..b606df63d7ab 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt @@ -909,15 +909,10 @@ class Godot(private val context: Context) { } fun onBackPressed() { - var shouldQuit = true for (plugin in pluginRegistry.allPlugins) { - if (plugin.onMainBackPressed()) { - shouldQuit = false - } - } - if (shouldQuit) { - renderView?.queueOnRenderThread { GodotLib.back() } + plugin.onMainBackPressed() } + renderView?.queueOnRenderThread { GodotLib.back() } } /** diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java index fb41cd00c025..36bee6ef2241 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java @@ -154,10 +154,6 @@ public void onPointerCaptureChange(boolean hasCapture) { } public boolean onKeyUp(final int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - return true; - } - if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { return false; } @@ -183,13 +179,6 @@ public boolean onKeyUp(final int keyCode, KeyEvent event) { } public boolean onKeyDown(final int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - godot.onBackPressed(); - // press 'back' button should not terminate program - //normal handle 'back' event in game logic - return true; - } - if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { return false; }