fix(input): compare saved desktop profiles to their base and keep two-finger scroll with tap suppression

This commit is contained in:
Kurt Himebauch committed 2026-11-11 19:09:49 +00:00
1 parent f6e109ef61
commit a2a7adc83d
4 files changed
+30 -13

No files matched your search

@@ -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
@@ -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<InputRole, SavedInputBindings>): 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<InputRole, SavedInputBindings>, 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 } }
@@ -36,6 +36,7 @@ sealed interface InputAction {
data class InputProfile(
val id: String,
val base: String = id,
val bindings: Map<InputRole, Map<InputControl, InputAction>> = emptyMap(),
val keys: List<PhysicalInputBinding> = emptyList(),
val elements: Map<InputRole, Map<String, InputAction>> = 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<InputSurfaceElement>): 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 })
}
}
}