mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(input): release held mouse buttons and keys when the session loses focus (#2139)
* fix(input): release held mouse buttons and keys when the session loses focus A mouse button or key held in the guest stayed down when another window took focus or pointer capture ended before the release, because the release went to that window. A game that hides the cursor while a button is held, such as mouselook in World of Warcraft, then kept turning the camera with the cursor gone until the button was pressed again. Buttons sent to the guest are now tracked like keys, and every held button and key is released when the session window loses focus or pointer capture, and when picture-in-picture opens. * fix(input): release a held button where it was pressed A button pressed through the compositor was released through the raw mouse channel if that channel turned on while it was held, and the reverse, so the guest kept it down. Each held button now remembers where it was pressed. A scroll-touch drag is also cancelled when the session loses focus. * fix(input): release trackpad buttons on focus loss --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
1 parent
ecedf131e0
commit
b875b39905
1 file changed
+26
-7
@@ -164,6 +164,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private var unfoldedPanel: com.droiddeck.launcher.ui.DeckControlsPanel? = null
|
||||
private lateinit var sessionRoot: FrameLayout
|
||||
private val guestKeysDown = mutableSetOf<Int>()
|
||||
private val guestButtonsDown = mutableMapOf<Int, Boolean>()
|
||||
private val trackpadButtonsDown = mutableSetOf<Int>()
|
||||
private lateinit var surfaceView: SurfaceView
|
||||
private lateinit var sessionOverlay: ComposeView
|
||||
private lateinit var loading: LoadingState
|
||||
@@ -669,7 +671,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
override fun dispatchPointerCaptureChanged(hasCapture: Boolean) {
|
||||
super.dispatchPointerCaptureChanged(hasCapture)
|
||||
Log.i(TAG, "pointer capture " + if (hasCapture) "on" else "off")
|
||||
if (!hasCapture) uiHandler.postDelayed(::updatePointerCapture, 250)
|
||||
if (!hasCapture) {
|
||||
releaseHeldGuestInput()
|
||||
uiHandler.postDelayed(::updatePointerCapture, 250)
|
||||
}
|
||||
}
|
||||
}
|
||||
sessionRoot = root
|
||||
@@ -3321,9 +3326,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private fun secondScreenPresentation(target: Display) = SecondScreenPresentation(
|
||||
this, target,
|
||||
sendPointer = ::moveSecondScreenPointer,
|
||||
sendButton = { button, pressed ->
|
||||
WaylandCompositor.nativeSendSceneInput(3, button, if (pressed) 1 else 0)
|
||||
},
|
||||
sendButton = ::sendTrackpadButton,
|
||||
sendWheel = { steps -> WaylandCompositor.nativeSendSceneInput(4, steps, 0) },
|
||||
onSteamMenu = ::tapSteamButton,
|
||||
onQam = ::tapQam,
|
||||
@@ -3657,11 +3660,18 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
|
||||
private fun sendSceneButton(code: Int, down: Boolean) {
|
||||
val writer = if (evdevMouseActive) mouseWriter else null
|
||||
val raw = if (down) evdevMouseActive.also { guestButtonsDown[code] = it }
|
||||
else guestButtonsDown.remove(code) ?: evdevMouseActive
|
||||
val writer = if (raw) mouseWriter else null
|
||||
if (writer != null) writer.writeMouseButton(code.toShort(), down)
|
||||
else WaylandCompositor.nativeSendSceneInput(3, code, if (down) 1 else 0)
|
||||
}
|
||||
|
||||
private fun sendTrackpadButton(button: Int, pressed: Boolean) {
|
||||
if (pressed) trackpadButtonsDown.add(button) else trackpadButtonsDown.remove(button)
|
||||
WaylandCompositor.nativeSendSceneInput(3, button, if (pressed) 1 else 0)
|
||||
}
|
||||
|
||||
private fun sendSceneWheel(steps: Int) {
|
||||
val writer = if (evdevMouseActive) mouseWriter else null
|
||||
if (writer != null) writer.writeMouseWheel(-steps, 0, 120)
|
||||
@@ -4166,6 +4176,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private fun keyboardCoversPad() =
|
||||
SessionState.mode == SessionService.MODE_STEAM && AgentGuest.steamKeyboard
|
||||
|
||||
private fun releaseHeldGuestInput() {
|
||||
guestButtonsDown.keys.toList().forEach { sendSceneButton(it, false) }
|
||||
trackpadButtonsDown.toList().forEach { WaylandCompositor.nativeSendSceneInput(3, it, 0) }
|
||||
trackpadButtonsDown.clear()
|
||||
guestKeysDown.toList().forEach { sendGuestKey(it, false) }
|
||||
}
|
||||
|
||||
private fun sendGuestKey(key: Int, down: Boolean) {
|
||||
if (down && pipUi) return
|
||||
val code = if (key == KEY_RIGHTCTRL && SessionState.mode == SessionService.MODE_DESKTOP) KEY_LEFTCTRL else key
|
||||
@@ -4251,7 +4268,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
scrollTouch.cancel()
|
||||
directTouchHold.cancel()
|
||||
twoFingerGestures.cancel()
|
||||
guestKeysDown.toList().forEach { sendGuestKey(it, false) }
|
||||
releaseHeldGuestInput()
|
||||
keyboard?.hide()
|
||||
sessionClipboard.stop()
|
||||
padMotion?.stop()
|
||||
@@ -4822,7 +4839,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
androidx.compose.ui.viewinterop.AndroidView(
|
||||
factory = { context ->
|
||||
com.droiddeck.launcher.ui.SessionTrackpadView(context, ::moveSecondScreenPointer,
|
||||
{ button, pressed -> WaylandCompositor.nativeSendSceneInput(3, button, if (pressed) 1 else 0) },
|
||||
::sendTrackpadButton,
|
||||
{ steps -> WaylandCompositor.nativeSendSceneInput(4, steps, 0) })
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth().weight(1f),
|
||||
@@ -4987,6 +5004,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (!hasFocus) {
|
||||
if (::touchscreenGestures.isInitialized) touchscreenGestures.cancel()
|
||||
if (::touchpad.isInitialized) touchpad.cancel()
|
||||
if (::scrollTouch.isInitialized) scrollTouch.cancel()
|
||||
releaseHeldGuestInput()
|
||||
}
|
||||
if (hasFocus && !pipUi) {
|
||||
goFullscreen()
|
||||
|
||||
Reference in new issue
Block a user