Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android: Fix controllers opening nav drawer even after being bound to a hotkey #166

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,20 +272,28 @@ class EmulationActivity : AppCompatActivity() {
val button = preferences.getInt(InputBindingSetting.getInputButtonKey(event), event.scanCode)
val action: Int = when (event.action) {
KeyEvent.ACTION_DOWN -> {
hotkeyUtility.handleHotkey(button)

// On some devices, the back gesture / button press is not intercepted by androidx
// and fails to open the emulation menu. So we're stuck running deprecated code to
// cover for either a fault on androidx's side or in OEM skins (MIUI at least)
if (event.keyCode == KeyEvent.KEYCODE_BACK) {
onBackPressed()
// If the hotkey is pressed, we don't want to open the drawer
if (hotkeyUtility.HotkeyIsPressed) {
return true
} else {
onBackPressed()
}
}

hotkeyUtility.handleHotkey(button)

// Normal key events.
NativeLibrary.ButtonState.PRESSED
}

KeyEvent.ACTION_UP -> NativeLibrary.ButtonState.RELEASED
KeyEvent.ACTION_UP -> {
hotkeyUtility.HotkeyIsPressed = false
NativeLibrary.ButtonState.RELEASED
}
else -> return false
}
val input = event.device
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Citra Emulator Project
// Copyright 2025 Citra Project / Mandarine Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

Expand All @@ -14,6 +14,7 @@ import io.github.mandarine3ds.mandarine.display.ScreenAdjustmentUtil
class HotkeyUtility(private val screenAdjustmentUtil: ScreenAdjustmentUtil, private val context: Context) {

val hotkeyButtons = Hotkey.entries.map { it.button }
var HotkeyIsPressed = false

fun handleHotkey(bindedButton: Int): Boolean {
if (hotkeyButtons.contains(bindedButton)) {
Expand Down Expand Up @@ -41,6 +42,7 @@ class HotkeyUtility(private val screenAdjustmentUtil: ScreenAdjustmentUtil, priv
}
else -> {}
}
HotkeyIsPressed = true
return true
}
return false
Expand Down
Loading