Make frame generation and game zoom controller-friendly (#3669)

Add the session engine picker and the stepped Game zoom slider. Keep Frame Generation in its own tab and use the standard controller focus ring on its buttons.
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-12-04 07:20:03 -05:00
1 parent a6ffbe7d81
commit bf8faf06e1
6 files changed
+492 -89

No files matched your search

@@ -1,21 +1,35 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.withFrameNanos
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.input.InputMode
import androidx.compose.ui.platform.LocalInputModeManager
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
@@ -34,7 +48,9 @@ internal fun FrameGenMenu(
focusModifier: Modifier = Modifier,
legacyButtons: Boolean = false,
listLayout: Boolean = false,
sessionHost: MenuHost? = null,
) {
val sessionEngineAnchor = remember { FocusRequester() }
val need = stringResource(R.string.lsfg_needs_steam)
val selectedEngine = mode.engine.takeIf { it != FrameGen.ENGINE_OFF }
val offLabel = FrameGen.label(LocalContext.current, FrameGen.Mode.OFF)
@@ -95,60 +111,67 @@ internal fun FrameGenMenu(
}
Column(Modifier.fillMaxWidth().padding(start = 10.dp, end = 10.dp, top = 0.dp, bottom = 8.dp)) {
OutlinedButton(
onClick = { onPick(FrameGen.Mode.OFF.copy(multiplier = mode.multiplier)) },
modifier = Modifier.fillMaxWidth().controllerConfirm(
onClick = { onPick(FrameGen.Mode.OFF.copy(multiplier = mode.multiplier)) },
),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selectedEngine == null) colors.primary.copy(alpha = 0.16f) else colors.surface,
contentColor = if (selectedEngine == null) colors.primary else colors.onSurface,
),
) { Text(offLabel) }
if (listLayout) {
Column(Modifier.fillMaxWidth().padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
engines.forEach { (engine, label) ->
val selected = selectedEngine == engine
val enabled = selected || engine != FrameGen.ENGINE_LSFG || lossless.ready
val pick = {
onPick(if (selected) FrameGen.Mode.OFF.copy(multiplier = mode.multiplier) else FrameGen.Mode(engine, mode.multiplier.coerceIn(2, 4)))
}
OutlinedButton(
onClick = pick,
enabled = enabled,
modifier = Modifier.fillMaxWidth().controllerConfirm(enabled = enabled, onClick = pick),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selected) colors.primary.copy(alpha = 0.16f) else colors.surface,
contentColor = if (selected) colors.primary else colors.onSurface,
),
) { Text(label) }
}
}
if (sessionHost != null) {
SessionFrameGenEngine(
sessionHost, mode, listOf(FrameGen.ENGINE_OFF to offLabel) + engines,
lossless.ready, need, focusModifier, sessionEngineAnchor, onPick,
)
} else {
Row(Modifier.fillMaxWidth().padding(top = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
val focusIndex = engines.indexOfFirst { (engine, _) ->
selectedEngine == engine || engine != FrameGen.ENGINE_LSFG || lossless.ready
OutlinedButton(
onClick = { onPick(FrameGen.Mode.OFF.copy(multiplier = mode.multiplier)) },
modifier = Modifier.fillMaxWidth().controllerConfirm(
onClick = { onPick(FrameGen.Mode.OFF.copy(multiplier = mode.multiplier)) },
),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selectedEngine == null) colors.primary.copy(alpha = 0.16f) else colors.surface,
contentColor = if (selectedEngine == null) colors.primary else colors.onSurface,
),
) { Text(offLabel) }
if (listLayout) {
Column(Modifier.fillMaxWidth().padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
engines.forEach { (engine, label) ->
val selected = selectedEngine == engine
val enabled = selected || engine != FrameGen.ENGINE_LSFG || lossless.ready
val pick = {
onPick(if (selected) FrameGen.Mode.OFF.copy(multiplier = mode.multiplier) else FrameGen.Mode(engine, mode.multiplier.coerceIn(2, 4)))
}
OutlinedButton(
onClick = pick,
enabled = enabled,
modifier = Modifier.fillMaxWidth().controllerConfirm(enabled = enabled, onClick = pick),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selected) colors.primary.copy(alpha = 0.16f) else colors.surface,
contentColor = if (selected) colors.primary else colors.onSurface,
),
) { Text(label) }
}
}
engines.forEachIndexed { index, (engine, label) ->
val selected = selectedEngine == engine
val enabled = selected || engine != FrameGen.ENGINE_LSFG || lossless.ready
val pick = {
onPick(if (selected) FrameGen.Mode.OFF.copy(multiplier = mode.multiplier) else FrameGen.Mode(engine, mode.multiplier.coerceIn(2, 4)))
} else {
Row(Modifier.fillMaxWidth().padding(top = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
val focusIndex = engines.indexOfFirst { (engine, _) ->
selectedEngine == engine || engine != FrameGen.ENGINE_LSFG || lossless.ready
}
engines.forEachIndexed { index, (engine, label) ->
val selected = selectedEngine == engine
val enabled = selected || engine != FrameGen.ENGINE_LSFG || lossless.ready
val pick = {
onPick(if (selected) FrameGen.Mode.OFF.copy(multiplier = mode.multiplier) else FrameGen.Mode(engine, mode.multiplier.coerceIn(2, 4)))
}
OutlinedButton(
onClick = pick,
enabled = enabled,
modifier = (if (index == focusIndex) focusModifier else Modifier)
.weight(1f).controllerConfirm(enabled = enabled, onClick = pick),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selected) colors.primary.copy(alpha = 0.16f) else colors.surface,
contentColor = if (selected) colors.primary else colors.onSurface,
),
) { Text(label) }
}
OutlinedButton(
onClick = pick,
enabled = enabled,
modifier = (if (index == focusIndex) focusModifier else Modifier)
.weight(1f).controllerConfirm(enabled = enabled, onClick = pick),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selected) colors.primary.copy(alpha = 0.16f) else colors.surface,
contentColor = if (selected) colors.primary else colors.onSurface,
),
) { Text(label) }
}
}
}
@@ -165,7 +188,8 @@ internal fun FrameGenMenu(
OutlinedButton(
onClick = pickMultiplier,
enabled = multiplierEnabled,
modifier = Modifier.fillMaxWidth().controllerConfirm(enabled = multiplierEnabled, onClick = pickMultiplier),
modifier = Modifier.fillMaxWidth().controllerConfirm(enabled = multiplierEnabled, onClick = pickMultiplier)
.frameGenFocus(sessionHost),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selected) colors.secondary.copy(alpha = 0.18f) else colors.surface,
@@ -185,7 +209,8 @@ internal fun FrameGenMenu(
OutlinedButton(
onClick = pickMultiplier,
enabled = multiplierEnabled,
modifier = Modifier.weight(1f).controllerConfirm(enabled = multiplierEnabled, onClick = pickMultiplier),
modifier = Modifier.weight(1f).controllerConfirm(enabled = multiplierEnabled, onClick = pickMultiplier)
.frameGenFocus(sessionHost),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selected) colors.secondary.copy(alpha = 0.18f) else colors.surface,
@@ -204,7 +229,7 @@ internal fun FrameGenMenu(
OutlinedButton(
onClick = togglePacer,
modifier = Modifier.fillMaxWidth().padding(top = 8.dp)
.controllerConfirm(onClick = togglePacer),
.controllerConfirm(onClick = togglePacer).frameGenFocus(sessionHost),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (pacerEnabled) colors.primary.copy(alpha = 0.16f) else colors.surface,
@@ -230,7 +255,7 @@ internal fun FrameGenMenu(
modifier = Modifier.weight(1f).controllerConfirm(
enabled = lossless.ready,
onClick = pickTarget,
),
).frameGenFocus(sessionHost),
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selected) colors.secondary.copy(alpha = 0.18f) else colors.surface,
@@ -243,21 +268,107 @@ internal fun FrameGenMenu(
}
}
if (selectedEngine == FrameGen.ENGINE_LSFG && !lossless.ready) {
if (sessionHost == null && selectedEngine == FrameGen.ENGINE_LSFG && !lossless.ready) {
Text(need, color = colors.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.padding(top = 6.dp))
}
if (gameProfileId != null) {
val resetGame = onResetGame
if (gameProfileId != null && (sessionHost == null || hasGameOverride)) {
val input = LocalInputModeManager.current
val resetGame = {
if (sessionHost != null && input.inputMode == InputMode.Keyboard) {
sessionEngineAnchor.requestFocus()
}
onResetGame()
}
OutlinedButton(
onClick = resetGame,
modifier = Modifier.fillMaxWidth().padding(top = 8.dp)
.controllerConfirm(onClick = resetGame),
.testTag("framegen-use-global").controllerConfirm(onClick = resetGame)
.frameGenFocus(sessionHost),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
) {
Text(stringResource(R.string.comp_game_use_general) + if (hasGameOverride) "" else " ✓")
Text(if (sessionHost != null) stringResource(R.string.frame_gen_use_global)
else stringResource(R.string.comp_game_use_general) + if (hasGameOverride) "" else " ✓")
}
}
}
}
@Composable
private fun Modifier.frameGenFocus(sessionHost: MenuHost?): Modifier =
if (sessionHost != null) focusGlide(RoundedCornerShape(percent = 50)) else this
@Composable
private fun SessionFrameGenEngine(
host: MenuHost,
mode: FrameGen.Mode,
options: List<Pair<String, String>>,
losslessReady: Boolean,
losslessNote: String,
focusModifier: Modifier,
anchor: FocusRequester,
onPick: (FrameGen.Mode) -> Unit,
) {
val label = stringResource(R.string.frame_gen_engine)
val selectedLabel = options.firstOrNull { (engine, _) -> engine == mode.engine }?.second
?: options.first().second
val key = "frame-generation-engine"
val open = host.open == key
val input = LocalInputModeManager.current
var anchorFocused by remember { mutableStateOf(false) }
var restoreFocus by remember { mutableStateOf(false) }
// The menu has its own focusable window; wait for its exit transition before restoring the anchor.
LaunchedEffect(open) {
if (!open && restoreFocus && host.open == null) {
repeat(24) {
withFrameNanos { }
runCatching { anchor.requestFocus() }
if (anchorFocused) {
restoreFocus = false
return@LaunchedEffect
}
}
restoreFocus = false
}
}
val blockedSelection = !losslessReady && mode.engine == FrameGen.ENGINE_LSFG
SettingsRow(label, losslessNote.takeIf { blockedSelection && !open }, highlighted = open) {
Box {
ValueChip(
selectedLabel, open,
modifier = focusModifier.focusRequester(anchor).onFocusChanged { anchorFocused = it.isFocused }
.heightIn(min = 48.dp).testTag("setting-$key")
.semantics { contentDescription = label; stateDescription = selectedLabel },
) {
if (open) host.open = null
else {
restoreFocus = anchorFocused || input.inputMode == InputMode.Keyboard
host.open = key
}
}
AnchoredMenu(open, onDismiss = { if (host.open == key) host.open = null }, keyboardFocus = restoreFocus) { firstFocus ->
val initial = options.firstOrNull { (engine, _) -> engine == mode.engine }?.first
?: FrameGen.ENGINE_OFF
options.forEach { (engine, text) ->
val selected = engine == mode.engine
val enabled = selected || engine != FrameGen.ENGINE_LSFG || losslessReady
MenuItem(
label = text, checked = selected, enabled = enabled,
detail = losslessNote.takeIf { engine == FrameGen.ENGINE_LSFG && !losslessReady },
focusRequester = firstFocus.takeIf { engine == initial },
modifier = Modifier.heightIn(min = 48.dp).testTag("framegen-engine:$engine"),
) {
host.open = null
if (!selected) {
onPick(if (engine == FrameGen.ENGINE_OFF) FrameGen.Mode.OFF.copy(multiplier = mode.multiplier)
else FrameGen.Mode(engine, mode.multiplier.coerceIn(2, 4)))
}
}
}
}
}
}
@@ -18,9 +18,11 @@ import androidx.compose.ui.input.key.type
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection
import kotlin.math.roundToInt
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
@@ -89,6 +91,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Slider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@@ -933,6 +936,7 @@ private fun DrawerFrameGenSettings(host: MenuHost, a: DrawerActions, track: (Str
hasGameOverride = a.hasGameOverride,
onResetGame = a.onFrameGenReset,
focusModifier = track("frame-generation"),
sessionHost = host,
)
}
}
@@ -948,7 +952,7 @@ private fun DrawerDisplayPage(host: MenuHost, a: DrawerActions, track: (String)
val orientations = SessionPrefs.orientationOptions.map { (value, label) -> value to stringResource(label) }
SettingsGroup(stringResource(R.string.drawer_page_display), key = "display",
detail = summary(if (a.gameZoomAvailable) "${(a.gameZoom * 100.0f).toInt()}%" else null, orientations.labelOf(a.orientation))) {
if (a.gameZoomAvailable) GameZoomRow(a, track)
if (a.gameZoomAvailable) GameZoomRow(a.gameZoom, track, a.onGameZoom)
ChoiceRow(host, "orientation", stringResource(R.string.setup_session_orientation), null,
orientations, a.orientation, chipModifier = track("orientation"), onPick = a.onOrientation)
if (a.steam) PicturePositionRow(host, a.picturePosition, track("picture-position"), onPick = a.onPicturePosition)
@@ -970,27 +974,66 @@ private fun DrawerDisplayPage(host: MenuHost, a: DrawerActions, track: (String)
SecondScreenGroup(host, a, track)
}
private const val GAME_ZOOM_MIN = 100
private const val GAME_ZOOM_MAX = 300
private const val GAME_ZOOM_STEP = 25
private const val GAME_ZOOM_INTERVALS = (GAME_ZOOM_MAX - GAME_ZOOM_MIN) / GAME_ZOOM_STEP
@Composable
private fun GameZoomRow(a: DrawerActions, track: (String) -> Modifier) {
SettingsRow(stringResource(R.string.game_zoom_title), stringResource(R.string.game_zoom_hint)) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(4.dp)) {
val zoomOutEnabled = a.gameZoom > 1.0f
val zoomInEnabled = a.gameZoom < 3.0f
val zoomOut = { a.onGameZoom((a.gameZoom - 0.25f).coerceAtLeast(1.0f)) }
val zoomIn = { a.onGameZoom((a.gameZoom + 0.25f).coerceAtMost(3.0f)) }
val zoomReset = { a.onGameZoom(1.0f) }
OutlinedButton(onClick = zoomOut, enabled = zoomOutEnabled,
modifier = track("game-zoom-out").width(42.dp).controllerConfirm(enabled = zoomOutEnabled, onClick = zoomOut),
contentPadding = PaddingValues(horizontal = 4.dp, vertical = 0.dp)) { Text("−") }
Text("${(a.gameZoom * 100.0f).toInt()}%", fontSize = 12.sp)
OutlinedButton(onClick = zoomIn, enabled = zoomInEnabled,
modifier = track("game-zoom-in").width(42.dp).controllerConfirm(enabled = zoomInEnabled, onClick = zoomIn),
contentPadding = PaddingValues(horizontal = 4.dp, vertical = 0.dp)) { Text("+") }
OutlinedButton(onClick = zoomReset, enabled = zoomOutEnabled,
modifier = track("game-zoom-reset").width(48.dp).controllerConfirm(enabled = zoomOutEnabled, onClick = zoomReset),
contentPadding = PaddingValues(horizontal = 2.dp, vertical = 0.dp)) { Text("1×") }
}
internal fun GameZoomRow(
zoom: Float,
track: (String) -> Modifier,
onZoom: (Float) -> Unit,
) {
val source = remember { MutableInteractionSource() }
val focused by source.collectIsFocusedAsState()
val label = stringResource(R.string.game_zoom_title)
val percent = (zoom * 100f).roundToInt().coerceIn(GAME_ZOOM_MIN, GAME_ZOOM_MAX)
val value = stringResource(R.string.game_zoom_value, percent)
fun detent(value: Float): Int = ((value - GAME_ZOOM_MIN) / GAME_ZOOM_STEP).roundToInt()
val selectedDetent = detent(percent.toFloat())
val rtl = LocalLayoutDirection.current == LayoutDirection.Rtl
val pal = LocalPalette.current
val colors = MaterialTheme.colorScheme
fun chooseDetent(index: Int) {
val next = GAME_ZOOM_MIN + index.coerceIn(0, GAME_ZOOM_INTERVALS) * GAME_ZOOM_STEP
if (next != percent) onZoom(next / 100f)
}
Column(Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 6.dp)) {
Row(
Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
) {
Text(label, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground)
Text(value, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.SemiBold,
color = colors.onSurface, modifier = Modifier.testTag("game-zoom-value"))
}
Slider(
value = (GAME_ZOOM_MIN + selectedDetent * GAME_ZOOM_STEP).toFloat(),
onValueChange = { chooseDetent(detent(it)) },
valueRange = GAME_ZOOM_MIN.toFloat()..GAME_ZOOM_MAX.toFloat(),
steps = GAME_ZOOM_INTERVALS - 1,
interactionSource = source,
modifier = track("game-zoom-slider").fillMaxWidth().heightIn(min = 48.dp)
.glideBorder(focused, RoundedCornerShape(10.dp), pal.signal)
.testTag("game-zoom-slider")
.semantics { contentDescription = label; stateDescription = value }
.onPreviewKeyEvent { event ->
val delta = when (event.key) {
Key.DirectionLeft -> if (rtl) 1 else -1
Key.DirectionRight -> if (rtl) -1 else 1
else -> return@onPreviewKeyEvent false
}
if (event.type == KeyEventType.KeyDown && event.nativeKeyEvent.repeatCount == 0) {
chooseDetent(selectedDetent + delta)
}
true
},
)
}
Box(Modifier.fillMaxWidth().height(1.dp).background(pal.line))
}
@Composable
@@ -322,6 +322,7 @@ private fun PassTriggerMotion(host: android.view.View) {
fun AnchoredMenu(
open: Boolean, onDismiss: () -> Unit, title: String? = null, note: String? = null,
compact: Boolean = false, minWidth: androidx.compose.ui.unit.Dp = 120.dp,
keyboardFocus: Boolean = false,
content: @Composable ColumnScope.(FocusRequester) -> Unit,
) {
val state = remember { MutableTransitionState(false) }
@@ -335,9 +336,9 @@ fun AnchoredMenu(
}
val hostView = androidx.compose.ui.platform.LocalView.current
val firstItemFocus = remember { FocusRequester() }
val inputMode = LocalInputModeManager.current.inputMode
LaunchedEffect(open, inputMode) {
if (open && inputMode == InputMode.Keyboard) {
val requestKeyboardFocus = keyboardFocus || LocalInputModeManager.current.inputMode == InputMode.Keyboard
LaunchedEffect(open, requestKeyboardFocus) {
if (open && requestKeyboardFocus) {
repeat(2) { androidx.compose.runtime.withFrameNanos { } }
runCatching { firstItemFocus.requestFocus() }
android.util.Log.i("AnchoredMenu", "requested first option focus")
@@ -353,10 +354,10 @@ fun AnchoredMenu(
TrackKeyWindow()
PassTriggerMotion(hostView)
val popupInput = LocalInputModeManager.current
LaunchedEffect(open, inputMode) {
if (!open || inputMode != InputMode.Keyboard) return@LaunchedEffect
LaunchedEffect(open, requestKeyboardFocus) {
if (!open || !requestKeyboardFocus) return@LaunchedEffect
popupInput.requestInputMode(InputMode.Keyboard)
repeat(8) {
repeat(if (keyboardFocus) 24 else 8) {
androidx.compose.runtime.withFrameNanos { }
if (runCatching { firstItemFocus.captureFocus() }.getOrDefault(false)) {
firstItemFocus.freeFocus()
@@ -2,7 +2,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path android:fillColor="#FFFFFFFF" android:fillType="evenOdd" android:pathData="M 142 335 L 148 343 L 148 345 L 155 352 L 165 365 L 166 368 L 169 370 L 171 374 L 176 379 L 177 382 L 179 383 L 181 387 L 187 393 L 187 395 L 193 401 L 196 400 L 200 392 L 206 386 L 259 419 L 262 418 L 266 411 L 264 406 L 250 398 L 249 396 L 242 391 L 237 389 L 236 387 L 231 385 L 227 381 L 215 374 L 215 371 L 222 361 L 222 356 L 220 353 Z M 472 198 L 463 195 L 446 195 L 436 198 L 431 198 L 426 200 L 418 201 L 415 203 L 382 209 L 375 212 L 361 214 L 353 217 L 349 224 L 349 226 L 346 229 L 339 245 L 336 248 L 281 354 L 274 365 L 275 370 L 279 376 L 279 379 L 311 450 L 311 453 L 317 465 L 325 473 L 327 474 L 339 474 L 348 470 L 353 465 L 360 454 L 369 436 L 369 434 L 372 430 L 374 424 L 385 404 L 388 396 L 399 376 L 463 246 L 466 243 L 470 232 L 480 214 L 479 205 Z M 444 224 L 445 226 L 337 439 L 334 435 L 332 428 L 316 393 L 315 388 L 312 384 L 312 381 L 305 367 L 305 364 L 307 362 L 348 282 L 369 244 L 369 242 L 372 239 L 381 238 L 386 236 L 390 236 L 395 234 L 409 232 L 423 228 L 432 227 L 440 224 Z M 211 187 L 201 192 L 201 194 L 203 196 L 203 198 L 228 249 L 225 251 L 166 265 L 165 266 L 169 280 L 234 264 L 242 278 L 242 280 L 265 327 L 278 321 L 278 319 L 250 261 L 252 259 L 313 244 L 310 229 L 244 246 L 235 230 L 235 228 L 226 211 L 226 209 L 224 207 L 215 186 Z M 233 127 L 233 129 L 235 131 L 240 133 L 243 136 L 248 138 L 287 162 L 287 165 L 279 178 L 281 181 L 288 183 L 290 182 L 304 186 L 310 186 L 313 188 L 316 187 L 320 189 L 343 192 L 350 195 L 352 194 L 357 196 L 362 196 L 354 186 L 351 184 L 350 181 L 347 179 L 339 168 L 335 165 L 335 163 L 324 152 L 323 149 L 320 147 L 311 135 L 307 134 L 302 136 L 302 138 L 297 144 L 297 146 L 295 148 L 292 148 L 282 141 L 276 139 L 266 132 L 264 132 L 253 125 L 247 123 L 242 119 L 237 120 Z M 221 73 L 212 70 L 195 70 L 175 75 L 170 75 L 154 80 L 140 82 L 135 84 L 130 84 L 123 87 L 103 91 L 95 103 L 88 119 L 86 121 L 79 136 L 75 141 L 73 147 L 66 158 L 59 174 L 56 177 L 23 240 L 24 245 L 34 266 L 34 269 L 44 289 L 44 292 L 60 326 L 63 335 L 67 342 L 72 347 L 76 349 L 91 348 L 95 346 L 106 334 L 118 310 L 118 308 L 120 306 L 229 88 L 228 80 Z M 193 99 L 194 100 L 190 107 L 190 109 L 183 121 L 183 123 L 181 125 L 176 137 L 174 139 L 132 224 L 130 226 L 123 242 L 112 261 L 89 307 L 88 311 L 85 314 L 58 250 L 53 241 L 62 223 L 74 202 L 118 117 L 121 114 L 129 113 L 134 111 L 139 111 L 162 105 L 167 105 L 188 99 Z" />
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M4.5,7.5 H13.8 Q15.5,7.5 15.5,9.2 V18.8 Q15.5,20.5 13.8,20.5 H4.5 Q2.8,20.5 2.8,18.8 V9.2 Q2.8,7.5 4.5,7.5 Z M7.2,4 H18.2 Q20,4 20,5.8 V9 M20,12.2 V18.2 M17,15.2 H23"
android:fillColor="@android:color/transparent"
android:strokeColor="#FFFFFFFF"
android:strokeWidth="1.75"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</vector>
+3
View File
@@ -2838,6 +2838,9 @@
<string name="display_image_scaling">Image scaling</string>
<string name="game_zoom_hint">Adjust game magnification from 100% to 300%</string>
<string name="game_zoom_title">Game zoom</string>
<string name="game_zoom_value">%1$d%%</string>
<string name="frame_gen_engine">Engine</string>
<string name="frame_gen_use_global">Use global setting</string>
<string name="display_integer_scaling">Integer scaling</string>
<string name="display_integer_scaling_hint">Uses the largest whole-number scale that fits. May crop screen edges. If the source is larger than the output, fractional scaling fits the full image. Resolution is configured separately.</string>
<string name="display_scaling_fit">Fit</string>
@@ -0,0 +1,239 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.InputMode
import androidx.compose.ui.input.InputModeManager
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.platform.LocalInputModeManager
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.SemanticsActions
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsFocused
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.click
import androidx.compose.ui.test.performTouchInput
import androidx.compose.ui.test.swipe
import androidx.compose.ui.test.performKeyInput
import androidx.compose.ui.test.performSemanticsAction
import androidx.compose.ui.test.pressKey
import androidx.compose.ui.unit.dp
import com.droiddeck.launcher.gpu.FrameGen
import com.droiddeck.launcher.gpu.Lossless
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNotSame
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
@OptIn(ExperimentalTestApi::class, androidx.compose.ui.ExperimentalComposeUiApi::class)
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], qualifiers = "w360dp-h640dp-port", application = android.app.Application::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class SessionControlDesignTest {
@get:Rule val compose = createRobolectricComposeRule()
private val engineAnchor get() = compose.onNodeWithTag("setting-frame-generation-engine")
private fun engine(name: String) = compose.onNodeWithTag("framegen-engine:$name")
private fun zoom(name: String) = compose.onNodeWithTag("game-zoom-$name")
private fun zoomValue(value: Int) = zoom("value").assertTextEquals("$value%")
// Popup focus transfers after the other window attaches or finishes exiting.
private fun settlePopupFocus() {
compose.runOnIdle { resumeDroppedUiDispatch() }
compose.mainClock.advanceTimeBy(500)
compose.waitForIdle()
}
@Test
fun enginePickerStartsOnSelectionSkipsUnavailableEngineAndRestoresFocus() {
val mode = mutableStateOf(FrameGen.Mode(FrameGen.ENGINE_DDFG, 3))
lateinit var input: InputModeManager
compose.setContent {
DroidDeckTheme {
input = LocalInputModeManager.current
Box(Modifier.width(300.dp)) {
FrameGenMenu(mode.value, Lossless.State.NONE, { mode.value = it }, sessionHost = rememberMenuHost())
}
}
}
compose.runOnIdle { input.requestInputMode(InputMode.Keyboard) }
engineAnchor.performSemanticsAction(SemanticsActions.RequestFocus)
engineAnchor.assertIsFocused().performKeyInput { pressKey(Key.ButtonA) }
settlePopupFocus()
engine(FrameGen.ENGINE_LSFG).assertIsNotEnabled()
engine(FrameGen.ENGINE_DDFG).assertIsFocused().performKeyInput { pressKey(Key.DirectionUp) }
engine(FrameGen.ENGINE_OFF).assertIsFocused().performKeyInput { pressKey(Key.DirectionDown) }
engine(FrameGen.ENGINE_DDFG).assertIsFocused().performKeyInput { pressKey(Key.DirectionDown) }
engine(FrameGen.ENGINE_ZEROFG).assertIsFocused().performKeyInput { pressKey(Key.ButtonA) }
settlePopupFocus()
engine(FrameGen.ENGINE_ZEROFG).assertDoesNotExist()
assertEquals(FrameGen.Mode(FrameGen.ENGINE_ZEROFG, 3), mode.value)
engineAnchor.assertIsFocused().performKeyInput { pressKey(Key.ButtonA) }
settlePopupFocus()
engine(FrameGen.ENGINE_ZEROFG).assertIsFocused().performKeyInput { pressKey(Key.ButtonB) }
settlePopupFocus()
engine(FrameGen.ENGINE_ZEROFG).assertDoesNotExist()
assertEquals(FrameGen.Mode(FrameGen.ENGINE_ZEROFG, 3), mode.value)
engineAnchor.assertIsFocused()
}
@Test
fun gameOverrideCanReturnToGlobalWithoutLosingControllerFocus() {
val override = mutableStateOf(true)
lateinit var input: InputModeManager
compose.setContent {
DroidDeckTheme {
input = LocalInputModeManager.current
FrameGenMenu(
mode = if (override.value) FrameGen.Mode(FrameGen.ENGINE_ZEROFG, 2) else FrameGen.Mode.OFF,
lossless = Lossless.State.NONE,
onPick = {},
gameProfileId = "8400",
hasGameOverride = override.value,
onResetGame = { override.value = false },
sessionHost = rememberMenuHost(),
)
}
}
compose.runOnIdle { input.requestInputMode(InputMode.Keyboard) }
val reset = compose.onNodeWithTag("framegen-use-global")
reset.assertTextEquals("Use global setting").performSemanticsAction(SemanticsActions.RequestFocus)
reset.assertIsFocused().performKeyInput { pressKey(Key.ButtonA) }
reset.assertDoesNotExist()
engineAnchor.assertIsFocused()
}
@Test
fun frameGenButtonsMoveTheDrawerFocusRing() {
lateinit var input: InputModeManager
lateinit var glide: FocusGlide
compose.setContent {
DroidDeckTheme {
FocusGlideHost {
input = LocalInputModeManager.current
glide = checkNotNull(LocalFocusGlide.current)
FrameGenMenu(
mode = FrameGen.Mode(FrameGen.ENGINE_ZEROFG, 2),
lossless = Lossless.State.NONE,
onPick = {},
gameProfileId = "8400",
hasGameOverride = true,
sessionHost = rememberMenuHost(),
)
}
}
}
compose.runOnIdle { input.requestInputMode(InputMode.Keyboard) }
var previous: GlideSource? = null
for (label in listOf("2×", "3×", "4×", "ZeroPacer", "Use global setting")) {
val button = if (label == "ZeroPacer") compose.onNodeWithText(label, substring = true)
else compose.onNodeWithText(label)
button.performSemanticsAction(SemanticsActions.RequestFocus).assertIsFocused()
compose.runOnIdle {
assertNotNull("Missing focus ring for $label", glide.current)
assertNotSame("Focus ring did not move to $label", previous, glide.current)
previous = glide.current
}
}
}
@Test
fun legacyFrameGenerationStillUsesTheFlatOptions() {
compose.setContent {
DroidDeckTheme {
FrameGenMenu(FrameGen.Mode.OFF, Lossless.State.NONE, {}, legacyButtons = true)
}
}
engineAnchor.assertDoesNotExist()
compose.onNodeWithText("ZeroFG 2×").assertExists()
}
@Test
fun zoomStepsBy25PercentAndDpadCanLeaveIt() {
val value = mutableStateOf(1f)
val changes = mutableListOf<Float>()
lateinit var input: InputModeManager
compose.setContent {
DroidDeckTheme {
input = LocalInputModeManager.current
Column(Modifier.width(300.dp)) {
OutlinedButton(onClick = {}, modifier = Modifier.fillMaxWidth().testTag("above")) { Text("Above") }
GameZoomRow(value.value, { Modifier }) { changes += it; value.value = it }
OutlinedButton(onClick = {}, modifier = Modifier.fillMaxWidth().testTag("below")) { Text("Below") }
}
}
}
compose.runOnIdle { input.requestInputMode(InputMode.Keyboard) }
val slider = zoom("slider")
zoomValue(100)
zoom("reset").assertDoesNotExist()
slider.performSemanticsAction(SemanticsActions.RequestFocus)
slider.assertIsFocused().performKeyInput { pressKey(Key.DirectionLeft) }
zoomValue(100)
assertEquals(emptyList<Float>(), changes)
slider.assertIsFocused().performKeyInput { pressKey(Key.DirectionUp) }
compose.onNodeWithTag("above").assertIsFocused().performKeyInput { pressKey(Key.DirectionDown) }
slider.assertIsFocused().performKeyInput { pressKey(Key.DirectionDown) }
compose.onNodeWithTag("below").assertIsFocused().performKeyInput { pressKey(Key.DirectionUp) }
slider.assertIsFocused()
for (percent in 125..300 step 25) {
slider.performKeyInput { pressKey(Key.DirectionRight) }
zoomValue(percent)
slider.assertIsFocused()
}
slider.performKeyInput { pressKey(Key.DirectionRight) }
zoomValue(300)
assertEquals((125..300 step 25).map { it / 100f }, changes)
slider.performKeyInput { pressKey(Key.DirectionLeft) }
zoomValue(275)
zoom("reset").assertDoesNotExist()
slider.performKeyInput { pressKey(Key.DirectionDown) }
compose.onNodeWithTag("below").assertIsFocused().performKeyInput { pressKey(Key.DirectionUp) }
slider.assertIsFocused()
for (percent in 250 downTo 100 step 25) {
slider.performKeyInput { pressKey(Key.DirectionLeft) }
zoomValue(percent)
}
}
@Test
fun touchTapAndDragSnapToTheNineValues() {
val value = mutableStateOf(1f)
val changes = mutableListOf<Float>()
compose.setContent {
DroidDeckTheme {
Box(Modifier.width(300.dp)) {
GameZoomRow(value.value, { Modifier }) { changes += it; value.value = it }
}
}
}
val slider = zoom("slider").assertIsDisplayed()
slider.performTouchInput { click(center) }
zoomValue(200)
slider.performTouchInput { swipe(center, Offset(width - 2f, center.y)) }
zoomValue(300)
slider.performTouchInput { click(Offset(2f, center.y)) }
zoomValue(100)
val allowed = (100..300 step 25).map { it / 100f }.toSet()
assertEquals(true, changes.all { it in allowed })
}
}