From 0b7ba68e38d40fa51d886b7b376b24f927cccfc1 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Sat, 10 Oct 2026 18:48:33 -0400 Subject: [PATCH] feat(ui): Components as one stack of layers with a fixed detail frame --- .../com/droiddeck/launcher/MainActivity.kt | 74 +- .../droiddeck/launcher/ui/ComponentsPage.kt | 1021 +++++++++++++---- .../droiddeck/launcher/ui/FrontEndScreen.kt | 2 +- .../droiddeck/launcher/ui/GpuDriversPanel.kt | 271 +---- .../launcher/ui/ModeSettingsDialog.kt | 53 +- .../com/droiddeck/launcher/ui/ProtonPage.kt | 88 -- .../java/com/droiddeck/launcher/ui/StepOut.kt | 7 +- .../java/com/droiddeck/launcher/ui/Steps.kt | 2 + app/src/main/res/values/strings.xml | 17 + .../droiddeck/launcher/ui/LayerStepTest.kt | 24 + 10 files changed, 912 insertions(+), 647 deletions(-) delete mode 100644 app/src/main/java/com/droiddeck/launcher/ui/ProtonPage.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/ui/LayerStepTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index f77893bb9..bab510fab 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -46,7 +46,6 @@ import com.droiddeck.launcher.session.GameSaves import com.droiddeck.launcher.session.SessionLogShare import com.droiddeck.launcher.session.SessionPrefs import com.droiddeck.launcher.session.SteamRepair -import com.droiddeck.launcher.ui.ProtonPage import com.droiddeck.launcher.core.CpuCores import com.droiddeck.launcher.core.PhantomProcessLimit import com.droiddeck.launcher.core.PhantomProcessStatus @@ -124,7 +123,6 @@ class MainActivity : ComponentActivity() { private var steamRepairQueued by mutableStateOf(false) private var mangoapp by mutableStateOf(true) private var steamController by mutableStateOf(SessionPrefs.CONTROLLER_DECK) - private var showProtons by mutableStateOf(false) // Components page: FEX / DXVK / VKD3D-Proton per Proton (ComponentsManager). private var showComponents by mutableStateOf(false) private var focusComponentsContent by mutableStateOf(true) @@ -550,7 +548,6 @@ class MainActivity : ComponentActivity() { com.droiddeck.launcher.ui.FocusGlideHost(androidx.compose.ui.Modifier.fillMaxSize().exposeTestTags()) { val page: (@Composable () -> Unit)? = when { showPerformance -> { { PerformanceHost() } } - showProtons -> { { ProtonHost() } } showComponents -> { { ComponentsHost() } } showMapping -> { { MappingHost() } } else -> null @@ -569,7 +566,7 @@ class MainActivity : ComponentActivity() { steamGames = steamGames, emulators = emulatorList, running = runningLabel, frameGen = FrameGen.mode(this), lossless = lossless, - pageKey = if (showPerformance) "performance" else if (showProtons) "protons" else if (showComponents) "components" else if (showMapping) "controller-mapping" else null, + pageKey = if (showPerformance) "performance" else if (showComponents) "components" else if (showMapping) "controller-mapping" else null, theme = theme, language = com.droiddeck.launcher.core.AppLanguage.chosen(this), appScale = appScale, @@ -692,7 +689,7 @@ class MainActivity : ComponentActivity() { // A game page's Manage saves: the game's Proton and saves are read when the work runs, off the main thread. onSaveImport = { sg -> importSaves(sg.name) { GameSaves.game(sg) } }, onSaveExport = { sg, layout -> exportSaves(sg.name, layout) { GameSaves.game(sg) } }, - onPerformance = { refreshCores(); showProtons = false; showComponents = false; showMapping = false; showPerformance = true }, + onPerformance = { refreshCores(); showComponents = false; showMapping = false; showPerformance = true }, onRoms = { showRoms = true }, onFiles = { startActivity(Intent(this, com.droiddeck.launcher.files.FileManagerActivity::class.java)) }, onBrowseFiles = { dir -> @@ -727,7 +724,7 @@ class MainActivity : ComponentActivity() { OfflineMode.setEnabled(this, !OfflineMode.enabled(this)) offline = OfflineMode.enabled(this) }, - onPageBack = { showPerformance = false; showProtons = false; showComponents = false; showMapping = false }, + onPageBack = { showPerformance = false; showComponents = false; showMapping = false }, onTheme = { id -> SessionPrefs.setTheme(this, id); theme = id }, onLanguage = { tag -> if (tag != com.droiddeck.launcher.core.AppLanguage.chosen(this)) { @@ -837,7 +834,7 @@ class MainActivity : ComponentActivity() { onSelectSteam = { on -> ControllerPrefs.setSelectSteam(this, on); refreshController() }, onEditLayout = { startActivity(Intent(this, ControllerEditorActivity::class.java)) }, onResetLayout = { ControllerPrefs.resetAllLayouts(this); refreshController() }, - onMapping = { showPerformance = false; showProtons = false; showComponents = false; showMapping = true }, + onMapping = { showPerformance = false; showComponents = false; showMapping = true }, onResetAll = { ControllerPrefs.resetAll(this); refreshController() }, ), ), @@ -957,14 +954,12 @@ class MainActivity : ComponentActivity() { } } - /** On the Components page the pad's LB / RB step through GPU drivers, FEX, DXVK and VKD3D-Proton, wrapping around. */ + /** On the Components page the pad's LB / RB step through the stack's layers, wrapping around. */ override fun dispatchKeyEvent(event: KeyEvent): Boolean { if (event.keyCode == KeyEvent.KEYCODE_BUTTON_A) com.droiddeck.launcher.ui.HeldKeys.confirm = event.action == KeyEvent.ACTION_DOWN if (showComponents && (event.keyCode == KeyEvent.KEYCODE_BUTTON_L1 || event.keyCode == KeyEvent.KEYCODE_BUTTON_R1)) { if (event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) { - val all = listOf(com.droiddeck.launcher.ui.GPU_TAB) + ComponentsManager.COMPONENTS - val step = if (event.keyCode == KeyEvent.KEYCODE_BUTTON_R1) 1 else all.size - 1 - components.compComp = all[(all.indexOf(components.compComp).coerceAtLeast(0) + step) % all.size] + components.compComp = com.droiddeck.launcher.ui.layerStep(components.compComp, if (event.keyCode == KeyEvent.KEYCODE_BUTTON_R1) 1 else -1) } return true } @@ -1117,13 +1112,8 @@ class MainActivity : ComponentActivity() { }, "game-saves-action").start() } - private fun openProtons() { - showPerformance = false - showComponents = false - showMapping = false - showProtons = true - protons.refreshProtons() - } + /** The Protons DroidDeck installs are the Components page's Proton layer. */ + private fun openProtons() = openComponents(focusContent = true, tab = com.droiddeck.launcher.ui.PROTON_TAB) private fun refreshController() { controllerSettings = ControllerPrefs.read(this) @@ -1144,11 +1134,17 @@ class MainActivity : ComponentActivity() { focusComponentsContent = focusContent if (tab != null) components.compComp = tab showPerformance = false - showProtons = false showMapping = false showComponents = true + // The Proton layer's options for every Proton, as they are now. + fexPreset = SessionPrefs.fexPreset(this) + forceSsbs = SessionPrefs.forceSsbs(this) + fastSync = SessionPrefs.fastSync(this) + fsyncFirst = SessionPrefs.fsyncFirst(this) + syncFallback = SessionPrefs.syncFallback(this) components.refreshComponents(snapshotFirst = true) drivers.refreshDrivers() + protons.refreshProtons() } private fun importComponent(uri: Uri) { @@ -1200,23 +1196,31 @@ class MainActivity : ComponentActivity() { onImportZip = { pickAnyDriver.launch(InAppFilePicker.buildIntent(this, ZIP_EXT, getString(R.string.drivers_pick_any))) }, onRestoreBundled = { TurnipDriver(this).restoreBundled(); drivers.refreshDrivers() }, ), + protons = com.droiddeck.launcher.ui.ProtonsState( + rows = protons.protonRows, busyId = protons.protonBusyId, stage = protons.protonStage, percent = protons.protonPercent, + runtimeReady = ready && !busy, sessionRunning = SessionState.running, + ), + protonActions = com.droiddeck.launcher.ui.ProtonsActions( + onInstall = { id -> protons.installProton(id) }, + onCancel = { id -> ProtonExtras.tools.firstOrNull { it.id == id }?.let { ProtonExtras.unqueue(this, it) }; protons.refreshProtons() }, + onRemove = { id -> protons.removeProton(id) }, + ), + protonOptions = { + com.droiddeck.launcher.ui.ProtonOptions( + syncBackend = SessionPrefs.syncBackendOf(fastSync, fsyncFirst, syncFallback), fexPreset = fexPreset, forceSsbs = forceSsbs, + onSyncBackend = { id -> + SessionPrefs.setSyncBackend(this, id) + fastSync = SessionPrefs.fastSync(this) + fsyncFirst = SessionPrefs.fsyncFirst(this) + syncFallback = SessionPrefs.syncFallback(this) + }, + onFexPreset = { id -> SessionPrefs.setFexPreset(this, id); fexPreset = id }, + onForceSsbs = { on -> SessionPrefs.setForceSsbs(this, on); forceSsbs = on }, + ) + }, ) - } - - @Composable - private fun ProtonHost() { - ProtonPage( - rows = protons.protonRows, - busyId = protons.protonBusyId, - stage = protons.protonStage, - percent = protons.protonPercent, - runtimeReady = ready && !busy, - sessionRunning = SessionState.running, - onInstall = { id -> protons.installProton(id) }, - onCancel = { id -> ProtonExtras.tools.firstOrNull { it.id == id }?.let { ProtonExtras.unqueue(this, it) }; protons.refreshProtons() }, - onRemove = { id -> protons.removeProton(id) }, - onBack = { showProtons = false }, - ) + // A Proton installed or removed changes the stack's list of Protons. + androidx.compose.runtime.LaunchedEffect(protons.protonBusyId) { if (protons.protonBusyId == null) components.refreshComponents() } } private fun refreshPackages() { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt index 47e38d76d..1b31ba26f 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt @@ -1,21 +1,27 @@ package com.droiddeck.launcher.ui -import androidx.compose.ui.platform.LocalContext -import com.droiddeck.launcher.R -import androidx.compose.ui.res.stringResource import androidx.activity.compose.BackHandler +import androidx.compose.animation.AnimatedContent +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.slideInVertically +import androidx.compose.animation.slideOutVertically +import androidx.compose.animation.togetherWith import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable +import androidx.compose.foundation.focusGroup +import androidx.compose.foundation.gestures.detectTapGestures 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.IntrinsicSize import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height @@ -23,16 +29,13 @@ import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width -import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Delete -import androidx.compose.material.icons.outlined.Info import androidx.compose.material.icons.outlined.Refresh -import androidx.compose.material3.AlertDialog import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.Icon import androidx.compose.material3.LinearProgressIndicator @@ -41,28 +44,60 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberUpdatedState +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.focus.FocusRequester import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.focus.onFocusChanged +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.geometry.Rect import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.input.InputMode +import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.layout.boundsInRoot +import androidx.compose.ui.layout.onGloballyPositioned +import androidx.compose.ui.layout.positionInRoot +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalInputModeManager +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.Role import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import com.droiddeck.launcher.R import com.droiddeck.launcher.session.ComponentsManager import com.droiddeck.launcher.session.ComponentsManager.CatalogItem import com.droiddeck.launcher.session.ComponentsManager.Snapshot +import kotlinx.coroutines.delay import java.text.DateFormat import java.util.Date +/** The Components page's layer for the GPU drivers, under every Proton's. */ +const val GPU_TAB = "gpu" + +/** The Components page's layer for the Proton itself, the one the indented layers belong to. */ +const val PROTON_TAB = "proton" + +/** The stack's layers, top to bottom: LB / RB and the d-pad walk them in this order. */ +internal val LAYERS = listOf(PROTON_TAB, "dxvk", "vkd3d", "fex", GPU_TAB) + +/** The layer [by] steps from [current] (LB -1, RB +1), wrapping round the stack. */ +internal fun layerStep(current: String, by: Int): String { + val i = LAYERS.indexOf(current).coerceAtLeast(0) + return LAYERS[((i + by) % LAYERS.size + LAYERS.size) % LAYERS.size] +} + /** One installed row: a Proton's original bundle (one per Proton build) or a stored package. */ private class InstalledItem( val name: String, val detail: String, val tag: String, @@ -74,15 +109,18 @@ private class InstalledItem( ) private val GOLD = Color(0xFFF2C66D) +private val QUEUED = Color(0xFFFFB86B) private val ROW_SHAPE = RoundedCornerShape(10.dp) +private val LAYER_SHAPE = RoundedCornerShape(12.dp) /** - * FEX, DXVK and VKD3D-Proton per Proton, as a full page opened from the rail's "Components" entry. - * A title row with the Nightlies refresh, then the Proton and the component (LB / RB turn it), what - * is in use, and the installed packages beside the ones on the Nightlies - stacked when the page is - * narrow. Tapping an installed row swaps it in; the refresh button is the only thing that goes online. + * Everything a game runs on, as one stack: the Proton, its DXVK, VKD3D-Proton and FEX indented + * under it because they belong to it, then the GPU drivers that every Proton shares. One selection + * glides along the stack (LB / RB, or the d-pad in it); beside it a detail frame that never moves - + * what is in use, what is installed and what is available, and what else can be done - only its + * rows trade places. A swap is asked for by stepping out of its row, and the row flies home to its + * layer. On a narrow page the stack is the page, and a layer's detail floods out of its card. */ -@OptIn(androidx.compose.foundation.layout.ExperimentalLayoutApi::class) @Composable fun ComponentsPage( snapshot: Snapshot?, @@ -105,212 +143,327 @@ fun ComponentsPage( onImport: () -> Unit, onBack: () -> Unit, requestInitialFocus: Boolean = true, - /** The GPU drivers tab ([GPU_TAB]): what it shows and does. */ + /** The GPU drivers layer ([GPU_TAB]): what it shows and does. */ gpu: GpuDriversState = GpuDriversState(), gpuActions: GpuDriversActions = GpuDriversActions(), + /** The Proton layer ([PROTON_TAB]): the Protons DroidDeck can install, and installing them. */ + protons: ProtonsState = ProtonsState(), + protonActions: ProtonsActions = ProtonsActions(), + /** The Proton layer's options for every Proton (sync, FEX preset, SSBS, environment). */ + protonOptions: @Composable () -> Unit = {}, ) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val narrow = LocalNarrowPane.current - BackHandler(onBack = onBack) - var confirm by remember { mutableStateOf Unit>?>(null) } - var confirmTitle by remember { mutableStateOf("") } - var about by remember { mutableStateOf(false) } - var protonMenu by remember { mutableStateOf(false) } - var confirmVerb by remember { mutableStateOf(R.string.comp_swap) } val ctx = LocalContext.current - fun ask(title: String, body: String, verb: Int, action: () -> Unit) { confirmTitle = title; confirmVerb = verb; confirm = body to action } - // The GPU drivers tab's Advanced pages: one driver list on its own, full page. - var driverPage by remember { mutableStateOf(null) } - val gpuTab = comp == GPU_TAB - when (driverPage) { - "rt" -> { - DriverPage( - title = stringResource(R.string.comp_runtime_driver), hint = stringResource(R.string.comp_runtime_driver_hint), - rows = gpu.linuxRows, selected = gpu.linuxSelected, downloads = gpu.linuxDownloads, - status = gpu.releaseStatus, checking = gpu.checking, importLabel = stringResource(R.string.comp_import_turnip), canRestore = false, - onSelect = gpuActions.onSelectLinux, onDelete = gpuActions.onRemoveLinux, onRefresh = gpuActions.onRefresh, - onDownload = gpuActions.onDownloadDriver, onImport = gpuActions.onImportLinux, onRestore = {}, onBack = { driverPage = null }, - ) - return - } - "panel" -> { - DriverPage( - title = stringResource(R.string.comp_display_driver), hint = stringResource(R.string.comp_display_driver_hint), - rows = gpu.androidRows, selected = gpu.androidSelected, downloads = gpu.androidDownloads, - status = gpu.releaseStatus, checking = gpu.checking, importLabel = stringResource(R.string.comp_import_adrenotools), - canRestore = gpu.canRestoreBundled, - onSelect = gpuActions.onSelectAndroid, onDelete = gpuActions.onRemoveAndroid, onRefresh = gpuActions.onRefresh, - onDownload = gpuActions.onDownloadDriver, onImport = gpuActions.onImportAndroid, onRestore = gpuActions.onRestoreBundled, - onBack = { driverPage = null }, - ) - return - } - } + val density = LocalDensity.current + val inputMode = LocalInputModeManager.current + val layer = if (comp in LAYERS) comp else GPU_TAB + BackHandler(onBack = onBack) val views = snapshot?.protons ?: emptyList() val view = views.firstOrNull { it.proton.id == protonId } ?: views.firstOrNull() - val label = ComponentsManager.LABEL[comp] ?: comp - val checked = if (catalogAt > 0) DateFormat.getTimeInstance(DateFormat.SHORT).format(Date(catalogAt * 1000)) else stringResource(R.string.comp_never) - val nightlies = if (gpuTab) gpu.releaseStatus else if (busy != null) "$busy…" else stringResource(R.string.comp_nightlies_checked, checked) - Column(Modifier.fillMaxSize().padding(horizontal = if (narrow) 16.dp else 22.dp, vertical = if (narrow) 12.dp else 18.dp)) { - // ---- title, and the one thing that goes online ----------------------------------------- - Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth()) { - Text( - stringResource(R.string.comp_title), fontSize = if (narrow) 22.sp else 26.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, - maxLines = 1, - ) - // The status gives way to the title, not the other way round. - if (!narrow) Text( - nightlies, fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, - textAlign = androidx.compose.ui.text.style.TextAlign.End, modifier = Modifier.weight(1f), - ) else Spacer(Modifier.weight(1f)) - if (!gpuTab) ToolIcon(Icons.Outlined.Info, stringResource(R.string.comp_about)) { about = true } - if (gpuTab) ToolIcon(Icons.Outlined.Refresh, stringResource(R.string.comp_check_drivers), busy = gpu.checking, enabled = !gpu.checking && gpu.busy == null, onClick = gpuActions.onRefresh) - else ToolIcon(Icons.Outlined.Refresh, stringResource(R.string.comp_check_nightlies), busy = checking, enabled = !checking, onClick = onRefresh) - } - if (narrow) Text(nightlies, fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) + // Where things sit, root px: each layer card, each row (for a swap's dot), the page itself. + val cardsAt = remember { mutableStateMapOf() } + val rowsAt = remember { HashMap() } + var stackAt by remember { mutableStateOf(Offset.Zero) } + var pageAt by remember { mutableStateOf(Offset.Zero) } + // A layer card pops and rings as a swap's dot lands on it, and rings as a hop arrives on it. + val landed = remember { mutableStateMapOf() } + val rings = remember { mutableStateMapOf() } + fun land(l: String) { landed[l] = (landed[l] ?: 0) + 1; rings[l] = (rings[l] ?: 0) + 1 } + val arrivedSeen = remember { intArrayOf(Hops.arrived) } + LaunchedEffect(Hops.arrived) { + if (Hops.arrived == arrivedSeen[0]) return@LaunchedEffect + arrivedSeen[0] = Hops.arrived + // Once the page has flooded in from the rail. + delay(Motion.ms(700).toLong()) + rings[layer] = (rings[layer] ?: 0) + 1 + } + /** The row at [key] squashes into a dot and flies home to [to]'s card, which pops on landing. */ + fun flyHome(key: String, to: String) { + val from = rowsAt[key] ?: return land(to) + Flights.fly(Flight(from, to = { cardsAt[to]?.center }, onLand = { land(to) })) + } - // ---- which Proton, which component ------------------------------------------------------ - val comps = ComponentsManager.COMPONENTS - androidx.compose.foundation.layout.FlowRow( - horizontalArrangement = Arrangement.spacedBy(12.dp), verticalArrangement = Arrangement.spacedBy(8.dp), - modifier = Modifier.fillMaxWidth().padding(top = 12.dp), + // A confirm stepping out of the row that asked: right of a left-column row, left of a right one. + fun ask(key: String, right: Boolean, title: String, note: String, verb: String, danger: Boolean, face: String = "", then: () -> Unit) { + val at = rowsAt[key] ?: return then() + val cancel = ctx.getString(R.string.common_cancel) + Steps.ask(StepAsk( + anchor = at, side = if (right) StepSide.Left else StepSide.Right, + accent = if (danger) colors.error else pal.signal, pillCorner = 10.dp, items = 3, maxWidth = 340.dp, + // The row's own name rides on top, as the pull's handle. + handle = { + Box(Modifier.fillMaxSize().padding(start = 46.dp, end = 14.dp), contentAlignment = Alignment.CenterStart) { + Text(face, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = if (danger) colors.error else pal.signal, maxLines = 2, overflow = TextOverflow.Ellipsis) + } + }, ) { - if (view != null && !gpuTab) Box { - ValueChip(view.proton.name, protonMenu, modifier = Modifier.widthIn(max = 300.dp).heightIn(min = 44.dp)) { protonMenu = !protonMenu } - AnchoredMenu(protonMenu, onDismiss = { protonMenu = false }, title = stringResource(R.string.comp_proton), - note = stringResource(R.string.comp_proton_note)) { first -> - views.forEachIndexed { i, v -> - val swaps = v.components.values.count { it.activeFile != null } - MenuItem( - v.proton.name, checked = v.proton.id == view.proton.id, - detail = (if (swaps > 0) stringResource(R.string.comp_swapped, v.proton.version, swaps) else stringResource(R.string.comp_all_original, v.proton.version)) - .let { - when (v.sync?.state) { - "pack" -> stringResource(R.string.comp_esync_pack, it) - "wanted" -> stringResource(R.string.comp_esync_wanted, it) - "builtin" -> stringResource(R.string.comp_esync_builtin, it) - else -> it - } - } - .let { if (v.inUseByGame) stringResource(R.string.comp_game_running_suffix, it) else it }, - focusRequester = if (i == 0) first else null, - ) { onProton(v.proton.id); protonMenu = false } - } - } + StepTitle(title) + if (note.isNotEmpty()) Text(note, fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.stepItem(1).padding(start = 4.dp, bottom = 12.dp)) + Row(horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End), modifier = Modifier.fillMaxWidth().stepItem(2)) { + StepChoice(cancel, enabled = open, modifier = Modifier.focusRequester(first)) { Steps.fold() } + StepChoice(verb, danger = danger, enabled = open) { Steps.fold(); then() } } - val tabs = listOf(GPU_TAB) + comps - TabStrip(tabs.map { ComponentsManager.LABEL[it] ?: stringResource(R.string.comp_gpu_drivers) }, tabs.indexOf(comp).coerceAtLeast(0), { onComp(tabs[it]) }) - } + }) + } - // ---- what is in use ----------------------------------------------------------------------- - if (view != null && !gpuTab) { - val st = view.components.getValue(comp) - val reappliedAt = if (view.reappliedAt > 0) DateFormat.getTimeInstance(DateFormat.SHORT).format(Date(view.reappliedAt * 1000)) else null - Row( - verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), - modifier = Modifier.fillMaxWidth().padding(top = 12.dp).clip(RoundedCornerShape(12.dp)).background(colors.surface) - .border(1.dp, pal.line, RoundedCornerShape(12.dp)).padding(horizontal = 14.dp, vertical = 8.dp).heightIn(min = 28.dp), - ) { - Box(Modifier.size(8.dp).background(if (st.queued != null) Color(0xFFFFB86B) else pal.good, CircleShape)) - Text( - (if (st.queued != null) stringResource(R.string.comp_next_queued, st.queued) else stringResource(R.string.comp_in_use, label, st.inUse)) - .let { if (reappliedAt != null) stringResource(R.string.comp_reapplied, it, reappliedAt) else it }, - fontSize = 14.sp, color = colors.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f), - ) - if (st.queued != null) FocusText(stringResource(R.string.common_cancel), pal.signal, onClick = onCancelQueued) - else if (!narrow) Text( - if (view.inUseByGame) stringResource(R.string.comp_waits) else stringResource(R.string.comp_applies_next_game), - fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 1, + // The runtime and display drivers on their own pages, flooding out of the link that opens them. + var driverPage by remember { mutableStateOf(null) } + var driverShown by remember { mutableStateOf(null) } + var driverLeaving by remember { mutableStateOf(false) } + var driverFrom by remember { mutableStateOf(null) } + LaunchedEffect(driverPage) { + val d = driverPage + if (d != null) { driverLeaving = false; driverShown = d } + else if (driverShown != null) { + if (driverFrom != null) { driverLeaving = true; delay(Motion.ms(PAGE_RETURN_MS).toLong()) } + driverShown = null; driverLeaving = false; driverFrom = null + } + } + // Narrow: a layer's detail floods out of its card, and B draws it back in. + var narrowOpen by rememberSaveable { mutableStateOf(null) } + var narrowShown by remember { mutableStateOf(null) } + var narrowLeaving by remember { mutableStateOf(false) } + LaunchedEffect(narrowOpen) { + val d = narrowOpen + if (d != null) { narrowLeaving = false; narrowShown = d } + else if (narrowShown != null) { + narrowLeaving = true; delay(Motion.ms(PAGE_RETURN_MS).toLong()) + narrowShown = null; narrowLeaving = false + } + } + if (!narrow && narrowOpen != null) narrowOpen = null + BackHandler(enabled = driverPage != null || narrowOpen != null) { + if (driverPage != null) driverPage = null else narrowOpen = null + } + // Leaving the page: nothing stays stepped out of a row that is no longer on screen. + androidx.compose.runtime.DisposableEffect(Unit) { onDispose { Steps.drop() } } + + val checked = if (catalogAt > 0) DateFormat.getTimeInstance(DateFormat.SHORT).format(Date(catalogAt * 1000)) else stringResource(R.string.comp_never) + val firstRow = remember { FocusRequester() } + val layerFocus = remember { LAYERS.associateWith { FocusRequester() } } + // Arrived (from the rail, a hop, a game's card): a pad starts on the chosen layer. + LaunchedEffect(requestInitialFocus) { + if (!requestInitialFocus || inputMode.inputMode != InputMode.Keyboard) return@LaunchedEffect + delay(Motion.ms(200).toLong()) + focusWithinFrames({ false }) { layerFocus.getValue(layer) } + } + var travel by remember { mutableIntStateOf(1) } + val pick: (String) -> Unit = { l -> + if (l != layer) { travel = if (LAYERS.indexOf(l) > LAYERS.indexOf(layer)) 1 else -1; onComp(l) } + } + + // ---- one layer's detail, a slot at a time ------------------------------------------------------ + val compState = { l: String -> view?.components?.get(l) } + val bar: @Composable (String) -> Unit = { l -> + when (l) { + GPU_TAB -> { + val active = gpu.activePair + InUseBar( + queued = gpu.busy != null, + sentence = (active?.let { "${it.name} ${it.version}" } ?: gpu.activeBundle ?: stringResource(R.string.gpu_builtin)) + .let { if (gpu.auto) stringResource(R.string.gpu_bar_auto, it) else it }, + note = if (gpu.busy != null) (if (gpu.percent >= 0) "${gpu.percent}%" else "…") + else gpu.autoStatus.ifEmpty { if (active != null || gpu.activeBundle != null) "" else gpu.pairs.firstOrNull { it.recommended }?.let { stringResource(R.string.gpu_recommended_for, it.name) } ?: stringResource(R.string.gpu_refresh_hint) }, ) } - } - - // ---- the lists ------------------------------------------------------------------------------ - when { - gpuTab -> Column(Modifier.weight(1f).fillMaxWidth().verticalScroll(rememberScrollState()).padding(bottom = 16.dp)) { - GpuDriversPanel(gpu, gpuActions) { driverPage = it } - Row(modifier = Modifier.padding(top = 14.dp)) { - SmallButton(stringResource(R.string.comp_import_zip), onClick = gpuActions.onImportZip) - } - } - snapshot == null -> Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(16.dp)) { - CircularProgressIndicator(strokeWidth = 2.dp, modifier = Modifier.size(18.dp)) - Spacer(Modifier.width(12.dp)) - Text(stringResource(R.string.comp_reading), fontSize = 14.sp, color = colors.onSurfaceVariant) - } - view == null -> Text( - stringResource(R.string.comp_no_proton), - fontSize = 14.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(vertical = 16.dp), + PROTON_TAB -> InUseBar( + queued = false, + sentence = view?.let { stringResource(R.string.comp_proton_bar, it.proton.name) } ?: stringResource(R.string.comp_no_proton), + note = if (view?.inUseByGame == true) stringResource(R.string.comp_waits) else "", ) else -> { - val p = view.proton - val st = view.components.getValue(comp) - val build = ComponentsManager.safeName(p.version) - val originals = view.originals.filter { it.comp == comp } - val stored = snapshot.packages.filter { it.comp == comp } - val activeIsOriginal = st.activeFile == null - val rows = originals.map { o -> - val isCurrent = o.protonVersion == build - InstalledItem( - stringResource(R.string.comp_original, o.protonVersion), - o.label.substringAfterLast(" · ", "").ifEmpty { o.label }.let { if (isCurrent) stringResource(R.string.comp_this_build, it) else stringResource(R.string.comp_earlier_build, it) }, - "ORIGINAL", activeIsOriginal && isCurrent, !isCurrent, null, o.protonVersion, + val st = compState(l) + val label = ComponentsManager.LABEL[l] ?: l + if (st == null) InUseBar(false, stringResource(R.string.comp_no_proton), "") + else { + val reappliedAt = view?.reappliedAt?.takeIf { it > 0 }?.let { DateFormat.getTimeInstance(DateFormat.SHORT).format(Date(it * 1000)) } + InUseBar( + queued = st.queued != null, + sentence = (if (st.queued != null) stringResource(R.string.comp_next_queued, st.queued) else stringResource(R.string.comp_in_use, label, st.inUse)) + .let { if (reappliedAt != null) stringResource(R.string.comp_reapplied, it, reappliedAt) else it }, + note = if (view?.inUseByGame == true) stringResource(R.string.comp_waits) else stringResource(R.string.comp_applies_next_game), + onCancel = if (st.queued != null) onCancelQueued else null, ) - } + stored.map { s -> - InstalledItem(s.version, stringResource(R.string.common_size_mb, s.size / 1048576.0), "STORED", s.file == st.activeFile, true, s.file, null) - } - val storedNames = snapshot.packages.map { it.file }.toSet() - val available = catalog.filter { it.comp == comp && ComponentsManager.safeName(it.file) !in storedNames } - val first = remember { FocusRequester() } - LaunchedEffect(p.id, comp, requestInitialFocus) { - if (requestInitialFocus) runCatching { first.requestFocus() } } + } + } + } - val installed: @Composable () -> Unit = { - SettingsGroup(stringResource(R.string.comp_installed_count, rows.size)) { - if (rows.isEmpty()) Text( - stringResource(R.string.comp_nothing_stored, label), - fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 12.dp), - ) - rows.forEachIndexed { i, item -> - InstalledLine( - item, modifier = if (i == 0) Modifier.focusRequester(first) else Modifier, - onSelect = { - if (item.selected) return@InstalledLine - val waits = if (view.inUseByGame) ctx.getString(R.string.comp_waits_long) else ctx.getString(R.string.comp_applies_long) - if (item.file != null) ask(ctx.getString(R.string.comp_swap_title, label), ctx.getString(R.string.comp_swap_body, item.name, p.name, waits), R.string.comp_swap) { onSwap(item.file) } - else ask(ctx.getString(R.string.comp_restore_title, label), ctx.getString(R.string.comp_restore_body, item.protonVersion, p.name, waits), R.string.common_restore) { onRestore(item.protonVersion!!) } - }, - onDelete = { - if (item.file != null) ask(ctx.getString(R.string.common_delete_named, item.name) + "?", ctx.getString(R.string.comp_delete_package_body), R.string.common_delete) { onDeletePackage(item.file) } - else ask(ctx.getString(R.string.comp_delete_original_title), ctx.getString(R.string.comp_delete_original_body, item.protonVersion, p.name), R.string.common_delete) { onDeleteOriginal(item.protonVersion!!) } - }, - ) + // Installed and Available, as (title, rows) for a layer; [right] says which column it is in. + var showAllPairs by rememberSaveable { mutableStateOf(false) } + val installedTitle: @Composable (String) -> String = { l -> + when (l) { + GPU_TAB -> stringResource(R.string.comp_installed_count, 1 + gpu.pairs.count { it.installed && (it.suits || showAllPairs) }) + PROTON_TAB -> stringResource(R.string.comp_installed_count, views.size) + else -> stringResource(R.string.comp_installed_count, installedFor(l, view, snapshot).size) + } + } + val availableTitle: @Composable (String) -> String = { l -> + when (l) { + GPU_TAB -> stringResource(R.string.comp_available_count, gpu.pairs.count { !it.installed && it.complete && (it.suits || showAllPairs) }) + PROTON_TAB -> stringResource(R.string.comp_available_count, protons.rows.count { it.installed == null }) + else -> stringResource(R.string.comp_nightlies_count, availableFor(l, catalog, snapshot).size) + } + } + val installedRows: @Composable ColumnScope.(String, Boolean) -> Unit = { l, right -> + when (l) { + GPU_TAB -> { + val autoKey = "gpu:auto" + ChoiceLine( + stringResource(R.string.common_auto), stringResource(R.string.gpu_auto_keeps), gpu.auto, removable = false, + modifier = Modifier.focusRequester(firstRow).trackRow(autoKey, rowsAt), + onSelect = { + if (gpu.auto) return@ChoiceLine + ask(autoKey, right, ctx.getString(R.string.gpu_use_title, ctx.getString(R.string.common_auto)), ctx.getString(R.string.gpu_auto_hint), ctx.getString(R.string.common_use), false, ctx.getString(R.string.common_auto)) { + gpuActions.onAuto(true); flyHome(autoKey, GPU_TAB) + } + }, + ) + for (p in gpu.pairs.filter { it.installed && (it.suits || showAllPairs) }) { + val key = "gpu:${p.key}" + ChoiceLine( + p.name, "${p.version} · ${p.detail}", !gpu.auto && p.active, removable = false, + badge = if (p.recommended) stringResource(R.string.gpu_recommended_caps) else null, + progress = if (gpu.busy == p.key) gpu.percent else null, + modifier = Modifier.trackRow(key, rowsAt), + onSelect = { + if (!gpu.auto && p.active || gpu.busy != null) return@ChoiceLine + ask(key, right, ctx.getString(R.string.gpu_use_title, p.name), "${p.version} · ${p.detail}", ctx.getString(R.string.common_use), false, p.name) { + gpuActions.onAuto(false); gpuActions.onPair(p.key); flyHome(key, GPU_TAB) + } + }, + ) + } + } + PROTON_TAB -> { + if (views.isEmpty()) EmptyLine(stringResource(if (snapshot == null) R.string.comp_reading else R.string.comp_no_proton)) + views.forEachIndexed { i, v -> + val key = "proton:${v.proton.id}" + val swaps = v.components.values.count { it.activeFile != null } + val extra = protons.rows.firstOrNull { it.installed == v.proton.dir.name } + val removable = extra != null && protons.busyId == null && protons.runtimeReady && !protons.sessionRunning + ChoiceLine( + v.proton.name, + (if (swaps > 0) stringResource(R.string.comp_swapped, v.proton.version, swaps) else stringResource(R.string.comp_all_original, v.proton.version)) + .let { if (v.inUseByGame) stringResource(R.string.comp_game_running_suffix, it) else it }, + v.proton.id == view?.proton?.id, removable = removable, + modifier = (if (i == 0) Modifier.focusRequester(firstRow) else Modifier).trackRow(key, rowsAt), + onSelect = { if (v.proton.id != view?.proton?.id) { onProton(v.proton.id); flyHome(key, PROTON_TAB) } }, + onDelete = { + if (extra != null) ask(key, right, ctx.getString(R.string.proton_remove_title, v.proton.name), "", ctx.getString(R.string.store_remove), true, v.proton.name) { + protonActions.onRemove(extra.id) + } + }, + ) + } + } + else -> { + val label = ComponentsManager.LABEL[l] ?: l + val rows = installedFor(l, view, snapshot) + if (rows.isEmpty()) EmptyLine(stringResource(R.string.comp_nothing_stored, label)) + val p = view?.proton + rows.forEachIndexed { i, item -> + val key = "row:$l:${item.file ?: item.protonVersion}" + ChoiceLine( + item.name, item.detail, item.selected, item.removable, tag = item.tag, + modifier = (if (i == 0) Modifier.focusRequester(firstRow) else Modifier).trackRow(key, rowsAt), + onSelect = { + if (item.selected || p == null) return@ChoiceLine + val waits = if (view.inUseByGame) ctx.getString(R.string.comp_waits_long) else ctx.getString(R.string.comp_applies_long) + if (item.file != null) ask(key, right, ctx.getString(R.string.comp_swap_title, label), ctx.getString(R.string.comp_swap_body, item.name, p.name, waits), ctx.getString(R.string.comp_swap), false, item.name) { + onSwap(item.file); flyHome(key, l) + } + else ask(key, right, ctx.getString(R.string.comp_restore_title, label), ctx.getString(R.string.comp_restore_body, item.protonVersion, p.name, waits), ctx.getString(R.string.common_restore), false, item.name) { + onRestore(item.protonVersion!!); flyHome(key, l) + } + }, + onDelete = { + if (p == null) return@ChoiceLine + if (item.file != null) ask(key, right, ctx.getString(R.string.common_delete_named, item.name) + "?", ctx.getString(R.string.comp_delete_package_body), ctx.getString(R.string.common_delete), true, item.name) { onDeletePackage(item.file) } + else ask(key, right, ctx.getString(R.string.comp_delete_original_title), ctx.getString(R.string.comp_delete_original_body, item.protonVersion, p.name), ctx.getString(R.string.common_delete), true, item.name) { onDeleteOriginal(item.protonVersion!!) } + }, + ) + } + } + } + } + val availableRows: @Composable ColumnScope.(String) -> Unit = { l -> + when (l) { + GPU_TAB -> { + val shown = gpu.pairs.filter { !it.installed && it.complete && (it.suits || showAllPairs) } + if (shown.isEmpty()) EmptyLine(stringResource(if (gpu.checking) R.string.gpu_checking else R.string.gpu_none_listed)) + for (p in shown) GetLine( + p.name, "${p.version} · ${p.detail}", progress = if (gpu.busy == p.key) gpu.percent else null, enabled = gpu.busy == null, + badge = if (p.recommended) stringResource(R.string.gpu_recommended_caps) else null, + ) { gpuActions.onAuto(false); gpuActions.onPair(p.key) } + if (gpu.pairs.any { !it.suits }) Box(Modifier.padding(horizontal = 6.dp, vertical = 4.dp)) { + FocusText(stringResource(if (showAllPairs) R.string.gpu_hide_other else R.string.gpu_show_other), pal.signal) { showAllPairs = !showAllPairs } + } + } + PROTON_TAB -> { + val rows = protons.rows.filter { it.installed == null } + if (rows.isEmpty()) EmptyLine(stringResource(R.string.comp_nothing_new)) + for (row in rows) GetLine( + row.name, if (row.queued) stringResource(R.string.proton_queued) else stringResource(R.string.proton_not_installed), + progress = if (protons.busyId == row.id) protons.percent else null, + stage = if (protons.busyId == row.id) protons.stage else null, + enabled = protons.busyId == null && protons.runtimeReady && !protons.sessionRunning, + onCancel = if (row.queued && protons.busyId == null && !protons.sessionRunning) ({ protonActions.onCancel(row.id) }) else null, + ) { protonActions.onInstall(row.id) } + } + else -> { + val available = availableFor(l, catalog, snapshot) + if (available.isEmpty()) EmptyLine(if (catalogAt == 0L) stringResource(R.string.comp_refresh_to_list) else stringResource(R.string.comp_nothing_new)) + for (d in available) GetLine( + d.file.removeSuffix(".wcp"), "${d.release} · " + stringResource(R.string.common_size_mb, d.size / 1048576.0), + progress = downloads[d.file], enabled = busy == null, + ) { onDownload(d) } + } + } + } + val actions: @Composable (String) -> Unit = { l -> + Row(horizontalArrangement = Arrangement.spacedBy(14.dp), verticalAlignment = Alignment.CenterVertically) { + when (l) { + GPU_TAB -> { + SmallButton(stringResource(R.string.comp_import_zip), onClick = gpuActions.onImportZip) + var at by remember { mutableStateOf(null) } + Box(Modifier.onGloballyPositioned { at = it.boundsInRoot() }) { + FocusText(stringResource(R.string.gpu_separately) + " ›", pal.signal) { + val from = at + val title = ctx.getString(R.string.gpu_separately) + if (from == null) { driverPage = "rt"; return@FocusText } + Steps.ask(StepAsk(anchor = from, side = StepSide.Right, accent = pal.signal, pillCorner = 10.dp, items = 3, handle = {}) { + StepTitle(title) + StepList { + StepChoice(ctx.getString(R.string.comp_runtime_driver), enabled = open, modifier = Modifier.fillMaxWidth().stepItem(1).focusRequester(first)) { + Steps.fold(); driverFrom = Origin(from.translate(-pageAt), 10f * density.density); driverPage = "rt" + } + StepChoice(ctx.getString(R.string.comp_display_driver), enabled = open, modifier = Modifier.fillMaxWidth().stepItem(2)) { + Steps.fold(); driverFrom = Origin(from.translate(-pageAt), 10f * density.density); driverPage = "panel" + } + } + }) } } } - val nightly: @Composable () -> Unit = { - SettingsGroup(stringResource(R.string.comp_nightlies_count, available.size)) { - if (available.isEmpty()) Text( - if (catalogAt == 0L) stringResource(R.string.comp_refresh_to_list) else stringResource(R.string.comp_nothing_new), - fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 12.dp), - ) - available.forEach { d -> AvailableLine(d, downloads[d.file], enabled = busy == null) { onDownload(d) } } - } - } - Column(Modifier.weight(1f).fillMaxWidth().verticalScroll(rememberScrollState()).padding(bottom = 16.dp)) { - if (narrow) { installed(); nightly() } - else Row(horizontalArrangement = Arrangement.spacedBy(14.dp), verticalAlignment = Alignment.Top) { - Column(Modifier.weight(1f)) { installed() } - Column(Modifier.weight(1f)) { nightly() } - } - Row(horizontalArrangement = Arrangement.spacedBy(14.dp), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(top = 14.dp)) { - SmallButton(stringResource(R.string.comp_import_wcp), onClick = onImport) - if (!activeIsOriginal && originals.any { it.protonVersion == build }) FocusText(stringResource(R.string.comp_restore_original), pal.signal) { - ask(ctx.getString(R.string.comp_restore_title, label), ctx.getString(R.string.comp_restore_original_body, p.name, label), R.string.common_restore) { onRestore(build) } + PROTON_TAB -> {} + else -> { + SmallButton(stringResource(R.string.comp_import_wcp), onClick = onImport) + val st = compState(l) + val p = view?.proton + val build = p?.let { ComponentsManager.safeName(it.version) } + if (st != null && p != null && st.activeFile != null && view.originals.any { it.comp == l && it.protonVersion == build }) { + val label = ComponentsManager.LABEL[l] ?: l + Box(Modifier.trackRow("restore:$l", rowsAt)) { + FocusText(stringResource(R.string.comp_restore_original), pal.signal) { + ask("restore:$l", false, ctx.getString(R.string.comp_restore_title, label), ctx.getString(R.string.comp_restore_original_body, p.name, label), ctx.getString(R.string.common_restore), false, ctx.getString(R.string.comp_restore_original)) { + onRestore(build!!); flyHome("restore:$l", l) + } + } } } } @@ -318,34 +471,298 @@ fun ComponentsPage( } } - if (about) AlertDialog( - onDismissRequest = { about = false }, - title = { Text(stringResource(R.string.comp_title)) }, - text = { - Text( - stringResource(R.string.comp_about_text), - fontSize = 14.sp, - ) - }, - confirmButton = { FocusText(stringResource(R.string.common_ok), pal.signal) { about = false } }, - ) - confirm?.let { (body, action) -> - AlertDialog( - onDismissRequest = { confirm = null }, - title = { Text(confirmTitle) }, - text = { Text(body, fontSize = 14.sp) }, - // Opens on Cancel, so a stray A press on a controller never swaps or deletes anything. - confirmButton = { - val del = confirmVerb == R.string.common_delete - FocusText(stringResource(confirmVerb), if (del) colors.error else pal.signal) { confirm = null; action() } - }, - dismissButton = { - val cancelFocus = remember { FocusRequester() } - LaunchedEffect(Unit) { runCatching { cancelFocus.requestFocus() } } - FocusText(stringResource(R.string.common_cancel), colors.onBackground, modifier = Modifier.focusRequester(cancelFocus)) { confirm = null } + // ---- the frame ------------------------------------------------------------------------------ + val detail: @Composable (String, Boolean) -> Unit = { l, narrowPage -> + androidx.compose.foundation.layout.BoxWithConstraints(Modifier.fillMaxSize()) { + // Two columns while each gets room for a row's name and its Get; one under the other below that. + val single = narrowPage || maxWidth < 600.dp + Column(Modifier.fillMaxSize()) { + // The in-use bar keeps its place; only its words change. + AnimatedContent(l, transitionSpec = { fadeIn(Motion.tw(240)) togetherWith fadeOut(Motion.tw(160)) }, label = "inUse") { k -> bar(k) } + Column(Modifier.weight(1f).fillMaxWidth().verticalScroll(rememberScrollState()).padding(top = 12.dp, bottom = 16.dp)) { + val slide: @Composable (@Composable (String) -> Unit) -> Unit = { body -> + AnimatedContent( + l, + transitionSpec = { + val d = travel + val shift = with(density) { 16.dp.roundToPx() } + (slideInVertically(Motion.tw(240)) { shift * d } + fadeIn(Motion.tw(240))) + .togetherWith(slideOutVertically(Motion.tw(240)) { -shift * d } + fadeOut(Motion.tw(240))) + }, + label = "layerRows", + ) { k -> body(k) } + } + if (single) { + slide { k -> RowGroup(installedTitle(k)) { installedRows(k, false) } } + Spacer(Modifier.height(12.dp)) + slide { k -> RowGroup(availableTitle(k)) { availableRows(k) } } + } else Row(horizontalArrangement = Arrangement.spacedBy(14.dp), verticalAlignment = Alignment.Top) { + Column(Modifier.weight(1f)) { slide { k -> RowGroup(installedTitle(k)) { installedRows(k, false) } } } + Column(Modifier.weight(1f)) { slide { k -> RowGroup(availableTitle(k)) { availableRows(k) } } } + } + Box(Modifier.padding(top = 14.dp)) { slide { k -> actions(k) } } + if (l == PROTON_TAB) { + Spacer(Modifier.height(10.dp)) + if (!protons.runtimeReady) EmptyLine(stringResource(R.string.content_needs_runtime)) + if (protons.sessionRunning) EmptyLine(stringResource(R.string.proton_stop_first)) + SettingsGroup(stringResource(R.string.comp_for_every_proton)) { protonOptions() } + Spacer(Modifier.height(12.dp)) + Note(stringResource(R.string.comp_about_text)) + } + } + } + } + } + + Box(Modifier.fillMaxSize().onGloballyPositioned { pageAt = it.positionInRoot() }) { + Column( + Modifier.fillMaxSize().padding(horizontal = if (narrow) 16.dp else 22.dp, vertical = if (narrow) 12.dp else 18.dp) + .bumpers(onPrevious = { pick(layerStep(layer, -1)) }, onNext = { pick(layerStep(layer, 1)) }), + ) { + // ---- header: the title, the device, when the lists were checked and the one refresh ---- + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth()) { + Text(stringResource(R.string.comp_title), fontSize = if (narrow) 22.sp else 26.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1) + if (!narrow) DeviceChip(gpu) + Spacer(Modifier.weight(1f)) + HopBackChip(onBack) + if (!narrow) Text( + if (busy != null) "$busy…" else stringResource(R.string.comp_checked, checked), + fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, + ) + val refreshing = checking || gpu.checking + ToolIcon(Icons.Outlined.Refresh, stringResource(R.string.comp_check_all), busy = refreshing, enabled = !refreshing && gpu.busy == null) { + onRefresh(); gpuActions.onRefresh() + } + } + if (narrow) Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(top = 6.dp)) { DeviceChip(gpu) } + Spacer(Modifier.height(14.dp)) + Row(Modifier.weight(1f).fillMaxWidth()) { + // ---- the stack ---- + Box( + (if (narrow) Modifier.fillMaxWidth() else Modifier.width(250.dp)).fillMaxHeight() + .onGloballyPositioned { stackAt = it.positionInRoot() }, + ) { + val tint = rememberUpdatedState(pal.signal) + val local = cardsAt[layer]?.translate(-stackAt) + ChipGlide(LAYERS.indexOf(layer), local, tint, GlideAxis.Vertical, corner = 12.dp) + Stack( + layer, view, gpu, focus = layerFocus, landed = landed, rings = rings, + onPlaced = { l, r -> cardsAt[l] = r }, + onFocus = { l -> pick(l) }, + onOpen = { l -> + pick(l) + if (narrow) narrowOpen = l + else runCatching { firstRow.requestFocus() } + }, + ) + } + if (!narrow) { + Spacer(Modifier.width(16.dp)) + Box(Modifier.weight(1f).fillMaxHeight()) { detail(layer, false) } + } + } + } + // Narrow: the layer's detail over the stack, out of its card. + narrowShown?.let { l -> + val from = cardsAt[l]?.let { Origin(it.translate(-pageAt), 12f * density.density) } + val body: @Composable () -> Unit = { + Column( + Modifier.fillMaxSize().background(colors.background).pointerInput(Unit) { detectTapGestures { } } + .padding(horizontal = 16.dp, vertical = 12.dp).focusGroup(), + ) { + BackLink(LayerTitle(l), compact = true) { narrowOpen = null } + Spacer(Modifier.height(8.dp)) + detail(layer, true) + } + } + if (from == null) body() else PageFlood(from, narrowLeaving) { body() } + } + // The runtime or display driver on its own page. + driverShown?.let { d -> + val body: @Composable () -> Unit = { + Box(Modifier.fillMaxSize().background(colors.background).pointerInput(Unit) { detectTapGestures { } }) { + if (d == "rt") DriverPage( + title = stringResource(R.string.comp_runtime_driver), hint = stringResource(R.string.comp_runtime_driver_hint), + rows = gpu.linuxRows, selected = gpu.linuxSelected, downloads = gpu.linuxDownloads, + status = gpu.releaseStatus, checking = gpu.checking, importLabel = stringResource(R.string.comp_import_turnip), canRestore = false, + onSelect = gpuActions.onSelectLinux, onDelete = gpuActions.onRemoveLinux, onRefresh = gpuActions.onRefresh, + onDownload = gpuActions.onDownloadDriver, onImport = gpuActions.onImportLinux, onRestore = {}, onBack = { driverPage = null }, + ) + else DriverPage( + title = stringResource(R.string.comp_display_driver), hint = stringResource(R.string.comp_display_driver_hint), + rows = gpu.androidRows, selected = gpu.androidSelected, downloads = gpu.androidDownloads, + status = gpu.releaseStatus, checking = gpu.checking, importLabel = stringResource(R.string.comp_import_adrenotools), + canRestore = gpu.canRestoreBundled, + onSelect = gpuActions.onSelectAndroid, onDelete = gpuActions.onRemoveAndroid, onRefresh = gpuActions.onRefresh, + onDownload = gpuActions.onDownloadDriver, onImport = gpuActions.onImportAndroid, onRestore = gpuActions.onRestoreBundled, + onBack = { driverPage = null }, + ) + } + } + val from = driverFrom + if (from == null) body() else PageFlood(from, driverLeaving) { body() } + } + } +} + +/** The Installed rows of one component layer for the Proton the page shows. */ +@Composable +private fun installedFor(l: String, view: ComponentsManager.ProtonView?, snapshot: Snapshot?): List { + view ?: return emptyList() + val st = view.components[l] ?: return emptyList() + val build = ComponentsManager.safeName(view.proton.version) + val activeIsOriginal = st.activeFile == null + return view.originals.filter { it.comp == l }.map { o -> + val isCurrent = o.protonVersion == build + InstalledItem( + stringResource(R.string.comp_original, o.protonVersion), + o.label.substringAfterLast(" · ", "").ifEmpty { o.label }.let { if (isCurrent) stringResource(R.string.comp_this_build, it) else stringResource(R.string.comp_earlier_build, it) }, + "ORIGINAL", activeIsOriginal && isCurrent, !isCurrent, null, o.protonVersion, + ) + } + (snapshot?.packages ?: emptyList()).filter { it.comp == l }.map { s -> + InstalledItem(s.version, stringResource(R.string.common_size_mb, s.size / 1048576.0), "STORED", s.file == st.activeFile, true, s.file, null) + } +} + +/** The Nightlies of one component layer that are not stored yet. */ +private fun availableFor(l: String, catalog: List, snapshot: Snapshot?): List { + val stored = (snapshot?.packages ?: emptyList()).map { it.file }.toSet() + return catalog.filter { it.comp == l && ComponentsManager.safeName(it.file) !in stored } +} + +@Composable +private fun LayerTitle(l: String): String = when (l) { + GPU_TAB -> stringResource(R.string.comp_gpu_drivers) + PROTON_TAB -> stringResource(R.string.comp_proton) + else -> ComponentsManager.LABEL[l] ?: l +} + +/** Records where a row sits, for the confirm that steps out of it and the dot that flies from it. */ +private fun Modifier.trackRow(key: String, into: HashMap): Modifier = onGloballyPositioned { into[key] = it.boundsInRoot() } + +/** + * The stack: a heading over the Proton and the three layers that belong to it (indented, on a + * line), then a heading over the GPU drivers that every Proton shares. Each card is a layer's name + * and what it is set to; a dot marks a layer swapped away from its original. + */ +@Composable +private fun Stack( + layer: String, view: ComponentsManager.ProtonView?, gpu: GpuDriversState, + focus: Map, landed: Map, rings: Map, + onPlaced: (String, Rect) -> Unit, onFocus: (String) -> Unit, onOpen: (String) -> Unit, +) { + val pal = LocalPalette.current + val original = stringResource(R.string.comp_tag_original) + val auto = stringResource(R.string.common_auto) + val card: @Composable (String) -> Unit = { l -> + val st = view?.components?.get(l) + LayerCard( + title = LayerTitle(l), + value = when (l) { + GPU_TAB -> if (gpu.auto) auto else gpu.activePair?.name ?: gpu.activeBundle ?: auto + PROTON_TAB -> (view?.proton?.name ?: "") + " ▾" + else -> st?.let { if (it.activeFile == null) original else it.inUse } ?: "" }, + swapped = l in ComponentsManager.COMPONENTS && st?.activeFile != null, + selected = l == layer, + landed = landed[l] ?: 0, ring = rings[l] ?: 0, + modifier = Modifier.focusRequester(focus.getValue(l)).onGloballyPositioned { onPlaced(l, it.boundsInRoot()) }, + onFocus = { onFocus(l) }, onClick = { onOpen(l) }, ) } + Column(Modifier.fillMaxWidth().verticalScroll(rememberScrollState()), verticalArrangement = Arrangement.spacedBy(3.dp)) { + StackHeading(stringResource(R.string.comp_this_proton)) + card(PROTON_TAB) + Row(Modifier.fillMaxWidth().height(IntrinsicSize.Min)) { + Box(Modifier.padding(start = 8.dp, top = 4.dp, bottom = 4.dp).width(2.dp).fillMaxHeight().background(pal.line2)) + Column(Modifier.weight(1f).padding(start = 6.dp), verticalArrangement = Arrangement.spacedBy(3.dp)) { + card("dxvk"); card("vkd3d"); card("fex") + } + } + Spacer(Modifier.height(6.dp)) + StackHeading(stringResource(R.string.comp_every_proton)) + card(GPU_TAB) + } +} + +@Composable +private fun StackHeading(text: String) { + Text( + text.uppercase(), fontSize = 11.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.4.sp, + color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(start = 4.dp, top = 6.dp, bottom = 2.dp), + ) +} + +/** One layer: 40dp to see, 44 to touch; its name, what it is set to, and a dot when it is swapped. */ +@Composable +private fun LayerCard( + title: String, value: String, swapped: Boolean, selected: Boolean, landed: Int, ring: Int, + modifier: Modifier, onFocus: () -> Unit, onClick: () -> Unit, +) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val src = remember { MutableInteractionSource() } + val hot = rememberHot(src) + Box(Modifier.fillMaxWidth().heightIn(min = 44.dp), contentAlignment = Alignment.Center) { + Row( + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), + modifier = modifier.fillMaxWidth().height(40.dp) + .landingPop(landed).pulseRing(ring, pal.signal) + .clip(LAYER_SHAPE) + .background(if (selected) Color.Transparent else colors.surface) + .glideBorder(hot, LAYER_SHAPE, pal.signal, if (selected) Color.Transparent else pal.line) + .onFocusChanged { if (it.isFocused) onFocus() } + .hoverable(src).clickable(interactionSource = src, indication = null, role = Role.Tab, onClick = onClick) + .controllerConfirm(onClick = onClick) + .padding(horizontal = 12.dp), + ) { + if (swapped) Box(Modifier.size(7.dp).clip(CircleShape).background(pal.signal)) + Text(title, fontSize = 13.5.sp, fontWeight = FontWeight.Bold, color = if (selected || hot) colors.onBackground else colors.onSurfaceVariant, maxLines = 1) + Spacer(Modifier.weight(1f)) + // The value ticks over as a swap lands. + AnimatedContent( + value, + transitionSpec = { (slideInVertically(Motion.tw(260)) { it / 2 } + fadeIn(Motion.tw(260))) togetherWith (slideOutVertically(Motion.tw(160)) { -it / 2 } + fadeOut(Motion.tw(160))) }, + label = "layerValue", + ) { v -> Text(v, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) } + } + } +} + +/** What is in use for the layer: a dot (green, or amber while a change waits), a sentence, and a note or Cancel. */ +@Composable +private fun InUseBar(queued: Boolean, sentence: String, note: String, onCancel: (() -> Unit)? = null) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + Row( + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), + modifier = Modifier.fillMaxWidth().heightIn(min = 48.dp).clip(RoundedCornerShape(12.dp)).background(colors.surface) + .border(1.dp, pal.line, RoundedCornerShape(12.dp)).padding(horizontal = 14.dp, vertical = 8.dp), + ) { + Box(Modifier.size(8.dp).background(if (queued) QUEUED else pal.good, CircleShape)) + Text(sentence, fontSize = 14.sp, color = colors.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f)) + if (onCancel != null) FocusText(stringResource(R.string.common_cancel), pal.signal, onClick = onCancel) + else if (note.isNotEmpty() && !LocalNarrowPane.current) Text(note, fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) + } +} + +/** A titled column of rows. */ +@Composable +private fun RowGroup(title: String, content: @Composable ColumnScope.() -> Unit) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + Column(Modifier.fillMaxWidth()) { + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().padding(bottom = 6.dp)) { + Text(title.uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, color = colors.onSurfaceVariant, maxLines = 1) + Box(Modifier.weight(1f).height(1.dp).background(pal.line)) + } + Column(Modifier.fillMaxWidth().clip(RoundedCornerShape(14.dp)).background(colors.surface).border(1.dp, pal.line, RoundedCornerShape(14.dp)), content = content) + } +} + +@Composable +private fun EmptyLine(text: String) { + Text(text, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 12.dp)) } @Composable @@ -353,10 +770,10 @@ internal fun ToolIcon(icon: ImageVector, description: String, busy: Boolean = fa val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val src = remember { MutableInteractionSource() } - val hot = src.collectIsFocusedAsState().value || src.collectIsHoveredAsState().value + val hot = rememberHot(src) Box( contentAlignment = Alignment.Center, - modifier = Modifier.size(40.dp).clip(RoundedCornerShape(12.dp)) + modifier = Modifier.size(44.dp).clip(RoundedCornerShape(12.dp)) .background(if (hot) pal.signal.copy(alpha = 0.16f) else Color.Transparent) .glideBorder(hot, RoundedCornerShape(12.dp), pal.signal, pal.line2) .hoverable(src).clickable(interactionSource = src, indication = null, enabled = enabled, onClick = onClick) @@ -376,7 +793,7 @@ private fun SmallButton(text: String, enabled: Boolean = true, accent: Boolean = val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val src = remember { MutableInteractionSource() } - val hot = (src.collectIsFocusedAsState().value || src.collectIsHoveredAsState().value) && enabled + val hot = rememberHot(src) && enabled Box( contentAlignment = Alignment.Center, modifier = modifier.heightIn(min = 44.dp).clip(RoundedCornerShape(10.dp)) @@ -415,60 +832,73 @@ private fun Tag(text: String) { ) } +/** + * One installed choice: a radio for the one in use, its name and detail, and a trash at the right + * of the ones that can go. [progress] shows a download for it in place of the tag. + */ @Composable -private fun InstalledLine(item: InstalledItem, modifier: Modifier = Modifier, onSelect: () -> Unit, onDelete: () -> Unit) { +private fun ChoiceLine( + name: String, detail: String, selected: Boolean, removable: Boolean, + modifier: Modifier = Modifier, tag: String? = null, badge: String? = null, progress: Int? = null, + onSelect: () -> Unit, onDelete: () -> Unit = {}, +) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val src = remember { MutableInteractionSource() } - val hot = src.collectIsFocusedAsState().value || src.collectIsHoveredAsState().value + val hot = rememberHot(src) Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth() - .background(if (hot) pal.signal.copy(alpha = 0.14f) else if (item.selected) pal.signal.copy(alpha = 0.07f) else Color.Transparent), + .background(if (hot) pal.signal.copy(alpha = 0.14f) else if (selected) pal.signal.copy(alpha = 0.07f) else Color.Transparent), ) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.weight(1f).heightIn(min = 56.dp).then(modifier) .glideBorder(hot, ROW_SHAPE, pal.signal) - .hoverable(src).clickable(interactionSource = src, indication = null, onClick = onSelect) + .hoverable(src).clickable(interactionSource = src, indication = null, role = Role.RadioButton, onClick = onSelect) .controllerConfirm(onClick = onSelect) .padding(start = 14.dp, end = 8.dp, top = 8.dp, bottom = 8.dp), ) { - Box(contentAlignment = Alignment.Center, modifier = Modifier.size(20.dp).border(2.dp, if (item.selected) pal.signal else colors.onSurfaceVariant, CircleShape)) { - if (item.selected) Box(Modifier.size(9.dp).background(pal.signal, CircleShape)) + Box(contentAlignment = Alignment.Center, modifier = Modifier.size(20.dp).border(2.dp, if (selected) pal.signal else colors.onSurfaceVariant, CircleShape)) { + if (selected) Box(Modifier.size(9.dp).background(pal.signal, CircleShape)) } Column(Modifier.weight(1f)) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) { Text( - item.name, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis, - color = if (item.selected) pal.signal else colors.onBackground, modifier = Modifier.weight(1f, fill = false), + name, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, maxLines = 2, overflow = TextOverflow.Ellipsis, + color = if (selected) pal.signal else colors.onBackground, modifier = Modifier.weight(1f, fill = false), ) - Tag(item.tag) + if (tag != null) Tag(tag) } - Text(item.detail, fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 2.dp)) + DetailLine(detail, badge) } - if (item.selected) Tag("IN USE") + // The radio says which is in use; a download in flight shows where a tag would. + if (progress != null) ProgressBit(progress) } // The trash column is always there (empty when the row can't be deleted) so rows line up. - if (!item.removable) Spacer(Modifier.padding(end = 6.dp).size(40.dp)) + if (!removable) Spacer(Modifier.padding(end = 6.dp).size(44.dp)) else { val delSrc = remember { MutableInteractionSource() } - val delHot = delSrc.collectIsFocusedAsState().value || delSrc.collectIsHoveredAsState().value + val delHot = rememberHot(delSrc) Box( contentAlignment = Alignment.Center, - modifier = Modifier.padding(end = 6.dp).size(40.dp).clip(ROW_SHAPE) + modifier = Modifier.padding(end = 6.dp).size(44.dp).clip(ROW_SHAPE) .background(if (delHot) colors.error.copy(alpha = 0.14f) else Color.Transparent) .glideBorder(delHot, ROW_SHAPE, colors.error) .hoverable(delSrc).clickable(interactionSource = delSrc, indication = null, onClick = onDelete) .controllerConfirm(onClick = onDelete), - ) { Icon(Icons.Outlined.Delete, contentDescription = stringResource(R.string.common_delete_named, item.name), tint = if (delHot) colors.error else colors.onSurfaceVariant, modifier = Modifier.size(19.dp)) } + ) { Icon(Icons.Outlined.Delete, contentDescription = stringResource(R.string.common_delete_named, name), tint = if (delHot) colors.error else colors.onSurfaceVariant, modifier = Modifier.size(19.dp)) } } } Box(Modifier.fillMaxWidth().height(1.dp).background(pal.line)) } +/** One thing not installed yet: its name and detail, and Get - its download shown in the row once started. */ @Composable -private fun AvailableLine(d: CatalogItem, progress: Int?, enabled: Boolean, onDownload: () -> Unit) { +private fun GetLine( + name: String, detail: String, progress: Int?, enabled: Boolean, + badge: String? = null, stage: String? = null, onCancel: (() -> Unit)? = null, onGet: () -> Unit, +) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current Row( @@ -476,22 +906,105 @@ private fun AvailableLine(d: CatalogItem, progress: Int?, enabled: Boolean, onDo modifier = Modifier.fillMaxWidth().heightIn(min = 56.dp).padding(start = 14.dp, end = 10.dp, top = 8.dp, bottom = 8.dp), ) { Column(Modifier.weight(1f)) { - Text(d.file.removeSuffix(".wcp"), fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) - Text( - "${d.release} · " + stringResource(R.string.common_size_mb, d.size / 1048576.0), fontSize = 13.sp, color = colors.onSurfaceVariant, - maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 2.dp), - ) + Text(name, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis) + DetailLine(stage ?: detail, badge) } - if (progress == null) SmallButton(stringResource(R.string.common_download), enabled = enabled, accent = true, onClick = onDownload) - else Column(horizontalAlignment = Alignment.End, modifier = Modifier.width(96.dp)) { - Text(if (progress < 0) "…" else "$progress%", fontSize = 13.sp, color = colors.onSurfaceVariant) - Spacer(Modifier.height(4.dp)) - if (progress < 0) LinearProgressIndicator(modifier = Modifier.fillMaxWidth()) - else LinearProgressIndicator(progress = { progress / 100f }, modifier = Modifier.fillMaxWidth()) + if (progress != null) ProgressBit(progress) + else { + if (onCancel != null) FocusText(stringResource(R.string.proton_cancel_queued), pal.signal, onClick = onCancel) + SmallButton(stringResource(R.string.comp_get), enabled = enabled, accent = true, onClick = onGet) } } Box(Modifier.fillMaxWidth().height(1.dp).background(pal.line)) } -/** The Components page's tab for the GPU drivers, before the Proton components' own. */ -const val GPU_TAB = "gpu" +/** A row's second line, led by [badge] (Recommended) in green when there is one. */ +@Composable +private fun DetailLine(detail: String, badge: String?) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val text = androidx.compose.ui.text.buildAnnotatedString { + if (badge != null) { + pushStyle(androidx.compose.ui.text.SpanStyle(color = pal.good, fontWeight = FontWeight.SemiBold)) + append(badge.lowercase().replaceFirstChar { it.uppercase() }) + pop() + append(" · ") + } + append(detail) + } + Text(text, fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 2, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 2.dp)) +} + +@Composable +private fun ProgressBit(progress: Int) { + val colors = MaterialTheme.colorScheme + Column(horizontalAlignment = Alignment.End, modifier = Modifier.width(96.dp)) { + Text(if (progress < 0) "…" else "$progress%", fontSize = 13.sp, color = colors.onSurfaceVariant) + Spacer(Modifier.height(4.dp)) + if (progress < 0) LinearProgressIndicator(modifier = Modifier.fillMaxWidth()) + else LinearProgressIndicator(progress = { progress / 100f }, modifier = Modifier.fillMaxWidth()) + } +} + +/** + * The GPU and how far it is supported, as a chip: a green dot and " · tested", amber when it + * is not. A steps the device's full details out of it, with the copy for a bug report. + */ +@Composable +private fun DeviceChip(s: GpuDriversState) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val tint = if (s.supported && !s.unsupported) pal.good else AttentionAmber + val label = stringResource( + when { + s.unsupported -> R.string.comp_device_unsupported + s.supported -> R.string.comp_device_tested + else -> R.string.comp_device_untested + }, s.gpuName, + ) + val src = remember { MutableInteractionSource() } + val hot = rememberHot(src) + var at by remember { mutableStateOf(null) } + val shape = RoundedCornerShape(99.dp) + val face: @Composable () -> Unit = { + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(7.dp)) { + Box(Modifier.size(8.dp).clip(CircleShape).background(tint)) + Text(label, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) + } + } + val open: () -> Unit = { + at?.let { from -> + Steps.ask(StepAsk(anchor = from, side = StepSide.Right, accent = pal.signal, items = 2, maxWidth = 420.dp, handle = face) { + Box(Modifier.stepItem(0)) { DeviceDetails(first) } + }) + } + } + Box( + contentAlignment = Alignment.Center, + modifier = Modifier.onGloballyPositioned { at = it.boundsInRoot() }.heightIn(min = 44.dp).paneItem("gpu-device").clip(shape) + .background(if (hot) pal.signal.copy(alpha = 0.14f) else colors.surface) + .glideBorder(hot, shape, pal.signal, pal.line) + .hoverable(src).clickable(interactionSource = src, indication = null, role = Role.Button, onClick = open) + .controllerConfirm(onClick = open) + .padding(horizontal = 14.dp, vertical = 8.dp), + ) { face() } +} + +/** What the Proton layer installs: the Protons DroidDeck can download, and one being installed. */ +class ProtonsState( + val rows: List = emptyList(), + val busyId: String? = null, + val stage: String? = null, + val percent: Int = -1, + val runtimeReady: Boolean = true, + val sessionRunning: Boolean = false, +) + +class ProtonsActions( + val onInstall: (String) -> Unit = {}, + val onCancel: (String) -> Unit = {}, + val onRemove: (String) -> Unit = {}, +) + +/** A Proton DroidDeck can install, and the folder it is installed as (null when it is not). */ +class ProtonRow(val id: String, val name: String, val installed: String?, val queued: Boolean) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 9253bd6ae..eb2a7acc9 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -461,7 +461,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com Hops.origin != null && s.pageKey == Hops.origin?.page -> Hops.origin!!.dest // Performance opens from Play's sheet, and is Steam's. s.pageKey == "performance" -> "steam" - s.pageKey == "protons" || s.pageKey == "controller-mapping" -> "setup" + s.pageKey == "controller-mapping" -> "setup" selected.startsWith("app:") -> "games" selected.startsWith("emu:") || selected.startsWith("rom:") || selected.startsWith("user:") -> "desktop" else -> s.pageKey ?: selected diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GpuDriversPanel.kt b/app/src/main/java/com/droiddeck/launcher/ui/GpuDriversPanel.kt index 9fe6ab6be..eec0f2087 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GpuDriversPanel.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GpuDriversPanel.kt @@ -57,6 +57,10 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester /** One matched driver pair in the list (DriverPairs), and what this device makes of it. */ class PairRow( @@ -119,155 +123,38 @@ class GpuDriversActions( ) /** - * The GPU drivers tab: this GPU, and the drivers it draws with - a runtime (Linux) driver for the - * games and a display (Android) driver for the screen, set together as one matched pair. Auto keeps - * the pair recommended for the GPU installed and current; Manual picks a pair from the list; the - * two lists each on their own, and imports, are under Advanced. + * Everything about the chip - SoC, GPU, CPU, memory, system, the phone's own Vulkan driver, the + * drivers in use - gathered once, off the main thread, with a button that copies it for a bug + * report. Stepped out of the Components page's device chip; [first] is where a pad starts. */ @Composable -internal fun GpuDriversPanel(s: GpuDriversState, a: GpuDriversActions, onAdvanced: (String) -> Unit) { +internal fun DeviceDetails(first: FocusRequester) { val colors = MaterialTheme.colorScheme - val pal = LocalPalette.current - var showAll by rememberSaveable { mutableStateOf(false) } - Column(verticalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().padding(top = 12.dp)) { - DeviceCard(s) - if (!s.unsupported) { - Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) { - ModeCard(Icons.Outlined.AutoAwesome, stringResource(R.string.common_auto), stringResource(R.string.gpu_auto_hint), s.auto, Modifier.weight(1f)) { a.onAuto(true) } - ModeCard(Icons.Outlined.Tune, stringResource(R.string.mode_suspend_manual), stringResource(R.string.gpu_manual_hint), !s.auto, Modifier.weight(1f)) { a.onAuto(false) } - } - if (s.auto) AutoCard(s) - else { - val shown = s.pairs.filter { it.suits || showAll } - if (shown.isEmpty()) Text( - if (s.checking) stringResource(R.string.gpu_checking) else stringResource(R.string.gpu_none_listed), - fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(vertical = 8.dp), - ) - for (p in shown) PairLine(p, s.busy == p.key, s.percent, enabled = s.busy == null) { a.onPair(p.key) } - if (s.pairs.any { !it.suits }) FocusText( - if (showAll) stringResource(R.string.gpu_hide_other) else stringResource(R.string.gpu_show_other), pal.signal, - ) { showAll = !showAll } - } - } - SettingsGroup(stringResource(R.string.gpu_advanced)) { - SettingsRow(stringResource(R.string.comp_runtime_driver), s.activeBundle?.let { stringResource(R.string.gpu_set_with_display, it) } ?: stringResource(R.string.gpu_runtime_hint)) { - DriverDropdown(s.linuxRows, s.linuxSelected, stringResource(R.string.gpu_runtime_default), a.onSelectLinux) { onAdvanced("rt") } - } - SettingsRow(stringResource(R.string.comp_display_driver), s.activeBundle?.let { stringResource(R.string.gpu_set_with_runtime, it) } ?: stringResource(R.string.gpu_display_hint)) { - DriverDropdown(s.androidRows, s.androidSelected, stringResource(R.string.gpu_auto_by_gpu), a.onSelectAndroid) { onAdvanced("panel") } - } - } - } -} - -/** - * One driver list as a drop-down: the installed drivers to pick from, and the full page for - * downloading and deleting them. An Android + Linux bundle's row is tagged, and picking it sets both. - */ -@Composable -private fun DriverDropdown(rows: List, selected: String, fallback: String, onSelect: (String) -> Unit, onManage: () -> Unit) { - val colors = MaterialTheme.colorScheme - val pal = LocalPalette.current - var open by remember { mutableStateOf(false) } - Box { - SecondaryButton((rows.firstOrNull { it.id == selected }?.name ?: fallback) + " ▾", compact = true) { open = true } - DropdownMenu(open, onDismissRequest = { open = false }, modifier = Modifier.heightIn(max = 360.dp)) { - for (row in rows) DropdownMenuItem( - leadingIcon = { Radio(row.id == selected) }, - text = { - Column { - Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) { - Text(row.name, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = if (row.id == selected) pal.signal else colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) - if (row.tag == DriverRow.BUNDLE) Text(driverTagLabel(row.tag), fontSize = 10.5.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.sp, color = colors.onSurfaceVariant) - } - if (row.detail.isNotEmpty()) Text(row.detail, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) - } - }, - onClick = { open = false; if (row.id != selected) onSelect(row.id) }, - ) - HorizontalDivider(color = pal.line) - DropdownMenuItem(text = { Text(stringResource(R.string.gpu_manage), fontSize = 14.sp, color = pal.signal) }, onClick = { open = false; onManage() }) - } - } -} - -/** - * This GPU and how far it is supported. A tap (or A) opens the card onto everything about the chip - - * SoC, GPU, CPU, memory, system, the phone's own Vulkan driver, the drivers in use - gathered once, - * off the main thread, with a button that copies it for a bug report. - */ -@Composable -private fun DeviceCard(s: GpuDriversState) { - val colors = MaterialTheme.colorScheme - val pal = LocalPalette.current val context = LocalContext.current val clipboard = LocalClipboardManager.current - val tint = when { - s.unsupported -> pal.error - s.supported -> pal.good - else -> AttentionAmber - } - var open by rememberSaveable { mutableStateOf(false) } var details by remember { mutableStateOf?>(null) } var copied by remember { mutableStateOf(false) } - LaunchedEffect(open) { - if (open && details == null) details = withContext(Dispatchers.IO) { DeviceInfo.collect(context) } - } - val src = remember { MutableInteractionSource() } - val hot = rememberHot(src) - val toggle = { open = !open; copied = false } + LaunchedEffect(Unit) { details = withContext(Dispatchers.IO) { DeviceInfo.collect(context) } } Column( - Modifier.fillMaxWidth().clip(Shape14).background(colors.surface) - .background(if (hot) pal.signal.copy(alpha = 0.10f) else Color.Transparent) - .glideBorder(hot, Shape14, pal.signal, pal.line), + verticalArrangement = Arrangement.spacedBy(10.dp), + modifier = Modifier.fillMaxWidth().heightIn(max = 360.dp).verticalScroll(rememberScrollState()), ) { - Row( - verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(14.dp), - modifier = Modifier.fillMaxWidth().paneItem("gpu-device") - .hoverable(src).clickable(interactionSource = src, indication = null, role = Role.Button, onClick = toggle) - .controllerConfirm(onClick = toggle) - .padding(14.dp), - ) { - Box(contentAlignment = Alignment.Center, modifier = Modifier.size(44.dp).clip(Shape12).background(tint.copy(alpha = 0.14f))) { - Icon(Icons.Outlined.Memory, contentDescription = null, tint = tint, modifier = Modifier.size(24.dp)) - } - Column(Modifier.weight(1f)) { - Text(s.gpuName, fontSize = 18.sp, fontWeight = FontWeight.Bold, color = colors.onBackground) - Text(listOf(s.soc, s.gpuFamily).filter { it.isNotEmpty() }.joinToString(" · "), fontSize = 13.sp, color = colors.onSurfaceVariant) - } - // The verdict shares the width with the GPU's name and wraps, rather than taking all it - // needs: a long one (in some languages) would squeeze the name to a letter a line. - Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp), modifier = Modifier.weight(1f, fill = false)) { - Box(Modifier.size(7.dp).clip(CircleShape).background(tint)) - Text(s.supportText, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = tint, maxLines = 3, overflow = TextOverflow.Ellipsis) - } - Icon( - if (open) Icons.Outlined.ExpandLess else Icons.Outlined.ExpandMore, - contentDescription = stringResource(if (open) R.string.device_info_hide else R.string.device_info_show), - tint = colors.onSurfaceVariant, modifier = Modifier.size(24.dp), - ) - } - AnimatedVisibility(open) { - Column(verticalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.fillMaxWidth().padding(start = 14.dp, end = 14.dp, bottom = 14.dp)) { - HorizontalDivider(color = pal.line) - val sections = details - if (sections == null) { - Text(stringResource(R.string.device_info_loading), fontSize = 13.sp, color = colors.onSurfaceVariant) - LinearProgressIndicator(Modifier.fillMaxWidth()) - } else { - for (section in sections) DeviceInfoSection(section) - Row(verticalAlignment = Alignment.CenterVertically) { - Text( - stringResource(if (copied) R.string.device_info_copied else R.string.device_info_copy_hint), - fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.weight(1f), - ) - SecondaryButton(stringResource(R.string.device_info_copy), compact = true) { - clipboard.setText(AnnotatedString(DeviceInfo.text(sections))) - copied = true - } - } + val sections = details + if (sections == null) { + Text(stringResource(R.string.device_info_loading), fontSize = 13.sp, color = colors.onSurfaceVariant) + LinearProgressIndicator(Modifier.fillMaxWidth()) + } else { + Row(verticalAlignment = Alignment.CenterVertically) { + Text( + stringResource(if (copied) R.string.device_info_copied else R.string.device_info_copy_hint), + fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.weight(1f), + ) + SecondaryButton(stringResource(R.string.device_info_copy), compact = true, modifier = Modifier.focusRequester(first)) { + clipboard.setText(AnnotatedString(DeviceInfo.text(sections))) + copied = true } } + for (section in sections) DeviceInfoSection(section) } } } @@ -288,115 +175,9 @@ private fun DeviceInfoSection(section: DeviceInfo.Section) { Text(section.title.uppercase(), fontSize = 11.5.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.2.sp, color = colors.onSurfaceVariant) for ((label, value) in section.rows) { Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) { - Text(label, fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.width(190.dp)) + Text(label, fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.width(150.dp)) Text(value, fontSize = 13.sp, fontWeight = FontWeight.Medium, color = colors.onBackground, modifier = Modifier.weight(1f)) } } } } - -/** What Auto has set and what it is doing. */ -@Composable -private fun AutoCard(s: GpuDriversState) { - val colors = MaterialTheme.colorScheme - val pal = LocalPalette.current - val active = s.activePair - val recommended = s.pairs.firstOrNull { it.recommended } - Column( - verticalArrangement = Arrangement.spacedBy(4.dp), - modifier = Modifier.fillMaxWidth().clip(Shape14).background(colors.surface).border(1.dp, pal.line, Shape14).padding(14.dp), - ) { - Text(stringResource(R.string.gpu_in_use_caps), fontSize = 11.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.2.sp, color = colors.onSurfaceVariant) - Text( - active?.let { "${it.name} ${it.version}" } ?: s.activeBundle ?: stringResource(R.string.gpu_builtin), - fontSize = 16.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, - ) - Text( - if (active != null || s.activeBundle != null) stringResource(R.string.gpu_matched_pair) - else recommended?.let { stringResource(R.string.gpu_recommended_for, it.name) } ?: stringResource(R.string.gpu_refresh_hint), - fontSize = 13.sp, color = colors.onSurfaceVariant, - ) - if (s.busy != null) { - LinearProgressIndicator( - progress = { (s.percent.coerceAtLeast(0)) / 100f }, - modifier = Modifier.fillMaxWidth().padding(top = 8.dp).height(6.dp).clip(CircleShape), - ) - } - if (s.autoStatus.isNotEmpty()) Text(s.autoStatus, fontSize = 13.sp, color = colors.onBackground, modifier = Modifier.padding(top = 4.dp)) - } -} - -@Composable -private fun ModeCard(icon: ImageVector, title: String, hint: String, selected: Boolean, modifier: Modifier, onClick: () -> Unit) { - val colors = MaterialTheme.colorScheme - val pal = LocalPalette.current - val src = remember { MutableInteractionSource() } - val hot = rememberHot(src) - // Selection is the radio; the ring is only ever focus. - val fill = if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent - Row( - verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), - modifier = modifier.paneItem("gpu-mode:$title").heightIn(min = 56.dp) - .clip(Shape14).background(colors.surface).background(fill) - .glideBorder(hot, Shape14, pal.signal, pal.line) - .hoverable(src).clickable(interactionSource = src, indication = null, role = Role.RadioButton, onClick = onClick) - .controllerConfirm(onClick = onClick) - .padding(horizontal = 14.dp, vertical = 10.dp), - ) { - Icon(icon, contentDescription = null, tint = if (selected) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(22.dp)) - Column(Modifier.weight(1f)) { - Text(title, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground) - Text(hint, fontSize = 12.5.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) - } - Radio(selected) - } -} - -@Composable -private fun PairLine(p: PairRow, busy: Boolean, percent: Int, enabled: Boolean, onClick: () -> Unit) { - val colors = MaterialTheme.colorScheme - val pal = LocalPalette.current - val src = remember { MutableInteractionSource() } - val hot = rememberHot(src) - val usable = enabled && p.complete && !p.active - val fill = if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent - Row( - verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), - modifier = Modifier.fillMaxWidth().paneItem("pair:${p.key}").heightIn(min = 56.dp) - .clip(Shape12).background(colors.surface).background(fill) - .glideBorder(hot, Shape12, pal.signal, pal.line) - .hoverable(src).clickable(interactionSource = src, indication = null, enabled = usable, role = Role.RadioButton, onClick = onClick) - .controllerConfirm(enabled = usable, onClick = onClick) - .padding(horizontal = 14.dp, vertical = 8.dp), - ) { - Radio(p.active) - Column(Modifier.weight(1f)) { - Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) { - Text(p.name, fontSize = 14.5.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false)) - if (p.recommended) Text( - stringResource(R.string.gpu_recommended_caps), fontSize = 10.5.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.sp, color = pal.good, - modifier = Modifier.clip(RoundedCornerShape(5.dp)).background(pal.good.copy(alpha = 0.12f)).padding(horizontal = 6.dp, vertical = 2.dp), - ) - } - Text("${p.version} · ${p.detail}", fontSize = 12.5.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) - } - when { - busy -> Column(horizontalAlignment = Alignment.End, modifier = Modifier.width(96.dp)) { - Text(if (percent >= 0) "$percent%" else "…", fontSize = 12.sp, color = colors.onSurfaceVariant) - LinearProgressIndicator(progress = { percent.coerceAtLeast(0) / 100f }, modifier = Modifier.fillMaxWidth().padding(top = 4.dp)) - } - p.active -> Text(stringResource(R.string.comp_tag_in_use), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = pal.signal) - !p.complete -> Text(stringResource(R.string.gpu_unavailable), fontSize = 13.sp, color = colors.onSurfaceVariant) - p.installed -> Text(stringResource(R.string.common_use), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground) - else -> Text(stringResource(R.string.common_download), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground) - } - } -} - -@Composable -private fun Radio(selected: Boolean) { - val pal = LocalPalette.current - Box(contentAlignment = Alignment.Center, modifier = Modifier.size(20.dp).clip(CircleShape).border(2.dp, if (selected) pal.signal else pal.line2, CircleShape)) { - if (selected) Box(Modifier.size(10.dp).clip(CircleShape).background(pal.signal)) - } -} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt index 4b6c4300d..53384b186 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt @@ -361,29 +361,6 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras: onChange = a.onStorageDiagnostics, ) } - if (s.fexPreset != null) SettingsGroup(stringResource(R.string.game_settings_title)) { - if (s.syncBackend != null) SettingsRow( - stringResource(R.string.sync_backend_title), - stringResource(R.string.sync_backend_hint), - ) { - SegmentedTabs( - listOf( - SessionPrefs.SYNC_NTSYNC to stringResource(R.string.sync_backend_ntsync), - SessionPrefs.SYNC_FSYNC to stringResource(R.string.sync_backend_fsync), - SessionPrefs.SYNC_ESYNC to stringResource(R.string.sync_backend_esync), - SessionPrefs.SYNC_WINESERVER to stringResource(R.string.sync_backend_wineserver), - ), - s.syncBackend, - ) { id -> host.open = null; a.onSyncBackend(id) } - } - ChoiceRow( - host, "fex", stringResource(R.string.fex_preset_title), stringResource(R.string.fex_next_launch), - FexPreset.all.map { it.id to stringResource(it.label) }, s.fexPreset, - note = stringResource(FexPreset.byId(s.fexPreset).detail), onPick = a.onFexPreset, - ) - ToggleRow(host, "ssbs", stringResource(R.string.force_ssbs_title), stringResource(R.string.force_ssbs_hint), s.forceSsbs, onChange = a.onForceSsbs) - GameEnvironmentRow() - } } if (tab == SheetTab.STEAM && steam) { SettingsGroup(stringResource(R.string.mode_decky)) { @@ -503,6 +480,36 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras: ) } +/** + * The options that apply to every Proton - how Wine syncs, FEX's preset, Force SSBS and the games' + * environment - for the Components page's Proton layer. + */ +@Composable +internal fun ProtonOptions( + syncBackend: String, fexPreset: String, forceSsbs: Boolean, + onSyncBackend: (String) -> Unit, onFexPreset: (String) -> Unit, onForceSsbs: (Boolean) -> Unit, +) { + val host = rememberMenuHost() + SettingsRow(stringResource(R.string.sync_backend_title), stringResource(R.string.sync_backend_hint)) { + SegmentedTabs( + listOf( + SessionPrefs.SYNC_NTSYNC to stringResource(R.string.sync_backend_ntsync), + SessionPrefs.SYNC_FSYNC to stringResource(R.string.sync_backend_fsync), + SessionPrefs.SYNC_ESYNC to stringResource(R.string.sync_backend_esync), + SessionPrefs.SYNC_WINESERVER to stringResource(R.string.sync_backend_wineserver), + ), + syncBackend, + ) { id -> host.open = null; onSyncBackend(id) } + } + ChoiceRow( + host, "fex", stringResource(R.string.fex_preset_title), stringResource(R.string.fex_next_launch), + FexPreset.all.map { it.id to stringResource(it.label) }, fexPreset, + note = stringResource(FexPreset.byId(fexPreset).detail), onPick = onFexPreset, + ) + ToggleRow(host, "ssbs", stringResource(R.string.force_ssbs_title), stringResource(R.string.force_ssbs_hint), forceSsbs, onChange = onForceSsbs) + GameEnvironmentRow() +} + /** * Uninstall for Decky Loader: are you sure steps out of it in red, Cancel first, so a stray A * costs nothing. diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ProtonPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/ProtonPage.kt deleted file mode 100644 index 3515f2180..000000000 --- a/app/src/main/java/com/droiddeck/launcher/ui/ProtonPage.kt +++ /dev/null @@ -1,88 +0,0 @@ -package com.droiddeck.launcher.ui - -import com.droiddeck.launcher.R -import androidx.compose.ui.res.stringResource -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.LinearProgressIndicator -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp - -class ProtonRow(val id: String, val name: String, val installed: String?, val queued: Boolean) - -@Composable -fun ProtonPage( - rows: List, - busyId: String?, - stage: String?, - percent: Int, - runtimeReady: Boolean, - sessionRunning: Boolean, - onInstall: (String) -> Unit, - onCancel: (String) -> Unit, - onRemove: (String) -> Unit, - onBack: () -> Unit, -) { - val host = rememberMenuHost() - val colors = MaterialTheme.colorScheme - SettingsPage( - host, - title = stringResource(R.string.setup_tool_protons), - eyebrow = stringResource(R.string.setup_title), - lede = stringResource(R.string.proton_lede), - onBack = onBack, - ) { - if (!runtimeReady) Text( - stringResource(R.string.content_needs_runtime), - fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 8.dp, bottom = 6.dp), - ) - if (sessionRunning) Text( - stringResource(R.string.proton_stop_first), - fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 8.dp, bottom = 6.dp), - ) - val compatible = stringResource(R.string.steam_compat_label) - Text( - stringResource(R.string.proton_compatible_note, compatible), - fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 8.dp, bottom = 6.dp), - ) - SettingsGroup(stringResource(R.string.proton_available)) { - for (row in rows) { - SettingsRow( - row.name, - when { - row.installed != null -> stringResource(R.string.proton_installed_compatible, row.installed, compatible) - row.queued -> stringResource(R.string.proton_queued) - else -> stringResource(R.string.proton_not_installed) - }, - ) { - Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) { - when { - row.installed != null -> SecondaryButton(stringResource(R.string.store_remove), enabled = busyId == null && runtimeReady && !sessionRunning) { onRemove(row.id) } - busyId != null -> SecondaryButton(if (busyId == row.id) stringResource(R.string.store_installing) else stringResource(R.string.store_install), enabled = false) {} - else -> SecondaryButton(stringResource(R.string.proton_install_now), enabled = runtimeReady && !sessionRunning) { onInstall(row.id) } - } - if (row.queued && row.installed == null && busyId == null) { - SecondaryButton(stringResource(R.string.proton_cancel_queued), enabled = !sessionRunning) { onCancel(row.id) } - } - } - } - if (busyId == row.id) Column(modifier = Modifier.fillMaxWidth().padding(start = 12.dp, end = 12.dp, bottom = 10.dp)) { - Text( - if (stage != null && percent >= 0) stringResource(R.string.store_busy_percent_short, stage, percent) else stage ?: stringResource(R.string.store_starting), - fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(bottom = 5.dp), - ) - if (percent >= 0) LinearProgressIndicator(progress = { percent / 100f }, modifier = Modifier.fillMaxWidth().height(4.dp)) - else LinearProgressIndicator(modifier = Modifier.fillMaxWidth().height(4.dp)) - } - } - } - } -} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StepOut.kt b/app/src/main/java/com/droiddeck/launcher/ui/StepOut.kt index 7ab5cbcc0..624176b51 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StepOut.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StepOut.kt @@ -184,6 +184,10 @@ internal fun StepOut( BoxWithConstraints(Modifier.fillMaxSize()) { val hostWidth = constraints.maxWidth.toFloat() + val hostHeight = constraints.maxHeight.toFloat() + // No room under the control (a row near the foot of the screen): it steps out upward + // instead, the same outline mirrored about the control. + val up = measured?.let { pill.bottom + pull + it.height > hostHeight && pill.top - pull - it.height >= 0f } ?: false val room = if (side == StepSide.Left) pill.right else hostWidth - pill.left val maxW = with(density) { maxWidth.toPx() }.coerceAtMost(room).coerceAtLeast(pill.width) LaunchedEffect(open, measured) { @@ -246,6 +250,7 @@ internal fun StepOut( if (!grown) return@Canvas if (side == StepSide.Left) stepPath(path, pill, edge.value, bottom.value, pill.bottom + pull, boxCorner, fillet, corner) else stepPathRight(path, pill, edge.value, bottom.value, pill.bottom + pull, boxCorner, fillet, corner) + if (up) path.transform(Matrix().apply { this[1, 1] = -1f; this[3, 1] = pill.top + pill.bottom }) drawPath(path, lerp(hotFill, restFill, tint.value)) drawPath(path, accent.copy(alpha = lerpF(0.9f, 0.55f, tint.value)), style = Stroke(rim)) } @@ -258,7 +263,7 @@ internal fun StepOut( val x = if (side == StepSide.Left) pill.right - (measured?.width?.toFloat() ?: maxW) else pill.left Column( modifier = Modifier - .offset { IntOffset(x.roundToInt(), (pill.bottom + pull).roundToInt()) } + .offset { IntOffset(x.roundToInt(), (if (up) pill.top - pull - (measured?.height ?: 0) else pill.bottom + pull).roundToInt()) } .widthIn(min = with(density) { pill.width.toDp() }, max = with(density) { maxW.toDp() }) .onSizeChanged { if (measured != it) measured = it } .controllerBack(onDismiss) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/Steps.kt b/app/src/main/java/com/droiddeck/launcher/ui/Steps.kt index 057fa1ff5..d0b9369a3 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/Steps.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/Steps.kt @@ -43,6 +43,8 @@ internal object Steps { @Composable internal fun StepsLayer(origin: Offset) { val ask = Steps.step ?: return + // Back (B, or the system's) folds what is stepped out, before it reaches the page under it. + androidx.activity.compose.BackHandler(enabled = Steps.open) { Steps.fold() } key(ask) { StepOut( open = Steps.open, pill = ask.anchor.translate(-origin), side = ask.side, accent = ask.accent, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dbe5c5a0c..2cb73381d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2180,4 +2180,21 @@ %1$d fps Touch off Graphics drivers + + This Proton + Every Proton + For every Proton + Available · %1$d + Checked %1$s + Check for new components and drivers + Get + %1$s · DXVK, VKD3D-Proton and FEX below are this Proton\'s + %1$s · tested + %1$s · untested + %1$s · unsupported + Keeps the recommended pair current + Auto · %1$s + Runtime and display drivers separately + Use %1$s? + Remove %1$s? diff --git a/app/src/test/java/com/droiddeck/launcher/ui/LayerStepTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/LayerStepTest.kt new file mode 100644 index 000000000..a8581d893 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/ui/LayerStepTest.kt @@ -0,0 +1,24 @@ +package com.droiddeck.launcher.ui + +import org.junit.Assert.assertEquals +import org.junit.Test + +class LayerStepTest { + @Test fun theStackRunsFromTheProtonDownToTheGpuDrivers() { + assertEquals(listOf(PROTON_TAB, "dxvk", "vkd3d", "fex", GPU_TAB), LAYERS) + } + + @Test fun rbStepsDownAndWraps() { + assertEquals("dxvk", layerStep(PROTON_TAB, 1)) + assertEquals(PROTON_TAB, layerStep(GPU_TAB, 1)) + } + + @Test fun lbStepsUpAndWraps() { + assertEquals("fex", layerStep(GPU_TAB, -1)) + assertEquals(GPU_TAB, layerStep(PROTON_TAB, -1)) + } + + @Test fun anUnknownLayerStartsFromTheTop() { + assertEquals("dxvk", layerStep("tab-from-an-older-build", 1)) + } +}