Skip to content

Commit

Permalink
Enable BUTTON_FORWARD and BUTTON_BACK mouse buttons on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
m4gr3d committed Aug 30, 2024
1 parent a5830f6 commit a917a0f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
11 changes: 11 additions & 0 deletions editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3270,6 +3270,17 @@ void ScriptEditor::input(const Ref<InputEvent> &p_event) {
}
}
}

const Ref<InputEventKey> 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<InputEvent> &p_event) {
Expand Down
9 changes: 2 additions & 7 deletions platform/android/java/lib/src/org/godotengine/godot/Godot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit a917a0f

Please sign in to comment.