mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 22:05:59 +00:00
fix(input): system Back only turns into a right-click with an external mouse (#2323)
* fix(input): injected Back is a right-click only while an external mouse is attached * input: order imports * fix(input): reject built-in devices for injected Back * fix(input): log matched mouse for injected Back * fix(input): ignore mice that name themselves virtual for injected Back
This commit is contained in:
1 parent
40242fa082
commit
9bf638a3c4
3 files changed
+85
-3
No files matched your search
@@ -391,8 +391,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
)
|
||||
private val mouseBackInput = com.droiddeck.launcher.input.MouseBackInput(
|
||||
sendRight = { down -> heldButtons.set(32, PointerGestures.BTN_RIGHT, down) },
|
||||
mouseAttached = ::mouseAttached,
|
||||
mouseAttached = ::externalMouseAttached,
|
||||
)
|
||||
private var lastExternalMouse: InputDevice? = null
|
||||
private var drawerDirectionKey = KeyEvent.KEYCODE_UNKNOWN
|
||||
private var drawerDirectionDownTime = 0L
|
||||
private var drawerDirectionDeviceId = -1
|
||||
@@ -2683,7 +2684,22 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
val mouseToGuest = !pipUi && !appTextFocus && !drawerOpen && !pcKeyboardOpen && !achievementsOpen && !gestureSettingsOpen && !inputSettingsOpen &&
|
||||
!SessionState.suspended && !(::loading.isInitialized && (loading.visible || loading.ended))
|
||||
if (mouseBackInput.onKeyEvent(event, mouseToGuest)) return true
|
||||
if (event.keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0 &&
|
||||
com.droiddeck.launcher.input.MouseBackInput.isInjectedBack(event)) lastExternalMouse = null
|
||||
val mouseBackHandled = mouseBackInput.onKeyEvent(event, mouseToGuest)
|
||||
if (event.keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0 &&
|
||||
com.droiddeck.launcher.input.MouseBackInput.isInjectedBack(event) && mouseToGuest) {
|
||||
val device = lastExternalMouse
|
||||
if (mouseBackHandled && device != null) {
|
||||
Log.i(TAG, String.format(java.util.Locale.ROOT,
|
||||
"injected Back right-click mouse=\"%s\" (%04x:%04x, id %d, sources 0x%x, external=%s, virtual=%s)",
|
||||
device.name, device.vendorId, device.productId, device.id, device.sources,
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || device.isExternal, device.isVirtual))
|
||||
} else if (!mouseBackHandled) {
|
||||
Log.i(TAG, "injected Back no external mouse found")
|
||||
}
|
||||
}
|
||||
if (mouseBackHandled) return true
|
||||
val backToQam = !pipUi && !appTextFocus && !drawerOpen && !pcKeyboardOpen && !achievementsOpen &&
|
||||
!inputSettingsOpen && !gestureSettingsOpen &&
|
||||
SessionState.mode == SessionService.MODE_STEAM && SessionState.running && SessionState.firstFrameSeen &&
|
||||
@@ -4163,6 +4179,12 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
isHardwareMouse(d) && d?.supportsSource(InputDevice.SOURCE_TOUCHPAD) != true
|
||||
}
|
||||
|
||||
private fun externalMouseAttached(): Boolean {
|
||||
lastExternalMouse = InputDevice.getDeviceIds().map { InputDevice.getDevice(it) }
|
||||
.firstOrNull { device -> device != null && com.droiddeck.launcher.input.MouseBackInput.isExternalMouse(device) }
|
||||
return lastExternalMouse != null
|
||||
}
|
||||
|
||||
private fun relativeMouseAttached(): Boolean = !isInMultiWindowMode && !glassesOutputActive && InputDevice.getDeviceIds().any { id ->
|
||||
val d = InputDevice.getDevice(id)
|
||||
isHardwareMouse(d) && d?.supportsSource(InputDevice.SOURCE_TOUCHPAD) != true
|
||||
|
||||
Reference in new issue
Block a user