From 38a84a8e8f48142ba5e17f02528651176f120692 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Thu, 8 Oct 2026 09:20:07 -0400 Subject: [PATCH] feat: Steam touch icon picker as in-session panels; layout colour; docs --- .../launcher/input/SteamTouchBindings.kt | 2 +- .../launcher/input/SteamTouchControls.kt | 50 ++++++-- .../launcher/input/SteamTouchIconPicker.kt | 121 ++++++++++++++---- docs/development/steam-touch-controls.md | 20 +++ 4 files changed, 156 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/input/SteamTouchBindings.kt b/app/src/main/java/com/droiddeck/launcher/input/SteamTouchBindings.kt index 131e29cbfe..f5f46d88ce 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/SteamTouchBindings.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/SteamTouchBindings.kt @@ -234,7 +234,7 @@ object SteamTouchBindings { // ---- Icons ---- - private val cache = object : LruCache(8 * 1024 * 1024) { + private val cache = object : LruCache(24 * 1024 * 1024) { override fun sizeOf(key: String, value: Bitmap) = value.byteCount } private val missing = HashSet() diff --git a/app/src/main/java/com/droiddeck/launcher/input/SteamTouchControls.kt b/app/src/main/java/com/droiddeck/launcher/input/SteamTouchControls.kt index 04abe51f27..e67c6f0fbd 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/SteamTouchControls.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/SteamTouchControls.kt @@ -249,7 +249,7 @@ class SteamTouchControls( */ private fun drawFace(canvas: Canvas, type: Int, binding: SteamTouchBindings.Binding?, x: Float, y: Float, r: Float, baseAlpha: Int, pressed: Boolean) { - val icon = binding?.icon?.takeIf { it.isNotEmpty() }?.let { SteamTouchBindings.cachedIcon(appId, it, ICON_PX) } + val icon = binding?.icon?.takeIf { it.isNotEmpty() }?.let(::iconOrLoad) if (icon != null) { val alpha = min(255, baseAlpha + if (pressed) 150 else 90) val disc = Paint(Paint.ANTI_ALIAS_FLAG).apply { @@ -258,8 +258,7 @@ class SteamTouchControls( } canvas.drawCircle(x, y, r, disc) val s = r * 0.62f - SteamTouchIconPicker.drawSteamIcon(canvas, icon, RectF(x - s, y - s, x + s, y + s), - parseColor(binding.foreground, SteamTouchBindings.DEFAULT_FOREGROUND), + 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).apply { this.alpha = alpha }) canvas.drawCircle(x, y, r, stroke) return @@ -278,6 +277,35 @@ class SteamTouchControls( canvas.drawText(line, x, y - (text.descent() + text.ascent()) / 2, text) } + private val iconsLoading = HashSet() + + // Icons already in their foreground colour. Drawn plain: a colour filter on the icon bitmap + // itself stopped drawing on the hardware canvas once a dialog had been over the view. + private val tintedIcons = android.util.LruCache(48) + + private fun tinted(name: String, icon: android.graphics.Bitmap, foreground: String): android.graphics.Bitmap { + val key = "$name|$foreground|${icon.width}" + tintedIcons.get(key)?.let { return it } + val out = android.graphics.Bitmap.createBitmap(icon.width, icon.height, android.graphics.Bitmap.Config.ARGB_8888) + SteamTouchIconPicker.drawSteamIcon(Canvas(out), icon, RectF(0f, 0f, icon.width.toFloat(), icon.height.toFloat()), + parseColor(foreground, SteamTouchBindings.DEFAULT_FOREGROUND), Paint(Paint.FILTER_BITMAP_FLAG)) + tintedIcons.put(key, out) + return out + } + + /** An icon from the cache, or null while it is (re)loaded; the view redraws when it comes in. */ + private fun iconOrLoad(name: String): android.graphics.Bitmap? { + SteamTouchBindings.cachedIcon(appId, name, ICON_PX)?.let { return it } + if (iconsLoading.add(name)) { + val app = appId + loader.execute { + SteamTouchBindings.icon(context, app, name, ICON_PX) + handler.post { iconsLoading.remove(name); invalidate() } + } + } + return null + } + private fun parseColor(hex: String, fallback: String) = try { Color.parseColor(hex.ifEmpty { fallback }) } catch (_: IllegalArgumentException) { Color.parseColor(fallback) } @@ -299,7 +327,7 @@ class SteamTouchControls( if (dirs and bit != 0L) fill.color = Color.argb(200, 20, 24, 30) if (isSelected && armIndex == selectedArm) stroke.color = Color.rgb(255, 200, 60) val binding = armVisuals.getOrNull(armIndex)?.binding - val icon = binding?.icon?.takeIf { it.isNotEmpty() }?.let { SteamTouchBindings.cachedIcon(appId, it, ICON_PX) } + val icon = binding?.icon?.takeIf { it.isNotEmpty() }?.let(::iconOrLoad) if (icon != null) { val disc = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = parseColor(binding.background, SteamTouchBindings.DEFAULT_BACKGROUND) @@ -307,8 +335,8 @@ class SteamTouchControls( } canvas.drawRoundRect(rect, arm * 0.4f, arm * 0.4f, disc) val s = min(rect.width(), rect.height()) * 0.42f - SteamTouchIconPicker.drawSteamIcon(canvas, icon, RectF(rect.centerX() - s, rect.centerY() - s, rect.centerX() + s, rect.centerY() + s), - parseColor(binding.foreground, SteamTouchBindings.DEFAULT_FOREGROUND), + canvas.drawBitmap(tinted(binding.icon, icon, binding.foreground), null, + RectF(rect.centerX() - s, rect.centerY() - s, rect.centerX() + s, rect.centerY() + s), Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG).apply { alpha = disc.alpha }) canvas.drawRoundRect(rect, arm * 0.4f, arm * 0.4f, stroke) fill.color = old @@ -604,7 +632,8 @@ class SteamTouchControls( return } val name = if (e.type == SteamTouchConfig.DPAD) "D-pad " + listOf("up", "down", "left", "right")[selectedArm] else label(e.type) - SteamTouchIconPicker(context, appId, "Icon for $name", binding) { picked -> + val host = parent as? android.view.ViewGroup ?: return + SteamTouchIconPicker(context, host, appId, "Icon for $name", binding) { picked -> pendingBindings[ref] = picked rebuildVisuals() invalidate() @@ -647,11 +676,8 @@ class SteamTouchControls( }) } root.addView(android.widget.HorizontalScrollView(context).apply { addView(opacityRow) }) - android.app.AlertDialog.Builder(context, android.R.style.Theme_DeviceDefault_Dialog_Alert) - .setTitle("Touch layout colour") - .setView(root) - .setPositiveButton(android.R.string.ok, null) - .show() + val host = parent as? android.view.ViewGroup ?: return + SteamTouchIconPicker.showPanel(host, "Touch layout colour", root, listOf("Done" to {})) } private fun save() { diff --git a/app/src/main/java/com/droiddeck/launcher/input/SteamTouchIconPicker.kt b/app/src/main/java/com/droiddeck/launcher/input/SteamTouchIconPicker.kt index 353ede0cde..ef5032b00b 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/SteamTouchIconPicker.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/SteamTouchIconPicker.kt @@ -1,6 +1,5 @@ package com.droiddeck.launcher.input -import android.app.AlertDialog import android.content.Context import android.graphics.Bitmap import android.graphics.Canvas @@ -31,6 +30,7 @@ import java.util.concurrent.Executors */ class SteamTouchIconPicker( private val context: Context, + private val host: ViewGroup, private val appId: Int, private val title: String, private val current: SteamTouchBindings.Binding, @@ -46,14 +46,16 @@ class SteamTouchIconPicker( private fun dp(v: Int) = (v * density).toInt() fun show() { - val root = LinearLayout(context).apply { orientation = LinearLayout.VERTICAL; setPadding(dp(16), dp(8), dp(16), 0) } + // Side by side, for a landscape screen: what is picked on the left, the icons on the right. + val root = LinearLayout(context).apply { orientation = LinearLayout.HORIZONTAL; setPadding(dp(16), dp(8), dp(16), 0) } + val left = LinearLayout(context).apply { orientation = LinearLayout.VERTICAL } val label = EditText(context).apply { hint = "Label (optional)" setText(current.label) inputType = InputType.TYPE_CLASS_TEXT setSingleLine() } - root.addView(label) + left.addView(label) val preview = ImageView(context) val names = SteamTouchBindings.iconNames(context, appId) val grid = GridView(context).apply { @@ -70,31 +72,30 @@ class SteamTouchIconPicker( adapter.notifyDataSetChanged() updatePreview(preview) } - root.addView(LinearLayout(context).apply { + left.addView(LinearLayout(context).apply { gravity = Gravity.CENTER_VERTICAL + setPadding(0, dp(8), 0, 0) addView(preview, LinearLayout.LayoutParams(dp(56), dp(56))) addView(TextView(context).apply { text = if (names.isEmpty()) "Steam's icons were not found" else "${names.size} icons from Steam" setPadding(dp(12), 0, 0, 0) }) }) - root.addView(grid, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp(220))) - root.addView(paletteRow("Icon colour", { foreground }) { foreground = it; adapter.notifyDataSetChanged(); updatePreview(preview) }) - root.addView(paletteRow("Button colour", { background }) { background = it; adapter.notifyDataSetChanged(); updatePreview(preview) }) + left.addView(paletteRow("Icon colour", { foreground }) { foreground = it; adapter.notifyDataSetChanged(); updatePreview(preview) }) + left.addView(paletteRow("Button colour", { background }) { background = it; adapter.notifyDataSetChanged(); updatePreview(preview) }) + root.addView(left, LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)) + root.addView(grid, LinearLayout.LayoutParams(0, dp(250), 1.2f).apply { marginStart = dp(16) }) updatePreview(preview) - AlertDialog.Builder(context, android.R.style.Theme_DeviceDefault_Dialog_Alert) - .setTitle(title) - .setView(root) - .setPositiveButton("Use") { _, _ -> + showPanel(host, title, root, listOf( + "No icon" to { + onPicked(current.copy(label = label.text.toString().replace(",", " ").trim(), icon = "", foreground = "", background = "")) + }, + "Cancel" to {}, + "Use" to { onPicked(current.copy(label = label.text.toString().replace(",", " ").trim(), icon = icon, foreground = if (icon.isEmpty()) "" else foreground, background = if (icon.isEmpty()) "" else background)) - } - .setNeutralButton("No icon") { _, _ -> - onPicked(current.copy(label = label.text.toString().replace(",", " ").trim(), icon = "", foreground = "", background = "")) - } - .setNegativeButton(android.R.string.cancel, null) - .setOnDismissListener { loader.shutdown() } - .show() + }, + )) { loader.shutdown() } } private fun paletteRow(name: String, value: () -> String, onPick: (String) -> Unit): View { @@ -142,6 +143,23 @@ class SteamTouchIconPicker( } private inner class IconAdapter(val names: List) : BaseAdapter() { + private val loading = HashSet() + private var refreshQueued = false + + /** Loads an icon in the background; the grid redraws from the cache once some have come in. */ + private fun load(name: String) { + if (!loading.add(name)) return + loader.execute { + SteamTouchBindings.icon(context, appId, name, 96) + main.post { + loading.remove(name) + if (refreshQueued) return@post + refreshQueued = true + main.postDelayed({ refreshQueued = false; notifyDataSetChanged() }, 120) + } + } + } + override fun getCount() = names.size override fun getItem(position: Int) = names[position] override fun getItemId(position: Int) = position.toLong() @@ -159,25 +177,80 @@ class SteamTouchIconPicker( } view.colorFilter = null val cached = SteamTouchBindings.cachedIcon(appId, name, 96) - if (cached != null) view.setImageBitmap(tinted(cached)) else { + if (cached != null) { + val t = tinted(name, cached) + if ((view.drawable as? android.graphics.drawable.BitmapDrawable)?.bitmap !== t) view.setImageBitmap(t) + } else { view.setImageDrawable(null) - loader.execute { - val bitmap = SteamTouchBindings.icon(context, appId, name, 96) - main.post { if (view.tag == name && bitmap != null) view.setImageBitmap(tinted(bitmap)) } - } + load(name) } return view } - private fun tinted(icon: Bitmap): Bitmap { + // One thumbnail per icon and colour, reused when the grid rebinds. + private val thumbs = android.util.LruCache(64) + + private fun tinted(name: String, icon: Bitmap): Bitmap { + val key = "$name|$foreground" + thumbs.get(key)?.let { return it } val out = Bitmap.createBitmap(icon.width, icon.height, Bitmap.Config.ARGB_8888) drawSteamIcon(Canvas(out), icon, android.graphics.RectF(0f, 0f, icon.width.toFloat(), icon.height.toFloat()), Color.parseColor(foreground), Paint(Paint.FILTER_BITMAP_FLAG)) + thumbs.put(key, out) return out } } companion object { + /** + * A panel over the session, in the session's own window: a dialog's window of its own left + * new bitmaps and layers undrawn in the session window afterwards on the Thor. + */ + fun showPanel(host: ViewGroup, title: String, content: View, buttons: List Unit>>, onClose: () -> Unit = {}) { + val context = host.context + val density = context.resources.displayMetrics.density + fun dp(v: Int) = (v * density).toInt() + val scrim = android.widget.FrameLayout(context).apply { + setBackgroundColor(Color.argb(140, 0, 0, 0)) + isClickable = true + isFocusable = true + } + val card = LinearLayout(context).apply { + orientation = LinearLayout.VERTICAL + background = GradientDrawable().apply { cornerRadius = dp(16).toFloat(); setColor(Color.rgb(32, 34, 30)) } + setPadding(dp(12), dp(14), dp(12), dp(8)) + isClickable = true + } + card.addView(TextView(context).apply { + text = title + textSize = 20f + setTextColor(Color.WHITE) + setPadding(dp(16), 0, dp(16), dp(4)) + }) + card.addView(content) + val row = LinearLayout(context).apply { gravity = Gravity.END; setPadding(dp(8), dp(4), dp(8), 0) } + fun close() { + (scrim.parent as? ViewGroup)?.removeView(scrim) + val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as android.view.inputmethod.InputMethodManager + imm.hideSoftInputFromWindow(host.windowToken, 0) + onClose() + } + buttons.forEachIndexed { i, (name, action) -> + row.addView(android.widget.Button(context, null, android.R.attr.borderlessButtonStyle).apply { + text = name + setTextColor(Color.rgb(200, 230, 160)) + setOnClickListener { close(); action() } + }, LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { + if (i == 0 && buttons.size > 2) marginEnd = dp(120) + }) + } + card.addView(row) + val width = minOf(dp(640), (context.resources.displayMetrics.widthPixels * 0.9f).toInt()) + scrim.addView(card, android.widget.FrameLayout.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER)) + scrim.setOnClickListener { close() } + host.addView(scrim, ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)) + } + /** Steam's binding icon look (steamui: the icon multiplied with its foreground colour, * background-blend-mode: multiply, keeping the icon's own alpha). */ fun drawSteamIcon(canvas: Canvas, icon: Bitmap, into: android.graphics.RectF, foreground: Int, paint: Paint) { diff --git a/docs/development/steam-touch-controls.md b/docs/development/steam-touch-controls.md index c05b9280a4..c2b96e7bfa 100644 --- a/docs/development/steam-touch-controls.md +++ b/docs/development/steam-touch-controls.md @@ -75,3 +75,23 @@ the client reads it again. Steam Cloud uploads the file like any autosaved confi (calibration, an enable setting). - Custom touch icons (`SetTouchIconData` on Steam Link) are not drawn; controls use text labels. - Not tried on a retail phone with SELinux enforcing (the Deck pad's sysfs works there). + +## Icons, labels and colours + +Each control shows what its binding carries, as Steam Link does: a binding is +`,