mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
Every menu, dialog and overlay on Jetpack Compose
The main screen, the loading overlay, the HUD line, the drawer and the three dialogs are composables now, driven by state the activities own. The session's SurfaceView and the on-screen pad stay Views underneath a single Compose layer, which is what they are in any Compose app: a compositor surface and a canvas, not menus. The XML layouts are gone; the activities extend ComponentActivity and Back goes through its dispatcher.
This commit is contained in:
1 parent
18364845ad
commit
aa7c71bfb6
15 files changed
+783
-741
No files matched your search
@@ -0,0 +1,67 @@
|
||||
package com.steamdeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.steamdeck.launcher.gpu.FrameGen
|
||||
|
||||
/**
|
||||
* Off, or an engine at 2x/3x/4x. The LSFG rows are dimmed and unpickable until Lossless Scaling
|
||||
* is installed in the Steam client — the engine cannot run without its DLL, so offering it would
|
||||
* only produce a setting that quietly does nothing.
|
||||
*/
|
||||
@Composable
|
||||
fun FrameGenDialog(
|
||||
engine: String,
|
||||
multiplier: Int,
|
||||
lsfgReady: Boolean,
|
||||
onPick: (engine: String, multiplier: Int) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
data class Row(val label: String, val engine: String, val multiplier: Int, val enabled: Boolean)
|
||||
val note = if (lsfgReady) "" else " — install Lossless Scaling in Steam"
|
||||
val rows = listOf(Row("Off", FrameGen.ENGINE_OFF, 2, true)) +
|
||||
(2..4).map { Row("Win-FG ${it}×", FrameGen.ENGINE_WINFG, it, true) } +
|
||||
(2..4).map { Row("LSFG ${it}×$note", FrameGen.ENGINE_LSFG, it, lsfgReady) }
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text("Frame generation") },
|
||||
text = {
|
||||
Column {
|
||||
Text(
|
||||
"Extra frames are generated between the real ones on the way to the screen, so a game running at 30 fps looks like 60. Takes effect at once, mid-game included.",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(bottom = 8.dp),
|
||||
)
|
||||
for (row in rows) {
|
||||
val selected = row.engine == engine && (row.engine == FrameGen.ENGINE_OFF || row.multiplier == multiplier)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.alpha(if (row.enabled) 1f else 0.38f)
|
||||
.clickable(enabled = row.enabled) { onPick(row.engine, row.multiplier) }
|
||||
.padding(vertical = 2.dp),
|
||||
) {
|
||||
RadioButton(selected = selected, onClick = null, enabled = row.enabled)
|
||||
Text(row.label, style = MaterialTheme.typography.bodyMedium, modifier = Modifier.padding(start = 4.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = { TextButton(onClick = onDismiss) { Text("OK") } },
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package com.steamdeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.steamdeck.launcher.R
|
||||
|
||||
/** Everything the main screen shows; the activity owns the values and the work behind them. */
|
||||
class MainUiState(
|
||||
val installed: String?,
|
||||
val ready: Boolean,
|
||||
val available: String?,
|
||||
val availableSize: String?,
|
||||
val busy: Boolean,
|
||||
val stage: String,
|
||||
val percent: Int,
|
||||
val failed: Boolean,
|
||||
val frameGenLabel: String,
|
||||
)
|
||||
|
||||
/**
|
||||
* The whole app outside a session, in one scrolling column that stays a sensible width on a wide
|
||||
* panel: is the runtime installed, is there a newer one, frame generation, and Play.
|
||||
*/
|
||||
@Composable
|
||||
fun MainScreen(
|
||||
state: MainUiState,
|
||||
onPlay: () -> Unit,
|
||||
onRuntime: () -> Unit,
|
||||
onFrameGen: () -> Unit,
|
||||
onCredits: () -> Unit,
|
||||
) {
|
||||
BoxWithConstraints(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(MaterialTheme.colorScheme.background),
|
||||
contentAlignment = Alignment.TopCenter,
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(horizontal = 24.dp, vertical = 20.dp),
|
||||
) {
|
||||
// The column never spans a landscape panel: the buttons stay a readable width.
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.widthIn(max = 420.dp).fillMaxWidth(),
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(R.drawable.logo),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(if (maxWidth > 600.dp) 88.dp else 72.dp),
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text("SteamDeck", style = MaterialTheme.typography.headlineSmall, color = MaterialTheme.colorScheme.onBackground)
|
||||
Text(
|
||||
"Valve's native ARM64 Steam client, under gamescope",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
Spacer(Modifier.height(18.dp))
|
||||
|
||||
val status = when {
|
||||
state.busy -> "Working…"
|
||||
!state.ready -> "Linux runtime not installed"
|
||||
else -> "Ready"
|
||||
}
|
||||
Text(status, style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.onBackground)
|
||||
val detail = when {
|
||||
state.busy -> if (state.percent >= 0) "${state.stage} ${state.percent}%" else state.stage
|
||||
state.failed -> "Install failed — nothing was changed"
|
||||
!state.ready -> state.available?.let { "$it · ${state.availableSize} download, one time" }
|
||||
?: "Could not reach the runtime catalog"
|
||||
state.available != null && state.available != state.installed ->
|
||||
"Runtime ${state.installed ?: "?"} installed · ${state.available} available"
|
||||
else -> "Runtime ${state.installed ?: "?"} installed"
|
||||
}
|
||||
Text(
|
||||
detail,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.padding(top = 4.dp),
|
||||
)
|
||||
if (state.busy) {
|
||||
Spacer(Modifier.height(8.dp))
|
||||
if (state.percent >= 0) {
|
||||
LinearProgressIndicator(progress = { state.percent / 100f }, modifier = Modifier.fillMaxWidth())
|
||||
} else {
|
||||
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(18.dp))
|
||||
|
||||
Button(onClick = onPlay, enabled = state.ready && !state.busy, modifier = Modifier.fillMaxWidth()) {
|
||||
Text("Play")
|
||||
}
|
||||
val runtimeLabel = when {
|
||||
state.busy -> "Working…"
|
||||
!state.ready -> "Install Linux runtime"
|
||||
state.available != null && state.available != state.installed -> "Update Linux runtime"
|
||||
else -> "Remove Linux runtime"
|
||||
}
|
||||
OutlinedButton(onClick = onRuntime, enabled = !state.busy, modifier = Modifier.fillMaxWidth().padding(top = 6.dp)) {
|
||||
Text(runtimeLabel)
|
||||
}
|
||||
OutlinedButton(onClick = onFrameGen, modifier = Modifier.fillMaxWidth().padding(top = 6.dp)) {
|
||||
Text("Frame generation: ${state.frameGenLabel}")
|
||||
}
|
||||
Spacer(Modifier.height(14.dp))
|
||||
Text(
|
||||
"by The412Banner and maxjivi05 · credits",
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.clickable(onClick = onCredits).padding(6.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ConfirmDialog(title: String, text: String, confirm: String, onConfirm: () -> Unit, onDismiss: () -> Unit) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(title) },
|
||||
text = { Text(text) },
|
||||
confirmButton = { TextButton(onClick = { onDismiss(); onConfirm() }) { Text(confirm) } },
|
||||
dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } },
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CreditsDialog(onDismiss: () -> Unit) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text("Credits") },
|
||||
text = {
|
||||
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
|
||||
Text("The412Banner — the app, the Wayland compositor, the runtime and the Steam session.", style = MaterialTheme.typography.bodyMedium)
|
||||
Spacer(Modifier.height(10.dp))
|
||||
Text("maxjivi05 (Max) — the gamescope runtime this is built on: the proot session, the session shim, the fake-evdev interposer and the controller work, from WinNative.", style = MaterialTheme.typography.bodyMedium)
|
||||
Spacer(Modifier.height(10.dp))
|
||||
Text(
|
||||
"GPL-3.0. Valve, Steam, Steam Deck and Proton are trademarks of Valve Corporation; this project is not affiliated with Valve. gamescope, Mesa, Turnip, Xwayland, PulseAudio, proot and Arch Linux ARM are their authors' own.",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
},
|
||||
confirmButton = { TextButton(onClick = onDismiss) { Text("OK") } },
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.steamdeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
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
|
||||
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.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.steamdeck.launcher.R
|
||||
|
||||
/** A line of numbers in the top-right corner. It takes no touches: everything goes to the game. */
|
||||
@Composable
|
||||
fun HudText(text: String) {
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.TopEnd) {
|
||||
Text(
|
||||
text,
|
||||
fontFamily = FontFamily.Monospace,
|
||||
fontSize = 12.sp,
|
||||
color = Color.White,
|
||||
modifier = Modifier
|
||||
.padding(12.dp)
|
||||
.background(Color(0x8C000000))
|
||||
.padding(horizontal = 8.dp, vertical = 3.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What the user sees until the client draws its first frame: the runtime's milestone, the
|
||||
* client's download progress lifted out of its log, a clock, and a hint. Opaque, so a stale
|
||||
* frame from an earlier session never shows through, and it swallows touches.
|
||||
*/
|
||||
@Composable
|
||||
fun LoadingOverlay(step: String, percent: Int, elapsed: String, hint: String, ended: Boolean) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = androidx.compose.foundation.layout.Arrangement.Center,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.Black)
|
||||
.clickable(interactionSource = MutableInteractionSource(), indication = null) {}
|
||||
.padding(32.dp),
|
||||
) {
|
||||
Image(painterResource(R.drawable.logo), contentDescription = null, modifier = Modifier.size(64.dp))
|
||||
Spacer(Modifier.height(14.dp))
|
||||
Text(if (ended) "The session ended" else "Steam is loading", color = Color.White, fontSize = 17.sp)
|
||||
Text(step, color = Color(0xFFB8C4D0), fontSize = 13.sp, textAlign = TextAlign.Center, modifier = Modifier.padding(top = 6.dp))
|
||||
if (!ended) {
|
||||
Spacer(Modifier.height(14.dp))
|
||||
if (percent >= 0) LinearProgressIndicator(progress = { percent / 100f }, modifier = Modifier.width(220.dp))
|
||||
else LinearProgressIndicator(modifier = Modifier.width(220.dp))
|
||||
Text(elapsed, color = Color(0xFF667788), fontSize = 11.sp, modifier = Modifier.padding(top = 8.dp))
|
||||
Text(
|
||||
hint, color = Color(0xFF667788), fontSize = 11.sp, textAlign = TextAlign.Center,
|
||||
modifier = Modifier.padding(top = 18.dp).widthIn(max = 360.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Everything the drawer shows and does. */
|
||||
class DrawerActions(
|
||||
val hudOn: Boolean,
|
||||
val frameGenLabel: String,
|
||||
val oscMode: String,
|
||||
val shapeMode: String,
|
||||
val onHud: (Boolean) -> Unit,
|
||||
val onFrameGen: () -> Unit,
|
||||
val onOsc: () -> Unit,
|
||||
val onShape: () -> Unit,
|
||||
val onBackground: () -> Unit,
|
||||
val onStop: () -> Unit,
|
||||
val onClose: () -> Unit,
|
||||
)
|
||||
|
||||
/**
|
||||
* The drawer Back opens over a running session: the switches a player reaches for mid-game, and
|
||||
* the two things that leave the session. A tap on the dimmed area closes it.
|
||||
*/
|
||||
@Composable
|
||||
fun SessionDrawer(a: DrawerActions) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color(0x66000000))
|
||||
.clickable(interactionSource = MutableInteractionSource(), indication = null, onClick = a.onClose),
|
||||
contentAlignment = Alignment.CenterEnd,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.width(264.dp)
|
||||
.background(Color(0xF2151A22))
|
||||
// The panel swallows its own touches so they do not close it.
|
||||
.clickable(interactionSource = MutableInteractionSource(), indication = null) {}
|
||||
.padding(16.dp),
|
||||
) {
|
||||
Text("SteamDeck", color = Color.White, fontSize = 16.sp, modifier = Modifier.padding(bottom = 12.dp))
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
|
||||
Text("Performance HUD", color = Color(0xFFDDDDDD), fontSize = 13.sp, modifier = Modifier.weight(1f))
|
||||
Switch(checked = a.hudOn, onCheckedChange = a.onHud)
|
||||
}
|
||||
OutlinedButton(onClick = a.onFrameGen, modifier = Modifier.fillMaxWidth().padding(top = 8.dp)) {
|
||||
Text("Frame generation: ${a.frameGenLabel}", fontSize = 13.sp)
|
||||
}
|
||||
OutlinedButton(onClick = a.onOsc, modifier = Modifier.fillMaxWidth().padding(top = 6.dp)) {
|
||||
Text("On-screen controls: ${a.oscMode}", fontSize = 13.sp)
|
||||
}
|
||||
OutlinedButton(onClick = a.onShape, modifier = Modifier.fillMaxWidth().padding(top = 6.dp)) {
|
||||
Text("Display shape: ${a.shapeMode} · next session", fontSize = 13.sp)
|
||||
}
|
||||
Spacer(Modifier.weight(1f))
|
||||
OutlinedButton(onClick = a.onBackground, modifier = Modifier.fillMaxWidth()) {
|
||||
Text("Send to background", fontSize = 13.sp)
|
||||
}
|
||||
OutlinedButton(onClick = a.onStop, modifier = Modifier.fillMaxWidth().padding(top = 6.dp)) {
|
||||
Text("Stop session", fontSize = 13.sp, color = MaterialTheme.colorScheme.error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.steamdeck.launcher.ui
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
/** One dark scheme, the icon's purple as the accent. The app is never light. */
|
||||
private val Scheme = darkColorScheme(
|
||||
primary = Color(0xFFC77DFF),
|
||||
onPrimary = Color(0xFF1B0730),
|
||||
secondary = Color(0xFF8899A6),
|
||||
background = Color(0xFF101418),
|
||||
onBackground = Color(0xFFDDDDDD),
|
||||
surface = Color(0xFF151A22),
|
||||
onSurface = Color(0xFFDDDDDD),
|
||||
surfaceVariant = Color(0xFF1E2530),
|
||||
onSurfaceVariant = Color(0xFF8899A6),
|
||||
error = Color(0xFFFF8A80),
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun SteamDeckTheme(content: @Composable () -> Unit) {
|
||||
MaterialTheme(colorScheme = Scheme, content = content)
|
||||
}
|
||||
Reference in new issue
Block a user