diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index 68663f8064..e525ddc03f 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -1069,9 +1069,16 @@ class MainActivity : ComponentActivity() { /** The added games as the settings page lists them; a scan of the folder, on this thread (one level, small). */ private fun refreshAddedGames() { - addedGames = com.droiddeck.launcher.frontend.AddedGames.scan(this).map { g -> - com.droiddeck.launcher.ui.AddedGameRow(g.folder.path, g.folderName(), g.exe.path, g.exe.name, g.candidates.map { c -> c.path to c.name }.distinctBy { it.first }) - } + addedGames = scanAddedGames() + fetchAddedGameArt() + } + + /** Walks the added-games folders, which can sit on slow shared storage or an SD card. */ + private fun scanAddedGames() = com.droiddeck.launcher.frontend.AddedGames.scan(this).map { g -> + com.droiddeck.launcher.ui.AddedGameRow(g.folder.path, g.folderName(), g.exe.path, g.exe.name, g.candidates.map { c -> c.path to c.name }.distinctBy { it.first }) + } + + private fun fetchAddedGameArt() { // Art the games do not have yet, from Steam's store, off the main thread; the rail // redraws when something arrives. if (SessionPrefs.addedGamesArt(this) && !artFetchRunning) { @@ -1092,7 +1099,6 @@ class MainActivity : ComponentActivity() { showProtons = false showComponents = false showMapping = false - drivers.refreshDrivers() resolutionCap = SessionPrefs.resolutionCap(this, mode) customResolution = SessionPrefs.customResolution(this, mode) fexPreset = SessionPrefs.fexPreset(this) @@ -1102,7 +1108,6 @@ class MainActivity : ComponentActivity() { steamController = SessionPrefs.steamController(this) runSteamAtStartup = SessionPrefs.runSteamAtStartup(this) addedGamesDirs = SessionPrefs.addedGamesDirs(this) - refreshAddedGames() shapeMode = SessionPrefs.shapeMode(this) hdrOn = SessionPrefs.hdr(this, mode) fpsLimit = SessionPrefs.fpsLimit(this, mode) @@ -1118,13 +1123,26 @@ class MainActivity : ComponentActivity() { mic = SessionPrefs.micEnabled(this) renderer = SessionPrefs.desktopRenderer(this) gameStorage = SessionPrefs.gameStorage(this) - storageOptions = GameStorage.options(this).map { it.label to it.path } - if (mode == SessionService.MODE_STEAM) { - decky.deckyInstalled = DeckyManager.installed(this) - decky.deckySupervisor = DeckyManager.supervisorEnabled(this) - decky.refreshDecky() - } settingsMode = mode + // The page opens at once, on what was last read; the slow part (driver files, a walk of the + // added-games folders, the storage volumes) lands while it animates in. + Thread({ + drivers.refreshDrivers() + val games = scanAddedGames() + val storage = GameStorage.options(this).map { it.label to it.path } + val deckyInstalled = if (mode == SessionService.MODE_STEAM) DeckyManager.installed(this) else null + val deckySupervisor = mode == SessionService.MODE_STEAM && DeckyManager.supervisorEnabled(this) + ui.post { + addedGames = games + storageOptions = storage + if (mode == SessionService.MODE_STEAM) { + decky.deckyInstalled = deckyInstalled + decky.deckySupervisor = deckySupervisor + decky.refreshDecky() + } + fetchAddedGameArt() + } + }, "mode-settings").start() } /** A second Steam library, proven writable first; "" = internal only. */ diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java index 43d0687014..6e58dd84e6 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java @@ -367,9 +367,7 @@ public final class LinuxRuntime { * Valve's mangoapp (Deck mode's performance overlay) reads an Adreno GPU's load, clock and * temperatures from where they are on Valve's own hardware; every Adreno under Android keeps * them in KGSL's sysfs, readable by the app, though which files a kernel has differs between - * Snapdragon generations - so each value takes the first source that exists, the order other - * Android PC emulators (GameNative, Winlator forks) read them in. A value found nowhere is left - * alone. + * Snapdragon generations. */ private static void bindAdrenoStats(List cmd, List extraBinds) { String kgsl = "/sys/class/kgsl/kgsl-3d0/"; diff --git a/app/src/main/java/com/droiddeck/launcher/session/GpuStatsComponent.kt b/app/src/main/java/com/droiddeck/launcher/session/GpuStatsComponent.kt index 9a2cac46ef..205240fa28 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/GpuStatsComponent.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/GpuStatsComponent.kt @@ -14,9 +14,7 @@ import java.io.RandomAccessFile * not on one that is missing, which it skips. An enforcing SELinux policy (every retail phone) * refuses apps some or all of KGSL's sysfs, each vendor differently, so mangoapp died on start and * the session ran with no overlay. Where any of the three is refused, a directory of our own is - * bound there instead, each value fed twice a second from the first source this device lets the - * app read - the places other Android overlays (GameNative, WinNative, Bannerlator) read an - * Adreno's numbers from, across Snapdragon generations and vendor kernels. A value with no + * bound there instead. A value with no * readable source is left out, and the overlay shows no line for it. Where all three are * readable, nothing is done. * diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndContent.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndContent.kt index cc9e641a5b..941d49b499 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndContent.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndContent.kt @@ -4,6 +4,17 @@ import androidx.compose.ui.res.pluralStringResource import androidx.compose.runtime.CompositionLocalProvider import android.os.Build import androidx.compose.animation.AnimatedContent +import androidx.compose.animation.EnterExitState +import androidx.compose.animation.ExitTransition +import androidx.compose.animation.core.FastOutSlowInEasing +import androidx.compose.animation.core.animateFloat +import androidx.compose.animation.scaleIn +import androidx.compose.animation.scaleOut +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.rememberUpdatedState +import androidx.compose.ui.geometry.Rect +import androidx.compose.ui.layout.onGloballyPositioned +import androidx.compose.ui.layout.positionInRoot import androidx.compose.animation.Crossfade import androidx.compose.animation.core.Spring import androidx.compose.animation.core.animateFloatAsState @@ -86,6 +97,7 @@ import java.io.File // The front end's right-hand pane and the page it shows: backdrop, desktop card and emulators. +@OptIn(androidx.compose.animation.ExperimentalAnimationApi::class) @Composable internal fun Pane( s: FrontEndState, selected: String, a: FrontEndActions, page: (@Composable () -> Unit)?, modifier: Modifier, @@ -102,17 +114,53 @@ internal fun Pane( else -> null } Backdrop(backdropArt) + val pal = LocalPalette.current + // Pages keep drawing while they leave, so one can fold away instead of blinking out. + val pages = remember { HashMap Unit>() } + // Pages opened from a control (the cog), with where that control sat, in this pane's coordinates. + val origins = remember { HashMap() } + val paneAt = remember { arrayOf(Offset.Zero) } + val livePage by rememberUpdatedState(s.pageKey) + // Picking another game changes the detail beside the list, not the whole page. + val target = if (page != null && s.pageKey != null) s.pageKey else if (selected.startsWith("app:")) "games" else selected + if (page != null && s.pageKey != null) { + pages[s.pageKey] = page + if (s.pageKey !in origins) PageOrigin.take()?.let { origins[s.pageKey] = it.translate(-paneAt[0]) } + } AnimatedContent( - // Picking another game changes the detail beside the list, not the whole page. - targetState = if (page != null && s.pageKey != null) s.pageKey else if (selected.startsWith("app:")) "games" else selected, + targetState = target, + modifier = Modifier.onGloballyPositioned { paneAt[0] = it.positionInRoot() }, transitionSpec = { - (fadeIn(Motion.tw(300, 80)) + slideInVertically(Motion.tw(420, 80)) { it / 24 }) - .togetherWith(fadeOut(Motion.tw(170)) + slideOutVertically(Motion.tw(170)) { -it / 40 }) - .apply { targetContentZIndex = 1f } + when { + // Into a page from its control: the page blooms over a pane that sinks back. + targetState in origins -> (fadeIn(Motion.tw(120))) + .togetherWith(fadeOut(Motion.tw(320, 80)) + scaleOut(Motion.tw(480), targetScale = 0.95f)) + .apply { targetContentZIndex = 1f } + // Back out of it: the page folds into the control as the pane comes forward again. + initialState in origins -> (fadeIn(Motion.tw(300, 100)) + scaleIn(Motion.tw(460, 40), initialScale = 0.95f)) + .togetherWith(ExitTransition.None) + .apply { targetContentZIndex = -1f } + else -> (fadeIn(Motion.tw(300, 80)) + slideInVertically(Motion.tw(420, 80)) { it / 24 }) + .togetherWith(fadeOut(Motion.tw(170)) + slideOutVertically(Motion.tw(170)) { -it / 40 }) + .apply { targetContentZIndex = 1f } + } }, label = "pane", ) { key -> - if (page != null && key == s.pageKey) page() + val shown = if (page != null && key == s.pageKey) page else pages[key] + if (shown != null) { + DisposableEffect(key) { onDispose { if (key != livePage) { pages.remove(key); origins.remove(key) } } } + val from = origins[key] + if (from == null) shown() + else { + val open by transition.animateFloat( + // An even ease, not Motion.Ease: that one covers most of the pane in its first tenth. + transitionSpec = { if (targetState == EnterExitState.Visible) Motion.tw(620, easing = FastOutSlowInEasing) else Motion.tw(440, easing = FastOutSlowInEasing) }, + label = "bloom", + ) { if (it == EnterExitState.Visible) 1f else 0f } + Box(Modifier.fillMaxSize().bloom({ open }, from.center, from.minDimension / 2f, pal.background, pal.signal)) { shown() } + } + } else Content(s, if (key == "games") selected else key, a, Modifier.fillMaxSize(), onSelect, onAndroidAppClick, onOpenDeveloperOptions, onRequestWirelessAdb) } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndWidgets.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndWidgets.kt index 311f839d31..50d66bb3d8 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndWidgets.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndWidgets.kt @@ -43,6 +43,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment @@ -229,11 +230,18 @@ internal fun Cog(size: androidx.compose.ui.unit.Dp = 48.dp, onClick: () -> Unit) val colors = MaterialTheme.colorScheme val src = remember { MutableInteractionSource() } val hot = rememberHot(src) - val rot by animateFloatAsState(if (hot) 90f else 0f, Motion.sp(0.55f), label = "cog") + // A press spins it on a half turn as the page it opens blooms out of it (PageOrigin). + var spins by remember { mutableIntStateOf(0) } + val rot by animateFloatAsState((if (hot) 90f else 0f) + spins * 180f, Motion.sp(0.55f), label = "cog") val pal = LocalPalette.current + val placed = remember { arrayOfNulls(1) } Box( contentAlignment = Alignment.Center, - modifier = Modifier.paneItem("cog").downToFirstTile().size(size).clip(if (size > 48.dp) Shape14 else Shape12).background(Color.White.copy(alpha = 0.03f)).glideBorder(hot, if (size > 48.dp) Shape14 else Shape12, pal.signal, pal.line2) - .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, onClick = onClick), + modifier = Modifier.paneItem("cog").downToFirstTile().size(size).onGloballyPositioned { placed[0] = it }.clip(if (size > 48.dp) Shape14 else Shape12).background(Color.White.copy(alpha = 0.03f)).glideBorder(hot, if (size > 48.dp) Shape14 else Shape12, pal.signal, pal.line2) + .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current) { + placed[0]?.takeIf { it.isAttached }?.let { PageOrigin.mark(it.boundsInRoot()) } + spins++ + onClick() + }, ) { Icon(Icons.Filled.Settings, stringResource(R.string.drawer_page_settings), tint = if (hot) pal.signal else colors.onBackground, modifier = Modifier.size(if (size > 48.dp) 20.dp else 18.dp).rotate(rot)) } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/PageBloom.kt b/app/src/main/java/com/droiddeck/launcher/ui/PageBloom.kt new file mode 100644 index 0000000000..93701978ba --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/PageBloom.kt @@ -0,0 +1,81 @@ +package com.droiddeck.launcher.ui + +import android.os.SystemClock +import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.geometry.Rect +import androidx.compose.ui.geometry.Size +import androidx.compose.ui.draw.drawWithContent +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.Outline +import androidx.compose.ui.graphics.drawscope.Stroke +import androidx.compose.ui.graphics.Path +import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.graphics.TransformOrigin +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.unit.Density +import androidx.compose.ui.unit.LayoutDirection +import androidx.compose.ui.unit.dp +import kotlin.math.hypot +import kotlin.math.max + +// A page that opens from a control (the cog beside Play) blooms out of it: a circle growing from +// the control until it fills the pane, and folding back into it on the way out. + +internal object PageOrigin { + private var bounds: Rect? = null + private var at = 0L + + /** The control a page is about to open from, in root coordinates. */ + fun mark(r: Rect) { + bounds = r + at = SystemClock.uptimeMillis() + } + + /** The control just pressed, once: stale after a second, so a page opened another way never blooms. */ + fun take(): Rect? = bounds.takeIf { SystemClock.uptimeMillis() - at < 1_000 }.also { bounds = null } +} + +/** + * Clips to a circle around [origin] (in this element's own coordinates) that grows from [from] px + * to past the farthest corner as [progress] goes 0 to 1, filled with [fill] so the disc reads even + * over a page that draws no ground of its own, a [rim] tracing its edge, and a small zoom in from + * the same point. At 1 nothing is clipped. + */ +internal fun Modifier.bloom(progress: () -> Float, origin: Offset, from: Float, fill: Color, rim: Color): Modifier = + graphicsLayer { + val p = progress() + if (p >= 1f) { + clip = false + return@graphicsLayer + } + shape = CircleAt(origin, radius(size, origin, from, p)) + clip = true + val zoom = 0.94f + 0.06f * p + scaleX = zoom + scaleY = zoom + if (size.width > 0f && size.height > 0f) transformOrigin = TransformOrigin(origin.x / size.width, origin.y / size.height) + }.drawWithContent { + val p = progress() + // Solid while it grows; it gives way to the pane's own backdrop over the last stretch, by + // when the page it covered has faded out underneath. + if (p < 1f) drawRect(fill, alpha = ((1f - p) / 0.3f).coerceIn(0f, 1f)) + drawContent() + if (p < 1f) { + val width = 2.dp.toPx() + drawCircle(rim.copy(alpha = rim.alpha * (1f - p)), radius(size, origin, from, p) - width / 2f, origin, style = Stroke(width)) + } + } + +private fun radius(size: Size, origin: Offset, from: Float, p: Float): Float { + val far = max( + max(hypot(origin.x, origin.y), hypot(size.width - origin.x, origin.y)), + max(hypot(origin.x, size.height - origin.y), hypot(size.width - origin.x, size.height - origin.y)), + ) + return from + (far - from) * p +} + +private class CircleAt(private val centre: Offset, private val radius: Float) : Shape { + override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density) = + Outline.Generic(Path().apply { addOval(Rect(centre, radius)) }) +}