mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(input): Back gesture opens the menu when a controller exposes its own mouse (#2666)
The 8BitDo Ultimate Mobile registers a mouse interface next to its gamepad. On REDMAGIC the back gesture has no virtual-hard-key flag, so with that mouse attached it was sent to the game as a right-click. A mouse that shares its USB id with an attached controller no longer counts.
This commit is contained in:
1 parent
c2663ebee8
commit
9c349e185e
3 files changed
+24
-2
No files matched your search
@@ -4786,8 +4786,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
|
||||
private fun externalMouseAttached(): Boolean {
|
||||
lastExternalMouse = InputDevice.getDeviceIds().map { InputDevice.getDevice(it) }
|
||||
.firstOrNull { device -> device != null && com.droiddeck.launcher.input.MouseBackInput.isExternalMouse(device) }
|
||||
lastExternalMouse = com.droiddeck.launcher.input.MouseBackInput.externalMouse(
|
||||
InputDevice.getDeviceIds().map { InputDevice.getDevice(it) })
|
||||
return lastExternalMouse != null
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,16 @@ class MouseBackInput(private val sendRight: (Boolean) -> Unit, private val mouse
|
||||
!device.supportsSource(InputDevice.SOURCE_TOUCHSCREEN)
|
||||
}
|
||||
|
||||
/** A controller's own mouse interface (8BitDo Ultimate Mobile) is not a mouse the user right-clicks with. */
|
||||
fun externalMouse(devices: List<InputDevice?>): InputDevice? {
|
||||
val controllers = devices.filterNotNull().filter { PadBridge.isFromController(it) }
|
||||
return devices.filterNotNull().firstOrNull { mouse ->
|
||||
isExternalMouse(mouse) && controllers.none {
|
||||
it.vendorId != 0 && it.vendorId == mouse.vendorId && it.productId == mouse.productId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val VIRTUAL_NAME = Regex("\\bvirtual\\b", RegexOption.IGNORE_CASE)
|
||||
|
||||
fun declaresVirtual(name: String?): Boolean = name != null && VIRTUAL_NAME.containsMatchIn(name)
|
||||
|
||||
@@ -195,4 +195,16 @@ class MouseBackInputTest {
|
||||
assertTrue(external.onKeyEvent(injected(KeyEvent.ACTION_DOWN), toGuest = true))
|
||||
assertEquals(listOf(true), presses)
|
||||
}
|
||||
|
||||
@Test fun aControllersOwnMouseInterfaceDoesNotCount() {
|
||||
fun usb(id: Int, name: String, sources: Int, product: Int) = InputDeviceBuilder.newBuilder().setId(id).setName(name)
|
||||
.setDescriptor("$name-$id").setExternal(true).setSources(sources).setVendorId(0x2dc8).setProductId(product).build()
|
||||
val padMouse = usb(26, "8BitDo Ultimate Mobile Gaming Controller", 0x20004, 0x301f)
|
||||
val pad = usb(28, "8BitDo Ultimate Mobile Gaming Controller", 0x1000511, 0x301f)
|
||||
val mouse = usb(30, "8BitDo Retro R8 Mouse", InputDevice.SOURCE_MOUSE, 0x5200)
|
||||
assertTrue(MouseBackInput.isExternalMouse(padMouse))
|
||||
assertNull(MouseBackInput.externalMouse(listOf(padMouse, pad, null)))
|
||||
assertSame(padMouse, MouseBackInput.externalMouse(listOf(padMouse)))
|
||||
assertSame(mouse, MouseBackInput.externalMouse(listOf(padMouse, pad, mouse)))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user