Merge origin/main into feat/malibridge-v25

This commit is contained in:
DroidDeck Merge committed 2026-11-01 19:59:31 +08:00
commit a2a5f84711
132 files changed
+7212 -156

No files matched your search

@@ -46,6 +46,9 @@ class DroidDeckHudHost(context: Context) {
var onPresentingWindowChanged: (() -> Unit)? = null
/** The frame rate the HUD shows; null while the HUD is off and not counting frames. */
val liveFps: Float? get() = if (polling) feed.stats.fps else null
/** The HUD itself changed a setting: a tap cycles the size, a long press locks it. */
var onConfigChanged: (() -> Unit)? = null
@@ -91,7 +94,7 @@ class DroidDeckHudHost(context: Context) {
hud.onRefresh = Runnable { refreshLabels(hud) }
hud.setOnMovedListener { x, y ->
wantX = x; wantY = y
dockEdgeFor(hud)?.let { edge -> setDock(hud, edge); return@setOnMovedListener }
if (!hud.isStrip) dockEdgeFor(hud)?.let { edge -> setDock(hud, edge); return@setOnMovedListener }
keepOnScreen(hud)
wantX = hud.x; wantY = hud.y
SessionPrefs.setDroidDeckHudPosition(context, hud.x, hud.y)
@@ -335,6 +338,7 @@ class DroidDeckHudHost(context: Context) {
val maxY = (p.height - v.height).toFloat().coerceAtLeast(0f)
var x = wantX.coerceIn(0f, maxX)
var y = wantY.coerceIn(0f, maxY)
if ((v as? DroidDeckHudView)?.isStrip == true) y = if (y + v.height / 2f < p.height / 2f) 0f else maxY
when (v.let { it as? DroidDeckHudView }?.dock) {
DroidDeckHudDock.LEFT -> x = 0f
DroidDeckHudDock.RIGHT -> x = maxX
@@ -23,9 +23,10 @@ enum class DroidDeckHudSize(val token: String, val label: String) {
TILES("tiles", "Tiles"),
PILL("pill", "Pill"),
MINIMAL("minimal", "Minimal"),
MEGA("mega", "Mega");
MEGA("mega", "Mega"),
STRIP("strip", "Strip");
/** Next size in the tap-cycle: Full → Tiles → Pill → Minimal → Mega → Full. */
/** Next size in the tap-cycle: Full → Tiles → Pill → Minimal → Mega → Strip → Full. */
fun next(): DroidDeckHudSize {
val all = values()
return all[(ordinal + 1) % all.size]
@@ -40,7 +41,7 @@ enum class DroidDeckHudSize(val token: String, val label: String) {
fun supportedChips(): Set<String> = when (this) {
MINIMAL -> MINIMAL_CHIPS
PILL -> PILL_CHIPS
FULL, TILES -> STANDARD_CHIPS
FULL, TILES, STRIP -> STANDARD_CHIPS
MEGA -> MEGA_CHIPS
}
@@ -22,12 +22,16 @@ import android.graphics.Paint
import android.graphics.Path
import android.graphics.RectF
import android.graphics.Typeface
import android.os.SystemClock
import android.text.format.DateFormat
import android.view.GestureDetector
import android.view.MotionEvent
import android.view.View
import androidx.annotation.VisibleForTesting
import androidx.compose.ui.graphics.toArgb
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.ui.Motion
import com.droiddeck.launcher.ui.Palette
import com.droiddeck.launcher.ui.Themes
import java.util.Date
import java.util.Locale
@@ -43,6 +47,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@@ -75,6 +80,7 @@ class DroidDeckHudView(context: Context) : View(context) {
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
private var updateJob: Job? = null
private var hueJob: Job? = null
private val metrics = HudMetrics(context)
private val density = resources.displayMetrics.density
@@ -152,6 +158,8 @@ class DroidDeckHudView(context: Context) : View(context) {
var dock = DroidDeckHudDock.NONE
private set
private var tabRect: RectF? = null
// The Strip is a bar across the whole screen, kept against the top or bottom edge.
private var stripRect: RectF? = null
private val tabPath = Path()
// Every size sits in the DroidDeck mark's D: a straight left side, round on the
@@ -368,9 +376,11 @@ class DroidDeckHudView(context: Context) : View(context) {
private fun stopUpdates() {
updateJob?.cancel(); updateJob = null
hueJob?.cancel(); hueJob = null
}
private fun startUpdates() {
startHueCycle()
if (updateJob?.isActive == true) return
updateJob = scope.launch {
while (isActive) {
@@ -397,13 +407,50 @@ class DroidDeckHudView(context: Context) : View(context) {
var onRefresh: Runnable? = null
private fun applyTheme() {
val palette = Themes.current(context)
applyPalette(Themes.current(context))
if (isAttachedToWindow && isShown) startHueCycle()
}
private fun applyPalette(palette: Palette) {
accent = palette.primary.toArgb()
surfaceRgb = palette.surface.toArgb() and 0xFFFFFF
colFps = accent
colGraph = lighten(accent, 0.3f)
}
/**
* Inner Gamer turns the colour wheel inside the app's Compose UI, which is not running while the drawer is
* closed, so the HUD turns it here and shares the hue so the drawer picks up where the HUD is.
*/
private fun startHueCycle() {
if (hueJob?.isActive == true) return
if (SessionPrefs.theme(context) != Themes.INNER_GAMER) return
hueJob = scope.launch {
var hue = Themes.rgbHue
var shown = Float.NaN
var last = SystemClock.uptimeMillis()
while (isActive && SessionPrefs.theme(context) == Themes.INNER_GAMER) {
val now = SystemClock.uptimeMillis()
val cycle = Themes.rgbCycleMillis(Themes.rgbSpeed).toFloat()
if (Motion.scale == 0f) {
last = now
delay(HUE_IDLE_MS)
continue
}
hue = (hue + (now - last) / cycle * 360f) % 360f
last = now
val stepped = (hue / Themes.RGB_HUE_STEP).toInt() * Themes.RGB_HUE_STEP
if (stepped != shown) {
shown = stepped
Themes.moveRgbHue(stepped)
applyPalette(Themes.innerGamer(stepped))
rebuildAndInvalidate()
}
delay((cycle * Themes.RGB_HUE_STEP / 360f).toLong().coerceAtLeast(16L))
}
}
}
private fun lighten(color: Int, amount: Float): Int = Color.rgb(
(Color.red(color) + (255 - Color.red(color)) * amount).roundToInt(),
(Color.green(color) + (255 - Color.green(color)) * amount).roundToInt(),
@@ -534,7 +581,7 @@ class DroidDeckHudView(context: Context) : View(context) {
// ---- Layout builders --------------------------------------------------
private fun rebuild() {
glyphs.clear(); tileRects.clear(); graphRect = null
headerMark = null; chipRect = null; dPanel = null; dDividerTop = -1f; tabRect = null
headerMark = null; chipRect = null; dPanel = null; dDividerTop = -1f; tabRect = null; stripRect = null
val s = snap
if (s == null) { contentW = 0f; contentH = 0f; return }
if (dock != DroidDeckHudDock.NONE) { buildDockTab(); return }
@@ -544,6 +591,7 @@ class DroidDeckHudView(context: Context) : View(context) {
DroidDeckHudSize.PILL -> { buildPill(s); intoPanel(sp(10f), header = false) }
DroidDeckHudSize.MINIMAL -> buildMinimal(s)
DroidDeckHudSize.MEGA -> { buildMega(s); intoPanel(sp(10f), header = true) }
DroidDeckHudSize.STRIP -> buildStrip(s)
}
}
@@ -1078,6 +1126,94 @@ class DroidDeckHudView(context: Context) : View(context) {
finishPanel(panel, halfRound = true)
}
/**
* Full's readouts on one line across the screen: the mark, the FPS, the graph, the lows, then GPU, CPU,
* memory, battery, display server and GPU model, with the clock on the right end. Groups that no longer
* fit before the clock are left off, from the end.
*/
private fun buildStrip(s: HudMetrics.Snapshot) {
val rowPx = sp(11.5f); val unitPx = rowPx * 0.8f; val fpsPx = sp(15f)
val padX = sp(10f); val groupGap = sp(13f)
val h = sp(26f)
val w = ((parent as? View)?.width?.takeIf { it > 0 } ?: resources.displayMetrics.widthPixels).toFloat()
val mid = h / 2f
val baseline = mid + capHeight(fpsPx) / 2f
val markH = sp(13f)
val markLeft = padX - DroidDeckMark.inkLeftFor(markH)
headerMark = RectF(markLeft, mid - markH / 2f, markLeft + DroidDeckMark.widthFor(markH), mid + markH / 2f)
var x = markLeft + DroidDeckMark.inkRightFor(markH) + sp(8f)
var right = w - padX
if (showClockTime) {
val t = clockTimeString()
right -= measure(t, rowPx)
glyphs.add(Glyph(right, baseline, t, blend(colDim), rowPx))
right -= groupGap
}
val generating = differs(fpsNow)
val fps = ArrayList<Span>()
if (apiLabel() != "FPS") fps += Span("${apiLabel()} ", colDim, rowPx)
fps += Span(fpsText(fpsNow), colValue, if (generating) fpsPx * 0.8f else fpsPx, glow = true)
fps += Span("fps", colDim, unitPx)
x = placeRun(x, baseline, fps) + groupGap
if (showGraph) {
val gw = sp(72f); val gh = h * 0.55f
if (x + gw <= right) {
graphRect = RectF(x, mid - gh / 2f, x + gw, mid + gh / 2f)
x += gw + groupGap
}
}
val groups = ArrayList<List<Span>>()
run {
val l = ArrayList<Span>()
l += Span("1% ", colDim, rowPx); l += Span(lowText(lows.low1Fps) ?: "—", colFps, rowPx)
l += Span(" 0.1% ", colDim, rowPx); l += Span(lowText(lows.low01Fps) ?: "—", colFps, rowPx)
if (showLow001) { l += Span(" 0.01% ", colDim, rowPx); l += Span(lowText(lows.low001Fps) ?: "—", colFps, rowPx) }
groups += l
}
if (showGPU || showGpuTemp) {
val l = arrayListOf(Span("GPU", colGpu, rowPx))
if (showGPU) l += Span(" ${s.gpuPercent ?: "—"}%", colGpu, rowPx)
if (showGpuTemp && s.gpuTempC != null) { l += Span(" ", colDim, rowPx); l += tempSpans(s.gpuTempC, HudMetrics.TempSensor.GPU, rowPx, unitPx) }
groups += l
}
if (showCPU || showCpuTemp) {
val l = arrayListOf(Span("CPU", colCpu, rowPx))
if (showCPU) l += Span(" ${s.cpuPercent ?: "—"}%", colCpu, rowPx)
if (showCpuTemp && s.cpuTempC != null) { l += Span(" ", colDim, rowPx); l += tempSpans(s.cpuTempC, HudMetrics.TempSensor.CPU, rowPx, unitPx) }
groups += l
}
if (showVram) s.vramText()?.let { groups += listOf(Span("VRAM $it", colVram, rowPx)) }
if (showRAM) groups += listOf(Span("RAM ${s.ramPercent.roundToInt()}%", colRam, rowPx))
if (showBattery || showPower || showBatteryTemp) {
val l = ArrayList<Span>()
fun part(spans: List<Span>) {
l += if (l.isEmpty()) Span("BAT ", colBat, rowPx) else Span(" ", colDim, rowPx)
l += spans
}
if (showBattery && s.battery.percent != null) part(listOf(Span("${s.battery.percent}%", colBat, rowPx)))
if (showBatteryTemp && s.battery.tempC != null)
part(tempSpans(s.battery.tempC, HudMetrics.TempSensor.BATTERY, rowPx, unitPx))
if (showPower && s.battery.watts > 0f) part(listOf(Span("${fmt1(s.battery.watts)}W", colDim, rowPx)))
if (l.isNotEmpty()) groups += l
}
if (displayServer.isNotBlank()) groups += listOf(Span(displayServer, colDisp, rowPx))
if (hdrState != DroidDeckHudHdr.NONE) groups += hdrLine(rowPx)
if (showGpuModel && gpuNameText().isNotBlank()) groups += gpuModelSpans(rowPx, colDim, compact = true)
for (g in groups) {
if (x + runWidth(g) > right) break
x = placeRun(x, baseline, g) + groupGap
}
stripRect = RectF(0f, 0f, w, h)
contentW = w; contentH = h
}
private fun capHeight(px: Float): Float {
measurePaint.textSize = px
measurePaint.getTextBounds("0", 0, 1, inkRect)
@@ -1267,6 +1403,8 @@ class DroidDeckHudView(context: Context) : View(context) {
// ---- Measure / draw ---------------------------------------------------
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
// The Strip spans the parent, past the side margin the floating sizes keep.
if (stripRect != null) { setMeasuredDimension(contentW.roundToInt(), resolveSize(contentH.roundToInt(), heightMeasureSpec)); return }
setMeasuredDimension(
resolveSize(contentW.roundToInt(), widthMeasureSpec),
resolveSize(contentH.roundToInt(), heightMeasureSpec),
@@ -1287,6 +1425,7 @@ class DroidDeckHudView(context: Context) : View(context) {
chipRect?.let { drawChip(canvas, it) }
tabRect?.let { drawTab(canvas, it) }
stripRect?.let { drawStrip(canvas, it) }
// Text
for (g in glyphs) {
@@ -1328,6 +1467,21 @@ class DroidDeckHudView(context: Context) : View(context) {
canvas.drawPath(graphPath, graphPaint)
}
/** The bar, with the accent line on the side that faces the game (under it at the top, over it at the bottom). */
private fun drawStrip(canvas: Canvas, rect: RectF) {
headerPaint.shader = null
headerPaint.color = panelColor()
canvas.drawRect(rect, headerPaint)
val stroke = outlineWidth()
if (stroke <= 0f) return
val line = max(stroke / 2f, density)
val p = parent as? View
val atBottom = p != null && p.height > 0 && y + height / 2f > p.height / 2f
headerPaint.color = withAlpha(outlineColor(), (110 + 145 * outlineIntensity).roundToInt().coerceAtMost(255))
if (atBottom) canvas.drawRect(rect.left, rect.top, rect.right, rect.top + line, headerPaint)
else canvas.drawRect(rect.left, rect.bottom - line, rect.right, rect.bottom, headerPaint)
}
private fun outlineWidth(): Float = if (outlineIntensity > 0f) outlineIntensity * sp(3.5f) else 0f
private fun outlineColor(): Int = if (outlineFollowAccent) accent else Color.rgb(200, 200, 200)
private fun panelColor(): Int = Color.argb((bgOpacity.coerceIn(0f, 1f) * 255f).roundToInt(),
@@ -1443,6 +1597,8 @@ class DroidDeckHudView(context: Context) : View(context) {
return lockController.onTouchEvent(event)
}
internal val isStrip: Boolean get() = stripRect != null
internal val contentWidth: Float get() = contentW
internal val contentHeight: Float get() = contentH
@@ -1450,6 +1606,7 @@ class DroidDeckHudView(context: Context) : View(context) {
private companion object {
const val REFRESH_MS = 500L
private const val HUE_IDLE_MS = 500L
const val MIN_SCALE = 0.5f
const val MAX_SCALE = 2f
const val GRAPH_CLIP_MS = 49.9f