Glasses: Play SteamVR beside the glasses button instead of starting SteamVR with them, pad hands drawn as Index controllers and off while other VR controllers are connected, glasses sheet tabs sized like Steam's

This commit is contained in:
maxjivi05 committed 2026-10-13 16:52:41 -04:00
1 parent b2beed6290
commit b8fe2fbd88
27 files changed
+153 -56

No files matched your search

@@ -194,6 +194,7 @@ internal fun BoxWithConstraintsScope.DropSheet(
icon: ImageVector,
tabs: List<Pair<String, String>>,
covered: () -> Float = { 0f },
beside: @Composable (enabled: Boolean) -> Unit = {},
rows: @Composable (tab: String) -> Unit,
) {
val density = LocalDensity.current
@@ -417,7 +418,7 @@ internal fun BoxWithConstraintsScope.DropSheet(
if (k.keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { if (k.action == KeyEvent.ACTION_DOWN) close(); true } else false
},
) {
SheetChips(tabs.map { it.second }, state.tab, chipFocus) { i -> state.travel = if (i > state.tab) 1 else -1; state.tab = i }
SheetChips(tabs.map { it.second }, state.tab, chipFocus, width = LocalSheetChipWidth.current, end = true) { i -> state.travel = if (i > state.tab) 1 else -1; state.tab = i }
}
val closeSource = remember { MutableInteractionSource() }
val closeHot = rememberHot(closeSource)
@@ -437,6 +438,16 @@ internal fun BoxWithConstraintsScope.DropSheet(
val enabled = covered() < 0.5f
val toggle = { if (state.open) close() else state.open = true }
val sideInset = if (narrow) 20.dp else 44.dp
val besideShown = enabled && !state.open && !state.shown
val r1 = rest
if (r1 != null && (besideShown || state.sink.value < 0.99f)) Box(
Modifier
.align(Alignment.TopEnd)
.padding(top = sideInset, end = sideInset + with(density) { r1.width.toDp() } + 12.dp)
.graphicsLayer { alpha = (1f - state.sink.value) * (1f - covered()) }
.zIndex(2f)
.focusProperties { canFocus = besideShown },
) { beside(besideShown) }
Box(
Modifier
.align(Alignment.TopEnd)
@@ -153,6 +153,7 @@ class FrontEndState(
class FrontEndActions(
val onPlay: () -> Unit,
val onPlaySteamVr: () -> Unit = {},
val onPlayDesktopUi: () -> Unit,
val onSteamGame: (Library.SteamGame) -> Unit,
val onGameShortcut: (Library.SteamGame) -> Unit = {},
@@ -196,7 +196,7 @@ internal fun SetupPanel(
),
) {
PageHeader(stringResource(R.string.setup_title)) {
Box(Modifier.weight(1f)) { SheetChips(tabs, tab, chipFocus, pick) }
Box(Modifier.weight(1f)) { SheetChips(tabs, tab, chipFocus, onPick = pick) }
}
Column(modifier = Modifier.weight(1f).fillMaxWidth().verticalScroll(rememberScrollState()).padding(bottom = 24.dp)) {
when (tab) {
@@ -130,8 +130,6 @@ internal fun GlassesGroups(
format = { String.format(Locale.US, "%.1f m", it / 10f) }, modifier = track("glasses-distance")) { Glasses.setScreenDistanceDm(it) }
}
steamVr()
ToggleRow(host, "glasses-auto-steamvr", stringResource(R.string.glasses_auto_steamvr), stringResource(R.string.glasses_auto_steamvr_hint),
s.autoSteamVr, chipModifier = track("glasses-auto-steamvr")) { Glasses.setAutoSteamVr(it) }
SliderRow(stringResource(R.string.glasses_vr_fov), stringResource(R.string.glasses_vr_fov_hint), s.vrFovDeg,
GlassesSettings.VR_FOV_MIN..GlassesSettings.VR_FOV_MAX, step = 1,
format = { "$it°" }, modifier = track("glasses-vr-fov")) { Glasses.setVrFovDeg(it) }
@@ -54,6 +54,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf
@@ -105,6 +106,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.isSpecified
import androidx.compose.ui.unit.sp
import androidx.compose.ui.util.lerp
import com.droiddeck.launcher.R
@@ -157,6 +159,13 @@ internal class SheetBeat(private val pieces: List<Animatable<Float, AnimationVec
/** The sheet whose rows are being laid out, so each settings group can take its beat. */
internal val LocalSheetBeat = staticCompositionLocalOf<SheetBeat?> { null }
internal val LocalSheetChipWidth = compositionLocalOf { Dp.Unspecified }
private val ChipGap = 6.dp
internal fun sheetChipWidth(row: Dp, count: Int): Dp =
if (count > 0 && row / count >= 96.dp) (row - ChipGap * (count - 1)) / count else 0.dp
/** A settings group's piece of the sheet's entrance; nothing outside a sheet. */
@Composable
internal fun Modifier.sheetPiece(): Modifier {
@@ -368,7 +377,7 @@ internal fun LiftHero(
val lipFocus = remember { FocusRequester() }
val settingsLabel = stringResource(R.string.drawer_page_settings)
var lipFocused by remember { mutableStateOf(false) }
val lipWanted = !open && (!shown || lipBack) && (playFocused || playHovered || touchOnly || lipFocused)
val lipWanted = !open && (!shown || lipBack) && (playFocused || playHovered || touchOnly || lipFocused) && drop?.let { it.open || it.shown } != true
LaunchedEffect(lipWanted) {
if (lipWanted) {
// Back from the sheet it comes straight away; otherwise a beat after Play has focus.
@@ -507,6 +516,12 @@ internal fun LiftHero(
// Play's raised place: its centre 3dp under the sheet's edge, same left inset.
val raise = restRect?.let { (openTop + with(density) { 3.dp.toPx() } - buttonH / 2f) - it.top } ?: 0f
travelPx[0] = (h - openTop).coerceAtLeast(1f)
val pill = restRect?.translate(0f, raise)
// What the sheet holds: the chips to the right of Play, the rows under them.
val chipsX = with(density) {
if (narrow || pill == null) 16.dp.toPx() else pill.right + 20.dp.toPx() - inset
}
val chipWidth = with(density) { sheetChipWidth((w - 2 * inset - chipsX - 64.dp.toPx()).coerceAtLeast(0f).toDp(), tabs.size) }
// The wall behind sinks back about the pane's centre.
val foot = h
@@ -532,7 +547,6 @@ internal fun LiftHero(
val rimPath = remember { Path() }
val corner = with(density) { SheetCorner.toPx() }
val rim = with(density) { 1.4.dp.toPx() }
val pill = restRect?.translate(0f, raise)
Canvas(Modifier.fillMaxSize()) {
val f = fold.value
val ft = foldTop.value
@@ -560,10 +574,6 @@ internal fun LiftHero(
drawPath(rimPath, rimColor, style = Stroke(rim))
}
}
// What the sheet holds: the chips to the right of Play, the rows under them.
val chipsX = with(density) {
if (narrow || pill == null) 16.dp.toPx() else pill.right + 20.dp.toPx() - sheetLeft
}
val chipsY = with(density) { if (narrow && pill != null) (pill.bottom - openTop) + 10.dp.toPx() else ChipsTop.toPx() }
// The rows start under the chips, which are 44dp to touch: from 54dp they ran under the
// chips' feet and, scrolled, covered them.
@@ -656,7 +666,7 @@ internal fun LiftHero(
Box(
Modifier
.onGloballyPositioned { rest = it.boundsInRoot() }
.graphicsLayer { translationY = raise * ride.value }
.graphicsLayer { translationY = raise * ride.value; alpha = 1f - (drop?.sink?.value ?: 0f) }
.onFocusChanged {
// Left out of the sheet (from the chips or a row) folds it, as Up from the chips does.
if (it.hasFocus && leftForPlay[0]) { leftForPlay[0] = false; if (openState.value && !launchingState.value) close() }
@@ -702,7 +712,7 @@ internal fun LiftHero(
Modifier
.offset { IntOffset((r0.center.x - handleW / 2f).roundToInt(), (r0.bottom + raise * ride.value + (lipShow.value - 1f) * 8.dp.toPx()).roundToInt()) }
.onSizeChanged { handleW = it.width.toFloat() }
.graphicsLayer { alpha = lipShow.value * (1f - lipGone.value) }
.graphicsLayer { alpha = lipShow.value * (1f - lipGone.value) * (1f - (drop?.sink?.value ?: 0f)) }
// 44dp to touch, with a 32dp visible handle.
.heightIn(min = 44.dp).testTag("sheet-open")
.semantics { contentDescription = settingsLabel }
@@ -717,7 +727,7 @@ internal fun LiftHero(
}
}
}
overlay { sink.value }
CompositionLocalProvider(LocalSheetChipWidth provides chipWidth) { overlay { sink.value } }
}
}
@@ -785,7 +795,14 @@ private fun Modifier.drawBorderSidesAndFoot(color: Color, corner: Dp, flip: Bool
*/
@OptIn(ExperimentalComposeUiApi::class)
@Composable
internal fun SheetChips(labels: List<String>, selected: Int, focus: List<FocusRequester>? = null, onPick: (Int) -> Unit) {
internal fun SheetChips(
labels: List<String>,
selected: Int,
focus: List<FocusRequester>? = null,
width: Dp = Dp.Unspecified,
end: Boolean = false,
onPick: (Int) -> Unit,
) {
val pal = LocalPalette.current
val bounds = remember { mutableStateMapOf<Int, Rect>() }
val tint = rememberUpdatedState(pal.signal)
@@ -794,20 +811,24 @@ internal fun SheetChips(labels: List<String>, selected: Int, focus: List<FocusRe
var within by remember { mutableStateOf(false) }
// LB / RB with a pad on the chips: focus goes with the selection.
LaunchedEffect(selected) { if (within) runCatching { chips[selected].requestFocus() } }
BoxWithConstraints(Modifier.fillMaxWidth().onFocusChanged { within = it.hasFocus }) {
val equal = maxWidth / labels.size.coerceAtLeast(1) >= 96.dp
BoxWithConstraints(
Modifier.fillMaxWidth().onFocusChanged { within = it.hasFocus },
contentAlignment = if (end) Alignment.CenterEnd else Alignment.CenterStart,
) {
val equal = !width.isSpecified && maxWidth / labels.size.coerceAtLeast(1) >= 96.dp
val least = if (width.isSpecified) maxOf(width, 64.dp) else 64.dp
val scroll = rememberScrollState()
// Room inside the scroll for the focus ring, which the scroll's clip would otherwise cut.
Box(if (equal) Modifier.fillMaxWidth() else Modifier.edgeFade(scroll).horizontalScroll(scroll).padding(3.dp)) {
Row(
horizontalArrangement = Arrangement.spacedBy(6.dp),
horizontalArrangement = Arrangement.spacedBy(ChipGap),
// Up from the rows lands on the picked chip, not whichever sits above: landing picks.
modifier = (if (equal) Modifier.fillMaxWidth() else Modifier)
.focusProperties { enter = { chips.getOrNull(selected) ?: FocusRequester.Default } }
.focusGroup(),
) {
labels.forEachIndexed { i, label ->
val m = (if (equal) Modifier.weight(1f) else Modifier.widthIn(min = 64.dp))
val m = (if (equal) Modifier.weight(1f) else Modifier.widthIn(min = least))
.onGloballyPositioned { bounds[i] = it.boundsInParent() }
.focusRequester(chips[i])
SheetChip(label, i == selected, m.onFocusChanged { if (it.isFocused && i != selected) onPick(i) }) { onPick(i) }
@@ -110,7 +110,13 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier)
key = "steam", tabs = tabs,
drop = drop.takeIf { glasses.present },
overlay = { lifted ->
if (glasses.present) DropSheet(drop, glasses.model, GlassesIcon, glassesTabs(glasses), covered = lifted) { tab ->
if (glasses.present) DropSheet(
drop, glasses.model, GlassesIcon, glassesTabs(glasses), covered = lifted,
beside = { enabled ->
PrimaryButton(stringResource(R.string.games_play_steamvr), enabled = !s.busy, large = true, icon = Icons.Filled.PlayArrow,
modifier = Modifier.testTag("play-steamvr")) { if (enabled) a.onPlaySteamVr() }
},
) { tab ->
GlassesGroups(rememberMenuHost(), glasses, glassesSettings, inSession = false, tab = tab)
}
},