fix(input): keep kit bindings, D-pad directions and Steam touch tint through the redesign

This commit is contained in:
Kurt Himebauch committed 2026-11-18 20:02:37 -05:00
1 parent 695ae21f93
commit 6f564caba6
13 files changed
+118 -22

No files matched your search

@@ -130,9 +130,9 @@ object InputLibraries {
InputStockLayouts.layouts().firstOrNull { it.id == origin }?.let { return it.elements to it.aspect }
if (origin == OVERLAY) {
val (surfaceContext, metrics) = primaryDisplay(context)
val w = maxOf(metrics.widthPixels, metrics.heightPixels).coerceAtLeast(1)
val h = minOf(metrics.widthPixels, metrics.heightPixels).coerceAtLeast(1)
return KitLayout.elements(surfaceContext, PadKit.current(context), w, h) to w.toFloat() / h
val w = metrics.widthPixels.coerceAtLeast(1)
val h = metrics.heightPixels.coerceAtLeast(1)
return KitLayout.elements(surfaceContext, PadKit.current(context), w, h, scale = layout.scale) to w.toFloat() / h
}
return library.layouts.firstOrNull { it.id == origin && it.id != layout.id }?.let { it.elements to it.aspect }
}
@@ -147,10 +147,9 @@ object InputLibraries {
private fun upgradeOverlay(context: Context, library: InputLibrary): InputLibrary {
if (library.layouts.none { it.template == InputLayoutTemplate.OVERLAY }) return library
val settings = ControllerPrefs.read(context)
val elements = emptyList<InputSurfaceElement>()
val style = InputSurfaceStyle(opacity = settings.opacity)
val replacements = library.layouts.filter { it.template == InputLayoutTemplate.OVERLAY }.associate { old ->
old.id to old.copy(name = "Gamepad", elements = elements, template = InputLayoutTemplate.CUSTOM, style = style)
old.id to old.copy(name = "Gamepad", elements = emptyList(), template = InputLayoutTemplate.CUSTOM, style = style)
}
var result = library.copy(layouts = library.layouts.map { replacements[it.id] ?: it })
val migrated = mutableMapOf<Pair<String, String>, String>()
@@ -161,9 +160,8 @@ object InputLibraries {
val id = migrated.getOrPut(key) {
val old = library.preset(part.bindings)
val newId = migrationBindingId(result, old.id, layout.id)
val keyboard = elements.filter { it.id == "builtin:keyboard" }.associate { it.id to InputAction.Command(InputCommand.KEYBOARD) }
val clicks = if (settings.stickClick) old.clicks else old.clicks + elements.filter { it.hasClick }.associate { it.id to InputAction.Disabled }
result = result.withPreset(old.copy(id = newId, layoutId = layout.id, elements = old.elements + keyboard, clicks = clicks))
val clicks = if (settings.stickClick) old.clicks else old.clicks + KitLayout.clickIds.associateWith { InputAction.Disabled }
result = result.withPreset(old.copy(id = newId, layoutId = layout.id, clicks = clicks))
newId
}
part.copy(bindings = id)
@@ -271,8 +271,8 @@ data class InputLibrary(
require(preset.physical || preset.keys.isEmpty())
val layout = preset.layoutId?.let { id -> layouts.first { it.id == id } }
require(!preset.physical || layout == null && preset.elements.isEmpty() && preset.clicks.isEmpty())
require(preset.elements.all { (id, action) -> layout?.elements?.firstOrNull { it.id == id }?.let { action.validFor(it) } == true })
require(preset.clicks.all { (id, action) -> layout?.elements?.any { it.id == id && it.hasClick } == true && action.validForClick() })
require(preset.elements.all { (id, action) -> layout?.element(id)?.let { action.validFor(it) } == true })
require(preset.clicks.all { (id, action) -> layout?.element(id)?.hasClick == true && action.validForClick() })
require(preset.keys.all { it.key.device.isNotBlank() && it.key.keyCode >= 0 && it.key.scanCode >= 0 &&
it.action.validFor(InputControl.A) && (it.action !is InputAction.Native || it.action.target == null) })
}
@@ -312,3 +312,7 @@ internal fun InputAction.validFor(element: InputSurfaceElement): Boolean = when
element.kind == InputElementKind.TRIGGER -> target == InputControl.LT || target == InputControl.RT
else -> target.dimensions == 1 && target != InputControl.LT && target != InputControl.RT
}
/** A saved element, or, in a gamepad that keeps no kit positions, the kit control that [id] names. */
internal fun SavedInputLayout.element(id: String): InputSurfaceElement? =
elements.firstOrNull { it.id == id } ?: KitLayout.element(id)?.takeIf { OnScreenLayout.generated(this) }
@@ -3,6 +3,9 @@ package com.droiddeck.launcher.input
class InputSurfaceSource(private val pad: PadBridge, private val role: InputRole, val element: InputSurfaceElement) {
private val router = pad.inputRouter
private val route = router?.channel(role, element.control, element = element)
/** The kit's D-pad keeps each direction's own binding, as the separate direction buttons it replaced did. */
private val arms = if (element.id == KitLayout.DPAD_ID && router != null)
listOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT).map { router.channel(role, it) } else emptyList()
private val deck = DeckControls.source(role, routed = true)
private val clickDeck = DeckControls.source(role, routed = true)
private val clickOwner = Any()
@@ -55,6 +58,14 @@ class InputSurfaceSource(private val pad: PadBridge, private val role: InputRole
fingerDown = down
if (latched) 1f else 0f
} else value
if (arms.isNotEmpty() && route?.action is InputAction.Native) {
val values = listOf(y < -.5f, x > .5f, y > .5f, x < -.5f).map { if (it) 1f else 0f }
val toPad = arms.mapIndexed { i, arm -> arm.update(values[i])?.takeIf { it.isPad }?.let { it to values[i] } }.filterNotNull()
if (toPad.isNotEmpty() || nativePad) writePad(this, null) { state -> state.clear(); for ((t, v) in toPad) state.add(t, v) }
nativePad = toPad.isNotEmpty()
InputTiming.end(timing)
return
}
val target = if (router == null) element.control else route?.update(x, y, touching)
val toPad = target?.isPad == true
val toDeck = target != null && !target.isPad
@@ -112,13 +123,13 @@ class InputSurfaceSource(private val pad: PadBridge, private val role: InputRole
closed = true
router?.removeSnapshot(snapshot)
releaseNative(); resetLatch()
route?.close(); clickRoute?.close(); gestureWheel?.close(); gestureRight?.close(); gestureMiddle?.close(); deck.close(); clickDeck.close()
route?.close(); arms.forEach { it.close() }; clickRoute?.close(); gestureWheel?.close(); gestureRight?.close(); gestureMiddle?.close(); deck.close(); clickDeck.close()
}
fun release() {
if (closed) return
releaseNative(); resetLatch()
route?.release(); clickRoute?.release(); gestureWheel?.release(); gestureRight?.release(); gestureMiddle?.release()
route?.release(); arms.forEach { it.release() }; clickRoute?.release(); gestureWheel?.release(); gestureRight?.release(); gestureMiddle?.release()
}
}
@@ -17,6 +17,18 @@ object KitLayout {
/** Whether [id] names one of a kit's own controls rather than a key or control the player added. */
fun isKit(id: String) = id.startsWith("legacy:") || id == DPAD_ID || id == KEYBOARD_ID
/** The control a kit id stands for in a layout that keeps no kit positions, so bindings saved for it stay valid. */
fun element(id: String): InputSurfaceElement? = when {
id == DPAD_ID -> InputSurfaceElement(InputControl.LS, 0f, 0f, .1f, .1f, id, InputElementKind.DPAD)
id == KEYBOARD_ID -> InputSurfaceElement(InputControl.A, 0f, 0f, .1f, .1f, id)
id.startsWith("legacy:") -> InputControl.entries.firstOrNull { "legacy:${it.id}" == id }
?.let { InputSurfaceElement(it, 0f, 0f, .1f, .1f, id, InputElementKind.from(it)) }
else -> null
}
/** Every kit control that has a click, across all virtual controllers. */
val clickIds = listOf(InputControl.LS, InputControl.RS, InputControl.LEFT_PAD, InputControl.RIGHT_PAD).map { "legacy:${it.id}" }
private const val REF_W = 1600f
private const val REF_H = 900f
/** The widest pair of side controls on any kit: a larger size never pushes the two halves, or the rows, into each other. */
@@ -241,7 +241,10 @@ class SteamTouchControls(
private fun cx(e: Element) = e.x * width
private fun cy(e: Element) = e.y * height
private fun reach(e: Element, x: Float, y: Float) = hypot((x - cx(e)) / radius(e), (y - cy(e)) / radiusY(e))
private fun reach(e: Element, x: Float, y: Float): Float {
val dx = (x - cx(e)) / radius(e); val dy = (y - cy(e)) / radiusY(e)
return if (e.type in TRACKPADS) max(abs(dx), abs(dy)) else hypot(dx, dy)
}
private fun hit(list: List<Element>, x: Float, y: Float): Element? =
list.filter { reach(it, x, y) <= 1.15f }.minByOrNull { reach(it, x, y) }
@@ -282,6 +285,8 @@ class SteamTouchControls(
val r = radius(e)
val pressed = !editing && e.type in pressedTypes()
val alpha = (255 * alphaScale * if (faded) FADED else 1f).toInt().coerceIn(30, 255)
stroke.color = Color.rgb(Color.red(tint), Color.green(tint), Color.blue(tint)); stroke.strokeWidth = lineWidth()
fill.color = Color.argb(217, 230, 233, 236)
if (alpha < 255) canvas.saveLayerAlpha(x - r * 1.5f, y - r * 1.5f, x + r * 1.5f, y + r * 1.5f, alpha)
when (e.type) {
SteamTouchConfig.DPAD -> if (visuals[SteamTouchConfig.DPAD].orEmpty().any { it.binding?.hasIcon == true }) drawDpad(canvas, e, x, y, r) else {
@@ -304,8 +309,8 @@ class SteamTouchControls(
}
SteamTouchConfig.TRACKPAD_LEFT, SteamTouchConfig.TRACKPAD_RIGHT, SteamTouchConfig.TRACKPAD_CENTER -> {
val f = fingers.values.firstOrNull { it.element?.type == e.type }.takeIf { !editing }
canvas.save(); canvas.translate(x - r * 1.3f, y - r * .85f)
art.trackpad(canvas, r * 2.6f, r * 1.7f, f != null, (f?.x ?: x) - x + r * 1.3f, (f?.y ?: y) - y + r * .85f)
canvas.save(); canvas.translate(x - r, y - r)
art.trackpad(canvas, r * 2f, r * 2f, f != null, (f?.x ?: x) - x + r, (f?.y ?: y) - y + r)
canvas.restore()
if (editing) art.text(canvas, context.getString(R.string.deck_surface_trackpad), x, y, r * .3f, Color.argb(128, 255, 255, 255))
}
@@ -354,7 +359,7 @@ class SteamTouchControls(
val icon = binding?.icon?.takeIf { it.isNotEmpty() }?.let(::iconOrLoad)
val custom = binding != null && binding.background.isNotEmpty() && !binding.background.equals(SteamTouchBindings.DEFAULT_BACKGROUND, true)
art.glass(canvas, shape, pressed && !custom, if (custom) parseColor(binding!!.background, SteamTouchBindings.DEFAULT_BACKGROUND) else 0x850E1014.toInt())
val ink = if (pressed && !custom) com.droiddeck.launcher.ui.PadArt.ON_ACCENT else com.droiddeck.launcher.ui.PadArt.INK
val ink = if (pressed && !custom) com.droiddeck.launcher.ui.PadArt.ON_ACCENT else if (tint != Color.WHITE) tint else com.droiddeck.launcher.ui.PadArt.INK
if (icon != null) {
val s = r * 0.62f
if (custom) canvas.drawBitmap(tinted(binding!!.icon, icon, binding.foreground), null, RectF(x - s, y - s, x + s, y + s), Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG))
@@ -1444,6 +1449,7 @@ class SteamTouchControls(
var onSaved: () -> Unit = {}
companion object {
private val TRACKPADS = setOf(SteamTouchConfig.TRACKPAD_LEFT, SteamTouchConfig.TRACKPAD_RIGHT, SteamTouchConfig.TRACKPAD_CENTER)
private const val TAG = "SteamTouch"
private const val POLL_MS = 150L
private const val MOVE_REDRAW_MS = 33L