mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
Fix Air Triggers on RedMagic phones with unnamed input devices (#3755)
Recognize RedMagic triggers merged into an unnamed keyboard
This commit is contained in:
1 parent
b63a72affb
commit
0b7d7aa634
2 files changed
+47
-11
No files matched your search
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.input
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import android.os.Looper
|
||||
@@ -23,12 +24,20 @@ enum class AirTrigger(val keyCode: Int, val control: InputControl, val pressLigh
|
||||
LEFT(KeyEvent.KEYCODE_F7, InputControl.LT, 106, 107), RIGHT(KeyEvent.KEYCODE_F8, InputControl.RT, 108, 109);
|
||||
|
||||
companion object {
|
||||
// InputReader merges both trigger nodes into one device named after the left one.
|
||||
private const val DEVICE_PREFIX = "nubia_tgk"
|
||||
|
||||
fun isTriggerDevice(name: String?) = name?.startsWith(DEVICE_PREFIX) == true
|
||||
fun of(keyCode: Int, deviceName: String?): AirTrigger? =
|
||||
if (isTriggerDevice(deviceName)) entries.firstOrNull { it.keyCode == keyCode } else null
|
||||
internal fun isTriggerDevice(device: InputDevice?): Boolean {
|
||||
if (device == null) return false
|
||||
if (device.name.startsWith(DEVICE_PREFIX)) return true
|
||||
// Some RedMagic firmware merges the trigger sensors with an unnamed built-in keyboard.
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
|
||||
device.name.isEmpty() && !device.isVirtual && !device.isExternal &&
|
||||
device.supportsSource(InputDevice.SOURCE_KEYBOARD) &&
|
||||
device.hasKeys(LEFT.keyCode, RIGHT.keyCode).all { it }
|
||||
}
|
||||
|
||||
internal fun of(keyCode: Int, device: InputDevice?): AirTrigger? =
|
||||
entries.firstOrNull { it.keyCode == keyCode }?.takeIf { isTriggerDevice(device) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +127,7 @@ object RedMagicAirTriggers {
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun supported(context: Context) = context.packageManager.resolveContentProvider(AUTHORITY, 0) != null &&
|
||||
InputDevice.getDeviceIds().any { AirTrigger.isTriggerDevice(InputDevice.getDevice(it)?.name) }
|
||||
InputDevice.getDeviceIds().any { AirTrigger.isTriggerDevice(InputDevice.getDevice(it)) }
|
||||
|
||||
/** Call on the main thread. */
|
||||
fun open(context: Context) {
|
||||
@@ -240,8 +249,8 @@ class AirTriggerInput(
|
||||
}
|
||||
|
||||
fun onKey(event: KeyEvent, enabled: () -> Boolean): Boolean {
|
||||
if (AirTrigger.entries.none { it.keyCode == event.keyCode }) return false
|
||||
val trigger = AirTrigger.of(event.keyCode, event.device?.name) ?: return false
|
||||
if (event.keyCode != AirTrigger.LEFT.keyCode && event.keyCode != AirTrigger.RIGHT.keyCode) return false
|
||||
val trigger = AirTrigger.of(event.keyCode, event.device) ?: return false
|
||||
return onKey(trigger, event.action, event.repeatCount, event.action == KeyEvent.ACTION_DOWN && enabled())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user