From af1fe6c61cd5b8ee441db95be03f3f7608e9a493 Mon Sep 17 00:00:00 2001 From: Tushar Gandhe <19225304+2-Shar@users.noreply.github.com> Date: Wed, 25 Nov 2026 04:43:10 +0530 Subject: [PATCH] fix(launcher): LT and RT keep the focus ring on the tab rail (#3039) * fix(launcher): LT and RT keep the focus ring on the tab rail A trigger step selected the tab like a tap on the rail, which also sent focus into the new page, and each page put it somewhere different. The step now shows the page and focuses its rail item, and for a second puts focus back on the rail if the page takes it, until another key is pressed. Dual screens, which have no rail on the main screen, keep focusing the page. * fix(launcher): end the trigger step's rail hold when another navigation changes the page A navigation that changed the selected page during the hold, such as opening a game from a link, was undone: the hold focused the stepped tab's rail item, and that focus switched the page back. The hold now stops as soon as the selection is no longer the one the step made. * fix(launcher): end the trigger step's rail hold when another navigation opens a page Opening the Components page does not change the selected tab, so a navigation there during the hold kept it running and the hold could pull focus from Components back to the rail. The hold now also tracks the page key: once the page its own step opened is showing, any other page ends the hold. --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> --- .../droiddeck/launcher/FrontEndActivity.kt | 1 + .../droiddeck/launcher/ui/FrontEndScreen.kt | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index a26bb5d81e..583595fd0a 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -2170,6 +2170,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet if (!triggerKeys.synthesizing && triggerKeys.nativeKey(event)) return true val tabStep = com.droiddeck.launcher.ui.dualPageStep(event) val tabs = com.droiddeck.launcher.ui.MainTabSteps.handler + if (tabStep == null && event.action == KeyEvent.ACTION_DOWN) com.droiddeck.launcher.ui.MainTabSteps.otherKeys++ if (tabStep != null && tabs != null) { if (controllerHaptics) com.droiddeck.launcher.ui.ControllerHaptics.onKey(this, event) if (event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) tabs(tabStep) 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 74bd115145..6c46fced07 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -58,6 +58,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.snapshotFlow import androidx.compose.runtime.withFrameNanos +import kotlinx.coroutines.launch import kotlinx.coroutines.flow.first import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue @@ -764,12 +765,31 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com focusManager.clearFocus(force = true) onRailSelect(key) }, a) + val stepScope = androidx.compose.runtime.rememberCoroutineScope() + val pageKeyNow = androidx.compose.runtime.rememberUpdatedState(s.pageKey) + var railHold by remember { mutableStateOf(null) } val tabStep = androidx.compose.runtime.rememberUpdatedState { step: Int -> if (!processSettingsPageVisible) { val keys = navigationKeys(s) keys.getOrNull(keys.indexOf(railSelectionNow.value) + step)?.let { key -> PageSwipe.direction = step - onRailSelect(key) + if (s.dualScreen) { onRailSelect(key); return@let } + showRailPage(key, false) + if (inputModeManager.inputMode != InputMode.Keyboard) inputModeManager.requestInputMode(InputMode.Keyboard) + val since = MainTabSteps.otherKeys + val owner = selected + val ownPage = if (key == "components") "components" else null + railHold?.cancel() + // Pages focus their own first control as they appear; the ring stays on the rail until another key moves it. + railHold = stepScope.launch { + var pageShown = false + repeat(RAIL_HOLD_FRAMES) { + withFrameNanos { } + if (MainTabSteps.otherKeys != since || selected != owner) return@launch + if (pageKeyNow.value == ownPage) pageShown = true else if (pageShown) return@launch + if (frontFocus.focusedRail != key) runCatching { frontFocus.railFor(key).requestFocus() } + } + } } } } @@ -900,4 +920,7 @@ internal object ChildProcessSetup { internal object MainTabSteps { @Volatile var handler: ((Int) -> Unit)? = null + @Volatile var otherKeys = 0 } + +private const val RAIL_HOLD_FRAMES = 60