fix(input): restore the neutral look of the bottom-screen controls (#2221)

This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-07 12:06:03 -05:00
1 parent d5f3d1a0d5
commit 6026d72435
38 files changed
+74 -10

No files matched your search

@@ -9,7 +9,7 @@ import org.json.JSONObject
import java.util.UUID
object InputLibraries {
private const val VERSION = 8
private const val VERSION = 9
private const val KEY = "library"
private const val RECOVERY = "library-recovery."
const val OVERLAY = "builtin.overlay"
@@ -27,6 +27,7 @@ object InputLibraries {
var library = decoded ?: scopeLayouts(upgradeStockLayouts(upgradeOverlay(context, migrate(context))))
val version = raw?.let { JSONObject(it).getInt("version") } ?: 0
if (version < 5) library = scopeLayouts(upgradeStockLayouts(upgradeOverlay(context, library)))
if (version < 9) library = neutralStockLayouts(library)
if (version < 6 || !p.contains(LegacyScreenKeyMigration.BACKUP)) {
val legacy = LegacyScreenKeyMigration.snapshot(context)
if (legacy != null) {
@@ -148,6 +149,11 @@ object InputLibraries {
return result.validate()
}
private fun neutralStockLayouts(library: InputLibrary): InputLibrary = library.copy(layouts = library.layouts.map { layout ->
if ((layout.id == DECK || layout.id == TRACKPAD) && layout.style.tint == ControllerPrefs.STEAM_BLUE) layout.copy(style = layout.style.copy(tint = null))
else layout
})
private fun upgradeStockLayouts(library: InputLibrary): InputLibrary {
val stock = InputStockLayouts.layouts()
val replacements = library.layouts.filter { it.template == InputLayoutTemplate.DECK || it.template == InputLayoutTemplate.TRACKPAD }
@@ -208,7 +214,7 @@ object InputLibraries {
.put("width", e.width.toDouble()).put("height", e.height.toDouble()).put("floating", e.floating).put("hideWhenIdle", e.hideWhenIdle).put("mouseGestures", e.mouseGestures).put("toggle", e.toggle).put("icon", e.icon).put("image", e.image)
.put("elementOpacity", e.opacity.toDouble()).put("buttonShape", e.buttonShape.name).put("showLabel", e.showLabel))
layouts.put(JSONObject().put("id", layout.id).put("name", layout.name).put("template", layout.template.name).put("elements", elements)
.put("tint", layout.style.tint).put("opacity", layout.style.opacity).put("screen", layout.screen.name))
.put("tint", layout.style.tint ?: JSONObject.NULL).put("opacity", layout.style.opacity).put("screen", layout.screen.name))
}
val bindings = JSONArray()
for (b in library.bindings) {
@@ -249,7 +255,7 @@ object InputLibraries {
e.optDouble("elementOpacity", 1.0).toFloat(), InputButtonShape.valueOf(e.optString("buttonShape", InputButtonShape.ROUNDED.name)), e.optBoolean("showLabel", true))
}
SavedInputLayout(layout.getString("id"), layout.getString("name"), elements, InputLayoutTemplate.valueOf(layout.getString("template")),
InputSurfaceStyle(layout.optInt("tint", ControllerPrefs.STEAM_BLUE), layout.optInt("opacity", 100)),
InputSurfaceStyle(if (!layout.has("tint")) ControllerPrefs.STEAM_BLUE else if (layout.isNull("tint")) null else layout.getInt("tint"), layout.optInt("opacity", 100)),
InputLayoutScreen.valueOf(layout.optString("screen", InputLayoutScreen.BOTH.name)))
}
val bindings = doc.getJSONArray("bindings").objects(512).map { b ->
@@ -9,7 +9,7 @@ enum class InputLayoutScreen { MAIN, SECONDARY, BOTH;
if (role == InputRole.PRIMARY) this == MAIN else this == SECONDARY)
}
data class InputSurfaceStyle(val tint: Int = ControllerPrefs.STEAM_BLUE, val opacity: Int = 100)
data class InputSurfaceStyle(val tint: Int? = ControllerPrefs.STEAM_BLUE, val opacity: Int = 100)
data class SavedInputLayout(
val id: String, val name: String, val elements: List<InputSurfaceElement> = emptyList(),
@@ -1,6 +1,7 @@
package com.droiddeck.launcher.input
internal object InputStockLayouts {
private val NEUTRAL = InputSurfaceStyle(tint = null)
const val DECK = "preset.deck"
const val TRACKPAD = "preset.trackpad"
private fun commands(indices: List<Int>): List<InputSurfaceElement> {
@@ -20,9 +21,9 @@ internal object InputStockLayouts {
private fun pads() = listOf(InputSurfaceElement(InputControl.LEFT_PAD, .02f, .14f, .47f, .62f),
InputSurfaceElement(InputControl.RIGHT_PAD, .51f, .14f, .47f, .62f))
fun layouts() = listOf(
SavedInputLayout(InputLibraries.DECK, "Deck grips + trackpads", commands(listOf(2, 3, 0)) + pads() + grips(), screen = InputLayoutScreen.SECONDARY),
SavedInputLayout(InputLibraries.DECK, "Deck grips + trackpads", commands(listOf(2, 3, 0)) + pads() + grips(), style = NEUTRAL, screen = InputLayoutScreen.SECONDARY),
SavedInputLayout(InputLibraries.TRACKPAD, "Trackpad + keyboard", commands(listOf(0, 1)) +
InputSurfaceElement(InputControl.RIGHT_PAD, .02f, .14f, .96f, .84f, mouseGestures = true), screen = InputLayoutScreen.SECONDARY),
InputSurfaceElement(InputControl.RIGHT_PAD, .02f, .14f, .96f, .84f, mouseGestures = true), style = NEUTRAL, screen = InputLayoutScreen.SECONDARY),
)
fun actions(layout: SavedInputLayout): Map<String, InputAction> = (commandActions() + if (layout.id == InputLibraries.TRACKPAD) mapOf(
@@ -65,18 +65,19 @@ internal class InputLayoutPreviewView(context: Context) : View(context) {
}
@Composable
internal fun InputColorRow(host: MenuHost, value: Int, onPick: (Int) -> Unit) {
internal fun InputColorRow(host: MenuHost, value: Int?, onPick: (Int?) -> Unit) {
val open = host.open == "layout-color"
val tints = listOf<Pair<Int?, Int>>(null to R.string.ctrl_tint_gray) + ControllerPrefs.tints
SettingsRow(stringResource(R.string.ctrl_color), null, highlighted = open) {
Box {
ValueChip(ControllerPrefs.tints.firstOrNull { it.first == value }?.second?.let { stringResource(it) }
ValueChip(tints.firstOrNull { it.first == value }?.second?.let { stringResource(it) }
?: stringResource(R.string.ctrl_custom), open, modifier = Modifier.testTag("setting-layout-color")) {
host.open = if (open) null else "layout-color"
}
AnchoredMenu(open, onDismiss = { if (host.open == "layout-color") host.open = null }, title = stringResource(R.string.ctrl_color)) { firstItemFocus ->
ControllerPrefs.tints.forEachIndexed { index, (color, name) ->
tints.forEachIndexed { index, (color, name) ->
MenuItem(stringResource(name), checked = value == color, leading = {
Box(Modifier.size(14.dp).background(Color(color), CircleShape).border(1.dp, Color.White.copy(alpha = .35f), CircleShape))
Box(Modifier.size(14.dp).background(Color(color ?: GRAY_SWATCH), CircleShape).border(1.dp, Color.White.copy(alpha = .35f), CircleShape))
}, focusRequester = if (index == 0) firstItemFocus else null) {
onPick(color)
host.open = null
@@ -86,3 +87,5 @@ internal fun InputColorRow(host: MenuHost, value: Int, onPick: (Int) -> Unit) {
}
}
}
private const val GRAY_SWATCH = 0xFF26292E.toInt()