From b875b39905c435040990845b1902bafdad25fdd1 Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Thu, 5 Nov 2026 18:26:38 -0500 Subject: [PATCH] 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> --- .../com/droiddeck/launcher/SessionActivity.kt | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 540c7ed986..f8e11d2891 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -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() + private val guestButtonsDown = mutableMapOf() + private val trackpadButtonsDown = mutableSetOf() 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()