android: Fix hotkey presses opening nav drawer even after being bound (#1122)

* android: Fix hotkey presses opening nav drawer even after being bound

* Removed unnecessary return

---------

Co-authored-by: Kleidis <167202775+kleidis@users.noreply.github.com>
Co-authored-by: OpenSauce04 <opensauce04@gmail.com>
This commit is contained in:
kleidis 2025-06-20 00:48:18 +02:00 committed by GitHub
parent 11687fe32b
commit 2b51691d57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View File

@ -238,20 +238,26 @@ class EmulationActivity : AppCompatActivity() {
preferences.getInt(InputBindingSetting.getInputButtonKey(event.keyCode), event.keyCode)
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) {
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

View File

@ -17,6 +17,7 @@ class HotkeyUtility(
private val context: Context) {
private val hotkeyButtons = Hotkey.entries.map { it.button }
var HotkeyIsPressed = false
fun handleHotkey(bindedButton: Int): Boolean {
if(hotkeyButtons.contains(bindedButton)) {
@ -45,6 +46,7 @@ class HotkeyUtility(
}
else -> {}
}
HotkeyIsPressed = true
return true
}
return false