fix: FusionHUD Pill battery row, and a locked HUD lets on-screen controls work (#1763)

Pill: battery level, temperature and watts share one "BAT" row, as on the
other sizes, and each part follows its own switch. Turning Memory off no
longer hides the battery temperature (reported by Keegan), and watts show
without the battery level.

Touch (part of #1752, reported by ZZCSK): a locked HUD lets a touch through
where an on-screen control under it takes it: controller buttons and sticks,
Steam touch controls, screen keys and the controls panel below the game.
Each layer answers takesTouchAt with its own touch checks. Everywhere else
the HUD keeps the touch, so a long press still locks or unlocks it. A new
HUD starts locked. The "Lock in place" hint says so in every language.

Tests: Pill battery row per switch combination; takesTouchAt agrees with a
real touch over a grid for the controller buttons, screen keys and both
controls panel layouts (Deck and gamepad, landscape and portrait); a locked
HUD passes touches to a control under it, keeps the rest, and unlocks on a
long press.
This commit is contained in:
The412Banner authored and GitHub committed 2026-10-29 12:51:28 +00:00
1 parent 283e3b4549
commit 5de690ef39
46 files changed
+279 -61

No files matched your search

@@ -655,6 +655,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
hud = FusionHudHost(this)
hud.onConfigChanged = { hudConfig = FusionHudConfig.load(this) }
hud.passesTouchAt = ::controlTakesTouchAt
hud.attach(root, root.childCount)
memoryHud = com.droiddeck.launcher.session.MemoryHud(this)
hud.onPresentingWindowChanged = {
@@ -2439,6 +2440,22 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
override fun dispatchTrackballEvent(event: MotionEvent): Boolean =
onCapturedPointer(event) || super.dispatchTrackballEvent(event)
/** Whether one of the on-screen control layers takes a finger going down at this screen point. */
private fun controlTakesTouchAt(rawX: Float, rawY: Float): Boolean {
val at = IntArray(2)
fun takes(view: View, hit: (Float, Float) -> Boolean): Boolean {
if (!view.isShown) return false
view.getLocationOnScreen(at)
val x = rawX - at[0]
val y = rawY - at[1]
return x >= 0f && y >= 0f && x < view.width && y < view.height && hit(x, y)
}
return onScreenControls?.let { takes(it, it::takesTouchAt) } == true ||
steamTouchControls?.let { takes(it, it::takesTouchAt) } == true ||
screenKeys?.let { takes(it, it::takesTouchAt) } == true ||
unfoldedPanel?.let { takes(it, it::takesTouchAt) } == true
}
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
if (pipUi) return true
if (event.actionMasked == MotionEvent.ACTION_DOWN && event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN)) {
@@ -5,9 +5,12 @@ import com.droiddeck.launcher.session.SessionPrefs
/** FusionHUD's settings as one "key=value,…" string (FusionHudView.applyConfig), stored in SessionPrefs. */
internal object FusionHudConfig {
/** Bannerlator's Fusion defaults (DeckOverlaySettings), with the FPS graph from the old DroidDeck HUD. */
/**
* Bannerlator's Fusion defaults (DeckOverlaySettings), with the FPS graph from the old DroidDeck HUD. The HUD starts
* locked, so like the old HUD it lets touches through until it is unlocked to move it.
*/
val DEFAULTS: Map<String, String> = linkedMapOf(
"hudSize" to "minimal", "hudLocked" to "0", "hudScale" to "100", "hudOpacity" to "80", "hudColor" to "mid",
"hudSize" to "minimal", "hudLocked" to "1", "hudScale" to "100", "hudOpacity" to "80", "hudColor" to "mid",
"hudOutline" to "40", "hudOutlineAccent" to "1",
"showFPS" to "1", "showFPSGraph" to "1", "showCPUUsage" to "1", "showCPULoad" to "1", "showGPULoad" to "1",
"showVram" to "1", "showRAM" to "1", "showPower" to "1", "showTemp" to "1", "showBatteryTemp" to "1",
@@ -44,6 +44,9 @@ class FusionHudHost(context: Context) {
/** The HUD itself changed a setting: a tap cycles the size, a long press locks it. */
var onConfigChanged: (() -> Unit)? = null
/** Screen point → whether an on-screen control takes a touch there; a locked HUD lets those through. */
var passesTouchAt: ((rawX: Float, rawY: Float) -> Boolean)? = null
private val listener = object : WaylandCompositor.GameListener {
override fun onGameSurface(window: String?, gpuName: String?) {
if (!gpuName.isNullOrBlank()) handler.post { this@FusionHudHost.gpuName = cleanGpuName(gpuName) }
@@ -90,6 +93,7 @@ class FusionHudHost(context: Context) {
onConfigChanged?.invoke()
}
hud.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> if (!hud.isDragging) keepOnScreen(hud) }
hud.passesTouchAt = { x, y -> passesTouchAt?.invoke(x, y) == true }
hud.visibility = View.GONE
val margin = (16 * root.resources.displayMetrics.density).roundToInt()
root.addView(hud, index, FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply {
@@ -57,7 +57,8 @@ import kotlinx.coroutines.withTimeoutOrNull
*
* Gestures go through [HudLockController]: long-press toggles the position lock (with a lock/unlock
* badge fade), a tap cycles the size (Full→Tiles→Pill→Minimal→Full), and a drag repositions — tap +
* drag are frozen while locked.
* drag are frozen while locked. A locked HUD lets a touch through where an on-screen control under it
* takes it ([passesTouchAt]); everywhere else it keeps the touch, so a long press there unlocks it.
*/
class FusionHudView(context: Context) : View(context) {
@@ -294,7 +295,7 @@ class FusionHudView(context: Context) : View(context) {
showDxVer = cfg.get("showDxVer", "1") == "1"
showSession = cfg.get("showSession", "1") == "1"
tempDisplay = HudMetrics.TempDisplay.from(cfg)
lockController.setLocked(cfg.get("hudLocked", "0") == "1")
lockController.setLocked(cfg.get("hudLocked", "1") == "1")
colorIntensity = when (cfg.get("hudColor", "vivid")) {
"soft" -> 0.72f; "mid" -> 0.88f; else -> 1.0f
@@ -865,25 +866,20 @@ class FusionHudView(context: Context) : View(context) {
}
// RAM % (system-wide) takes the slot the latency row used to occupy, matching the GPU/CPU idiom
// on the row above it. colRam keeps RAM's identity colour consistent with the Full/Tiles sizes.
if (showRAM) {
if (showRAM) stack.add(listOf(Span("RAM ${s.ramPercent.roundToInt()}%", colRam, stkPx)))
// One battery row, as on the other sizes: each part shows on its own switch, so the battery
// temperature no longer goes with the RAM switch and watts show without the battery level.
if (showBattery || showPower || showBatteryTemp) {
val l = ArrayList<Span>()
l += Span("RAM ${s.ramPercent.roundToInt()}%", colRam, stkPx)
// Battery temperature as a "BAT" chip right after RAM (pill-only placement, per user
// request). Colour-banded warm→red via tempSpans/TempSensor.BATTERY — the exact same
// danger bands the GPU/CPU temps use. Only shown when the battery-temp toggle is on
// and a reading is available; the other sizes keep battery temp in the battery row.
if (showBatteryTemp && s.battery.tempC != null) {
l += Span(" · ", colDim, stkPx)
l += Span("BAT ", colBat, stkPx)
l += tempSpans(s.battery.tempC, HudMetrics.TempSensor.BATTERY, stkPx, stkPx * 0.62f)
fun part(spans: List<Span>) {
l += if (l.isEmpty()) Span("BAT ", colBat, stkPx) else Span(" · ", colDim, stkPx)
l += spans
}
stack.add(l)
}
if (showBattery || showPower) {
val l = ArrayList<Span>(); var any = false
if (showBattery && s.battery.percent != null) { l += Span("BAT ${s.battery.percent}%", colBat, stkPx); any = true }
if (showPower && s.battery.watts > 0f) { if (any) l += Span(" · ", colDim, stkPx); l += Span("${fmt1(s.battery.watts)}W", colDim, stkPx) }
if (any) stack.add(l)
if (showBattery && s.battery.percent != null) part(listOf(Span("${s.battery.percent}%", colBat, stkPx)))
if (showBatteryTemp && s.battery.tempC != null)
part(tempSpans(s.battery.tempC, HudMetrics.TempSensor.BATTERY, stkPx, stkPx * 0.62f))
if (showPower && s.battery.watts > 0f) part(listOf(Span("${fmt1(s.battery.watts)}W", colDim, stkPx)))
if (l.isNotEmpty()) stack.add(l)
}
// Latency (+ the display server, + optional VRAM) drops to the bottom of the stack, under the
// battery row. The display server sits here, not on the GPU-model line: that line is the
@@ -1340,6 +1336,8 @@ class FusionHudView(context: Context) : View(context) {
@VisibleForTesting internal fun panelForTest(): RectF? = dPanel
@VisibleForTesting internal fun panelRadiusForTest(): Float = dRadius
@VisibleForTesting internal fun graphForTest(): RectF? = graphRect
@VisibleForTesting internal fun linesForTest(): List<String> =
glyphs.groupBy { it.baseline.roundToInt() }.toSortedMap().values.map { line -> line.sortedBy { it.x }.joinToString("") { it.text } }
private fun drawChip(canvas: Canvas, rect: RectF) {
val r = sp(6f)
@@ -1355,7 +1353,15 @@ class FusionHudView(context: Context) : View(context) {
DroidDeckMark.draw(canvas, rect.centerX() - markW / 2f, rect.centerY() - markH / 2f, markH, blend(colValue), accent)
}
override fun onTouchEvent(event: MotionEvent): Boolean = lockController.onTouchEvent(event)
/** Screen point → whether an on-screen control under the HUD takes a touch there. */
internal var passesTouchAt: ((rawX: Float, rawY: Float) -> Boolean)? = null
// Declining the down event hands the whole gesture to the views under the HUD.
override fun onTouchEvent(event: MotionEvent): Boolean {
if (event.actionMasked == MotionEvent.ACTION_DOWN && lockController.isLocked() &&
passesTouchAt?.invoke(event.rawX, event.rawY) == true) return false
return lockController.onTouchEvent(event)
}
internal val isDragging: Boolean get() = lockController.isDragging()
@@ -39,7 +39,7 @@ import java.util.function.Consumer;
* position — disabled (frozen) while locked.</li>
* <li><b>long-press</b> → toggles {@code hudLocked}, persisted via {@link Callbacks#onLockChanged}
* and kept in sync with the "Lock in place" menu chip. Works locked or unlocked (so a long-press
* always unlocks).</li>
* always unlocks); a locked {@code FusionHudView} passes touches on only over on-screen controls.</li>
* </ul>
*
* <p>On every lock/unlock (and on a blocked gesture while locked) a small padlock badge fades in →
@@ -672,6 +672,11 @@ class OnScreenControls(
private fun closestSnap(position: Float, targets: List<Float>): Float? =
targets.minByOrNull { abs(position - it) }?.takeIf { abs(position - it) <= dp(SNAP_DP) }
/** Whether a finger going down at ([x], [y]) lands on something here, as [onTouchEvent] decides it. */
fun takesTouchAt(x: Float, y: Float): Boolean =
editing || keyboardContains(x, y) || (!buttonsOnly && quickContains(x, y)) ||
(!quickHidden && (controlAt(x, y) ?: adaptiveStickAt(x, y)) != null)
private fun controlAt(x: Float, y: Float): Control? =
controls.firstOrNull {
!quickHidden && isVisible(it) && (editing || !settings.adaptiveSticks || it.stick < 0) && it.contains(x, y, it.radius)
@@ -609,6 +609,9 @@ class ScreenKeys(context: Context, private val sendKey: (Int, Boolean) -> Unit)
else -> entry.halfH
}
/** Whether a finger going down at ([x], [y]) lands on something here, as [onTouchEvent] decides it. */
fun takesTouchAt(x: Float, y: Float): Boolean = editing || entryAt(x, y) != null
private fun entryAt(x: Float, y: Float): Entry? = entries.lastOrNull { entry ->
x >= entry.cx - entry.halfW && x <= entry.cx + entry.halfW && y >= entry.cy - entry.halfH && y <= entry.cy + entry.halfH
}
@@ -244,6 +244,9 @@ class SteamTouchControls(
private fun hit(list: List<Element>, x: Float, y: Float): Element? =
list.filter { reach(it, x, y) <= 1.15f }.minByOrNull { reach(it, x, y) }
/** Whether a finger going down at ([x], [y]) lands on something here, as [onTouchEvent] decides it. */
fun takesTouchAt(x: Float, y: Float): Boolean = editing || menuOpen || hit(live(), x, y) != null
private fun live(): List<Element> =
if (shakenAway) emptyList() else if (options.inputMode == SteamTouchConfig.INPUT_MOUSE) elements.filter { it.type == SteamTouchConfig.THUMB } else elements
@@ -254,6 +254,21 @@ class DeckControlsPanel(
show()
}
/** Whether a finger going down at ([x], [y]) lands on one of the panel's controls. */
fun takesTouchAt(x: Float, y: Float): Boolean = controlUnder(this, x, y)
// Every control here takes the touches it gets: buttons and tabs (clickable), the scrolling tab strip,
// and the drawn surfaces, pads and face buttons. The layouts around them do not.
private fun controlUnder(view: View, x: Float, y: Float): Boolean {
if (view.visibility != VISIBLE || x < 0f || y < 0f || x >= view.width || y >= view.height) return false
if (view.isClickable || view is HorizontalScrollView || view is Surface || view is DirectionPad || view is FaceButtons) return true
val group = view as? ViewGroup ?: return false
return (group.childCount - 1 downTo 0).any { i ->
val child = group.getChildAt(i)
controlUnder(child, x + group.scrollX - child.x, y + group.scrollY - child.y)
}
}
private fun roundButton(label: String, description: String, onClick: () -> Unit, wide: Boolean = false) =
roundButton(context, label, description, onClick, wide)