From 39141d5c23c35c89ff0e0ad875b3b3be2f53f649 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Wed, 23 Sep 2026 23:21:09 -0400 Subject: [PATCH] Make session menu controller driven --- app/build.gradle | 1 - .../com/droiddeck/launcher/SessionActivity.kt | 15 +++++++-- .../droiddeck/launcher/ui/FrontEndScreen.kt | 1 + .../droiddeck/launcher/ui/SessionOverlay.kt | 31 +++++++++++++++++-- .../droiddeck/launcher/ui/SettingsWidgets.kt | 25 +++++++++++++++ 5 files changed, 67 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 821f2afb2e..bf8efebbe9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,7 +30,6 @@ if (buildLabel == null || buildLabel.trim().isEmpty()) { buildLabel = "pr${pullRequest.number} at ${pullRequest.head.sha.take(7)}" } } catch (Exception ignored) { - // Local builds and unusual CI events can omit the pull-request payload. } } if (buildLabel == null || buildLabel.trim().isEmpty()) { diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index f2a088b7a1..8889ad34c1 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -94,6 +94,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private var drawerDirectionDownTime = 0L private var drawerDirectionLastRepeat = 0L private var drawerDirectionDeviceId = -1 + private val resumeKeysDown = mutableSetOf>() // Compose reads these; the activity writes them. private var drawerOpen by mutableStateOf(false) @@ -675,8 +676,18 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_MUTE -> return super.dispatchKeyEvent(event) } - // Keep keys in the Android/Compose focus tree while the drawer is open. Its Back key and - // controller B always dismiss the drawer; directional and confirm keys stay with the UI. + val fromController = PadBridge.isFromController(event.device) + val resumeKey = event.keyCode == KeyEvent.KEYCODE_BUTTON_A || event.keyCode == KeyEvent.KEYCODE_BUTTON_START + val resumeKeyId = event.deviceId to event.keyCode + if (fromController && resumeKey && (SessionState.suspended || resumeKeyId in resumeKeysDown)) { + if (event.action == KeyEvent.ACTION_DOWN) { + resumeKeysDown.add(resumeKeyId) + if (event.repeatCount == 0 && SessionState.suspended) SessionService.resume(this) + } else if (event.action == KeyEvent.ACTION_UP) { + resumeKeysDown.remove(resumeKeyId) + } + return true + } if (drawerOpen) { if (event.keyCode == KeyEvent.KEYCODE_BACK || event.keyCode == KeyEvent.KEYCODE_BUTTON_B) { if (event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) drawerOpen = false diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 35732091e3..6ed54f34b3 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -883,6 +883,7 @@ internal fun SecondaryButton(text: String, enabled: Boolean = true, onClick: () modifier = Modifier.graphicsLayer { scaleX = scale; scaleY = scale }.clip(Shape12).background(fill).border(1.dp, edge, Shape12) .alpha(if (enabled) 1f else 0.5f) .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, enabled = enabled, onClick = onClick) + .controllerConfirm(enabled = enabled, onClick = onClick) .padding(horizontal = 16.dp, vertical = 11.dp), ) { Text(text, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 0.5.sp, color = colors.onBackground, maxLines = 1) } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt index c0bbd47b50..febe2825bb 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.ui +import androidx.activity.compose.BackHandler import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -54,6 +55,7 @@ import androidx.compose.animation.slideOutHorizontally import androidx.compose.foundation.LocalIndication import androidx.compose.foundation.border import androidx.compose.foundation.hoverable +import androidx.compose.foundation.focusGroup import androidx.compose.foundation.interaction.collectIsFocusedAsState import androidx.compose.foundation.interaction.collectIsHoveredAsState import androidx.compose.foundation.layout.Arrangement @@ -65,6 +67,8 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.draw.clip +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.input.InputMode @@ -126,6 +130,11 @@ fun LoadingOverlay(step: String, percent: Int, elapsed: String, hint: String, en @Composable fun SessionPausedOverlay(onResume: () -> Unit) { val interactionSource = remember { MutableInteractionSource() } + val resumeFocus = remember { FocusRequester() } + LaunchedEffect(Unit) { + androidx.compose.runtime.withFrameNanos { } + runCatching { resumeFocus.requestFocus() } + } Box( modifier = Modifier .fillMaxSize() @@ -137,7 +146,10 @@ fun SessionPausedOverlay(onResume: () -> Unit) { horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(32.dp), ) { - OutlinedButton(onClick = onResume) { + OutlinedButton( + onClick = onResume, + modifier = Modifier.focusRequester(resumeFocus).controllerConfirm(onClick = onResume), + ) { Text("Resume session") } } @@ -199,6 +211,9 @@ fun SessionDrawer(open: Boolean, a: DrawerActions) { var firstControlFocused by remember { mutableStateOf(false) } val inputModeManager = LocalInputModeManager.current val steamButtons = a.onSteamMenu != null && a.onQam != null + BackHandler(enabled = open) { + if (host.open != null) host.open = null else a.onClose() + } LaunchedEffect(open) { if (open) { inputModeManager.requestInputMode(InputMode.Keyboard) @@ -228,6 +243,9 @@ fun SessionDrawer(open: Boolean, a: DrawerActions) { .background(pal.background.copy(alpha = 0.97f)) .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) {} .focusGroup() + .controllerBack { + if (host.open != null) host.open = null else a.onClose() + } .verticalScroll(rememberScrollState()) .padding(horizontal = 14.dp, vertical = 16.dp), ) { @@ -259,7 +277,10 @@ fun SessionDrawer(open: Boolean, a: DrawerActions) { onClick = { host.open = null; a.onSteamMenu.invoke() }, interactionSource = steamSrc, modifier = Modifier.weight(1f).height(48.dp).focusRequester(firstFocus) - .onFocusChanged { firstControlFocused = it.isFocused }, + .onFocusChanged { firstControlFocused = it.isFocused }.controllerConfirm { + host.open = null + a.onSteamMenu.invoke() + }, shape = RoundedCornerShape(12.dp), border = BorderStroke(if (steamHot) 2.dp else 1.dp, if (steamHot) pal.signal else colors.outline), colors = ButtonDefaults.outlinedButtonColors(containerColor = if (steamHot) pal.signal.copy(alpha = 0.16f) else Color.Transparent), @@ -273,7 +294,10 @@ fun SessionDrawer(open: Boolean, a: DrawerActions) { qamStartedOnPress = false }, interactionSource = qamInteraction, - modifier = Modifier.weight(1f).height(48.dp).semantics { contentDescription = "Open Quick Access Menu" }, + modifier = Modifier.weight(1f).height(48.dp).semantics { contentDescription = "Open Quick Access Menu" }.controllerConfirm { + host.open = null + a.onQam.invoke() + }, shape = RoundedCornerShape(12.dp), border = BorderStroke(if (qamHot) 2.dp else 1.dp, if (qamHot) pal.signal else colors.outline), colors = ButtonDefaults.outlinedButtonColors(containerColor = if (qamHot) pal.signal.copy(alpha = 0.16f) else Color.Transparent), @@ -410,6 +434,7 @@ private fun DangerButton(text: String, onClick: () -> Unit) { Box( modifier = Modifier.clip(RoundedCornerShape(12.dp)).background(fill).border(1.dp, colors.error.copy(alpha = if (hot) 0.9f else 0.5f), RoundedCornerShape(12.dp)) .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, onClick = onClick) + .controllerConfirm(onClick = onClick) .padding(horizontal = 16.dp, vertical = 11.dp), ) { Text(text, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 0.5.sp, color = colors.error, maxLines = 1) } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt b/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt index da7fd678db..7577264693 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.ui +import android.view.KeyEvent import androidx.compose.animation.AnimatedContent import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.animateColorAsState @@ -52,6 +53,7 @@ import androidx.compose.ui.draw.shadow import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.TransformOrigin import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.input.key.onPreviewKeyEvent import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow @@ -69,6 +71,26 @@ import androidx.compose.ui.window.PopupProperties private val RowShape = RoundedCornerShape(12.dp) private val GroupShape = RoundedCornerShape(14.dp) +internal fun Modifier.controllerConfirm(enabled: Boolean = true, onClick: () -> Unit): Modifier = onPreviewKeyEvent { event -> + val keyEvent = event.nativeKeyEvent + if (keyEvent.keyCode != KeyEvent.KEYCODE_BUTTON_A) { + false + } else { + if (enabled && keyEvent.action == KeyEvent.ACTION_DOWN && keyEvent.repeatCount == 0) onClick() + true + } +} + +internal fun Modifier.controllerBack(onBack: () -> Unit): Modifier = onPreviewKeyEvent { event -> + val keyEvent = event.nativeKeyEvent + if (keyEvent.keyCode != KeyEvent.KEYCODE_BUTTON_B && keyEvent.keyCode != KeyEvent.KEYCODE_BACK) { + false + } else { + if (keyEvent.action == KeyEvent.ACTION_DOWN && keyEvent.repeatCount == 0) onBack() + true + } +} + class MenuHost { var open by mutableStateOf(null) } @@ -114,6 +136,7 @@ fun AnchoredMenu(open: Boolean, onDismiss: () -> Unit, title: String? = null, no .clip(RowShape) .background(pal.surfaceVariant.copy(alpha = 0.95f)) .border(1.dp, pal.signal.copy(alpha = 0.22f), RowShape) + .controllerBack(onDismiss) .padding(6.dp), ) { if (title != null) Text( @@ -149,6 +172,7 @@ fun MenuItem( .background(if (hot && enabled) Color.White.copy(alpha = 0.07f) else Color.Transparent) .alpha(if (enabled) 1f else 0.4f) .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, enabled = enabled, onClick = onClick) + .controllerConfirm(enabled = enabled, onClick = onClick) .padding(horizontal = 10.dp, vertical = 9.dp), ) { Text("✓", fontSize = 12.sp, color = pal.signal, modifier = Modifier.width(18.dp).alpha(if (checked) 1f else 0f)) @@ -181,6 +205,7 @@ fun ValueChip(text: String, open: Boolean, enabled: Boolean = true, modifier: Mo .border(1.dp, edge, RoundedCornerShape(10.dp)) .alpha(if (enabled) 1f else 0.5f) .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, enabled = enabled, onClick = onClick) + .controllerConfirm(enabled = enabled, onClick = onClick) .padding(horizontal = 12.dp, vertical = 8.dp), ) { AnimatedContent(