Add VITURE glasses support: hardware control, 3D, head tracking

Glasses get their own controller over the MCU (permission, 120 Hz default, brightness, volume, sunblock, 2D/3D) and the game moves onto them when plugged in. The IMU drives Cardboard head tracking and the SteamVR driver. 3D falls back to one eye's view on phones that can't send the 3840x1080 signal. Options open from a glasses button in game and on the Steam page.
This commit is contained in:
maxjivi05 committed 2026-10-13 11:24:01 -04:00
1 parent 31d12a9f6c
commit 1e66ff17c1
37 files changed
+2624 -318

No files matched your search

@@ -0,0 +1,353 @@
package com.droiddeck.launcher.ui
import androidx.activity.compose.BackHandler
import androidx.compose.animation.core.Animatable
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.background
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.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraintsScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.runtime.withFrameNanos
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.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.lerp
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.input.InputMode
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.boundsInParent
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalInputModeManager
import androidx.compose.ui.platform.testTag
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.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.util.lerp
import androidx.compose.ui.zIndex
import com.droiddeck.launcher.R
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.math.roundToInt
private const val DROP_PIECES = 10
internal class DropSheetState(private val scope: CoroutineScope) {
var open by mutableStateOf(false)
var shown by mutableStateOf(false)
var settledByDrag = false
var engaged = false
private set
val lift = Animatable(0f)
val ride = Animatable(0f)
val sink = Animatable(0f)
val hot = Animatable(1f)
val pieces = List(DROP_PIECES) { Animatable(0f) }
var travelPx = 1f
private var from = 0f
private var progress = 0f
private var dragJob: Job? = null
fun cancelDrag() {
dragJob?.cancel()
dragJob = null
}
fun reset() {
cancelDrag()
engaged = false
settledByDrag = false
open = false
shown = false
scope.launch {
listOf(lift, ride, sink).forEach { it.snapTo(0f) }
pieces.forEach { it.snapTo(0f) }
hot.snapTo(1f)
}
}
fun beginDrag() {
cancelDrag()
settledByDrag = false
engaged = true
from = if (open) 1f else 0f
progress = from
if (!open) shown = true
}
fun drag(dy: Float) {
progress = (progress + dy / travelPx).coerceIn(0f, 1.04f)
val p = progress
scope.launch {
lift.snapTo(p); ride.snapTo(p); sink.snapTo(p.coerceIn(0f, 1f)); hot.snapTo(0f)
pieces.forEach { it.snapTo(p.coerceIn(0f, 1f)) }
}
}
fun settle(v: Float, flick: Float) {
engaged = false
val opens = when {
v > flick -> true
v < -flick -> false
from > 0.5f -> progress > 0.7f
else -> progress > 0.3f
}
settledByDrag = true
cancelDrag()
dragJob = scope.launch {
val to = if (opens) 1f else 0f
coroutineScope {
launch { lift.animateTo(to, Motion.sp(if (opens) 0.7f else 1f, 380f)) }
launch { ride.animateTo(to, Motion.sp(if (opens) 0.7f else 0.55f, if (opens) 380f else 300f)) }
launch { sink.animateTo(to, Motion.tw(220)) }
pieces.forEachIndexed { i, piece -> launch { if (opens) delay(Motion.ms(i * 35).toLong()); piece.animateTo(to, Motion.tw(if (opens) 200 else 90)) } }
}
if (!opens) { shown = false; hot.snapTo(1f) }
}
if (open != opens) open = opens else settledByDrag = false
}
}
@Composable
internal fun rememberDropSheetState(): DropSheetState {
val scope = rememberCoroutineScope()
return remember { DropSheetState(scope) }
}
@OptIn(androidx.compose.ui.ExperimentalComposeUiApi::class)
@Composable
internal fun BoxWithConstraintsScope.DropSheet(
state: DropSheetState,
title: String,
icon: ImageVector,
label: String,
covered: () -> Float = { 0f },
rows: @Composable () -> Unit,
) {
val density = LocalDensity.current
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val inputMode = LocalInputModeManager.current
val firstRow = remember { FocusRequester() }
val buttonFocus = remember { FocusRequester() }
var rest by remember { mutableStateOf<Rect?>(null) }
fun focusButton() { if (inputMode.inputMode == InputMode.Keyboard) runCatching { buttonFocus.requestFocus() } }
fun close() {
if (!state.open) return
state.open = false
focusButton()
}
val lifecycle = androidx.compose.ui.platform.LocalLifecycleOwner.current.lifecycle
DisposableEffect(lifecycle) {
val obs = androidx.lifecycle.LifecycleEventObserver { _, e ->
if (e == androidx.lifecycle.Lifecycle.Event.ON_STOP && (state.open || state.shown || state.engaged)) state.reset()
}
lifecycle.addObserver(obs)
onDispose { lifecycle.removeObserver(obs) }
}
LaunchedEffect(state.open) {
if (state.settledByDrag) {
state.settledByDrag = false
if (state.open) {
if (inputMode.inputMode == InputMode.Keyboard) { withFrameNanos { }; runCatching { firstRow.requestFocus() } }
} else focusButton()
return@LaunchedEffect
}
if (state.engaged) return@LaunchedEffect
state.cancelDrag()
if (state.open) {
state.shown = true
coroutineScope {
launch { state.sink.animateTo(1f, Motion.tw(260)) }
launch {
delay(Motion.ms(120).toLong())
launch { state.lift.animateTo(1f, Motion.sp(0.7f, 380f)) }
launch { state.ride.animateTo(1f, Motion.sp(0.7f, 380f)) }
launch { state.hot.snapTo(1f); delay(Motion.ms(100).toLong()); state.hot.animateTo(0f, Motion.tw(200)) }
}
state.pieces.forEachIndexed { i, p -> launch { delay(Motion.ms(120 + 260 + i * 55).toLong()); p.animateTo(1f, Motion.tw(220)) } }
if (inputMode.inputMode == InputMode.Keyboard) launch {
delay(Motion.ms(300).toLong())
withFrameNanos { }
runCatching { firstRow.requestFocus() }
}
}
} else if (state.shown) {
coroutineScope {
state.pieces.forEach { launch { it.animateTo(0f, Motion.tw(90)) } }
launch { delay(Motion.ms(60).toLong()); state.lift.animateTo(0f, Motion.sp(1f, 380f)) }
launch { delay(Motion.ms(100).toLong()); state.ride.animateTo(0f, Motion.sp(0.55f, 300f)) }
launch { state.sink.animateTo(0f, Motion.tw(300)) }
}
state.shown = false
state.hot.snapTo(1f)
} else {
listOf(state.sink, state.lift, state.ride).forEach { it.snapTo(0f) }
state.pieces.forEach { it.snapTo(0f) }
state.hot.snapTo(1f)
}
}
BackHandler(enabled = state.open) { close() }
val w = constraints.maxWidth.toFloat()
val h = constraints.maxHeight.toFloat()
val inset = with(density) { 12.dp.toPx() }
val edge = with(density) { 3.dp.toPx() }
val buttonH = rest?.height ?: with(density) { 48.dp.toPx() }
val openBottom = h - sheetTop(h, buttonH, with(density) { 16.dp.toPx() }, edge)
val lower = rest?.let { (openBottom - edge - buttonH / 2f) - it.top } ?: 0f
state.travelPx = openBottom.coerceAtLeast(1f)
if (state.shown || state.open) Box(
Modifier.fillMaxSize()
.graphicsLayer { alpha = state.sink.value }.background(Color.Black.copy(alpha = 0.42f))
.focusProperties { canFocus = false }
.clickable(interactionSource = remember { MutableInteractionSource() }, indication = null, enabled = state.open) { close() },
)
if (state.shown) {
val bottom = lerp(0f, openBottom, state.lift.value)
val corner = with(density) { 18.dp.toPx() }
val rim = with(density) { 1.4.dp.toPx() }
val path = remember { Path() }
val rimPath = remember { Path() }
Canvas(Modifier.fillMaxSize()) {
val l = inset
val r = w - inset
val t = -corner
rimPath.reset()
rimPath.moveTo(l, t)
rimPath.lineTo(l, bottom - corner)
rimPath.arcTo(Rect(l, bottom - 2 * corner, l + 2 * corner, bottom), 180f, -90f, false)
rimPath.lineTo(r - corner, bottom)
rimPath.arcTo(Rect(r - 2 * corner, bottom - 2 * corner, r, bottom), 90f, -90f, false)
rimPath.lineTo(r, t)
path.reset()
path.addPath(rimPath)
path.close()
drawPath(path, lerp(colors.surface, pal.signal, 0.22f * state.hot.value))
drawPath(rimPath, pal.signal.copy(alpha = lerp(0.55f, 0.9f, state.hot.value)), style = Stroke(rim))
}
val sheetW = w - 2 * inset
val rowsTop = with(density) { 62.dp.toPx() }
val rowsBottom = openBottom - edge - buttonH / 2f - with(density) { 8.dp.toPx() }
Box(
Modifier
.offset { IntOffset(inset.roundToInt(), (bottom - openBottom).roundToInt()) }
.size(with(density) { sheetW.toDp() }, with(density) { openBottom.toDp() })
.pointerInput(Unit) { detectTapGestures { } }
.controllerBack { close() }
.focusProperties { exit = { if (state.open) FocusRequester.Cancel else FocusRequester.Default } }
.focusGroup(),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.offset { IntOffset(0, 18.dp.roundToPx()) }
.fillMaxWidth()
.padding(start = 20.dp, end = 64.dp)
.graphicsLayer { val v = state.pieces[0].value; alpha = v; translationY = (1f - v) * -6.dp.toPx() },
) {
Icon(icon, null, tint = pal.signal, modifier = Modifier.size(22.dp))
Spacer(Modifier.width(10.dp))
Text(title, fontSize = 17.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
Column(
Modifier
.offset { IntOffset(0, rowsTop.roundToInt()) }
.fillMaxWidth()
.height(with(density) { (rowsBottom - rowsTop).coerceAtLeast(0f).toDp() })
.focusRequester(firstRow)
.focusGroup()
.verticalScroll(rememberScrollState())
.padding(start = 16.dp, end = 16.dp, bottom = 12.dp),
) {
CompositionLocalProvider(LocalSheetBeat provides remember { SheetBeat(state.pieces) }) { rows() }
}
val closeSource = remember { MutableInteractionSource() }
val closeHot = rememberHot(closeSource)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.offset { IntOffset((sheetW - 52.dp.toPx()).roundToInt(), 8.dp.roundToPx()) }
.zIndex(1f).size(44.dp).testTag("drop-close")
.clip(CircleShape).glideBorder(closeHot, CircleShape, pal.signal)
.hoverable(closeSource)
.clickable(interactionSource = closeSource, indication = LocalIndication.current, enabled = state.open, role = Role.Button) { close() }
.controllerConfirm(enabled = state.open) { close() },
) { Icon(Icons.Filled.Close, stringResource(R.string.common_close), tint = colors.onSurfaceVariant, modifier = Modifier.size(20.dp)) }
}
}
val src = remember { MutableInteractionSource() }
val hot = rememberHot(src)
val toggle = { if (state.open) close() else state.open = true }
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.align(Alignment.TopEnd)
.padding(top = 16.dp, end = 20.dp)
.onGloballyPositioned { rest = it.boundsInParent() }
.graphicsLayer { translationY = lower * state.ride.value; alpha = 1f - covered() }
.zIndex(2f)
.size(48.dp)
.testTag("glasses-open")
.focusRequester(buttonFocus)
.clip(CircleShape)
.background(lerp(colors.surface.copy(alpha = 0.82f), pal.signal, 0.22f * state.ride.value))
.glideBorder(hot, CircleShape, pal.signal, pal.line)
.hoverable(src)
.focusProperties { canFocus = covered() < 0.5f }
.clickable(interactionSource = src, indication = LocalIndication.current, enabled = covered() < 0.5f, role = Role.Button, onClick = toggle)
.controllerConfirm(enabled = covered() < 0.5f, onClick = toggle),
) {
Icon(icon, label, tint = if (hot || state.open) colors.onBackground else colors.onSurfaceVariant, modifier = Modifier.size(26.dp))
}
}
@@ -0,0 +1,175 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.sp
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.runtime.collectAsState
import com.droiddeck.launcher.R
import com.droiddeck.launcher.glasses.Glasses
import com.droiddeck.launcher.glasses.GlassesSettings
import com.droiddeck.launcher.glasses.GlassesState
import java.util.Locale
internal val GlassesIcon: ImageVector by lazy {
ImageVector.Builder("Glasses", 24.dp, 24.dp, 24f, 24f).apply {
path(fill = null, stroke = SolidColor(Color.Black), strokeLineWidth = 1.8f, strokeLineCap = StrokeCap.Round, strokeLineJoin = StrokeJoin.Round) {
moveTo(2.5f, 10f); lineTo(21.5f, 10f)
moveTo(3.2f, 10f); lineTo(3.8f, 15.2f); quadTo(4f, 17f, 6f, 17f); lineTo(8.6f, 17f); quadTo(10.2f, 17f, 10.6f, 15.4f); lineTo(11.2f, 12.6f)
quadTo(12f, 11.6f, 12.8f, 12.6f); lineTo(13.4f, 15.4f); quadTo(13.8f, 17f, 15.4f, 17f); lineTo(18f, 17f); quadTo(20f, 17f, 20.2f, 15.2f); lineTo(20.8f, 10f)
moveTo(2.5f, 10f); lineTo(1.8f, 7.6f)
moveTo(21.5f, 10f); lineTo(22.2f, 7.6f)
}
}.build()
}
@Composable
internal fun rememberGlasses(): Pair<GlassesState, GlassesSettings> {
val g by Glasses.state.collectAsState()
val s by Glasses.settings.collectAsState()
return g to s
}
@Composable
internal fun GlassesGroups(
host: MenuHost,
g: GlassesState,
s: GlassesSettings,
track: (String) -> Modifier = { Modifier },
onRecenter: (() -> Unit)? = null,
inSession: Boolean = true,
steamVr: @Composable () -> Unit = {},
) {
SettingsGroup(g.model) {
val status = if (g.hasDisplay) stringResource(R.string.glasses_status, g.width, g.height, kotlin.math.round(g.hz).toInt(),
stringResource(if (g.sbs) R.string.glasses_mode_3d else R.string.glasses_mode_2d)) else null
when {
g.noSignal -> SettingsRow(stringResource(R.string.glasses_output), stringResource(R.string.glasses_no_signal)) {}
!g.controllable && g.present && g.permission == Glasses.Permission.NONE && !g.connected ->
SettingsRow(stringResource(R.string.glasses_control), status ?: stringResource(R.string.glasses_no_control)) {}
g.permission == Glasses.Permission.ASKING ->
SettingsRow(stringResource(R.string.glasses_control), stringResource(R.string.glasses_asking)) {}
!g.connected && g.controllable -> ActionRow(stringResource(R.string.glasses_control),
stringResource(if (g.permission == Glasses.Permission.DENIED) R.string.glasses_denied else R.string.glasses_allow_hint),
stringResource(R.string.glasses_allow), { Glasses.requestControl() })
status != null -> SettingsRow(stringResource(R.string.glasses_output), status) {}
}
ToggleRow(host, "glasses-game", stringResource(R.string.glasses_game_on), stringResource(R.string.glasses_game_on_hint),
s.gameOnGlasses, chipModifier = track("glasses-game")) { Glasses.setGameOnGlasses(it) }
}
if (g.canControl) SettingsGroup(stringResource(R.string.glasses_display)) {
ChoiceRow(host, "glasses-hz", stringResource(R.string.glasses_refresh), null,
listOf(60, 90, 120).map { it to "$it Hz" }, s.refreshHz, chipModifier = track("glasses-hz")) { Glasses.setRefreshHz(it) }
if (g.sbsSupport == GlassesState.SBS_FAILS && !g.sbs) {
SettingsRow(stringResource(R.string.glasses_3d), stringResource(R.string.glasses_3d_unsupported)) {}
} else {
if (inSession || g.sbs) ToggleRow(host, "glasses-3d", stringResource(R.string.glasses_3d), stringResource(R.string.glasses_3d_hint),
g.sbs, chipModifier = track("glasses-3d")) { Glasses.set3d(it) }
if (g.sbs90) ChoiceRow(host, "glasses-3d-hz", stringResource(R.string.glasses_3d_refresh), null,
listOf(60, 90).map { it to "$it Hz" }, s.sbsHz, chipModifier = track("glasses-3d-hz")) { Glasses.setSbsHz(it) }
ToggleRow(host, "glasses-auto3d", stringResource(R.string.glasses_auto3d), stringResource(R.string.glasses_auto3d_hint),
s.auto3d, chipModifier = track("glasses-auto3d")) { Glasses.setAuto3d(it) }
}
ChoiceRow(host, "glasses-picture", stringResource(R.string.glasses_picture), stringResource(R.string.glasses_picture_hint),
listOf(
GlassesSettings.PICTURE_AUTO to stringResource(R.string.glasses_picture_auto),
GlassesSettings.PICTURE_SCREEN to stringResource(R.string.glasses_picture_screen),
GlassesSettings.PICTURE_SBS to stringResource(R.string.glasses_picture_sbs),
), s.picture3d, chipModifier = track("glasses-picture"), hintLines = 2) { Glasses.setPicture3d(it) }
if (s.picture3d != GlassesSettings.PICTURE_SBS) {
SliderRow(stringResource(R.string.glasses_screen_size), null, s.screenWidthDm, 5..60, step = 1,
format = { String.format(Locale.US, "%.1f m", it / 10f) }, modifier = track("glasses-width")) { Glasses.setScreenWidthDm(it) }
SliderRow(stringResource(R.string.glasses_screen_distance), null, s.screenDistanceDm, 5..100, step = 1,
format = { String.format(Locale.US, "%.1f m", it / 10f) }, modifier = track("glasses-distance")) { Glasses.setScreenDistanceDm(it) }
}
steamVr()
}
if (g.canControl) SettingsGroup(stringResource(R.string.glasses_hardware)) {
SliderRow(stringResource(R.string.glasses_brightness), null, g.brightness.coerceAtLeast(0), 0..g.brightnessMax, step = 1,
modifier = track("glasses-brightness")) { Glasses.setBrightness(it) }
SliderRow(stringResource(R.string.glasses_volume), null, g.volume.coerceAtLeast(0), 0..g.volumeMax, step = 1,
modifier = track("glasses-volume")) { Glasses.setVolume(it) }
ToggleRow(host, "glasses-sunblock", stringResource(R.string.glasses_sunblock), stringResource(R.string.glasses_sunblock_hint),
g.sunblock, chipModifier = track("glasses-sunblock")) { Glasses.setSunblock(it) }
}
if (g.canControl) SettingsGroup(stringResource(R.string.glasses_tracking)) {
ToggleRow(host, "glasses-tracking", stringResource(R.string.glasses_head_tracking), stringResource(R.string.glasses_head_tracking_hint),
s.headTracking, chipModifier = track("glasses-tracking")) { Glasses.setHeadTracking(it) }
if (onRecenter != null && s.headTracking) ActionRow(stringResource(R.string.glasses_recenter), null,
stringResource(R.string.cardboard_recenter_button), onRecenter)
}
}
@Composable
internal fun GlassesCornerButton(slot: Int, tint: Int, opacity: Int, onClick: () -> Unit) {
val density = androidx.compose.ui.platform.LocalDensity.current
androidx.compose.foundation.layout.BoxWithConstraints(
Modifier.fillMaxSize().windowInsetsPadding(WindowInsets.displayCutout),
) {
val x = if (slot < 0) maxWidth / 2 + 56.dp else 34.dp + 56.dp * slot
val bottom = if (slot < 0) 44.dp else 34.dp
val source = remember { MutableInteractionSource() }
val pressed by source.collectIsPressedAsState()
val base = Color(tint)
val alpha = opacity.coerceIn(0, 100) / 100f
val fill = Color(base.red * 0.12f, base.green * 0.12f, base.blue * 0.12f, 190 / 255f)
fun light(a: Int, f: Float) = Color(base.red + (1 - base.red) * f, base.green + (1 - base.green) * f, base.blue + (1 - base.blue) * f, a * alpha / 255f)
val line = if (pressed) light(230, 0.7f) else light(150, 0.25f)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.offset { with(density) { IntOffset((x - 18.dp).roundToPx(), (maxHeight - bottom - 18.dp).roundToPx()) } }
.size(36.dp)
.clip(CircleShape)
.background(fill)
.border(1.5.dp, line, CircleShape)
.clickable(interactionSource = source, indication = null, role = Role.Button, onClick = onClick)
.testTag("glasses-button"),
) {
Icon(GlassesIcon, stringResource(R.string.glasses_open), tint = line, modifier = Modifier.size(22.dp))
}
}
}
@Composable
internal fun GlassesPlayingHint(model: String) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Icon(GlassesIcon, null, tint = Color.White.copy(alpha = 0.35f), modifier = Modifier.size(56.dp))
Spacer(Modifier.height(10.dp))
Text(stringResource(R.string.glasses_playing, model), color = Color.White.copy(alpha = 0.45f), fontSize = 15.sp)
}
}
}
@@ -23,6 +23,7 @@ import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.BoxWithConstraintsScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@@ -210,6 +211,8 @@ internal fun LiftHero(
onOpenChange: (Boolean) -> Unit = {},
start: Dp = 44.dp,
bottom: Dp = 44.dp,
drop: DropSheetState? = null,
overlay: @Composable BoxWithConstraintsScope.(lifted: () -> Float) -> Unit = {},
) {
val density = LocalDensity.current
val inputMode = LocalInputModeManager.current
@@ -455,19 +458,36 @@ internal fun LiftHero(
// A swipe anywhere on the hero moves the sheet under the finger - up from rest, down
// when open - and lets go open or shut by how far it went and how fast. A swipe that
// starts the wrong way (down at rest) is left alone, for the page under it.
.pointerInput(Unit) {
.pointerInput(drop) {
val tracker = androidx.compose.ui.input.pointer.util.VelocityTracker()
var decided = false
val dropFlick = 600.dp.toPx()
detectVerticalDragGestures(
onDragStart = { tracker.resetTracking(); decided = false; drag.engaged = false },
onDragEnd = { if (drag.engaged) settleDrag(tracker.calculateVelocity().y) },
onDragCancel = { if (drag.engaged) settleDrag(0f) },
onDragEnd = {
if (drag.engaged) settleDrag(tracker.calculateVelocity().y)
else if (drop?.engaged == true) drop.settle(tracker.calculateVelocity().y, dropFlick)
},
onDragCancel = {
if (drag.engaged) settleDrag(0f)
else if (drop?.engaged == true) drop.settle(0f, dropFlick)
},
) { change, amount ->
if (launching) return@detectVerticalDragGestures
if (!decided) {
decided = true
// Up at rest opens; down when open closes. Anything else is not for the sheet.
if (if (open) amount > 0f else amount < 0f) beginDrag()
when {
drop != null && (drop.open || drop.shown) -> if (drop.open && amount < 0f) drop.beginDrag()
open || shown || amount < 0f -> if (if (open) amount > 0f else amount < 0f) beginDrag()
drop != null && amount > 0f -> drop.beginDrag()
}
}
if (drop?.engaged == true) {
change.consume()
tracker.addPosition(change.uptimeMillis, change.position)
drop.drag(amount)
return@detectVerticalDragGestures
}
if (!drag.engaged) return@detectVerticalDragGestures
change.consume()
@@ -488,7 +508,8 @@ internal fun LiftHero(
// The wall behind sinks back about the pane's centre.
val foot = h
Box(Modifier.fillMaxSize().clipToBounds().graphicsLayer { val k = 1f - 0.05f * sink.value; scaleX = k; scaleY = k }) { background() }
val wallSink = { maxOf(sink.value, drop?.sink?.value ?: 0f) }
Box(Modifier.fillMaxSize().clipToBounds().graphicsLayer { val k = 1f - 0.05f * wallSink(); scaleX = k; scaleY = k }) { background() }
// The fades stay put: scaled with the wall they stopped short of the pane's edges and left
// a bright band of unfaded wall down the side and along the top.
scrim { sink.value }
@@ -627,7 +648,7 @@ internal fun LiftHero(
// The words and the button, where they always were; the button rides the sheet's edge.
Column(Modifier.align(Alignment.BottomStart).padding(start = start, bottom = bottom, end = 20.dp)) {
Box(Modifier.graphicsLayer { alpha = 1f - sink.value }) { words() }
Box(Modifier.graphicsLayer { alpha = 1f - wallSink() }) { words() }
Spacer(Modifier.height(18.dp))
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
Box(
@@ -662,7 +683,7 @@ internal fun LiftHero(
val besideShown = !(open || shown)
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp),
modifier = Modifier.graphicsLayer { alpha = 1f - sink.value }
modifier = Modifier.graphicsLayer { alpha = 1f - wallSink() }
.focusProperties { canFocus = besideShown },
) { if (besideShown || sink.value < 0.99f) beside() }
}
@@ -694,6 +715,7 @@ internal fun LiftHero(
}
}
}
overlay { sink.value }
}
}
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.ui
/** Stable page identities keep focus and scroll positions when a secondary display comes and goes. */
internal enum class SessionDrawerPage(val firstControl: String) {
CONTROLLER("touch"),
GLASSES("glasses-game"),
SECOND_SCREEN("second-screen:none"),
DISPLAY("hud"),
EFFECTS("look"),
@@ -10,8 +11,10 @@ internal enum class SessionDrawerPage(val firstControl: String) {
SESSION("suspend"),
}
internal fun sessionDrawerPages(hasSecondScreen: Boolean): List<SessionDrawerPage> =
SessionDrawerPage.entries.filter { hasSecondScreen || it != SessionDrawerPage.SECOND_SCREEN }
internal fun sessionDrawerPages(hasSecondScreen: Boolean, hasGlasses: Boolean = false): List<SessionDrawerPage> =
SessionDrawerPage.entries.filter {
(hasSecondScreen || it != SessionDrawerPage.SECOND_SCREEN) && (hasGlasses || it != SessionDrawerPage.GLASSES)
}
internal fun List<SessionDrawerPage>.step(current: SessionDrawerPage, direction: Int): SessionDrawerPage {
val index = indexOf(current).coerceAtLeast(0)
@@ -149,6 +149,7 @@ import java.util.Locale
private val SessionDrawerPage.title: Int get() = when (this) {
SessionDrawerPage.CONTROLLER -> R.string.drawer_page_controller
SessionDrawerPage.GLASSES -> R.string.drawer_page_glasses
SessionDrawerPage.SECOND_SCREEN -> R.string.drawer_second_screen
SessionDrawerPage.DISPLAY -> R.string.drawer_page_display
SessionDrawerPage.EFFECTS -> R.string.drawer_page_effects
@@ -158,6 +159,7 @@ private val SessionDrawerPage.title: Int get() = when (this) {
private val SessionDrawerPage.icon get() = when (this) {
SessionDrawerPage.CONTROLLER -> Icons.Outlined.SportsEsports
SessionDrawerPage.GLASSES -> GlassesIcon
SessionDrawerPage.SECOND_SCREEN -> Icons.Outlined.ScreenShare
SessionDrawerPage.DISPLAY -> Icons.Outlined.DesktopWindows
SessionDrawerPage.EFFECTS -> Icons.Outlined.AutoFixHigh
@@ -217,6 +219,8 @@ class DrawerActions(
val cardboardSensor: Boolean = false,
/** SteamVR in the guest for Cardboard mode (gpu/SteamVr); null while unknown. */
val steamVr: SteamVr.Status? = null,
val glassesPresent: Boolean = false,
val glassesOutput: Boolean = false,
/** Texture filtering for DirectX 9-11 games (core/TextureFiltering); lands on their next launch. */
val textureAnisotropy: Int? = 0,
val textureLodBias: String? = TextureFiltering.LOD_BIAS_OFF,
@@ -254,6 +258,7 @@ class DrawerActions(
val onEffects: (ScreenEffects) -> Unit = {},
val onCardboard: (Cardboard) -> Unit = {},
val onCardboardRecenter: () -> Unit = {},
val onGlassesRecenter: () -> Unit = {},
/** install, start or stop SteamVR. */
val onSteamVr: (String) -> Unit = {},
val onTextureAnisotropy: (Int?) -> Unit = {},
@@ -309,7 +314,7 @@ class DrawerActions(
@OptIn(ExperimentalComposeUiApi::class)
@Composable
internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, controllerActive: Boolean, onPageChange: (SessionDrawerPage) -> Unit, a: DrawerActions) {
val pages = sessionDrawerPages(a.steam && a.secondScreenDisplays.isNotEmpty())
val pages = sessionDrawerPages(a.steam && a.secondScreenDisplays.isNotEmpty(), a.glassesPresent)
val page = requestedPage.takeIf { it in pages } ?: SessionDrawerPage.CONTROLLER
LaunchedEffect(requestedPage, pages) { if (page != requestedPage) onPageChange(page) }
val colors = MaterialTheme.colorScheme
@@ -477,7 +482,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
stringResource(R.string.display_sharpness), null, a.upscaleSharpness, 0..100, step = 5,
format = { "$it%" }, modifier = focus.track(page, "upscale-sharpness"), onChange = a.onUpscaleSharpness)
}
CardboardGroup(host, a) { key -> focus.track(page, key) }
if (!a.glassesOutput) CardboardGroup(host, a) { key -> focus.track(page, key) }
}
SessionDrawerPage.EFFECTS -> {
ScreenEffectsGroup(host, a, advancedEffectsExpanded,
@@ -541,6 +546,11 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
SessionDrawerPage.SECOND_SCREEN -> {
SecondScreenGroup(host, a) { key -> focus.track(page, key) }
}
SessionDrawerPage.GLASSES -> {
val (g, s) = rememberGlasses()
GlassesGroups(host, g, s, { key -> focus.track(page, key) }, onRecenter = a.onGlassesRecenter,
steamVr = { SteamVrRow(a) })
}
SessionDrawerPage.GAMES -> {
if (a.steam) SelectedGameProfileGroup(host, a) { key -> focus.track(page, key) }
Text(stringResource(R.string.fex_next_launch), fontSize = 12.sp,
@@ -948,18 +958,23 @@ private fun CardboardGroup(host: MenuHost, a: DrawerActions, track: (String) ->
}
if (c.headTracking && a.cardboardSensor)
ActionRow(stringResource(R.string.cardboard_recenter), null, stringResource(R.string.cardboard_recenter_button), a.onCardboardRecenter)
val vrLabel = stringResource(R.string.cardboard_steamvr)
when (a.steamVr) {
SteamVr.Status.NOT_INSTALLED -> ActionRow(vrLabel, stringResource(R.string.cardboard_steamvr_install_hint),
stringResource(R.string.cardboard_steamvr_install), { a.onSteamVr("install") })
SteamVr.Status.INSTALLING -> SettingsRow(vrLabel, stringResource(R.string.cardboard_steamvr_installing)) {}
SteamVr.Status.READY -> ActionRow(vrLabel, stringResource(R.string.cardboard_steamvr_ready_hint),
stringResource(R.string.cardboard_steamvr_start), { a.onSteamVr("start") })
SteamVr.Status.RUNNING -> ActionRow(vrLabel, stringResource(R.string.cardboard_steamvr_running_hint),
stringResource(R.string.cardboard_steamvr_stop), { a.onSteamVr("stop") })
SteamVr.Status.UNAVAILABLE -> SettingsRow(vrLabel, stringResource(R.string.cardboard_steamvr_unavailable)) {}
null -> {}
}
SteamVrRow(a)
}
}
@Composable
private fun SteamVrRow(a: DrawerActions) {
val vrLabel = stringResource(R.string.cardboard_steamvr)
when (a.steamVr) {
SteamVr.Status.NOT_INSTALLED -> ActionRow(vrLabel, stringResource(R.string.cardboard_steamvr_install_hint),
stringResource(R.string.cardboard_steamvr_install), { a.onSteamVr("install") })
SteamVr.Status.INSTALLING -> SettingsRow(vrLabel, stringResource(R.string.cardboard_steamvr_installing)) {}
SteamVr.Status.READY -> ActionRow(vrLabel, stringResource(R.string.cardboard_steamvr_ready_hint),
stringResource(R.string.cardboard_steamvr_start), { a.onSteamVr("start") })
SteamVr.Status.RUNNING -> ActionRow(vrLabel, stringResource(R.string.cardboard_steamvr_running_hint),
stringResource(R.string.cardboard_steamvr_stop), { a.onSteamVr("stop") })
SteamVr.Status.UNAVAILABLE -> SettingsRow(vrLabel, stringResource(R.string.cardboard_steamvr_unavailable)) {}
null -> {}
}
}
@@ -103,8 +103,18 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier)
}
},
)
val (glasses, glassesSettings) = rememberGlasses()
val drop = rememberDropSheetState()
LaunchedEffect(glasses.present) { if (!glasses.present && (drop.open || drop.shown)) drop.reset() }
val glassesLabel = stringResource(R.string.glasses_open)
LiftHero(
key = "steam", tabs = tabs,
drop = drop.takeIf { glasses.present },
overlay = { lifted ->
if (glasses.present) DropSheet(drop, glasses.model, GlassesIcon, glassesLabel, covered = lifted) {
GlassesGroups(rememberMenuHost(), glasses, glassesSettings, inSession = false)
}
},
onOpen = a.onSteamSettings, onPrimary = a.onPlay,
modifier = modifier.clipToBounds(),
start = if (narrow) 20.dp else 44.dp, bottom = if (narrow) 20.dp else 44.dp,