From a2a7adc83db6b315f3b2de6b9e3928bacb3b7154 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Wed, 11 Nov 2026 19:09:49 +0000 Subject: [PATCH] fix(input): compare saved desktop profiles to their base and keep two-finger scroll with tap suppression --- .../com/droiddeck/launcher/SessionActivity.kt | 12 +++++++++-- .../droiddeck/launcher/input/InputLibrary.kt | 20 ++++++++++--------- .../droiddeck/launcher/input/InputProfile.kt | 5 +++-- .../input/InputProfileMouseButtonTest.kt | 6 ++++++ 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index b2dad1721d..a5bcb0163c 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -804,7 +804,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { scrollRestY = 0f } override fun replay(event: MotionEvent) { - drawnRect()?.let { forwardTouch(event, it) } + if (directTouchMovesOnly) moveDirectPointer(event.x, event.y) + else drawnRect()?.let { forwardTouch(event, it) } } override fun rightClick(x: Float, y: Float) { pointerListener.onLongPress() @@ -4109,6 +4110,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private var directTouchMovesOnly = false + private fun moveDirectPointer(x: Float, y: Float) { + if (pointerLocked) gestureOutput.moveTo(x, y) else movePointer(x, y) + } + private fun dispatchDirectTouch(event: MotionEvent): Boolean { val rect = drawnRect() ?: return false if (event.actionMasked == MotionEvent.ACTION_DOWN) @@ -4124,13 +4129,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { if (event.actionMasked == MotionEvent.ACTION_DOWN) { directTouchMovesOnly = !programLocksPointer() && onScreenMouseButtonShown() if (directTouchMovesOnly) { + gesturePointerReady = false directTouchHold.cancel() WaylandCompositor.nativeSendTouch(3, -1, 0, 0) } } if (directTouchMovesOnly) { + val handled = SessionState.mode == SessionService.MODE_DESKTOP && twoFingerGestures.onTouch(event) + if (!handled && event.actionMasked != MotionEvent.ACTION_UP && event.actionMasked != MotionEvent.ACTION_CANCEL) + moveDirectPointer(event.x, event.y) if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) directTouchMovesOnly = false - else movePointer(event.x, event.y) return true } if (SessionState.mode == SessionService.MODE_DESKTOP && twoFingerGestures.onTouch(event)) return true diff --git a/app/src/main/java/com/droiddeck/launcher/input/InputLibrary.kt b/app/src/main/java/com/droiddeck/launcher/input/InputLibrary.kt index cc6313dc30..82f0995e7a 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/InputLibrary.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/InputLibrary.kt @@ -94,9 +94,11 @@ data class InputLibrary( fun panelPart(isDesktop: Boolean, panel: String?): InputPart = panel?.let { id -> bindings.firstOrNull { it.id == id } }?.let { InputPart(it.id, it.layoutId) } ?: activePart(isDesktop, InputRole.SECONDARY) fun panelLayout(isDesktop: Boolean, panel: String?) = panelPart(isDesktop, panel).layout?.let { id -> layouts.firstOrNull { it.id == id } } - fun compileActive(isDesktop: Boolean, panel: String? = null): InputProfile = compileParts(activeId(isDesktop), InputRole.entries.associateWith { - preset(if (it == InputRole.SECONDARY) panelPart(isDesktop, panel).bindings else activePart(isDesktop, it).bindings) - }) + fun compileActive(isDesktop: Boolean, panel: String? = null): InputProfile = activeId(isDesktop).let { id -> + compileParts(id, InputRole.entries.associateWith { + preset(if (it == InputRole.SECONDARY) panelPart(isDesktop, panel).bindings else activePart(isDesktop, it).bindings) + }, profile(id).base) + } fun saveSelection(isDesktop: Boolean, name: String, id: String = newInputId()): InputLibrary { val current = profile(activeId(isDesktop)) @@ -109,14 +111,14 @@ data class InputLibrary( fun compile(id: String): InputProfile { val profile = profile(id) val parts = InputRole.entries.associateWith { preset(profile.binding(it)) } - return compileParts(id, parts) + return compileParts(id, parts, profile.base) } - private fun compileParts(id: String, parts: Map): InputProfile { - return InputProfile(id, parts.mapValues { it.value.controls }.filterValues { it.isNotEmpty() }, - parts.getValue(InputRole.PHYSICAL).keys, - parts.mapValues { it.value.elements }.filterValues { it.isNotEmpty() }, - parts.mapValues { it.value.clicks }.filterValues { it.isNotEmpty() }) + private fun compileParts(id: String, parts: Map, base: String): InputProfile { + return InputProfile(id, base = base, bindings = parts.mapValues { it.value.controls }.filterValues { it.isNotEmpty() }, + keys = parts.getValue(InputRole.PHYSICAL).keys, + elements = parts.mapValues { it.value.elements }.filterValues { it.isNotEmpty() }, + clicks = parts.mapValues { it.value.clicks }.filterValues { it.isNotEmpty() }) } fun usersOfBindings(id: String) = profiles.filter { p -> p.parts.values.any { it.bindings == id } } diff --git a/app/src/main/java/com/droiddeck/launcher/input/InputProfile.kt b/app/src/main/java/com/droiddeck/launcher/input/InputProfile.kt index 3a1c80d2ec..ba2f956946 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/InputProfile.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/InputProfile.kt @@ -36,6 +36,7 @@ sealed interface InputAction { data class InputProfile( val id: String, + val base: String = id, val bindings: Map> = emptyMap(), val keys: List = emptyList(), val elements: Map> = emptyMap(), @@ -51,7 +52,7 @@ data class InputProfile( elements[role]?.get(id) ?: if (id == "legacy:${control.id}") action(role, control) else InputAction.Disabled fun hasMouseButton(role: InputRole, elements: List): Boolean { - val stock = defaults(id) + val stock = defaults(base) return elements.any { val action = elementAction(role, it.id, it.control) (it.kind == InputElementKind.BUTTON || it.kind == InputElementKind.TRIGGER) && action is InputAction.MouseButton && @@ -81,7 +82,7 @@ data class InputProfile( InputControl.LEFT_PAD to InputAction.Scroll(), InputControl.RIGHT_PAD to InputAction.Pointer(), InputControl.LEFT_CLICK to InputAction.MouseButton(273), InputControl.RIGHT_CLICK to InputAction.MouseButton(272), ) - return InputProfile(DESKTOP, InputRole.entries.associateWith { desktop }) + return InputProfile(DESKTOP, bindings = InputRole.entries.associateWith { desktop }) } } } diff --git a/app/src/test/java/com/droiddeck/launcher/input/InputProfileMouseButtonTest.kt b/app/src/test/java/com/droiddeck/launcher/input/InputProfileMouseButtonTest.kt index 98adefe3c0..1f2a53ea84 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/InputProfileMouseButtonTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/InputProfileMouseButtonTest.kt @@ -41,4 +41,10 @@ class InputProfileMouseButtonTest { assertTrue(bound.hasMouseButton(InputRole.PRIMARY, listOf(custom))) assertFalse(bound.hasMouseButton(InputRole.SECONDARY, listOf(custom))) } + + @Test fun savedDesktopProfileComparesAgainstItsDesktopBase() { + val saved = InputProfile.defaults(InputProfile.DESKTOP).copy(id = "saved:1", base = InputProfile.DESKTOP) + assertFalse(saved.hasMouseButton(InputRole.PRIMARY, listOf(a, trigger))) + assertTrue(saved.withBinding(InputRole.PRIMARY, InputControl.A, InputAction.MouseButton(274)).hasMouseButton(InputRole.PRIMARY, listOf(a))) + } }