settings without a pop-up: pages in the pane with anchored menus under each value; frame generation, logs and offline open in place on the rail

The cog's settings window and the Performance dialog become pages in the front end's pane:
one row per setting, its value in a chip, and a small faded menu that opens under the chip
(SettingsWidgets: AnchoredMenu on a Popup with its own position provider, MenuItem, ValueChip,
Choice/Toggle/Multi/Action rows). One menu at a time; the page dims while it is open; the back
key, the rail and the page's Back all leave it. Steam and Desktop each get a Settings entry in
the rail that lights while its page shows, as does Performance under Setup. Frame generation,
Session logs and Start offline open their menu right on their rail row; the frame-generation
dialog is gone.
This commit is contained in:
The412Banner committed 2026-09-22 18:28:33 -04:00
1 parent 39272cf0f2
commit 8dd36b794e
6 files changed
+661 -560

No files matched your search

@@ -12,6 +12,7 @@ import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
@@ -35,14 +36,13 @@ import com.steamdeck.launcher.ui.ProtonDialog
import com.steamdeck.launcher.ui.ProtonRow
import com.steamdeck.launcher.core.CpuCores
import com.steamdeck.launcher.ui.CoreRow
import com.steamdeck.launcher.ui.PerformanceDialog
import com.steamdeck.launcher.ui.ModeSettingsDialog
import com.steamdeck.launcher.ui.PerformancePage
import com.steamdeck.launcher.ui.ModeSettingsPage
import com.steamdeck.launcher.ui.ModeSettings
import com.steamdeck.launcher.ui.ModeSettingsActions
import com.steamdeck.launcher.ui.DriverRow
import com.steamdeck.launcher.ui.ConfirmDialog
import com.steamdeck.launcher.ui.CreditsDialog
import com.steamdeck.launcher.ui.FrameGenDialog
import com.steamdeck.launcher.ui.FrontEndScreen
import com.steamdeck.launcher.ui.FrontEndState
import com.steamdeck.launcher.ui.FrontEndActions
@@ -148,6 +148,12 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
setContent {
SteamDeckTheme {
val sm = settingsMode
val page: (@Composable () -> Unit)? = when {
sm != null -> { { ModeSettingsHost(sm) } }
showPerformance -> { { PerformanceHost() } }
else -> null
}
FrontEndScreen(
FrontEndState(
installed = installed, ready = ready, available = available?.version,
@@ -156,6 +162,9 @@ class MainActivity : ComponentActivity() {
offlineAccount = offlineAccount, offline = offline,
frameGenLabel = frameGenLabel, romsDir = romsDir, logsEnabled = logsEnabled,
steamGames = steamGames, emulators = emulatorList, running = runningLabel,
frameGenEngine = FrameGen.engine(this), frameGenMultiplier = FrameGen.multiplier(this),
lsfgReady = LsfgNative.isInstalled(this),
pageKey = sm?.let { "settings:$it" } ?: if (showPerformance) "performance" else null,
),
FrontEndActions(
onPlay = { startActivity(Intent(this, SessionActivity::class.java)) },
@@ -185,7 +194,10 @@ class MainActivity : ComponentActivity() {
onDesktopSettings = { openModeSettings(SessionService.MODE_DESKTOP) },
onApps = { openApps() },
onRuntime = { onRuntimeButton() },
onFrameGen = { showFrameGen = true },
onFrameGenPick = { engine, multiplier ->
FrameGen.set(this, engine, multiplier)
frameGenLabel = FrameGen.label(this)
},
onProtons = { refreshProtons(); showProtons = true },
onPerformance = { refreshCores(); showPerformance = true },
onRoms = { showRoms = true },
@@ -200,7 +212,9 @@ class MainActivity : ComponentActivity() {
},
onEmulatorHelp = { showEmulatorHelp = true },
onCredits = { showCredits = true },
onPageBack = { settingsMode = null; showPerformance = false },
),
page = page,
)
if (showRoms) RomsDialog(
path = romsDir,
@@ -225,73 +239,6 @@ class MainActivity : ComponentActivity() {
onRemove = { id -> ProtonExtras.tools.first { it.id == id }.let { ProtonExtras.remove(this, it) }; refreshProtons() },
onDismiss = { showProtons = false },
)
settingsMode?.let { mode ->
ModeSettingsDialog(
ModeSettings(
mode = mode, resolutionCap = resolutionCap, shapeMode = shapeMode,
hdr = hdrOn, hdrReason = hdrReason,
linuxRows = linuxRows,
linuxSelected = if (mode == SessionService.MODE_STEAM) linuxSteam else linuxDesktop,
androidRows = androidRows, androidSelected = androidSelected,
touchMode = touchMode,
oscMode = if (mode == SessionService.MODE_STEAM) oscMode else null,
directAudio = if (mode == SessionService.MODE_STEAM) directAudio else null,
mic = if (mode == SessionService.MODE_STEAM) mic else null,
renderer = if (mode == SessionService.MODE_DESKTOP) renderer else null,
gameStorage = if (mode == SessionService.MODE_STEAM) gameStorage else null,
storageOptions = storageOptions,
),
ModeSettingsActions(
onResolution = { cap -> SessionPrefs.setResolutionCap(this, mode, cap); resolutionCap = cap },
onShape = { shape -> SessionPrefs.setShapeMode(this, shape); shapeMode = shape },
onHdr = { on -> SessionPrefs.setHdr(this, mode, on); hdrOn = on },
onSelectLinux = { id -> SessionPrefs.setLinuxDriver(this, mode, id); refreshDrivers() },
onImportLinux = { pickLinuxDriver.launch(InAppFilePicker.buildIntent(this, ZIP_EXT, "Choose a Linux runtime driver (-Linux zip)")) },
onRemoveLinux = { id -> LinuxVulkanDriverManager(this).removeDriver(id); refreshDrivers() },
onSelectAndroid = { id -> SessionPrefs.setAndroidDriver(this, id); refreshDrivers() },
onImportAndroid = { pickAndroidDriver.launch(InAppFilePicker.buildIntent(this, ZIP_EXT, "Choose a display driver (AdrenoTools zip)")) },
onRemoveAndroid = { id -> TurnipDriver(this).remove(id); refreshDrivers() },
onTouch = { t -> SessionPrefs.setTouchMode(this, t); touchMode = t },
onOsc = { o -> SessionPrefs.setOscMode(this, o); oscMode = o },
onDirectAudio = { on -> SessionPrefs.setDirectAudio(this, on); directAudio = on },
onMic = { on ->
SessionPrefs.setMicEnabled(this, on)
mic = on
// The session checks the grant itself at start; asking here means the
// answer is in before the first session that wants it.
if (on && checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(arrayOf(Manifest.permission.RECORD_AUDIO), 2)
}
},
onRenderer = { r -> SessionPrefs.setDesktopRenderer(this, r); renderer = r },
onGameStorage = { path, label -> setGameStorage(path, label) },
onPickGameStorageFolder = {
pickGameStorage.launch(InAppFilePicker.buildDirIntent(this, "Choose the game storage folder", gameStorage.ifEmpty { null }))
},
onDismiss = { settingsMode = null },
),
)
}
if (showPerformance) PerformanceDialog(
cores = CpuCores.all.map { c -> CoreRow(c, "cpu$c" + (CpuCores.maxGhz(c)?.let { String.format(java.util.Locale.US, " · %.1f GHz", it) } ?: "")) },
clientOverride = clientOverride, clientCores = clientCores, gameCores = gameCores,
tuSysmem = tuSysmem, zinkLazy = zinkLazy, noXalia = noXalia,
prootNoSeccomp = prootNoSeccomp, phantomWarning = phantomWarning,
onClientOverride = { on -> SessionPrefs.setClientCpusOverride(this, on); clientOverride = on },
onTuSysmem = { on -> SessionPrefs.setTuSysmem(this, on); tuSysmem = on },
onZinkLazy = { on -> SessionPrefs.setZinkLazy(this, on); zinkLazy = on },
onNoXalia = { on -> SessionPrefs.setNoXalia(this, on); noXalia = on },
onProotNoSeccomp = { on -> SessionPrefs.setProotNoSeccomp(this, on); prootNoSeccomp = on },
onClientCore = { core, on ->
clientCores = if (on) clientCores + core else clientCores - core
SessionPrefs.setClientCpus(this, CpuCores.format(clientCores))
},
onGameCore = { core, on ->
gameCores = if (on) gameCores + core else gameCores - core
SessionPrefs.setGameCpus(this, CpuCores.format(gameCores))
},
onDismiss = { showPerformance = false },
)
if (showRemove) ConfirmDialog(
title = "Remove Linux runtime",
text = "This deletes the runtime, the Steam client inside it, and every game installed there.",
@@ -299,16 +246,6 @@ class MainActivity : ComponentActivity() {
onConfirm = { Thread({ LinuxRuntimeInstaller.uninstall(this); ui.post { refresh() } }, "uninstall").start() },
onDismiss = { showRemove = false },
)
if (showFrameGen) FrameGenDialog(
engine = FrameGen.engine(this), multiplier = FrameGen.multiplier(this),
lsfgReady = LsfgNative.isInstalled(this),
onPick = { engine, multiplier ->
FrameGen.set(this, engine, multiplier)
frameGenLabel = FrameGen.label(this)
showFrameGen = false
},
onDismiss = { showFrameGen = false },
)
if (showCredits) CreditsDialog { showCredits = false }
if (showEmulatorHelp) com.steamdeck.launcher.ui.EmulatorHelpDialog { showEmulatorHelp = false }
}
@@ -396,6 +333,81 @@ class MainActivity : ComponentActivity() {
/** Both driver lists as the dialog shows them, re-read from disk so an import or removal shows at once. */
/** Everything the mode's cog shows, read fresh, then the dialog. */
/** The Steam or Desktop settings page, in the front end's pane. */
@Composable
private fun ModeSettingsHost(mode: String) {
ModeSettingsPage(
ModeSettings(
mode = mode, resolutionCap = resolutionCap, shapeMode = shapeMode,
hdr = hdrOn, hdrReason = hdrReason,
linuxRows = linuxRows,
linuxSelected = if (mode == SessionService.MODE_STEAM) linuxSteam else linuxDesktop,
androidRows = androidRows, androidSelected = androidSelected,
touchMode = touchMode,
oscMode = if (mode == SessionService.MODE_STEAM) oscMode else null,
directAudio = if (mode == SessionService.MODE_STEAM) directAudio else null,
mic = if (mode == SessionService.MODE_STEAM) mic else null,
renderer = if (mode == SessionService.MODE_DESKTOP) renderer else null,
gameStorage = if (mode == SessionService.MODE_STEAM) gameStorage else null,
storageOptions = storageOptions,
),
ModeSettingsActions(
onResolution = { cap -> SessionPrefs.setResolutionCap(this, mode, cap); resolutionCap = cap },
onShape = { shape -> SessionPrefs.setShapeMode(this, shape); shapeMode = shape },
onHdr = { on -> SessionPrefs.setHdr(this, mode, on); hdrOn = on },
onSelectLinux = { id -> SessionPrefs.setLinuxDriver(this, mode, id); refreshDrivers() },
onImportLinux = { pickLinuxDriver.launch(InAppFilePicker.buildIntent(this, ZIP_EXT, "Choose a Linux runtime driver (-Linux zip)")) },
onRemoveLinux = { id -> LinuxVulkanDriverManager(this).removeDriver(id); refreshDrivers() },
onSelectAndroid = { id -> SessionPrefs.setAndroidDriver(this, id); refreshDrivers() },
onImportAndroid = { pickAndroidDriver.launch(InAppFilePicker.buildIntent(this, ZIP_EXT, "Choose a display driver (AdrenoTools zip)")) },
onRemoveAndroid = { id -> TurnipDriver(this).remove(id); refreshDrivers() },
onTouch = { t -> SessionPrefs.setTouchMode(this, t); touchMode = t },
onOsc = { o -> SessionPrefs.setOscMode(this, o); oscMode = o },
onDirectAudio = { on -> SessionPrefs.setDirectAudio(this, on); directAudio = on },
onMic = { on ->
SessionPrefs.setMicEnabled(this, on)
mic = on
// The session checks the grant itself at start; asking here means the
// answer is in before the first session that wants it.
if (on && checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(arrayOf(Manifest.permission.RECORD_AUDIO), 2)
}
},
onRenderer = { r -> SessionPrefs.setDesktopRenderer(this, r); renderer = r },
onGameStorage = { path, label -> setGameStorage(path, label) },
onPickGameStorageFolder = {
pickGameStorage.launch(InAppFilePicker.buildDirIntent(this, "Choose the game storage folder", gameStorage.ifEmpty { null }))
},
onDismiss = { settingsMode = null },
),
)
}
/** The Performance page, in the front end's pane. */
@Composable
private fun PerformanceHost() {
PerformancePage(
cores = CpuCores.all.map { c -> CoreRow(c, "cpu$c" + (CpuCores.maxGhz(c)?.let { String.format(java.util.Locale.US, " · %.1f GHz", it) } ?: "")) },
clientOverride = clientOverride, clientCores = clientCores, gameCores = gameCores,
tuSysmem = tuSysmem, zinkLazy = zinkLazy, noXalia = noXalia,
prootNoSeccomp = prootNoSeccomp, phantomWarning = phantomWarning,
onClientOverride = { on -> SessionPrefs.setClientCpusOverride(this, on); clientOverride = on },
onTuSysmem = { on -> SessionPrefs.setTuSysmem(this, on); tuSysmem = on },
onZinkLazy = { on -> SessionPrefs.setZinkLazy(this, on); zinkLazy = on },
onNoXalia = { on -> SessionPrefs.setNoXalia(this, on); noXalia = on },
onProotNoSeccomp = { on -> SessionPrefs.setProotNoSeccomp(this, on); prootNoSeccomp = on },
onClientCore = { core, on ->
clientCores = if (on) clientCores + core else clientCores - core
SessionPrefs.setClientCpus(this, CpuCores.format(clientCores))
},
onGameCore = { core, on ->
gameCores = if (on) gameCores + core else gameCores - core
SessionPrefs.setGameCpus(this, CpuCores.format(gameCores))
},
onDismiss = { showPerformance = false },
)
}
private fun openModeSettings(mode: String) {
refreshDrivers()
resolutionCap = SessionPrefs.resolutionCap(this, mode)
@@ -1,67 +0,0 @@
package com.steamdeck.launcher.ui
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.unit.dp
import com.steamdeck.launcher.gpu.FrameGen
/**
* Off, or an engine at 2x/3x/4x. The LSFG rows are dimmed and unpickable until Lossless Scaling
* is installed in the Steam client — the engine cannot run without its DLL, so offering it would
* only produce a setting that quietly does nothing.
*/
@Composable
fun FrameGenDialog(
engine: String,
multiplier: Int,
lsfgReady: Boolean,
onPick: (engine: String, multiplier: Int) -> Unit,
onDismiss: () -> Unit,
) {
data class Row(val label: String, val engine: String, val multiplier: Int, val enabled: Boolean)
val note = if (lsfgReady) "" else " — install Lossless Scaling in Steam"
val rows = listOf(Row("Off", FrameGen.ENGINE_OFF, 2, true)) +
(2..4).map { Row("Win-FG ${it}×", FrameGen.ENGINE_WINFG, it, true) } +
(2..4).map { Row("LSFG ${it}×$note", FrameGen.ENGINE_LSFG, it, lsfgReady) }
AlertDialog(
onDismissRequest = onDismiss,
title = { Text("Frame generation") },
text = {
Column {
Text(
"Extra frames are generated between the real ones on the way to the screen, so a game running at 30 fps looks like 60. Takes effect at once, mid-game included.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(bottom = 8.dp),
)
for (row in rows) {
val selected = row.engine == engine && (row.engine == FrameGen.ENGINE_OFF || row.multiplier == multiplier)
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.alpha(if (row.enabled) 1f else 0.38f)
.clickable(enabled = row.enabled) { onPick(row.engine, row.multiplier) }
.padding(vertical = 2.dp),
) {
RadioButton(selected = selected, onClick = null, enabled = row.enabled)
Text(row.label, style = MaterialTheme.typography.bodyMedium, modifier = Modifier.padding(start = 4.dp))
}
}
}
},
confirmButton = { TextButton(onClick = onDismiss) { Text("OK") } },
)
}
@@ -2,6 +2,7 @@ package com.steamdeck.launcher.ui
import android.os.Build
import android.provider.Settings
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.Crossfade
@@ -106,6 +107,7 @@ import androidx.compose.ui.zIndex
import coil.compose.AsyncImage
import com.steamdeck.launcher.R
import com.steamdeck.launcher.frontend.Library
import com.steamdeck.launcher.gpu.FrameGen
import java.io.File
import kotlin.math.roundToInt
@@ -127,6 +129,11 @@ class FrontEndState(
val emulators: List<Library.Emulator>,
/** A session alive in the background: what it is, or null. */
val running: String?,
val frameGenEngine: String = FrameGen.ENGINE_OFF,
val frameGenMultiplier: Int = 2,
val lsfgReady: Boolean = false,
/** A page shown in the pane instead of the selection ("settings:steam", "settings:lxqt", "performance"), or null. */
val pageKey: String? = null,
)
class FrontEndActions(
@@ -141,7 +148,7 @@ class FrontEndActions(
val onDesktopSettings: () -> Unit,
val onApps: () -> Unit,
val onRuntime: () -> Unit,
val onFrameGen: () -> Unit,
val onFrameGenPick: (engine: String, multiplier: Int) -> Unit,
val onProtons: () -> Unit,
val onPerformance: () -> Unit,
val onRoms: () -> Unit,
@@ -150,6 +157,8 @@ class FrontEndActions(
val onOffline: () -> Unit,
val onEmulatorHelp: () -> Unit,
val onCredits: () -> Unit,
/** Leaves the page in the pane (back key, the rail, or the page's own Back). */
val onPageBack: () -> Unit = {},
)
// ───────────────────────────── Motion ─────────────────────────────
@@ -159,7 +168,7 @@ class FrontEndActions(
* animator scale, so a device set to "no animations" in developer options collapses them to
* an instant snap instead of ignoring the user's choice.
*/
private object Motion {
internal object Motion {
var scale = 1f
val Ease = CubicBezierEasing(0.2f, 0.8f, 0.2f, 1f)
fun ms(base: Int) = (base * scale).roundToInt()
@@ -183,7 +192,7 @@ private fun artBrush(h: Float) = Brush.linearGradient(listOf(tint(h), tint((h +
* a page change reads as one cascade rather than a cut.
*/
@Composable
private fun Rise(i: Int, modifier: Modifier = Modifier, content: @Composable () -> Unit) {
internal fun Rise(i: Int, modifier: Modifier = Modifier, content: @Composable () -> Unit) {
val state = remember { MutableTransitionState(false) }.apply { targetState = true }
AnimatedVisibility(
visibleState = state, modifier = modifier,
@@ -231,7 +240,7 @@ private fun Modifier.shine(trigger: Boolean, strength: Float = 0.22f): Modifier
* to it. Landscape puts the rail beside the content; a narrow screen puts it above.
*/
@Composable
fun FrontEndScreen(s: FrontEndState, a: FrontEndActions) {
fun FrontEndScreen(s: FrontEndState, a: FrontEndActions, page: (@Composable () -> Unit)? = null) {
var selected by rememberSaveable { mutableStateOf("steam") }
var openDesktop by rememberSaveable { mutableStateOf(true) }
var openSteam by rememberSaveable { mutableStateOf(true) }
@@ -241,15 +250,17 @@ fun FrontEndScreen(s: FrontEndState, a: FrontEndActions) {
var openSetup by rememberSaveable { mutableStateOf(!s.ready) }
val colors = MaterialTheme.colorScheme
val ctx = LocalContext.current
BackHandler(enabled = s.pageKey != null && page != null) { a.onPageBack() }
remember { Motion.scale = Settings.Global.getFloat(ctx.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f); true }
BoxWithConstraints(modifier = Modifier.fillMaxSize().background(colors.background).systemBarsPadding()) {
val wide = maxWidth >= 640.dp
val rail: @Composable () -> Unit = {
Rail(
s, selected, openSteam, openDesktop, openEmu, openSetup,
s, s.pageKey ?: selected, openSteam, openDesktop, openEmu, openSetup,
onToggleSetup = { openSetup = !openSetup },
onSelect = { key ->
if (s.pageKey != null) a.onPageBack()
if (key == "steam") openSteam = if (selected == "steam") !openSteam else true
if (key == "desktop") openDesktop = if (selected == "desktop") !openDesktop else true
if (key.startsWith("emu:")) openEmu = if (selected == key && openEmu == key) "" else key
@@ -259,7 +270,7 @@ fun FrontEndScreen(s: FrontEndState, a: FrontEndActions) {
modifier = if (wide) Modifier.width(236.dp).fillMaxHeight() else Modifier.fillMaxWidth().height(maxHeight * 0.42f),
)
}
val content: @Composable (Modifier) -> Unit = { m -> Pane(s, selected, a, m) }
val content: @Composable (Modifier) -> Unit = { m -> Pane(s, selected, a, page, m) }
if (wide) Row(modifier = Modifier.fillMaxSize()) { rail(); content(Modifier.weight(1f).fillMaxHeight()) }
else Column(modifier = Modifier.fillMaxSize()) { rail(); content(Modifier.weight(1f).fillMaxWidth()) }
}
@@ -337,6 +348,7 @@ private fun Rail(
Sub(openSteam) {
for ((i, g) in s.steamGames.withIndex()) NavItem(g.name, "app:${g.appId}", selected == "app:${g.appId}", small = true, i = i, register = register, unregister = unregister) { onSelect("app:${g.appId}") }
if (s.steamGames.isEmpty()) NavItem("no games installed", "x", false, small = true, muted = true, register = register, unregister = unregister) {}
NavItem("Settings", "settings:steam", selected == "settings:steam", small = true, tiny = true, muted = true, i = s.steamGames.size, register = register, unregister = unregister) { a.onSteamSettings() }
}
NavItem("Desktop", "desktop", selected == "desktop", caret = openDesktop, count = s.emulators.count { it.installed }, register = register, unregister = unregister) { onSelect("desktop") }
Sub(openDesktop) {
@@ -352,31 +364,63 @@ private fun Rail(
}
}
if (s.emulators.none { it.installed }) NavItem("install emulators under Desktop & apps", "x", false, small = true, muted = true, register = register, unregister = unregister) { a.onApps() }
NavItem("Settings", "settings:lxqt", selected == "settings:lxqt", small = true, tiny = true, muted = true, i = s.emulators.count { it.installed }, register = register, unregister = unregister) { a.onDesktopSettings() }
}
}
}
Spacer(Modifier.height(6.dp))
// Setup: the same fold as Steam and Desktop, a header that opens its list.
val setup = listOf(
Triple("Files", null, a.onFiles), Triple("Desktop & apps", null, a.onApps), Triple("Compatibility tools", null, a.onProtons),
Triple("Frame generation", s.frameGenLabel, a.onFrameGen), Triple("Performance", null, a.onPerformance),
Triple("ROMs folder", s.romsDir?.substringAfterLast('/')?.ifEmpty { s.romsDir } ?: "choose", a.onRoms),
Triple("Session logs", if (s.logsEnabled) "on" else "off", a.onLogs),
Triple("Start offline", when { s.offlineAccount == null -> "sign in first"; s.offline -> "on"; else -> "off" }, a.onOffline),
Triple("Linux runtime", when {
// Setup: the same fold as Steam and Desktop. A row that holds a value opens a small menu
// in place; a row that opens a page lights up while the page is shown.
val menus = remember { MenuHost() }
val item: @Composable (String, String?, Int, String?, () -> Unit) -> Unit = { label, value, i, key, act ->
NavItem(label, key ?: "x", key != null && selected == key, small = true, tiny = true, muted = true, value = value, i = i, register = register, unregister = unregister) { act() }
}
NavItem("Setup", "x", false, caret = openSetup, count = 9, onClick = onToggleSetup)
Sub(openSetup) {
item("Files", null, 0, null, a.onFiles)
item("Desktop & apps", null, 1, null, a.onApps)
item("Compatibility tools", null, 2, null, a.onProtons)
Box {
item("Frame generation", s.frameGenLabel, 3, null) { menus.open = "fg" }
AnchoredMenu(
menus.open == "fg", onDismiss = { if (menus.open == "fg") menus.open = null }, title = "Frame generation",
note = "Extra frames between the real ones on the way to the screen, so 30 fps looks like 60. Takes effect at once, mid-game included.",
) {
val need = if (s.lsfgReady) null else "install Lossless Scaling in Steam"
MenuItem("Off", checked = s.frameGenEngine == FrameGen.ENGINE_OFF) { a.onFrameGenPick(FrameGen.ENGINE_OFF, 2); menus.open = null }
for (m in 2..4) MenuItem("Win-FG ${m}×", checked = s.frameGenEngine == FrameGen.ENGINE_WINFG && s.frameGenMultiplier == m) { a.onFrameGenPick(FrameGen.ENGINE_WINFG, m); menus.open = null }
for (m in 2..4) MenuItem("LSFG ${m}×", checked = s.frameGenEngine == FrameGen.ENGINE_LSFG && s.frameGenMultiplier == m, enabled = s.lsfgReady, detail = need) { a.onFrameGenPick(FrameGen.ENGINE_LSFG, m); menus.open = null }
}
}
item("Performance", null, 4, "performance", a.onPerformance)
item("ROMs folder", s.romsDir?.substringAfterLast('/')?.ifEmpty { s.romsDir } ?: "choose", 5, null, a.onRoms)
Box {
item("Session logs", if (s.logsEnabled) "on" else "off", 6, null) { menus.open = "logs" }
AnchoredMenu(
menus.open == "logs", onDismiss = { if (menus.open == "logs") menus.open = null }, title = "Session logs",
note = "Each session leaves a folder in Downloads: the guest log, the device and network reports, the app's own log.",
) {
MenuItem("On", checked = s.logsEnabled) { if (!s.logsEnabled) a.onLogs(); menus.open = null }
MenuItem("Off", checked = !s.logsEnabled) { if (s.logsEnabled) a.onLogs(); menus.open = null }
}
}
Box {
item("Start offline", when { s.offlineAccount == null -> "sign in first"; s.offline -> "on"; else -> "off" }, 7, null) { if (s.offlineAccount != null) menus.open = "offline" }
AnchoredMenu(
menus.open == "offline", onDismiss = { if (menus.open == "offline") menus.open = null }, title = "Start offline",
note = "The client starts as ${s.offlineAccount ?: "the saved account"} without the network: the library and installed games, no store.",
) {
MenuItem("On", checked = s.offline) { if (!s.offline) a.onOffline(); menus.open = null }
MenuItem("Off", checked = !s.offline) { if (s.offline) a.onOffline(); menus.open = null }
}
}
item("Linux runtime", when {
s.busy -> "working…"
!s.ready -> "install"
s.available != null && s.available != s.installed -> "update"
else -> "remove"
}, a.onRuntime),
)
NavItem("Setup", "x", false, caret = openSetup, count = setup.size, onClick = onToggleSetup)
Sub(openSetup) {
for ((i, t) in setup.withIndex()) {
val (label, value, act) = t
NavItem(label, "x", false, small = true, tiny = true, muted = true, value = value, i = i, register = { _, _ -> }, unregister = {}) { act() }
}
}, 8, null, a.onRuntime)
}
Text(
"credits", fontSize = 11.sp, color = colors.onSurfaceVariant,
@@ -481,9 +525,10 @@ private fun NavItem(
/** The chosen thing, behind a blurred wash of its own colour; a change sinks the old page out and cascades the new one in. */
@Composable
private fun Pane(s: FrontEndState, selected: String, a: FrontEndActions, modifier: Modifier) {
private fun Pane(s: FrontEndState, selected: String, a: FrontEndActions, page: (@Composable () -> Unit)?, modifier: Modifier) {
Box(modifier = modifier) {
val wash: Pair<File?, Float> = when {
s.pageKey != null && page != null -> null to 250f
selected == "steam" -> null to 268f
selected == "desktop" -> null to 200f
selected.startsWith("app:") -> s.steamGames.firstOrNull { "app:${it.appId}" == selected }.let { it?.art to hueOf(it?.name ?: "") }
@@ -493,14 +538,14 @@ private fun Pane(s: FrontEndState, selected: String, a: FrontEndActions, modifie
}
Backdrop(wash)
AnimatedContent(
targetState = selected,
targetState = if (page != null && s.pageKey != null) s.pageKey else selected,
transitionSpec = {
(fadeIn(Motion.tw(300, 80)) + slideInVertically(Motion.tw(420, 80)) { it / 24 })
.togetherWith(fadeOut(Motion.tw(170)) + slideOutVertically(Motion.tw(170)) { -it / 40 })
.apply { targetContentZIndex = 1f }
},
label = "pane",
) { key -> Content(s, key, a, Modifier.fillMaxSize()) }
) { key -> if (page != null && key == s.pageKey) page() else Content(s, key, a, Modifier.fillMaxSize()) }
}
}
@@ -657,7 +702,7 @@ private class Tile(val title: String, val sub: String, val art: File?, val key:
// ───────────────────────────── Type + small parts ─────────────────────────────
@Composable
private fun Eyebrow(t: String) {
internal fun Eyebrow(t: String) {
val colors = MaterialTheme.colorScheme
val rule = remember { Animatable(0f) }
LaunchedEffect(Unit) { rule.animateTo(1f, Motion.tw(600, 120)) }
@@ -666,8 +711,8 @@ private fun Eyebrow(t: String) {
Text(t.uppercase(), fontSize = 11.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp, color = colors.primary)
}
}
@Composable private fun Title(t: String) = Text(t, fontSize = 26.sp, fontWeight = FontWeight.Bold, color = MaterialTheme.colorScheme.onBackground, modifier = Modifier.padding(top = 4.dp, bottom = 4.dp))
@Composable private fun Lede(t: String) = Text(t, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(bottom = 12.dp))
@Composable internal fun Title(t: String) = Text(t, fontSize = 26.sp, fontWeight = FontWeight.Bold, color = MaterialTheme.colorScheme.onBackground, modifier = Modifier.padding(top = 4.dp, bottom = 4.dp))
@Composable internal fun Lede(t: String) = Text(t, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(bottom = 12.dp))
@Composable
private fun SectionTitle(t: String, detail: String?) {
val colors = MaterialTheme.colorScheme
@@ -719,7 +764,7 @@ private fun PrimaryButton(text: String, enabled: Boolean = true, onClick: () ->
}
@Composable
private fun SecondaryButton(text: String, enabled: Boolean = true, onClick: () -> Unit) {
internal fun SecondaryButton(text: String, enabled: Boolean = true, onClick: () -> Unit) {
val colors = MaterialTheme.colorScheme
val src = remember { MutableInteractionSource() }
val hot = rememberHot(src) && enabled
@@ -1,49 +1,23 @@
package com.steamdeck.launcher.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Surface
import androidx.compose.material3.VerticalDivider
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.steamdeck.launcher.session.SessionPrefs
import com.steamdeck.launcher.session.SessionService
/** One driver as the dialog shows it. [removable] is false for the runtime's own and the bundled builds. */
/** One driver as the page shows it. [removable] is false for the runtime's own and the bundled builds. */
class DriverRow(val id: String, val name: String, val detail: String, val removable: Boolean)
/** Everything one mode's settings dialog shows; the activity owns the values. */
/** Everything one mode's settings page shows; the activity owns the values. */
class ModeSettings(
val mode: String,
val resolutionCap: Int,
@@ -87,249 +61,140 @@ class ModeSettingsActions(
val onDismiss: () -> Unit,
)
/** One entry of the settings window's rail. */
private class SettingsSection(val key: String, val label: String)
/**
* The cog beside Play / Desktop: a settings window with a rail of sections down the left and the
* chosen section on the right, so each setting is found by name rather than by scrolling past
* every other one. What only matters for that one mode lives here - the display the session is
* sized to, HDR, the driver inside the runtime, the display driver, and the input and audio
* choices - so the main screen is left with what applies to both.
* The cog beside Play / Desktop: a page in the front end's pane, one row per setting with its
* value in a chip, and a small menu under the chip to change it. What only matters for that one
* mode lives here - the display the session is sized to, HDR, the driver inside the runtime,
* the display driver, and the input and audio choices - so the rail keeps what applies to both.
*/
@Composable
fun ModeSettingsDialog(s: ModeSettings, a: ModeSettingsActions) {
fun ModeSettingsPage(s: ModeSettings, a: ModeSettingsActions) {
val steam = s.mode == SessionService.MODE_STEAM
val sections = remember(steam) {
buildList {
add(SettingsSection("display", "Display"))
add(SettingsSection("hdr", "HDR"))
add(SettingsSection("runtime", "Runtime driver"))
add(SettingsSection("panel", "Display driver"))
add(SettingsSection("touch", if (steam) "Touch & controls" else "Touch"))
if (steam) add(SettingsSection("audio", "Audio"))
if (steam) add(SettingsSection("storage", "Game storage"))
if (!steam) add(SettingsSection("renderer", "Renderer"))
}
}
var selected by rememberSaveable(s.mode) { mutableStateOf("display") }
val host = rememberMenuHost()
val colors = MaterialTheme.colorScheme
Dialog(onDismissRequest = a.onDismiss, properties = DialogProperties(usePlatformDefaultWidth = false)) {
Surface(
shape = RoundedCornerShape(16.dp),
color = colors.surface,
tonalElevation = 2.dp,
modifier = Modifier.fillMaxWidth(0.94f).fillMaxHeight(0.86f),
) {
Column(modifier = Modifier.fillMaxSize()) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(start = 20.dp, end = 8.dp, top = 12.dp, bottom = 6.dp),
) {
Text(if (steam) "Steam session" else "Desktop session", style = MaterialTheme.typography.titleMedium, modifier = Modifier.weight(1f))
TextButton(onClick = a.onDismiss) { Text("Done") }
}
HorizontalDivider()
Row(modifier = Modifier.weight(1f).fillMaxWidth()) {
// The rail: one entry per section, the chosen one filled.
Column(
modifier = Modifier
.width(132.dp)
.fillMaxHeight()
.background(colors.surfaceVariant.copy(alpha = 0.35f))
.verticalScroll(rememberScrollState())
.padding(vertical = 6.dp),
SettingsPage(
host,
eyebrow = if (steam) "Steam · settings" else "Desktop · settings",
title = if (steam) "Steam session" else "Desktop session",
lede = "Each value opens where it is. Most take effect at the next session start; the ones that need the app closed say so.",
onBack = a.onDismiss,
) {
SettingsGroup("Display") {
val default = SessionPrefs.defaultResolutionCap(s.mode)
ChoiceRow(
host, "res", "Resolution", "Takes effect at the next session: gamescope sizes its display once, when it starts.",
listOf(720 to "Up to 720p", 900 to "Up to 900p", 1080 to "Up to 1080p", 0 to "The panel's own")
.map { (cap, label) -> cap to (if (cap == default) "$label — the default" else label) },
s.resolutionCap, note = "720p keeps the client's menus responsive; above 1080p costs frames for nothing a handheld can show.",
onPick = a.onResolution,
)
ChoiceRow(
host, "shape", "Shape", "16:9 is for a foldable: bars on either panel instead of a squashed picture.",
listOf("auto" to "The panel's shape", "16:9" to "16:9 with bars"), s.shapeMode, onPick = a.onShape,
)
}
SettingsGroup("HDR") {
ToggleRow(
host, "hdr", "HDR10 output",
s.hdrReason?.let { "Not available: $it." }
?: "Decided once when the compositor starts: a change applies after the app is fully closed and opened again.",
checked = s.hdr && s.hdrReason == null, enabled = s.hdrReason == null, onChange = a.onHdr,
)
}
SettingsGroup("Drivers") {
DriverRowMenu(
host, "rt", "Runtime driver",
"What " + (if (steam) "the Steam client and its games" else "the desktop's programs") + " render with inside the runtime. Applies at the next session start.",
s.linuxRows, s.linuxSelected, importLabel = "Import a \"-Linux\" Turnip zip…",
onSelect = a.onSelectLinux, onRemove = a.onRemoveLinux, onImport = a.onImportLinux,
)
DriverRowMenu(
host, "panel", "Display driver",
"What the app's compositor puts frames on the screen with; shared by both modes. Applies after the app is fully closed and opened again.",
s.androidRows, s.androidSelected, importLabel = "Import an AdrenoTools zip…",
onSelect = a.onSelectAndroid, onRemove = a.onRemoveAndroid, onImport = a.onImportAndroid,
)
}
SettingsGroup(if (steam) "Touch & controls" else "Touch") {
ChoiceRow(
host, "touch", "Touch", "How a finger drives the pointer. Also in the session's drawer.",
listOf("auto" to "Auto", "touchpad" to "Touchpad", "direct" to "Direct"), s.touchMode,
note = "Auto: touchpad on the desktop, direct in Steam. Touchpad: drag moves, tap clicks. Direct: the pointer jumps under the finger.",
onPick = a.onTouch,
)
if (steam && s.oscMode != null) ChoiceRow(
host, "osc", "On-screen controls", "The virtual pad drawn over a game.",
listOf("auto" to "Auto", "always" to "Always", "never" to "Never"), s.oscMode,
note = "Auto shows it when no controller is attached.", onPick = a.onOsc,
)
}
if (steam && s.directAudio != null && s.mic != null) SettingsGroup("Audio") {
ToggleRow(host, "da", "DirectAudio for games", "Games play straight to the device, bypassing PulseAudio: lower latency. Off = PulseAudio for everything.", s.directAudio, onChange = a.onDirectAudio)
ToggleRow(host, "mic", "Microphone", "The device's microphone for voice chat, as the client's input device. Asks for the permission once.", s.mic, onChange = a.onMic)
}
if (steam && s.gameStorage != null) SettingsGroup("Game storage") {
val custom = s.gameStorage.isNotEmpty() && s.gameStorage != "off" && s.storageOptions.none { it.second == s.gameStorage }
val options = buildList {
add("" to ("Automatic — the SD card when one is in" + (if (s.storageOptions.isEmpty()) " (none right now)" else "")))
add("off" to "Internal only")
for ((label, path) in s.storageOptions) add(path to label)
if (custom) add(s.gameStorage to "Folder: ${s.gameStorage}")
}
val open = host.open == "storage"
SettingsRow(
"Second library",
"With a second place registered, every Install in Steam asks which drive, Settings › Storage lists both, and Steam moves games between them. Applies at the next session start.",
highlighted = open,
) {
androidx.compose.foundation.layout.Box {
ValueChip(options.firstOrNull { it.first == s.gameStorage }?.second?.substringBefore(" —") ?: "—", open) { host.open = if (open) null else "storage" }
AnchoredMenu(
open, onDismiss = { if (host.open == "storage") host.open = null }, title = "Second library",
note = "An SD card and shared storage go through Android's file layer: a game that streams big assets from there can stall. Keep such games internal.",
) {
sections.forEach { section ->
val on = section.key == selected
Text(
section.label,
style = MaterialTheme.typography.bodyMedium,
color = if (on) colors.onPrimary else colors.onSurface,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 6.dp, vertical = 2.dp)
.clip(RoundedCornerShape(8.dp))
.background(if (on) colors.primary else Color.Transparent)
.clickable { selected = section.key }
.padding(horizontal = 10.dp, vertical = 9.dp),
)
}
}
VerticalDivider()
// The chosen section alone, scrolling only if it must.
Column(
modifier = Modifier
.weight(1f)
.fillMaxHeight()
.verticalScroll(rememberScrollState())
.padding(horizontal = 16.dp, vertical = 10.dp),
) {
when (selected) {
"display" -> {
Section("Display", "Takes effect at the next session: gamescope sizes its display once, when it starts.")
Text("Resolution", style = MaterialTheme.typography.labelLarge, modifier = Modifier.padding(top = 8.dp))
val default = SessionPrefs.defaultResolutionCap(s.mode)
listOf(
1080 to "Up to 1080p",
900 to "Up to 900p",
720 to "Up to 720p — lighter on the GPU, menus stay responsive",
0 to "The panel's own — above 1080p costs frames for nothing a handheld can show",
).forEach { (cap, label) ->
Choice(if (cap == default) "$label — the default" else label, s.resolutionCap == cap) { a.onResolution(cap) }
}
Text("Shape", style = MaterialTheme.typography.labelLarge, modifier = Modifier.padding(top = 10.dp))
Choice("The panel's shape (never narrower than 16:9)", s.shapeMode == "auto") { a.onShape("auto") }
Choice("16:9 — for a foldable, with bars on either panel", s.shapeMode == "16:9") { a.onShape("16:9") }
}
"hdr" -> {
Section("HDR10 output", "Decided once, when the compositor starts: a change applies after the app is fully closed and opened again.")
Spacer(Modifier.height(6.dp))
SwitchRow(
"HDR10 output",
s.hdrReason?.let { "Not available: $it." }
?: (if (steam) "The compositor offers games HDR10 and gamescope passes it on; a game that renders HDR shows as HDR on the panel."
else "Offered to the desktop's programs; labwc itself composites in SDR, so only a program that presents HDR directly shows it."),
checked = s.hdr && s.hdrReason == null, enabled = s.hdrReason == null, onChange = a.onHdr,
)
}
"runtime" -> {
Section(
"Linux runtime driver",
"What " + (if (steam) "the Steam client and its games" else "the desktop's programs") +
" render on, inside the runtime. \"-Linux\" Turnip zips only. Applies at the next session start.",
)
Spacer(Modifier.height(6.dp))
for (row in s.linuxRows) DriverChoice(row, row.id == s.linuxSelected, { a.onSelectLinux(row.id) }, { a.onRemoveLinux(row.id) })
OutlinedButton(onClick = a.onImportLinux, modifier = Modifier.fillMaxWidth().padding(top = 8.dp)) {
Text("Import \"-Linux\" Turnip zip…")
}
}
"panel" -> {
Section(
"Display driver (Android)",
"What the app's compositor puts frames on the screen with, the last step of every session; shared by both modes. " +
"AdrenoTools zips only. Applies after the app is fully closed and opened again.",
)
Spacer(Modifier.height(6.dp))
for (row in s.androidRows) DriverChoice(row, row.id == s.androidSelected, { a.onSelectAndroid(row.id) }, { a.onRemoveAndroid(row.id) })
OutlinedButton(onClick = a.onImportAndroid, modifier = Modifier.fillMaxWidth().padding(top = 8.dp)) {
Text("Import AdrenoTools zip…")
}
}
"touch" -> {
Section("Touch", "How a finger drives the pointer. Also in the session's drawer.")
Spacer(Modifier.height(4.dp))
Choice("Auto — touchpad on the desktop, direct in Steam", s.touchMode == "auto") { a.onTouch("auto") }
Choice("Touchpad — drag moves the pointer, tap clicks", s.touchMode == "touchpad") { a.onTouch("touchpad") }
Choice("Direct — the pointer jumps under the finger", s.touchMode == "direct") { a.onTouch("direct") }
if (steam && s.oscMode != null) {
Spacer(Modifier.height(12.dp))
Section("On-screen controls", "The virtual pad drawn over a game.")
Spacer(Modifier.height(4.dp))
Choice("Auto — shown when no controller is attached", s.oscMode == "auto") { a.onOsc("auto") }
Choice("Always", s.oscMode == "always") { a.onOsc("always") }
Choice("Never", s.oscMode == "never") { a.onOsc("never") }
}
}
"audio" -> if (s.directAudio != null && s.mic != null) {
Section("Audio", "Both apply at the next session start.")
Spacer(Modifier.height(4.dp))
SwitchRow(
"DirectAudio for games",
"Games play straight to the device, bypassing PulseAudio: lower latency. Off = PulseAudio for everything.",
s.directAudio, true, a.onDirectAudio,
)
SwitchRow(
"Microphone",
"The device's microphone for voice chat, as the client's input device. Asks for the permission once.",
s.mic, true, a.onMic,
)
}
"storage" -> if (s.gameStorage != null) {
Section(
"Game storage",
"The choice itself is made inside Steam: with a second place registered, every Install asks which " +
"drive, Settings › Storage lists both, and Steam moves games between them. Internal is the " +
"client's own library and always there. Applies at the next session start.",
)
Spacer(Modifier.height(6.dp))
Choice(
"Automatic — the SD card when one is in the phone" +
(if (s.storageOptions.isEmpty()) " (none right now)" else ""),
s.gameStorage.isEmpty(),
) { a.onGameStorage("", "") }
Choice("Internal only", s.gameStorage == "off") { a.onGameStorage("off", "") }
for ((label, path) in s.storageOptions) {
Choice(label, s.gameStorage == path) { a.onGameStorage(path, label.substringBefore(" ·")) }
}
val custom = s.gameStorage.isNotEmpty() && s.gameStorage != "off" && s.storageOptions.none { it.second == s.gameStorage }
if (custom) Choice("Folder: ${s.gameStorage}", true) {}
OutlinedButton(onClick = a.onPickGameStorageFolder, modifier = Modifier.fillMaxWidth().padding(top = 8.dp)) {
Text("Choose a folder…")
}
Spacer(Modifier.height(8.dp))
Text(
"Slow for streaming: an SD card and the phone's shared storage go through Android's file layer, " +
"and a game that streams video or big assets from there can stall. Keep such games internal; " +
"use the second place for size. On a card, the app may write only inside its own folder, which " +
"is the one offered.",
style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
"renderer" -> if (s.renderer != null) {
Section(
"Desktop renderer",
"How labwc composites the desktop. pixman is software and works everywhere; gles2 / vulkan need a real DRM render node, which the Adreno stand-in is not on most devices.",
)
Spacer(Modifier.height(4.dp))
Choice("pixman — software, the default", s.renderer == "pixman") { a.onRenderer("pixman") }
Choice("gles2", s.renderer == "gles2") { a.onRenderer("gles2") }
Choice("vulkan", s.renderer == "vulkan") { a.onRenderer("vulkan") }
}
for ((path, label) in options) MenuItem(label, checked = path == s.gameStorage) {
a.onGameStorage(path, if (path.isEmpty() || path == "off") "" else label.substringBefore(" ·"))
host.open = null
}
MenuItem("Choose a folder…", checked = false) { host.open = null; a.onPickGameStorageFolder() }
}
}
}
}
}
}
@Composable
private fun Section(title: String, detail: String?) {
Text(title, style = MaterialTheme.typography.titleSmall)
if (detail != null) Text(detail, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
@Composable
private fun Choice(label: String, selected: Boolean, onClick: () -> Unit) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
RadioButton(selected = selected, onClick = onClick)
Text(label, style = MaterialTheme.typography.bodyMedium, modifier = Modifier.weight(1f))
}
}
@Composable
private fun SwitchRow(label: String, detail: String, checked: Boolean, enabled: Boolean, onChange: (Boolean) -> Unit) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
Column(modifier = Modifier.weight(1f)) {
Text(label, style = MaterialTheme.typography.bodyMedium)
Text(detail, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
if (!steam && s.renderer != null) SettingsGroup("Renderer") {
ChoiceRow(
host, "renderer", "Desktop renderer", "How labwc composites the desktop. pixman is software and works everywhere.",
listOf("pixman" to "pixman — software", "gles2" to "gles2", "vulkan" to "vulkan"), s.renderer,
note = "gles2 and vulkan need a real DRM render node, which the Adreno stand-in is not on most devices.", onPick = a.onRenderer,
)
}
Switch(checked = checked, enabled = enabled, onCheckedChange = onChange)
Spacer(Modifier.height(8.dp))
Text("Values are saved as they are picked; there is nothing to confirm.", fontSize = 11.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 10.dp))
}
}
/** A driver list as a menu: each build a line, imported ones with a remove control, an import at the end. */
@Composable
private fun DriverChoice(row: DriverRow, selected: Boolean, onSelect: () -> Unit, onRemove: () -> Unit) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 2.dp)) {
RadioButton(selected = selected, onClick = onSelect)
Column(modifier = Modifier.weight(1f)) {
Text(row.name, style = MaterialTheme.typography.bodyMedium)
if (row.detail.isNotEmpty()) Text(row.detail, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
if (row.removable) TextButton(onClick = onRemove, contentPadding = PaddingValues(0.dp)) {
Text("Remove", style = MaterialTheme.typography.labelSmall)
private fun DriverRowMenu(
host: MenuHost, key: String, label: String, hint: String, rows: List<DriverRow>, selected: String, importLabel: String,
onSelect: (String) -> Unit, onRemove: (String) -> Unit, onImport: () -> Unit,
) {
val open = host.open == key
val colors = MaterialTheme.colorScheme
SettingsRow(label, hint, highlighted = open) {
androidx.compose.foundation.layout.Box {
ValueChip(rows.firstOrNull { it.id == selected }?.name ?: rows.firstOrNull()?.name ?: "—", open) { host.open = if (open) null else key }
AnchoredMenu(open, onDismiss = { if (host.open == key) host.open = null }, title = label) {
for (row in rows) MenuItem(
row.name, checked = row.id == selected, detail = row.detail.ifEmpty { null },
trailing = if (row.removable) ({
Text(
"✕", fontSize = 12.sp, color = colors.onSurfaceVariant,
modifier = Modifier.size(24.dp).padding(4.dp).clickable { onRemove(row.id); host.open = null },
)
}) else null,
) { onSelect(row.id); host.open = null }
MenuItem(importLabel, checked = false) { host.open = null; onImport() }
}
}
}
@@ -1,35 +1,33 @@
package com.steamdeck.launcher.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Checkbox
import androidx.compose.material3.HorizontalDivider
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
/** One core as the dialog labels it: its number and, where known, its ceiling. */
/** One core as the page labels it: its number and, where known, its ceiling. */
class CoreRow(val core: Int, val label: String)
/**
* The two core masks a Steam session carries, kept separate because they are wanted at the same
* time and suit different things: the client's menus and a game each get their own. Both apply
* at the next session start; the game's is applied by the Proton wrapper at each launch.
* at the next session start; the game's is applied by the Proton wrapper at each launch. Below
* them, the session fixes for a device the runtime does not sit well on.
*/
@Composable
fun PerformanceDialog(
fun PerformancePage(
cores: List<CoreRow>,
clientOverride: Boolean,
clientCores: Set<Int>,
@@ -48,121 +46,63 @@ fun PerformanceDialog(
onGameCore: (Int, Boolean) -> Unit,
onDismiss: () -> Unit,
) {
AlertDialog(
onDismissRequest = onDismiss,
title = { Text("Performance") },
text = {
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
Text("Steam client cores", style = MaterialTheme.typography.titleSmall)
Text(
"Steam pins its own interface to a subset of cores it chooses — on one device 5 of 8, leaving out the fastest — " +
"which suits a running game and makes the menus sluggish when the client is all there is. Turning this on " +
"pins the client, its UI helper and gamescope to the cores ticked below instead, re-applied every few seconds " +
"because the UI keeps spawning helpers that inherit Steam's choice. Every core ticked is the usual fix.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
Text("Override Steam's own core choice", style = MaterialTheme.typography.bodyMedium, modifier = Modifier.weight(1f))
Switch(checked = clientOverride, onCheckedChange = onClientOverride)
}
CoreGrid(cores, clientCores, enabled = clientOverride, onToggle = onClientCore)
Spacer(Modifier.height(12.dp))
HorizontalDivider()
Spacer(Modifier.height(10.dp))
Text("Game cores", style = MaterialTheme.typography.titleSmall)
Text(
"The cores a game the client launches may run on, applied by exec'ing it through taskset so every thread " +
"inherits the mask from its first instruction. Leaving every core ticked sends nothing — that is what the " +
"scheduler does unaided. Untick the small cores to keep a heavy game off them.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Spacer(Modifier.height(4.dp))
CoreGrid(cores, gameCores, enabled = true, onToggle = onGameCore)
Spacer(Modifier.height(12.dp))
HorizontalDivider()
Spacer(Modifier.height(10.dp))
Text("Session fixes", style = MaterialTheme.typography.titleSmall)
Text(
"For a device the runtime does not sit well on, tried one at a time. All apply at the next session start.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
Column(modifier = Modifier.weight(1f)) {
Text("Turnip: sysmem rendering", style = MaterialTheme.typography.bodyMedium)
Text(
"Renders without the GPU's tile memory (TU_DEBUG=sysmem). A fix for an Adreno 8xx that shows corruption, and required on a 710/720/722 (set on its own there). Not a speed setting: on every other GPU it turns tiled rendering off and COSTS frames - leave it off unless the picture is wrong.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
Switch(checked = tuSysmem, onCheckedChange = onTuSysmem)
}
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
Column(modifier = Modifier.weight(1f)) {
Text("Zink: lazy descriptors", style = MaterialTheme.typography.bodyMedium)
Text(
"The Steam client's menus are drawn through Zink (GL on Vulkan). Lazy descriptor updates (ZINK_DESCRIPTORS=lazy) is the mode Zink recommends on drivers without descriptor buffers, and the first thing to try when the menus are slow while games are fast.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
Switch(checked = zinkLazy, onCheckedChange = onZinkLazy)
}
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
Column(modifier = Modifier.weight(1f)) {
Text("Skip Steam's xalia helper", style = MaterialTheme.typography.bodyMedium)
Text(
"xalia is a Windows program Proton starts to give Windows programs gamepad navigation. On some devices its system calls are refused in a way it cannot cope with, and the session dies seconds after Big Picture appears — 89 refusals then a broken pipe, in the session log. Turn this on if a session will not stay up. Costs gamepad navigation in Windows programs that are not games.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
Switch(checked = noXalia, onCheckedChange = onNoXalia)
}
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
Column(modifier = Modifier.weight(1f)) {
Text("Run proot without seccomp", style = MaterialTheme.typography.bodyMedium)
Text(
"proot normally lets most system calls run untraced, which is most of its speed. Some kernels handle that badly and refuse calls that plainly exist — the log fills with \"Function not implemented\" where it makes no sense. This traces everything instead: slower, but correct. Try it if a session will not start or dies with those errors.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
Switch(checked = prootNoSeccomp, onCheckedChange = onProotNoSeccomp)
}
if (phantomWarning != null) {
Spacer(Modifier.height(10.dp))
Text("Android is set to kill this session", style = MaterialTheme.typography.titleSmall, color = MaterialTheme.colorScheme.error)
Text(
phantomWarning,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
val host = rememberMenuHost()
val colors = MaterialTheme.colorScheme
val coreItems = cores.map { it.core to it.label }
SettingsPage(
host, eyebrow = "Setup · performance", title = "Performance",
lede = "Which cores the client and its games may run on, and the fixes for a device the runtime does not sit well on. All apply at the next session start.",
onBack = onDismiss,
) {
SettingsGroup("Steam client cores") {
ToggleRow(
host, "override", "Override Steam's own core choice",
"Steam pins its interface to a subset of cores it picks — on one device 5 of 8, leaving out the fastest — which suits a running game and makes the menus sluggish when the client is all there is. On: the client, its UI helper and gamescope are pinned to the cores below instead, re-applied every few seconds.",
clientOverride, onChange = onClientOverride,
)
MultiRow(
host, "clientCores", "Client cores", if (clientOverride) "Every core ticked is the usual fix." else "Turn the override on to choose.",
coreItems, clientCores, enabled = clientOverride, note = "Tick or untick as many as you like; the menu stays open.", onToggle = onClientCore,
)
}
SettingsGroup("Game cores") {
MultiRow(
host, "gameCores", "Game cores",
"Applied by exec'ing the game through taskset, so every thread inherits the mask. Every core ticked sends nothing — that is what the scheduler does unaided. Untick the small cores to keep a heavy game off them.",
coreItems, gameCores, note = "Tick or untick as many as you like; the menu stays open.", onToggle = onGameCore,
)
}
SettingsGroup("Session fixes") {
ToggleRow(
host, "sysmem", "Turnip: sysmem rendering",
"Renders without the GPU's tile memory (TU_DEBUG=sysmem). A fix for an Adreno 8xx that shows corruption, and required on a 710/720/722 (set on its own there). Not a speed setting: elsewhere it COSTS frames — leave it off unless the picture is wrong.",
tuSysmem, onChange = onTuSysmem,
)
ToggleRow(
host, "zink", "Zink: lazy descriptors",
"The client's menus are drawn through Zink (GL on Vulkan). Lazy descriptor updates is the mode Zink recommends on drivers without descriptor buffers, and the first thing to try when the menus are slow while games are fast.",
zinkLazy, onChange = onZinkLazy,
)
ToggleRow(
host, "xalia", "Skip Steam's xalia helper",
"xalia is a Windows program Proton starts for gamepad navigation in Windows programs. On some devices its system calls are refused in a way it cannot cope with and the session dies seconds after Big Picture appears. Turn on if a session will not stay up.",
noXalia, onChange = onNoXalia,
)
ToggleRow(
host, "seccomp", "Run proot without seccomp",
"proot normally lets most system calls run untraced, which is most of its speed. Some kernels handle that badly and refuse calls that plainly exist (\"Function not implemented\" in the log). This traces everything: slower, but correct.",
prootNoSeccomp, onChange = onProotNoSeccomp,
)
}
if (phantomWarning != null) {
Spacer(Modifier.height(16.dp))
Column(
modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(12.dp)).background(colors.error.copy(alpha = 0.08f))
.border(1.dp, colors.error.copy(alpha = 0.4f), RoundedCornerShape(12.dp)).padding(12.dp),
) {
Text("Android is set to kill this session", fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = colors.error)
Text(phantomWarning, fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 4.dp))
}
},
confirmButton = { TextButton(onClick = onDismiss) { Text("OK") } },
)
}
@Composable
private fun CoreGrid(cores: List<CoreRow>, selected: Set<Int>, enabled: Boolean, onToggle: (Int, Boolean) -> Unit) {
for (row in cores.chunked(2)) {
Row(modifier = Modifier.fillMaxWidth()) {
for (c in row) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.weight(1f)) {
Checkbox(checked = c.core in selected, enabled = enabled, onCheckedChange = { onToggle(c.core, it) })
Text(c.label, style = MaterialTheme.typography.bodySmall)
}
}
if (row.size == 1) Spacer(Modifier.weight(1f))
}
}
}
@@ -0,0 +1,306 @@
package com.steamdeck.launcher.ui
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsFocusedAsState
import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntRect
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupPositionProvider
import androidx.compose.ui.window.PopupProperties
/*
* Settings without a pop-up: a page of rows, each with its value in a chip on the right, and a
* small faded menu that opens right under the chip when it is tapped. One menu at a time per
* page; the rest of the page dims a little while it is open.
*/
private val RowShape = RoundedCornerShape(12.dp)
private val GroupShape = RoundedCornerShape(14.dp)
private val Line = Color(0xFF26303C)
private val Line2 = Color(0xFF33404F)
/** Which row's menu is open on a page, so the page can dim and only one menu shows. */
class MenuHost {
var open by mutableStateOf<String?>(null)
}
@Composable
fun rememberMenuHost(): MenuHost = remember { MenuHost() }
/** Under the anchor, right edges aligned; above it when the bottom of the window is too close. */
private class BelowEndProvider(private val gap: Int) : PopupPositionProvider {
override fun calculatePosition(anchorBounds: IntRect, windowSize: IntSize, layoutDirection: LayoutDirection, popupContentSize: IntSize): IntOffset {
var x = anchorBounds.right - popupContentSize.width
if (x < 8) x = 8
var y = anchorBounds.bottom + gap
if (y + popupContentSize.height > windowSize.height - 8) y = anchorBounds.top - gap - popupContentSize.height
if (y < 8) y = 8
return IntOffset(x, y)
}
}
/**
* The menu itself, anchored to whatever composable it is placed inside (put it in the same Box as
* the chip). It fades and scales in from its top-right corner and out again on dismiss; the popup
* is only removed once the exit has finished.
*/
@Composable
fun AnchoredMenu(open: Boolean, onDismiss: () -> Unit, title: String? = null, note: String? = null, content: @Composable ColumnScope.() -> Unit) {
val state = remember { MutableTransitionState(false) }
state.targetState = open
if (!state.currentState && !state.targetState && state.isIdle) return
val gap = with(LocalDensity.current) { 6.dp.roundToPx() }
val provider = remember(gap) { BelowEndProvider(gap) }
val colors = MaterialTheme.colorScheme
Popup(popupPositionProvider = provider, onDismissRequest = onDismiss, properties = PopupProperties(focusable = true)) {
AnimatedVisibility(
visibleState = state,
enter = fadeIn(Motion.tw(180)) + scaleIn(Motion.sp(0.7f), initialScale = 0.94f, transformOrigin = TransformOrigin(1f, 0f)),
exit = fadeOut(Motion.tw(140)) + scaleOut(Motion.tw(140), targetScale = 0.96f, transformOrigin = TransformOrigin(1f, 0f)),
label = "menu",
) {
Column(
modifier = Modifier
.widthIn(min = 220.dp, max = 340.dp)
.shadow(24.dp, RowShape, ambientColor = Color.Black, spotColor = Color.Black)
.clip(RowShape)
.background(Color(0xF21E2530))
.border(1.dp, colors.primary.copy(alpha = 0.22f), RowShape)
.padding(6.dp),
) {
if (title != null) Text(
title.uppercase(), fontSize = 10.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp, color = colors.onSurfaceVariant,
modifier = Modifier.padding(start = 10.dp, top = 6.dp, bottom = 6.dp),
)
content()
if (note != null) {
Spacer(Modifier.height(4.dp))
Box(Modifier.fillMaxWidth().height(1.dp).background(Line))
Text(note, fontSize = 11.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 10.dp, vertical = 6.dp))
}
}
}
}
}
/** One line of a menu: a check mark when it is the current value, a label, an optional second line. */
@Composable
fun MenuItem(
label: String, checked: Boolean, enabled: Boolean = true, detail: String? = null,
trailing: (@Composable () -> Unit)? = null, onClick: () -> Unit,
) {
val colors = MaterialTheme.colorScheme
val src = remember { MutableInteractionSource() }
val hot = src.collectIsFocusedAsState().value || src.collectIsHoveredAsState().value
val shift by animateFloatAsState(if (hot) 2f else 0f, Motion.sp(0.5f), label = "miShift")
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
.graphicsLayer { translationX = shift.dp.toPx() }
.clip(RoundedCornerShape(8.dp))
.background(if (hot && enabled) Color.White.copy(alpha = 0.07f) else Color.Transparent)
.alpha(if (enabled) 1f else 0.4f)
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, enabled = enabled, onClick = onClick)
.padding(horizontal = 10.dp, vertical = 9.dp),
) {
Text("✓", fontSize = 12.sp, color = colors.primary, modifier = Modifier.width(18.dp).alpha(if (checked) 1f else 0f))
Column(modifier = Modifier.weight(1f)) {
Text(label, fontSize = 13.5.sp, color = if (checked) colors.primary else colors.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis)
if (detail != null) Text(detail, fontSize = 11.sp, color = colors.onSurfaceVariant, maxLines = 2, overflow = TextOverflow.Ellipsis)
}
if (trailing != null) { Spacer(Modifier.width(8.dp)); trailing() }
}
}
/** The value on the right of a row: the current choice and a caret that turns while the menu is open. */
@Composable
fun ValueChip(text: String, open: Boolean, enabled: Boolean = true, onClick: () -> Unit) {
val colors = MaterialTheme.colorScheme
val src = remember { MutableInteractionSource() }
val hot = src.collectIsFocusedAsState().value || src.collectIsHoveredAsState().value
val edge by animateColorAsState(if (open || hot) colors.primary else Line2, Motion.tw(200), label = "chipEdge")
val rot by animateFloatAsState(if (open) 180f else 0f, Motion.sp(0.6f), label = "chipCaret")
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier
.widthIn(min = 150.dp)
.clip(RoundedCornerShape(10.dp))
.background(colors.surfaceVariant)
.border(1.dp, edge, RoundedCornerShape(10.dp))
.alpha(if (enabled) 1f else 0.5f)
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, enabled = enabled, onClick = onClick)
.padding(horizontal = 12.dp, vertical = 8.dp),
) {
AnimatedContent(
targetState = text,
transitionSpec = { (fadeIn(Motion.tw(260)) + slideInVertically(Motion.tw(260)) { it / 2 }) togetherWith (fadeOut(Motion.tw(160)) + slideOutVertically(Motion.tw(160)) { -it / 2 }) },
label = "chipText",
) { t -> Text(t, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) }
Spacer(Modifier.width(8.dp))
Text("▾", fontSize = 10.sp, color = colors.onSurfaceVariant, modifier = Modifier.rotate(rot))
}
}
/** A group of rows on one surface, with a section label above it. */
@Composable
fun SettingsGroup(title: String, content: @Composable ColumnScope.() -> Unit) {
val colors = MaterialTheme.colorScheme
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().padding(top = 16.dp, bottom = 6.dp)) {
Text(title.uppercase(), fontSize = 11.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp, color = colors.onSurfaceVariant)
Box(modifier = Modifier.weight(1f).height(1.dp).background(Line))
}
Column(modifier = Modifier.fillMaxWidth().clip(GroupShape).background(colors.surface).border(1.dp, Line, GroupShape)) { content() }
}
/** A row: label and hint on the left, whatever control on the right. */
@Composable
fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, control: @Composable () -> Unit) {
val colors = MaterialTheme.colorScheme
val bg by animateColorAsState(if (highlighted) colors.primary.copy(alpha = 0.10f) else Color.Transparent, Motion.tw(200), label = "rowBg")
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().background(bg).padding(horizontal = 14.dp, vertical = 11.dp),
) {
Column(modifier = Modifier.weight(1f).padding(end = 12.dp)) {
Text(label, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground)
if (hint != null) Text(hint, fontSize = 11.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 2.dp))
}
control()
}
Box(Modifier.fillMaxWidth().height(1.dp).background(Line))
}
/** A row whose value is one of a list: the chip opens the menu, a pick closes it. */
@Composable
fun <T> ChoiceRow(
host: MenuHost, key: String, label: String, hint: String?,
options: List<Pair<T, String>>, selected: T, enabled: Boolean = true, note: String? = null,
onPick: (T) -> Unit,
) {
val open = host.open == key
SettingsRow(label, hint, highlighted = open) {
Box {
ValueChip(options.firstOrNull { it.first == selected }?.second ?: "—", open, enabled) { host.open = if (open) null else key }
AnchoredMenu(open, onDismiss = { if (host.open == key) host.open = null }, title = label, note = note) {
for ((value, text) in options) MenuItem(text, checked = value == selected) { onPick(value); host.open = null }
}
}
}
}
/** On or off, as a two-line menu, so every row on the page behaves the same way under a pad. */
@Composable
fun ToggleRow(host: MenuHost, key: String, label: String, hint: String?, checked: Boolean, enabled: Boolean = true, onChange: (Boolean) -> Unit) =
ChoiceRow(host, key, label, hint, listOf(true to "On", false to "Off"), checked, enabled, onPick = onChange)
/** Several of a list at once (the core masks): the menu stays open while boxes are ticked. */
@Composable
fun MultiRow(
host: MenuHost, key: String, label: String, hint: String?,
items: List<Pair<Int, String>>, selected: Set<Int>, enabled: Boolean = true, note: String? = null,
onToggle: (Int, Boolean) -> Unit,
) {
val open = host.open == key
val summary = when {
selected.size >= items.size -> "All ${items.size}"
selected.isEmpty() -> "None"
else -> "${selected.size} of ${items.size}"
}
SettingsRow(label, hint, highlighted = open) {
Box {
ValueChip(summary, open, enabled) { host.open = if (open) null else key }
AnchoredMenu(open, onDismiss = { if (host.open == key) host.open = null }, title = label, note = note) {
for ((value, text) in items) {
val on = value in selected
MenuItem(text, checked = on) { onToggle(value, !on) }
}
}
}
}
}
/** A row that does something (import, choose a folder) instead of holding a value. */
@Composable
fun ActionRow(label: String, hint: String?, button: String, onClick: () -> Unit) {
SettingsRow(label, hint) { SecondaryButton(button, onClick = onClick) }
}
/** A page: eyebrow with a way back, title, lede, and the rows below it, dimmed while a menu is open. */
@Composable
fun SettingsPage(host: MenuHost, eyebrow: String, title: String, lede: String, onBack: () -> Unit, content: @Composable ColumnScope.() -> Unit) {
val colors = MaterialTheme.colorScheme
val dim by animateFloatAsState(if (host.open != null) 0.6f else 1f, Motion.tw(220), label = "pageDim")
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 22.dp, vertical = 18.dp)) {
Rise(0) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
"‹ Back", fontSize = 12.sp, fontWeight = FontWeight.SemiBold, color = colors.onSurfaceVariant,
modifier = Modifier.clip(RoundedCornerShape(8.dp)).clickable(onClick = onBack).padding(horizontal = 6.dp, vertical = 4.dp),
)
Spacer(Modifier.width(10.dp))
Eyebrow(eyebrow)
}
}
Rise(1) { Title(title) }
Rise(2) { Lede(lede) }
Rise(3, Modifier.weight(1f).fillMaxWidth()) {
Column(modifier = Modifier.fillMaxSize().graphicsLayer { alpha = dim }.verticalScroll(rememberScrollState()).padding(bottom = 24.dp)) { content() }
}
}
}