feat(ui): resize the session menu by its edge, and set dual screen from the menu (#3080)

* feat(ui): resize the session menu by its edge handle, and set dual screen to auto, on or off from the menu

* fix(ui): the session menu resize handle follows the finger across several moves per frame

* fix(ui): the closed agent menu button has no gap inside its outline

* feat(ui): the session menu's resize handle hovers just past its left edge

* fix(session): turning dual screen on from the menu moves the menu itself to the second screen

* fix(ui): keep the menu width bounds current and restore a pinned second-screen menu after backgrounding
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-23 12:49:10 -05:00
1 parent 3502b43cea
commit 5df25c77ca
6 files changed
+153 -10

No files matched your search

@@ -594,6 +594,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private var backHold by mutableStateOf(true)
private var dockedMenuController by mutableStateOf(false)
private var sessionOrientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
private var dualScreenSessionMode by mutableStateOf(com.droiddeck.launcher.input.DualScreen.MODE_AUTO)
private var backActionsInverted by mutableStateOf(false)
private var backDoubleTapMs by mutableStateOf(500)
private var lowLatency by mutableStateOf(true)
@@ -1535,6 +1536,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
fexPreset = fexPreset,
secondScreenMode = secondScreenMode,
secondScreenNone = !bottomOutputActive && !dockDrawer(),
dualScreenMode = dualScreenSessionMode,
onDualScreenMode = ::chooseDualScreenSessionMode,
gameOnBottom = bottomOutputActive,
gameSwapAvailable = bottomSwapAvailable,
gameSwapBuiltIn = !::displayManager.isInitialized || displayManager.getDisplay(selectedSecondScreenDisplay)
@@ -2659,6 +2662,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
backHold = SessionPrefs.backHold(this)
dockedMenuController = SessionPrefs.dockedMenuController(this)
sessionOrientation = SessionPrefs.orientation(this)
dualScreenSessionMode = SessionPrefs.dualScreenSessionMode(this)
backActionsInverted = SessionPrefs.backActionsInverted(this)
physicalShortcuts.bindings = PhysicalShortcuts.read(this)
backDoubleTapMs = SessionPrefs.backDoubleTapMs(this)
@@ -4396,6 +4400,27 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
} else if (wanted != secondScreenMode) selectSecondScreenMode(wanted) else secondScreenPresentation?.retryTerminal()
}
private fun chooseDualScreenSessionMode(mode: String) {
if (mode !in com.droiddeck.launcher.input.DualScreen.modes || mode == dualScreenSessionMode) return
SessionPrefs.setDualScreenSessionMode(this, mode)
dualScreenSessionMode = mode
SessionState.secondScreenAutoOpened = false
val menuOnBottom = drawerDocked
val menuOnTop = drawerOpenState && !drawerDocked
if (mode == com.droiddeck.launcher.input.DualScreen.MODE_OFF) {
if (gameOnBottom) putGameOnBottom(false)
if (secondScreenMode != SecondScreenMode.NONE || menuOnBottom) closeSecondScreen(reset = true)
if (menuOnBottom) drawerOpen = true
} else if (menuOnTop) {
// The menu moves to the second screen as the menu itself, not as one of the control panels.
SessionState.secondScreenAutoOpened = true
refreshSecondScreenDisplays()
pinDockedMenu()
return
}
refreshSecondScreenDisplays()
}
private fun selectSecondScreenDisplay(displayId: Int) {
if (secondScreenDisplays.none { it.id == displayId }) return
selectedSecondScreenDisplay = displayId
@@ -5958,7 +5983,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
if (secondScreenPresentation == null) showSecondScreen(secondScreenMode)
if (com.droiddeck.launcher.input.DualScreen.menuReturnsOnStart(openingPanel(), SessionState.bottomMenu, menuShownOnBottom())) pinDockedMenu()
SessionState.bottomMenu = false
} else openDualScreenControls()
} else {
if (SessionState.bottomMenu && !menuShownOnBottom()) pinDockedMenu()
SessionState.bottomMenu = false
if (!menuShownOnBottom()) openDualScreenControls()
}
startedScreens++
SessionService.setActivityVisible(this, true, sessionActivityDisplayId)
Glasses.rescan()
@@ -63,6 +63,13 @@ object SessionPrefs {
.takeIf { value -> orientationOptions.any { it.first == value } }
?: ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
/** The session menu's width in dp the user dragged it to; null keeps the default. */
fun drawerWidthDp(context: Context): Int? = prefs(context).getInt("drawerWidthDp", 0).takeIf { it > 0 }
fun setDrawerWidthDp(context: Context, dp: Int) {
prefs(context).edit().putInt("drawerWidthDp", dp).apply()
}
fun setOrientation(context: Context, orientation: Int) {
require(orientationOptions.any { it.first == orientation })
prefs(context).edit().putInt("orientation", orientation).apply()
@@ -13,7 +13,7 @@ object SettingsReset {
internal val SESSION_KEYS = setOf(
"orientation", "launcherFullscreen", "controllerHaptics", "animations", "lowStorageWarning", "theme", "runSteamAtStartup", "startupSession", "addedGamesArt",
"dualScreenMode", "dualScreenSessionMode", "dualScreenLauncher", "dualScreenSessionControls", "androidTextFieldKeyboard",
"drawerWidthDp", "dualScreenMode", "dualScreenSessionMode", "dualScreenLauncher", "dualScreenSessionControls", "androidTextFieldKeyboard",
"soundtracksIngame", "gameStoresSpeedTier", "gameStoresParallel", "storesOpenTab", "storesShowMature",
"storesInstallLanguage",
"hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "__KEEP_droidDeckHud__", "__KEEP_droidDeckHudPos__", "backHold", "dockedMenuController", "backActionsInverted", "backDoubleTapMs", "touch", "pen", "penButton", "osc", "shape", "steamController",
@@ -408,10 +408,12 @@ private fun AgentMenu(open: Boolean, onOpen: (Boolean) -> Unit, onPanel: (AgentP
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val working = AgentHost.state == AgentHost.State.WORKING
// Closed, the outline sits flush against the lone button.
val shape = if (open) Shape16 else Shape12
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clip(Shape16).background(colors.surface.copy(alpha = if (open) 0.97f else 0.88f))
.border(1.dp, pal.line, Shape16).padding(top = 3.dp, bottom = 3.dp, end = 4.dp),
modifier = Modifier.clip(shape).background(colors.surface.copy(alpha = if (open) 0.97f else 0.88f))
.border(1.dp, pal.line, shape).then(if (open) Modifier.padding(top = 3.dp, bottom = 3.dp, end = 4.dp) else Modifier),
) {
androidx.compose.animation.AnimatedVisibility(open, enter = expandHorizontally(expandFrom = Alignment.End) + fadeIn(),
exit = shrinkHorizontally(shrinkTowards = Alignment.End) + fadeOut()) {
@@ -434,7 +436,7 @@ private fun AgentMenu(open: Boolean, onOpen: (Boolean) -> Unit, onPanel: (AgentP
}
}
}
HeaderAction(Icons.Outlined.MoreHoriz, stringResource(R.string.agent_more), selected = open, size = 36.dp, tag = "agent-menu") { onOpen(!open) }
HeaderAction(Icons.Outlined.MoreHoriz, stringResource(R.string.agent_more), selected = open, size = 36.dp, tag = "agent-menu", startPadding = if (open) null else 0.dp) { onOpen(!open) }
}
}
@@ -448,12 +450,13 @@ private fun AgentPanelBar(title: String, onClose: () -> Unit) {
@Composable
internal fun HeaderAction(
icon: ImageVector, label: String, enabled: Boolean = true, selected: Boolean = false, tag: String? = null, size: Dp = 44.dp, onClick: () -> Unit,
icon: ImageVector, label: String, enabled: Boolean = true, selected: Boolean = false, tag: String? = null, size: Dp = 44.dp,
startPadding: Dp? = null, onClick: () -> Unit,
) {
val pal = LocalPalette.current
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.padding(start = if (size < 44.dp) 4.dp else 8.dp).size(size).clip(Shape12)
modifier = Modifier.padding(start = startPadding ?: if (size < 44.dp) 4.dp else 8.dp).size(size).clip(Shape12)
.background(if (selected) pal.primary.copy(alpha = 0.2f) else pal.surfaceVariant)
.clickable(enabled = enabled, onClick = onClick)
.then(if (tag != null) Modifier.testTag(tag) else Modifier),
@@ -95,6 +95,14 @@ import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.unit.Dp
import androidx.compose.runtime.rememberUpdatedState
import android.view.KeyEvent
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.droiddeck.launcher.HomeApp
@@ -261,6 +269,8 @@ class DrawerActions(
val textureLodBias: String? = TextureFiltering.LOD_BIAS_OFF,
val secondScreenMode: SecondScreenMode,
val secondScreenNone: Boolean = true,
val dualScreenMode: String = com.droiddeck.launcher.input.DualScreen.MODE_AUTO,
val onDualScreenMode: (String) -> Unit = {},
val gameOnBottom: Boolean = false,
val gameSwapAvailable: Boolean = false,
val gameSwapBuiltIn: Boolean = true,
@@ -418,6 +428,8 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
var appToChooseDisplay by remember { mutableStateOf<HomeApp.LaunchableApp?>(null) }
var confirmStop by remember { mutableStateOf(false) }
var sheetCoords by remember { mutableStateOf<LayoutCoordinates?>(null) }
val widthContext = LocalContext.current
var savedWidth by remember { mutableStateOf(SessionPrefs.drawerWidthDp(widthContext)) }
var stopCoords by remember { mutableStateOf<LayoutCoordinates?>(null) }
val pageScroll = remember { SessionDrawerPage.entries.associateWith { ScrollState(0) } }
LaunchedEffect(glassesTab) {
@@ -506,17 +518,22 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
}
androidx.compose.foundation.layout.BoxWithConstraints(modifier = Modifier.fillMaxSize().exposeTestTags(), contentAlignment = Alignment.CenterEnd) {
val short = maxHeight < 440.dp
val sheetWidth = if (docked) maxWidth else minOf(420.dp, maxWidth * 0.92f)
// The handle keeps a strip on the left free, so a sheet dragged wide can always be dragged back.
val maxSheet = (maxWidth - DRAWER_EDGE_GAP).coerceAtLeast(0.dp)
val minSheet = minOf(DRAWER_MIN_WIDTH, maxSheet)
val defaultSheet = minOf(420.dp, maxWidth * 0.92f)
val sheetWidth = if (docked) maxWidth else (savedWidth?.dp ?: defaultSheet).coerceIn(minSheet, maxSheet)
val narrow = sheetWidth < 320.dp
AnimatedVisibility(
open,
enter = if (docked) fadeIn(Motion.tw(160)) else slideInHorizontally(Motion.sp(0.8f, Spring.StiffnessLow)) { it } + fadeIn(Motion.tw(220)),
exit = if (docked) fadeOut(Motion.tw(140)) else slideOutHorizontally(Motion.tw(240)) { it } + fadeOut(Motion.tw(200)),
) {
FocusGlideHost(Modifier.fillMaxHeight().width(sheetWidth)) { Box(Modifier.fillMaxSize().onGloballyPositioned { sheetCoords = it }) {
FocusGlideHost(Modifier.fillMaxHeight().width(if (docked) sheetWidth else sheetWidth + DRAWER_HANDLE_STRIP)) { Box(Modifier.fillMaxSize().onGloballyPositioned { sheetCoords = it }) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(start = if (docked) 0.dp else DRAWER_HANDLE_STRIP)
.background(if (docked) pal.background else pal.background.copy(alpha = 0.97f))
.blockTouches()
.focusGroup()
@@ -965,6 +982,12 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
} }
}
}
if (!docked) DrawerResizeHandle(
width = sheetWidth, min = minSheet, max = maxSheet,
onWidth = { savedWidth = it.value.roundToInt() },
onCommit = { savedWidth?.let { SessionPrefs.setDrawerWidthDp(widthContext, it) } },
modifier = Modifier.align(Alignment.CenterStart).then(focus.track(page, "resize")),
)
StopConfirm(
open = confirmStop,
pill = sheetCoords?.let { sc -> stopCoords?.takeIf { it.isAttached && sc.isAttached }?.let { sc.localBoundingBoxOf(it, clipBounds = false) } },
@@ -1338,12 +1361,92 @@ internal fun secondScreenModes(none: Boolean, deckPad: Boolean, dashboard: Boole
(if (dashboard) listOf(SecondScreenMode.DASHBOARD) else emptyList()) +
(if (desktop) listOf(SecondScreenMode.DESKTOP) else emptyList())
private val DRAWER_MIN_WIDTH = 300.dp
private val DRAWER_HANDLE_STRIP = 24.dp
private val DRAWER_EDGE_GAP = 80.dp
/** A grip on the sheet's left edge: dragging it, or pressing left and right on a controller, resizes the sheet. */
@Composable
private fun DrawerResizeHandle(width: Dp, min: Dp, max: Dp, onWidth: (Dp) -> Unit, onCommit: () -> Unit, modifier: Modifier) {
val pal = LocalPalette.current
val density = LocalDensity.current
val source = remember { MutableInteractionSource() }
val focused by source.collectIsFocusedAsState()
var dragging by remember { mutableStateOf(false) }
var coords by remember { mutableStateOf<LayoutCoordinates?>(null) }
val current by rememberUpdatedState(width)
val lower by rememberUpdatedState(min)
val upper by rememberUpdatedState(max)
val change by rememberUpdatedState(onWidth)
val commit by rememberUpdatedState(onCommit)
val hot = focused || dragging
val label = stringResource(R.string.drawer_resize)
Box(
contentAlignment = Alignment.Center,
modifier = modifier.width(24.dp).height(96.dp)
.onGloballyPositioned { coords = it }
.focusable(true, source)
.onPreviewKeyEvent { event ->
val key = event.nativeKeyEvent
val wider = key.keyCode == KeyEvent.KEYCODE_DPAD_LEFT
if (!wider && key.keyCode != KeyEvent.KEYCODE_DPAD_RIGHT) false
else {
if (key.action == KeyEvent.ACTION_DOWN) {
change((current + if (wider) 24.dp else (-24).dp).coerceIn(lower, upper))
commit()
}
true
}
}
// The handle moves with the finger as the sheet resizes, so the drag is measured on the screen.
.pointerInput(Unit) {
awaitEachGesture {
val down = awaitFirstDown(requireUnconsumed = false)
var last = (coords?.positionInRoot()?.x ?: 0f) + down.position.x
// Several moves can arrive before the sheet recomposes, so the width is accumulated here.
var live = current
dragging = true
do {
val event = awaitPointerEvent()
val pointer = event.changes.firstOrNull() ?: break
val x = (coords?.positionInRoot()?.x ?: 0f) + pointer.position.x
val delta = with(density) { (x - last).toDp() }
last = x
if (delta != 0.dp) {
live = (live - delta).coerceIn(lower, upper)
change(live)
}
pointer.consume()
} while (event.changes.any { it.pressed })
dragging = false
commit()
}
}
.semantics {
contentDescription = label
stateDescription = "${width.value.roundToInt()} dp"
},
) {
Box(
Modifier.width(if (hot) 6.dp else 4.dp).height(56.dp).clip(CircleShape)
.background(if (hot) pal.signal else pal.onSurfaceVariant.copy(alpha = 0.55f)),
)
}
}
@Composable
private fun SecondScreenGroup(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) {
val choosesDisplay = a.secondScreenDisplays.size > 1
val swapsGame = a.gameSwapAvailable || a.gameOnBottom
if (!choosesDisplay && !swapsGame) return
val hasSecondScreen = a.secondScreenDisplays.isNotEmpty()
if (!hasSecondScreen && !choosesDisplay && !swapsGame) return
SettingsGroup(stringResource(R.string.drawer_second_screen)) {
if (hasSecondScreen) ChoiceRow(host, "dual-screen-mode", stringResource(R.string.setup_dual_screen_sessions), null,
listOf(
com.droiddeck.launcher.input.DualScreen.MODE_AUTO to stringResource(R.string.setup_dual_screen_auto),
com.droiddeck.launcher.input.DualScreen.MODE_ON to stringResource(R.string.setup_dual_screen_on),
com.droiddeck.launcher.input.DualScreen.MODE_OFF to stringResource(R.string.setup_dual_screen_off),
), a.dualScreenMode, chipModifier = track("dual-screen-mode"), onPick = a.onDualScreenMode)
if (swapsGame) ChoiceRow(host, "game-screen", stringResource(R.string.swap_game_screen), null,
if (a.gameSwapBuiltIn) listOf(false to stringResource(R.string.swap_game_screen_top), true to stringResource(R.string.swap_game_screen_bottom))
else listOf(false to stringResource(R.string.main_primary), true to stringResource(R.string.main_secondary)),
+1
View File
@@ -864,6 +864,7 @@
<string name="drawer_pc_keyboard">PC keyboard</string>
<string name="drawer_android_keyboard">Android</string>
<string name="drawer_second_screen">Second screen</string>
<string name="drawer_resize">Resize the menu</string>
<string name="drawer_second_screen_shows">Shows</string>
<string name="drawer_android_apps">Android apps</string>
<string name="drawer_launch_app">Launch an app</string>