From eaaecf066143a6fd5efda6d53344f368c4cb48a3 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Mon, 26 Oct 2026 12:01:44 -0400 Subject: [PATCH] feat(session): add portrait sessions and controls below the game (#1612) --- .../droiddeck/launcher/FrontEndActivity.kt | 3 +- .../com/droiddeck/launcher/SessionActivity.kt | 63 ++++++++++--------- .../launcher/session/SessionDisplay.kt | 22 ++++--- .../launcher/session/SessionPrefs.kt | 29 ++++++++- .../launcher/session/SessionService.kt | 4 +- .../launcher/ui/DeckControlsPanel.kt | 26 ++++++-- .../droiddeck/launcher/ui/GamepadGeometry.kt | 43 ++++++++++++- .../launcher/ui/ModeSettingsDialog.kt | 11 +++- .../droiddeck/launcher/ui/ResolutionRow.kt | 7 ++- .../droiddeck/launcher/ui/SessionOverlay.kt | 36 ++++++++--- .../droiddeck/launcher/ui/SettingsWidgets.kt | 47 ++++++++++---- app/src/main/res/values/strings.xml | 10 +-- .../launcher/session/OrientationTest.kt | 40 +++++++++--- .../launcher/session/SessionDisplayTest.kt | 37 +++++++++++ .../session/SessionScalingPrefsTest.kt | 10 +++ .../launcher/ui/GamepadGeometryTest.kt | 62 +++++++++++++++++- 16 files changed, 359 insertions(+), 91 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index 1f754d0b78..8bf9166f0c 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -1710,8 +1710,7 @@ class FrontEndActivity : ComponentActivity() { steamDownloadsInBackground = steamDownloadsInBackground, pipSupported = com.droiddeck.launcher.session.SessionPipController.supported(this), pipAutoEnter = pipAutoEnter, - unfoldedControls = if (mode == SessionService.MODE_STEAM && - com.droiddeck.launcher.session.SessionDisplay.foldable(this)) unfoldedControls else null, + unfoldedControls = if (mode == SessionService.MODE_STEAM) unfoldedControls else null, unfoldedControlsWithController = unfoldedControlsWithController, oscMode = if (mode == SessionService.MODE_STEAM) oscMode else null, backActionsInverted = backActionsInverted, diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 9a762212d1..b9dce0e415 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -1084,7 +1084,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { pipAutoEnter = on pip.refresh(true) }, - unfoldedControls = if (com.droiddeck.launcher.session.SessionDisplay.foldable(this@SessionActivity)) unfoldedControls else null, + unfoldedControls = unfoldedControls, onUnfoldedControls = ::chooseUnfoldedControls, unfoldedControlsWithController = unfoldedControlsWithController, onUnfoldedControlsWithController = ::chooseUnfoldedControlsWithController, @@ -1786,9 +1786,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { val driverId = if (CompositorHost.isStarted) null else turnip.install() val previous = SessionState.outputSize - val live = if (SessionState.followScreen && !isInPictureInPictureMode) - com.droiddeck.launcher.session.SessionDisplay.followSize(holder.surfaceFrame.width(), holder.surfaceFrame.height()) - else null + val live = windowOutputSize(holder.surfaceFrame.width(), holder.surfaceFrame.height()) val size = live ?: if (SessionState.running) previous else glassesOutputSize() ?: outputSize() SessionState.outputSize = size if (!SessionState.running) SessionState.refreshHz = refreshHz() @@ -1845,7 +1843,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { ) onOutputAttached(holder) if (SessionState.running && size != previous) { - Log.i(TAG, "follow screen: ${previous.first}x${previous.second} -> ${size.first}x${size.second} on a new surface") + Log.i(TAG, "output resized: ${previous.first}x${previous.second} -> ${size.first}x${size.second} on a new surface") WaylandCompositor.nativeResizeOutput(size.first, size.second) } if (!SessionState.running) SessionEvents.record("compositor.started") @@ -1877,15 +1875,22 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { cancelTouchGestures() Log.i(TAG, "surface resized to ${width}x$height - rebinding the compositor") CompositorHost.resize(holder.surface) { applyFrameGen() } - followWindow(width, height) + resizeOutputForWindow(width, height) } } - private fun followWindow(width: Int, height: Int) { - if (!SessionState.followScreen || isInPictureInPictureMode || !CompositorHost.isStarted) return - val size = com.droiddeck.launcher.session.SessionDisplay.followSize(width, height) ?: return + private fun windowOutputSize(width: Int, height: Int): Pair? { + if (isInPictureInPictureMode || width <= 0 || height <= 0) return null + return if (SessionState.followScreen) + com.droiddeck.launcher.session.SessionDisplay.followSize(width, height, controlsBelowWanted()) + else if (glassesScreen == null) outputSize() else null + } + + private fun resizeOutputForWindow(width: Int, height: Int) { + if (!CompositorHost.isStarted) return + val size = windowOutputSize(width, height) ?: return if (size == SessionState.outputSize) return - Log.i(TAG, "follow screen: ${SessionState.outputSize.first}x${SessionState.outputSize.second} -> ${size.first}x${size.second}") + Log.i(TAG, "output resized: ${SessionState.outputSize.first}x${SessionState.outputSize.second} -> ${size.first}x${size.second}") SessionState.outputSize = size val panel = panelBounds() SessionState.upscaleRatio = maxOf(panel.width(), panel.height()).toFloat() / maxOf(size.first, size.second).coerceAtLeast(1) @@ -1899,11 +1904,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } private fun applyFollowOrientation(config: android.content.res.Configuration) { - val wanted = if (SessionState.followScreen && config.smallestScreenWidthDp >= 600) { - android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER - } else { - SessionPrefs.orientation(this) - } + val wanted = SessionPrefs.windowOrientation(this, SessionState.followScreen, config.smallestScreenWidthDp) if (requestedOrientation != wanted) requestedOrientation = wanted } @@ -1915,6 +1916,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { cancelTouchGestures() applyFollowOrientation(newConfig) applyUnfoldedControls() + resizeOutputForWindow(surfaceW, surfaceH) } override fun surfaceDestroyed(holder: SurfaceHolder) { @@ -1956,7 +1958,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { Library.drawsAtPanel(program) && !SessionPrefs.resolutionChosen(this, mode)) com.droiddeck.launcher.session.SessionDisplay.MATCH_SCREEN else SessionPrefs.resolutionChoice(this, mode, panel) - return com.droiddeck.launcher.session.SessionDisplay.resolveChoice(panel, choice) + return com.droiddeck.launcher.session.SessionDisplay.resolveChoice(panel, choice, + SessionPrefs.portrait(this) && !controlsBelowWanted()) } private fun refreshHz(): Float { @@ -2682,21 +2685,17 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { screenKeys?.refreshAppearance() } + private fun controlsBelowWanted(): Boolean { + if (!::sessionRoot.isInitialized || glassesScreen != null || cardboard.enabled) return false + return SessionPrefs.controlsBelowWanted(this, SessionState.mode, sessionRoot.width, sessionRoot.height, + pipUi || isInPictureInPictureMode) + } + private fun applyUnfoldedControls() { if (!::sessionRoot.isInitialized) return val width = sessionRoot.width val height = sessionRoot.height - val wanted = com.droiddeck.launcher.session.SessionDisplay.unfoldedControlsWanted( - enabled = unfoldedControls, - foldable = com.droiddeck.launcher.session.SessionDisplay.foldable(this), - controllerConnected = PadBridge.anyControllerConnected() || SteamControllerBle.connected, - keepWithController = unfoldedControlsWithController, - steamDeckPad = SessionState.mode == SessionService.MODE_STEAM && SessionState.deckPad, - pip = pipUi || isInPictureInPictureMode, - width = width, - height = height, - smallestWidthDp = resources.configuration.smallestScreenWidthDp, - ) + val wanted = controlsBelowWanted() val gameHeight = if (wanted) com.droiddeck.launcher.session.SessionDisplay.unfoldedGameHeight(width, height) else FrameLayout.LayoutParams.MATCH_PARENT val params = surfaceView.layoutParams as FrameLayout.LayoutParams @@ -2706,13 +2705,19 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { else "unfolded controls: game full screen") } var panel = unfoldedPanel + if (panel != null && panel.deckControls != SessionState.deckPad) { + sessionRoot.removeView(panel) + unfoldedPanel = null + panel = null + } if (!wanted) { if (panel != null) { sessionRoot.removeView(panel); unfoldedPanel = null; updateOnScreenControls() } return } if (panel == null) { panel = com.droiddeck.launcher.ui.DeckControlsPanel(this, onClose = { chooseUnfoldedControls(false) }, - onSteamMenu = ::tapSteamButton, onQam = ::tapQam, pad = padBridge) + onSteamMenu = ::tapSteamButton, onQam = ::tapQam, pad = padBridge, + portraitDock = !com.droiddeck.launcher.session.SessionDisplay.foldable(this)) sessionRoot.addView(panel, sessionRoot.indexOfChild(surfaceView) + 1) unfoldedPanel = panel updateOnScreenControls() @@ -3148,7 +3153,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { override fun onPictureInPictureModeChanged(inPip: Boolean, newConfig: android.content.res.Configuration) { super.onPictureInPictureModeChanged(inPip, newConfig) if (::pip.isInitialized) pip.changed(inPip) - if (!inPip && surfaceW > 0) followWindow(surfaceW, surfaceH) + if (!inPip && surfaceW > 0) resizeOutputForWindow(surfaceW, surfaceH) applyUnfoldedControls() updateGlassesScreen() } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionDisplay.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionDisplay.kt index 39ed2c43e9..31b9b10988 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionDisplay.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionDisplay.kt @@ -17,12 +17,13 @@ object SessionDisplay { fun screenSize(panel: Pair): Pair = (maxOf(panel.first, panel.second) and 1.inv()) to (minOf(panel.first, panel.second) and 1.inv()) - fun resolveChoice(panel: Pair, choice: String): Pair { - if (choice == MATCH_SCREEN || choice == FOLLOW_SCREEN) return screenSize(panel) - presetHeight(choice)?.let { return resolve(panel, it, SessionPrefs.SHAPE_AUTO) } + fun resolveChoice(panel: Pair, choice: String, portrait: Boolean = false): Pair { + fun orient(size: Pair) = if (portrait) size.second to size.first else size + if (choice == MATCH_SCREEN || choice == FOLLOW_SCREEN) return orient(screenSize(panel)) + presetHeight(choice)?.let { return orient(resolve(panel, it, SessionPrefs.SHAPE_AUTO)) } val parts = choice.split('x').map { it.toIntOrNull() } return if (parts.size == 2 && parts.all { it != null && it > 0 }) parts[0]!! to parts[1]!! - else resolve(panel, 720, SessionPrefs.SHAPE_AUTO) + else orient(resolve(panel, 720, SessionPrefs.SHAPE_AUTO)) } fun resolutionOptions(panel: Pair): List { @@ -31,8 +32,10 @@ object SessionDisplay { .filter { resolveChoice(panel, it) != screenSize(panel) } + MATCH_SCREEN + FOLLOW_SCREEN } - fun followSize(width: Int, height: Int): Pair? = - if (minOf(width, height) < FOLLOW_MIN_SIDE) null else (width and 1.inv()) to (height and 1.inv()) + fun followSize(width: Int, height: Int, controlsBelow: Boolean = false): Pair? = + if (width <= 0 || height <= 0 || + (if (controlsBelow) width else minOf(width, height)) < FOLLOW_MIN_SIDE) null + else (width and 1.inv()) to (height and 1.inv()) const val UNFOLDED_MAX_GAME_SHARE = 0.8f @@ -49,13 +52,14 @@ object SessionDisplay { foldable: Boolean, controllerConnected: Boolean, keepWithController: Boolean, - steamDeckPad: Boolean, + gamepadAvailable: Boolean, pip: Boolean, width: Int, height: Int, smallestWidthDp: Int, - ): Boolean = enabled && foldable && (keepWithController || !controllerConnected) && steamDeckPad && - !pip && width > 0 && height > 0 && smallestWidthDp >= UNFOLDED_MIN_DP + ): Boolean = enabled && (keepWithController || !controllerConnected) && gamepadAvailable && + !pip && width > 0 && height > 0 && + (height > width || (foldable && smallestWidthDp >= UNFOLDED_MIN_DP)) fun panelSize(context: Context): Pair { diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index 75f6e54bef..8ffaacd563 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -44,6 +44,8 @@ object SessionPrefs { private fun prefs(context: Context) = context.getSharedPreferences("session", Context.MODE_PRIVATE) val orientationOptions = listOf( + ActivityInfo.SCREEN_ORIENTATION_USER to R.string.setup_launcher_orientation_auto, + ActivityInfo.SCREEN_ORIENTATION_PORTRAIT to R.string.setup_orientation_portrait, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE to R.string.setup_orientation_auto, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE to R.string.setup_orientation_landscape, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE to R.string.setup_orientation_reverse, @@ -59,6 +61,17 @@ object SessionPrefs { prefs(context).edit().putInt("orientation", orientation).apply() } + fun windowOrientation(context: Context, followScreen: Boolean, smallestWidthDp: Int): Int = + if (followScreen && smallestWidthDp >= SessionDisplay.UNFOLDED_MIN_DP && !prefs(context).contains("orientation")) + ActivityInfo.SCREEN_ORIENTATION_USER else orientation(context) + + fun portrait(context: Context): Boolean = when (orientation(context)) { + ActivityInfo.SCREEN_ORIENTATION_PORTRAIT -> true + ActivityInfo.SCREEN_ORIENTATION_USER -> + context.resources.configuration.orientation == android.content.res.Configuration.ORIENTATION_PORTRAIT + else -> false + } + fun launcherFullscreen(context: Context): Boolean = prefs(context).getBoolean("launcherFullscreen", true) fun setLauncherFullscreen(context: Context, on: Boolean) { @@ -664,8 +677,10 @@ object SessionPrefs { parseResolution(value)?.let { return "${it.first}x${it.second}" } } if (!resolutionChosen(context, mode) && !saved.contains("shape")) return SessionDisplay.DEFAULT_RESOLUTION - val legacy = SessionDisplay.resolve(panel, resolutionCap(context, mode), shapeMode(context), customResolution(context, mode)) + val custom = customResolution(context, mode) + val legacy = SessionDisplay.resolve(panel, resolutionCap(context, mode), shapeMode(context), custom) return if (legacy == SessionDisplay.screenSize(panel)) SessionDisplay.MATCH_SCREEN + else if (custom == null && legacy == SessionDisplay.resolve(panel, legacy.second, SHAPE_AUTO)) "${legacy.second}p" else "${legacy.first}x${legacy.second}" } @@ -1117,6 +1132,18 @@ object SessionPrefs { fun unfoldedControls(context: Context): Boolean = prefs(context).getBoolean("unfoldedControls", false) + fun controlsBelowWanted(context: Context, mode: String, width: Int, height: Int, pip: Boolean = false): Boolean = + SessionDisplay.unfoldedControlsWanted( + enabled = unfoldedControls(context), + foldable = SessionDisplay.foldable(context), + controllerConnected = com.droiddeck.launcher.input.PadBridge.anyControllerConnected() || + com.droiddeck.launcher.input.SteamControllerBle.connected, + keepWithController = unfoldedControlsWithController(context), + gamepadAvailable = mode == SessionService.MODE_STEAM && builtinPad(context), + pip = pip, width = width, height = height, + smallestWidthDp = context.resources.configuration.smallestScreenWidthDp, + ) + fun setUnfoldedControls(context: Context, enabled: Boolean) { prefs(context).edit().putBoolean("unfoldedControls", enabled).apply() } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index dd844b71c1..b6f35f96a1 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -499,7 +499,9 @@ class SessionService : Service() { guest.add("BL_WIDTH=" + size.first) guest.add("BL_HEIGHT=" + size.second) - if (SessionState.followScreen) guest.add("BL_FOLLOW_OUTPUT=1") + if (SessionState.followScreen || size.first < size.second || + SessionPrefs.orientation(this) == android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER) + guest.add("BL_FOLLOW_OUTPUT=1") if (SessionState.hdr) { guest.add("BL_HDR=1") guest.add("DXVK_HDR=1") diff --git a/app/src/main/java/com/droiddeck/launcher/ui/DeckControlsPanel.kt b/app/src/main/java/com/droiddeck/launcher/ui/DeckControlsPanel.kt index 0a603d5a54..825b6980fb 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/DeckControlsPanel.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/DeckControlsPanel.kt @@ -37,10 +37,12 @@ class DeckControlsPanel( private val onSteamMenu: () -> Unit, private val onQam: () -> Unit, private val pad: PadBridge? = null, + private val portraitDock: Boolean = false, ) : LinearLayout(context) { private enum class Tab(val label: Int) { GAMEPAD(R.string.deck_tab_gamepad), GRIPS(R.string.deck_tab_grips), LEFT(R.string.deck_tab_left), RIGHT(R.string.deck_tab_right), BOTH(R.string.deck_tab_both) } private val content = FrameLayout(context) + val deckControls = pad == null || SessionState.deckPad private val tabViews = HashMap() private val topBar: View by lazy { topBar() } @@ -49,7 +51,7 @@ class DeckControlsPanel( setBackgroundColor(Color.BLACK) addView(topBar, LayoutParams(LayoutParams.MATCH_PARENT, dp(64))) addView(content, LayoutParams(LayoutParams.MATCH_PARENT, 0, 1f)) - select(if (pad != null) selectedWithPad else selected) + select(if (pad != null && !deckControls) Tab.GAMEPAD else if (pad != null) selectedWithPad else selected) } override fun onDetachedFromWindow() { @@ -67,6 +69,7 @@ class DeckControlsPanel( background = outline(CORNER_PILL, SURFACE) setPadding(dp(4), dp(4), dp(4), dp(4)) for (tab in Tab.values()) { + if (!deckControls && tab != Tab.GAMEPAD) continue if (tab == Tab.GAMEPAD && pad == null) continue val view = TextView(context).apply { text = context.getString(tab.label) @@ -170,7 +173,7 @@ class DeckControlsPanel( addView(grips, LayoutParams(LayoutParams.MATCH_PARENT, dp(84))) } - private fun gamepad(pad: PadBridge): View = GamepadLayout(context).apply { + private fun gamepad(pad: PadBridge): View = GamepadLayout(context, portraitDock).apply { fun pill(label: String, write: (PadState, Boolean) -> Unit) = PadButton(context, pad, label, write) place(surfaceSlot(pad, right = false), GamepadGeometry.Slot.LEFT_MAIN) place(DirectionPad(context, pad), GamepadGeometry.Slot.LEFT_SECOND) @@ -186,14 +189,22 @@ class DeckControlsPanel( place(centreTap("\u2022\u2022\u2022", context.getString(R.string.drawer_open_qam), onQam), GamepadGeometry.Slot.QAM) } place(pill("MENU") { st, d -> st.press(PadState.START, d) }, GamepadGeometry.Slot.MENU) - place(centreTap("\u25a6 " + context.getString(R.string.deck_panels), context.getString(R.string.deck_more_controls)) { select(Tab.BOTH) }, + if (deckControls) place(centreTap("\u25a6 " + context.getString(R.string.deck_panels), context.getString(R.string.deck_more_controls)) { select(Tab.BOTH) }, GamepadGeometry.Slot.PANELS) + if (portraitDock && deckControls) { + place(GripButton(context, "L4", null, DeckControls.L4), GamepadGeometry.Slot.L4) + place(GripButton(context, "L5", null, DeckControls.L5), GamepadGeometry.Slot.L5) + place(GripButton(context, "R5", null, DeckControls.R5), GamepadGeometry.Slot.R5) + place(GripButton(context, "R4", null, DeckControls.R4), GamepadGeometry.Slot.R4) + } } private fun centreTap(label: String, description: String, onClick: () -> Unit) = TextView(context).apply { text = label contentDescription = description textSize = 13f + maxLines = 1 + setAutoSizeTextTypeUniformWithConfiguration(9, 13, 1, android.util.TypedValue.COMPLEX_UNIT_SP) typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD) letterSpacing = 0.08f gravity = Gravity.CENTER @@ -206,6 +217,11 @@ class DeckControlsPanel( } private fun surfaceSlot(pad: PadBridge, right: Boolean): View = FrameLayout(context).apply { + if (!deckControls) { + addView(StickView(context, pad, right), + FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)) + return@apply + } val slot = this fun show() { slot.removeAllViews() @@ -617,7 +633,7 @@ class DeckControlsPanel( } } - private class GamepadLayout(context: Context) : ViewGroup(context) { + private class GamepadLayout(context: Context, private val portraitDock: Boolean) : ViewGroup(context) { private val slots = LinkedHashMap() fun place(view: View, slot: GamepadGeometry.Slot) { @@ -625,7 +641,7 @@ class DeckControlsPanel( addView(view) } - private fun boxes(w: Int, h: Int) = GamepadGeometry.layout(w.toFloat(), h.toFloat(), resources.displayMetrics.density) + private fun boxes(w: Int, h: Int) = GamepadGeometry.layout(w.toFloat(), h.toFloat(), resources.displayMetrics.density, portraitDock) override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { val w = MeasureSpec.getSize(widthMeasureSpec) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GamepadGeometry.kt b/app/src/main/java/com/droiddeck/launcher/ui/GamepadGeometry.kt index 466d57aecd..2b369c20aa 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GamepadGeometry.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GamepadGeometry.kt @@ -8,6 +8,7 @@ object GamepadGeometry { LEFT_OUTER_SHOULDER, LEFT_INNER_SHOULDER, RIGHT_INNER_SHOULDER, RIGHT_OUTER_SHOULDER, VIEW, STEAM, QAM, MENU, PANELS, + L4, L5, R5, R4, } data class Box(val cx: Float, val cy: Float, val width: Float, val height: Float) { @@ -25,8 +26,11 @@ object GamepadGeometry { fun tall(w: Float, h: Float): Boolean = h >= w * 0.45f - fun layout(w: Float, h: Float, density: Float): Map { + fun layout(w: Float, h: Float, density: Float, portraitDock: Boolean = false): Map { if (w <= 0f || h <= 0f) return emptyMap() + if (portraitDock && h >= w * 0.9f && w >= 300 * density && h >= 360 * density) { + return portraitLayout(w, h, density) + } val pad = 8 * density val buttonH = 40 * density val rowButton = 64 * density @@ -67,7 +71,7 @@ object GamepadGeometry { } middleGrid(columns, gap - 2 * gutter, shoulderY - buttonH / 2f) } else { - val side = min(w * 0.5f, h * 0.70f) + val side = min(min(w * 0.5f, h * 0.70f), (w - 2 * gridButton - 2 * gutter) / 1.42f) val main = side * 0.62f val second = side * 0.46f val secondCy = h - side * 0.97f @@ -87,4 +91,39 @@ object GamepadGeometry { } return boxes } + + private fun portraitLayout(w: Float, h: Float, density: Float): Map { + val pad = 8 * density + val gap = 8 * density + val buttonH = 44 * density + val scale = min(1f, (h - 2 * pad - 4 * gap - 3 * buttonH) / (w * 0.7f)) + val main = w * 0.4f * scale + val second = w * 0.3f * scale + val mainY = h - pad - main / 2f + val secondY = mainY - main / 2f - gap - second / 2f + val shoulderY = secondY - second / 2f - gap - buttonH / 2f + val boxes = linkedMapOf( + Slot.LEFT_MAIN to Box(w * 0.25f, mainY, main, main), + Slot.RIGHT_MAIN to Box(w * 0.75f, mainY, main, main), + Slot.LEFT_SECOND to Box(w * 0.25f, secondY, second, second), + Slot.RIGHT_SECOND to Box(w * 0.75f, secondY, second, second), + ) + val utilityW = (w - 2 * pad - 3 * gap) / 4f + for ((i, slot) in middle.withIndex()) { + boxes[slot] = Box(pad + utilityW / 2f + i * (utilityW + gap), pad + buttonH / 2f, utilityW, buttonH) + } + val gripTop = pad + buttonH + gap + val gripH = min(64 * density, shoulderY - buttonH / 2f - gap - gripTop) + for ((i, slot) in listOf(Slot.L4, Slot.L5, Slot.R5, Slot.R4).withIndex()) { + boxes[slot] = Box(pad + utilityW / 2f + i * (utilityW + gap), gripTop + gripH / 2f, utilityW, gripH) + } + val panelsW = min(112 * density, w * 0.22f) + val shoulderW = (w - 2 * pad - 4 * gap - panelsW) / 4f + boxes[Slot.PANELS] = Box(w / 2f, shoulderY, panelsW, buttonH) + boxes[Slot.LEFT_OUTER_SHOULDER] = Box(pad + shoulderW / 2f, shoulderY, shoulderW, buttonH) + boxes[Slot.LEFT_INNER_SHOULDER] = Box(pad + shoulderW * 1.5f + gap, shoulderY, shoulderW, buttonH) + boxes[Slot.RIGHT_INNER_SHOULDER] = Box(w - pad - shoulderW * 1.5f - gap, shoulderY, shoulderW, buttonH) + boxes[Slot.RIGHT_OUTER_SHOULDER] = Box(w - pad - shoulderW / 2f, shoulderY, shoulderW, buttonH) + return boxes + } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt index a2239bb725..86c03309f8 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt @@ -210,9 +210,16 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras: val host = rememberMenuHost() var explainWifiDiscovery by remember { mutableStateOf(false) } if (tab == SheetTab.DISPLAY) { - val displaySize = com.droiddeck.launcher.session.SessionDisplay.resolveChoice(s.panelSize, s.resolution) + val context = LocalContext.current + val portraitWindow = SessionPrefs.portrait(context) + val longSide = maxOf(s.panelSize.first, s.panelSize.second) + val shortSide = minOf(s.panelSize.first, s.panelSize.second) + val controlsBelow = SessionPrefs.controlsBelowWanted(context, s.mode, + if (portraitWindow) shortSide else longSide, if (portraitWindow) longSide else shortSide) + val portrait = portraitWindow && !controlsBelow + val displaySize = com.droiddeck.launcher.session.SessionDisplay.resolveChoice(s.panelSize, s.resolution, portrait) SettingsGroup(stringResource(R.string.display_session)) { - ResolutionRow(host, s.resolution, s.panelSize, a.onResolution) + ResolutionRow(host, s.resolution, s.panelSize, a.onResolution, portrait = portrait) s.picturePosition?.let { position -> ChoiceRow(host, "picture-position", stringResource(R.string.display_picture_position), null, listOf("top" to stringResource(R.string.display_position_top), diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ResolutionRow.kt b/app/src/main/java/com/droiddeck/launcher/ui/ResolutionRow.kt index 5a0b88daaf..8db8910a80 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ResolutionRow.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ResolutionRow.kt @@ -14,16 +14,17 @@ import com.droiddeck.launcher.session.SessionDisplay fun ResolutionRow( host: MenuHost, choice: String, panel: Pair, onPick: (String) -> Unit, chipModifier: Modifier = Modifier, + portrait: Boolean = false, ) { val custom = "custom" - val size = SessionDisplay.resolveChoice(panel, choice) - val screen = SessionDisplay.screenSize(panel) + val size = SessionDisplay.resolveChoice(panel, choice, portrait) + val screen = SessionDisplay.resolveChoice(panel, SessionDisplay.MATCH_SCREEN, portrait) val choices = SessionDisplay.resolutionOptions(panel) val selected = if (choice == SessionDisplay.FOLLOW_SCREEN) choice else if (size == screen) SessionDisplay.MATCH_SCREEN else choice var editCustom by remember { mutableStateOf(false) } val options = choices.map { value -> - val dimensions = SessionDisplay.resolveChoice(panel, value) + val dimensions = SessionDisplay.resolveChoice(panel, value, portrait) value to if (value == SessionDisplay.MATCH_SCREEN) stringResource(R.string.display_match_screen, screen.first, screen.second) else if (value == SessionDisplay.FOLLOW_SCREEN) stringResource(R.string.display_follow_screen) else if (value == SessionDisplay.DEFAULT_RESOLUTION) stringResource(R.string.mode_res_default, "${dimensions.first}×${dimensions.second}") 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 1adcfd860c..b526bea285 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -72,6 +72,8 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.ScrollState +import androidx.compose.foundation.horizontalScroll +import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.MaterialTheme @@ -405,6 +407,7 @@ 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 = minOf(360.dp, maxWidth * 0.92f) + val narrow = sheetWidth < 320.dp AnimatedVisibility( open, enter = slideInHorizontally(Motion.sp(0.8f, Spring.StiffnessLow)) { it } + fadeIn(Motion.tw(220)), @@ -420,14 +423,18 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont .controllerBack { if (host.open != null) host.open = null else a.onClose() } - .padding(if (short) 12.dp else 16.dp), + .padding(12.dp), ) { + val title = a.title ?: if (a.steam) stringResource(R.string.drawer_steam) else stringResource(R.string.drawer_desktop) + if (narrow) Text(title, fontSize = 18.sp, fontWeight = FontWeight.Bold, + color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, + modifier = Modifier.fillMaxWidth().padding(bottom = 6.dp)) Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth().heightIn(min = 44.dp), ) { - Text(a.title ?: if (a.steam) stringResource(R.string.drawer_steam) else stringResource(R.string.drawer_desktop), fontSize = if (short) 18.sp else 20.sp, fontWeight = FontWeight.Bold, + if (narrow) Spacer(Modifier.weight(1f)) else Text(title, fontSize = 18.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f)) if (a.pipSupported) SteamActionPill( stringResource(R.string.pip_title), Icons.Outlined.PictureInPictureAlt, focus.track(page, "pip"), @@ -468,12 +475,12 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont Row( verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.fillMaxWidth().padding(top = if (short) 6.dp else 12.dp), + modifier = Modifier.fillMaxWidth().padding(top = 6.dp), ) { DrawerBumper("LB", stringResource(R.string.drawer_prev_page), modifier = focus.track(page, "prev")) { host.open = null; onPageChange(pages.step(page, -1)) } - DrawerPageTabs(page = page, pages = pages, compact = short, modifier = Modifier.weight(1f)) { index -> host.open = null; onPageChange(index) } + DrawerPageTabs(page = page, pages = pages, compact = true, modifier = Modifier.weight(1f)) { index -> host.open = null; onPageChange(index) } DrawerBumper("RB", stringResource(R.string.drawer_next_page), modifier = focus.track(page, "next")) { host.open = null; onPageChange(pages.step(page, 1)) } @@ -484,7 +491,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont ) { selectedGlassesTab = it } Column( modifier = Modifier.weight(1f).fillMaxWidth().verticalScroll(pageScroll.getValue(page)), - ) { CompositionLocalProvider(LocalChipMinWidth provides 120.dp) { + ) { CompositionLocalProvider(LocalChipMinWidth provides 96.dp, LocalCompactSettings provides true) { when (page) { SessionDrawerPage.DISPLAY -> { SettingsGroup(stringResource(R.string.drawer_page_display)) { @@ -559,7 +566,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont stringResource(R.string.ctrl_edit), a.onGestureSettings, modifier = focus.track(page, "gesture-settings")) if (a.onScreenKeys != null) { - SettingsRow(stringResource(R.string.screen_keys), null) { + SettingsRow(stringResource(R.string.screen_keys), null, stacked = narrow) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), @@ -896,16 +903,22 @@ private fun DrawerPageTabs(page: SessionDrawerPage, pages: List + @Composable fun tabs() { pages.forEachIndexed { index, item -> androidx.compose.runtime.key(item) { val selected = item == page val source = remember { MutableInteractionSource() } val focused = source.collectIsFocusedAsState().value - val scale by animateFloatAsState(if (selected) 1f else DRAWER_TAB_SIDE_SCALE, motion, label = "tabScale") - val alpha by animateFloatAsState(if (selected) 1f else DRAWER_TAB_SIDE_ALPHA, motion, label = "tabAlpha") + val scale by animateFloatAsState(if (selected || scrolling) 1f else DRAWER_TAB_SIDE_SCALE, motion, label = "tabScale") + val alpha by animateFloatAsState(if (selected || scrolling) 1f else DRAWER_TAB_SIDE_ALPHA, motion, label = "tabAlpha") val glow by animateFloatAsState(if (selected) 1f else 0f, motion, label = "tabGlow") val pageDescription = stringResource(R.string.drawer_page_desc, stringResource(item.title)) val tint by animateColorAsState(if (selected) colors.onBackground else colors.onSurfaceVariant, Motion.tw(340, easing = FastOutSlowInEasing), label = "tabTint") @@ -913,7 +926,7 @@ private fun DrawerPageTabs(page: SessionDrawerPage, pages: List Unit) { } val LocalChipMinWidth = androidx.compose.runtime.compositionLocalOf { 150.dp } +internal val LocalCompactSettings = androidx.compose.runtime.compositionLocalOf { false } class MenuHost { var open by mutableStateOf(null) @@ -389,6 +390,7 @@ fun MenuItem( @Composable fun ValueChip(text: String, open: Boolean, enabled: Boolean = true, modifier: Modifier = Modifier, onClick: () -> Unit) { + val compact = LocalCompactSettings.current val colors = MaterialTheme.colorScheme val src = remember { MutableInteractionSource() } val hot = src.collectIsFocusedAsState().value || src.collectIsHoveredAsState().value @@ -405,13 +407,15 @@ fun ValueChip(text: String, open: Boolean, enabled: Boolean = true, modifier: Mo .alpha(if (enabled) 1f else 0.5f) .hoverable(src).clickable(role = androidx.compose.ui.semantics.Role.Button, interactionSource = src, indication = LocalIndication.current, enabled = enabled, onClick = onClick) .controllerConfirm(enabled = enabled, onClick = onClick) - .padding(horizontal = 12.dp, vertical = 8.dp), + .padding(horizontal = if (compact) 10.dp else 12.dp, vertical = if (compact) 6.dp else 8.dp), ) { AnimatedContent( targetState = text, transitionSpec = { (fadeIn(Motion.tw(260)) + slideInVertically(Motion.tw(260)) { it / 2 }) togetherWith (fadeOut(Motion.tw(160)) + slideOutVertically(Motion.tw(160)) { -it / 2 }) }, label = "chipText", - ) { t -> Text(t, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) } + ) { t -> Text(t, fontSize = if (compact) 12.sp else 13.sp, + lineHeight = if (compact) 16.sp else androidx.compose.ui.unit.TextUnit.Unspecified, + fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) } Spacer(Modifier.width(8.dp)) Text("▾", fontSize = 10.sp, color = colors.onSurfaceVariant, modifier = Modifier.rotate(rot)) } @@ -419,15 +423,16 @@ fun ValueChip(text: String, open: Boolean, enabled: Boolean = true, modifier: Mo @Composable fun SettingsGroup(title: String, compact: Boolean = false, content: @Composable ColumnScope.() -> Unit) { + val tight = compact || LocalCompactSettings.current val colors = MaterialTheme.colorScheme val pal = LocalPalette.current Column(Modifier.fillMaxWidth().sheetPiece()) { Row( verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(if (compact) 6.dp else 10.dp), - modifier = Modifier.fillMaxWidth().padding(top = if (compact) 4.dp else 16.dp, bottom = if (compact) 3.dp else 6.dp), + horizontalArrangement = Arrangement.spacedBy(if (tight) 6.dp else 10.dp), + modifier = Modifier.fillMaxWidth().padding(top = if (tight) 4.dp else 16.dp, bottom = if (tight) 3.dp else 6.dp), ) { - Text(title.uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, color = colors.onSurfaceVariant) + Text(title.uppercase(), fontSize = if (tight) 11.sp else 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, color = colors.onSurfaceVariant) Box(modifier = Modifier.weight(1f).height(1.dp).background(pal.line)) } Column(modifier = Modifier.fillMaxWidth().clip(GroupShape).background(colors.surface).border(1.dp, pal.line, GroupShape)) { content() } @@ -436,19 +441,34 @@ fun SettingsGroup(title: String, compact: Boolean = false, content: @Composable @Composable fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, hintLines: Int? = null, stacked: Boolean = false, control: @Composable () -> Unit) { + val compact = LocalCompactSettings.current val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val bg by animateColorAsState(if (highlighted) pal.signal.copy(alpha = 0.10f) else Color.Transparent, Motion.tw(200), label = "rowBg") val hintText: @Composable (androidx.compose.ui.unit.TextUnit) -> Unit = { size -> Text(hint ?: "", fontSize = size, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 2.dp), + lineHeight = if (compact) 14.sp else androidx.compose.ui.unit.TextUnit.Unspecified, minLines = hintLines ?: 1, maxLines = hintLines ?: Int.MAX_VALUE, overflow = TextOverflow.Ellipsis) } - if (stacked || LocalNarrowPane.current) Column( - modifier = Modifier.fillMaxWidth().background(bg).padding(start = 14.dp, end = 14.dp, top = 11.dp, bottom = 12.dp), + if (compact && !stacked) Column( + modifier = Modifier.fillMaxWidth().background(bg).padding(horizontal = 10.dp, vertical = 6.dp), ) { - Text(label, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground) - if (hint != null || hintLines != null) hintText(13.sp) - Box(Modifier.padding(top = 8.dp)) { control() } + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) { + Text(label, fontSize = 13.sp, lineHeight = 16.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, + modifier = Modifier.weight(1f)) + control() + } + if (hint != null || hintLines != null) hintText(11.sp) + } else if (stacked || LocalNarrowPane.current) Column( + modifier = Modifier.fillMaxWidth().background(bg).padding( + horizontal = if (compact) 10.dp else 14.dp, + vertical = if (compact) 6.dp else 12.dp), + ) { + Text(label, fontSize = if (compact) 13.sp else 15.sp, + lineHeight = if (compact) 16.sp else androidx.compose.ui.unit.TextUnit.Unspecified, + fontWeight = FontWeight.SemiBold, color = colors.onBackground) + if (hint != null || hintLines != null) hintText(if (compact) 11.sp else 13.sp) + Box(Modifier.padding(top = if (compact) 6.dp else 8.dp)) { control() } } else Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().background(bg).padding(horizontal = 14.dp, vertical = 11.dp), @@ -561,6 +581,7 @@ fun ValueSlider( value: Int, range: IntRange, step: Int, enabled: Boolean, label: String?, format: (Int) -> String, modifier: Modifier = Modifier, onChange: (Int) -> Unit, ) { + val compact = LocalCompactSettings.current val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val source = remember { MutableInteractionSource() } @@ -581,7 +602,7 @@ fun ValueSlider( } } Column( - modifier = modifier.fillMaxWidth().heightIn(min = 72.dp) + modifier = modifier.fillMaxWidth().heightIn(min = if (compact) 64.dp else 72.dp) .clip(shape).background(if (hot) pal.signal.copy(alpha = 0.12f) else Color.Transparent) .glideBorder(hot, shape, pal.signal) .alpha(if (enabled) 1f else 0.5f) @@ -610,10 +631,10 @@ fun ValueSlider( .padding(horizontal = 8.dp, vertical = 6.dp), ) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) { - if (label != null) Text(label, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, + if (label != null) Text(label, fontSize = if (compact) 13.sp else 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, modifier = Modifier.weight(1f)) else Spacer(Modifier.weight(1f)) - Text(text, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1) + Text(text, fontSize = if (compact) 12.sp else 14.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1) } Canvas( Modifier.fillMaxWidth().height(40.dp).onSizeChanged { trackPx = it.width } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 81d0ad94d2..6b598b8c25 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -832,8 +832,8 @@ Launcher orientation Follow device rotation Portrait - Game and desktop orientation - Applies to Steam, games, desktop, and the controller editor. + Session orientation + Applies to Steam, games, desktop, and the controller editor. Resolution presets rotate with the session; custom width and height stay as entered. Automatic landscape Landscape Reverse landscape @@ -1251,10 +1251,10 @@ Proton games Picture in picture Automatically enter PiP - Controls on the unfolded screen - Unfolded, the game sits above the Steam Deck trackpads and back grips. Folded, the game is full screen. + Controls below the game + In portrait or on an unfolded screen, place a landscape game above the touch controls. Keep them with a controller - Also show the unfolded controls while a controller is connected, for controllers that hold the phone. + Also show these touch controls while a controller is connected. Suspended Picture in picture is available once the session is ready. Allow picture in picture for DroidDeck in Android settings. diff --git a/app/src/test/java/com/droiddeck/launcher/session/OrientationTest.kt b/app/src/test/java/com/droiddeck/launcher/session/OrientationTest.kt index e694b8b3c7..1801ce756c 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/OrientationTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/OrientationTest.kt @@ -21,13 +21,9 @@ class OrientationTest { context.getSharedPreferences("app-ui", Context.MODE_PRIVATE).edit().clear().commit() } - @Test fun landscapeChoicesPersistGloballyAndCanRestoreAutomaticRotation() { + @Test fun sessionChoicesPersistGloballyWithLandscapeAsTheDefault() { assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context)) - for (value in listOf( - ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, - ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE, - ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, - )) { + for ((value, _) in SessionPrefs.orientationOptions) { SessionPrefs.setOrientation(context, value) assertEquals(value, SessionPrefs.orientation(context.createConfigurationContext(context.resources.configuration))) } @@ -35,11 +31,11 @@ class OrientationTest { @Test fun invalidStoredOrientationFallsBackAndInvalidChoicePreservesTheSavedValue() { val prefs = context.getSharedPreferences("session", Context.MODE_PRIVATE) - prefs.edit().putInt("orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT).commit() + prefs.edit().putInt("orientation", 999).commit() assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context)) SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) assertThrows(IllegalArgumentException::class.java) { - SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) + SessionPrefs.setOrientation(context, 999) } assertEquals(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE, SessionPrefs.orientation(context)) } @@ -54,6 +50,34 @@ class OrientationTest { AppUiPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, AppUiPrefs.orientation(context)) + AppUiPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) + SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) + assertEquals(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, AppUiPrefs.orientation(context)) + assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, SessionPrefs.orientation(context)) + } + + @Test fun explicitOrientationTakesPriorityOverLargeFollowScreenWindows() { + assertEquals(ActivityInfo.SCREEN_ORIENTATION_USER, SessionPrefs.windowOrientation(context, true, 700)) + assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.windowOrientation(context, true, 400)) + assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.windowOrientation(context, false, 700)) + for ((value, _) in SessionPrefs.orientationOptions) { + SessionPrefs.setOrientation(context, value) + assertEquals(value, SessionPrefs.windowOrientation(context, true, 700)) + } + } + + @Test fun sessionPortraitUsesItsOwnLockOrTheCurrentRotation() { + val config = android.content.res.Configuration(context.resources.configuration) + config.orientation = android.content.res.Configuration.ORIENTATION_PORTRAIT + val portrait = context.createConfigurationContext(config) + config.orientation = android.content.res.Configuration.ORIENTATION_LANDSCAPE + val landscape = context.createConfigurationContext(config) + assertFalse(SessionPrefs.portrait(portrait)) + SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) + assertTrue(SessionPrefs.portrait(landscape)) + SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_USER) + assertTrue(SessionPrefs.portrait(portrait)) + assertFalse(SessionPrefs.portrait(landscape)) } @Test fun invalidLauncherOrientationFallsBackAndInvalidChoicePreservesPreference() { diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionDisplayTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionDisplayTest.kt index 7962ef6fc8..5d51028b05 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionDisplayTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionDisplayTest.kt @@ -4,6 +4,23 @@ import org.junit.Assert.* import org.junit.Test class SessionDisplayTest { + @Test fun portraitPresetsSwapTheOutputAndRetainTheResolutionCap() { + assertEquals(720 to 1280, SessionDisplay.resolveChoice(1920 to 1080, "720p", portrait = true)) + assertEquals(900 to 1600, SessionDisplay.resolveChoice(1080 to 1920, "900p", portrait = true)) + assertEquals(720 to 1280, SessionDisplay.resolveChoice(1440 to 1080, "720p", portrait = true)) + assertEquals(720 to 1600, SessionDisplay.resolveChoice(2400 to 1080, "720p", portrait = true)) + assertEquals(1080 to 1920, SessionDisplay.resolveChoice(1921 to 1081, SessionDisplay.MATCH_SCREEN, portrait = true)) + assertEquals(1080 to 2400, SessionDisplay.resolveChoice(2400 to 1080, SessionDisplay.FOLLOW_SCREEN, portrait = true)) + assertEquals(720 to 1280, SessionDisplay.resolveChoice(1920 to 1080, "invalid", portrait = true)) + } + + @Test fun customDimensionsStayExplicitInEitherOrientation() { + for (portrait in listOf(false, true)) { + assertEquals(1280 to 720, SessionDisplay.resolveChoice(1920 to 1080, "1280x720", portrait)) + assertEquals(720 to 1280, SessionDisplay.resolveChoice(1920 to 1080, "720x1280", portrait)) + } + } + @Test fun fixedSizesAndMatchScreenResolveWithoutAnyAspectSetting() { assertEquals(1280 to 720, SessionDisplay.resolveChoice(1440 to 1080, "1280x720")) assertEquals(1600 to 900, SessionDisplay.resolveChoice(1280 to 720, "1600x900")) @@ -35,6 +52,7 @@ class SessionDisplayTest { } @Test fun unfoldedControlsKeepTheGameSixteenByNineAcrossTheWidth() { + assertEquals(606, SessionDisplay.unfoldedGameHeight(1080, 1920)) assertEquals(1376, SessionDisplay.unfoldedGameHeight(2448, 1848)) assertEquals(1038, SessionDisplay.unfoldedGameHeight(1848, 2448)) assertEquals(864, SessionDisplay.unfoldedGameHeight(1920, 1080)) @@ -67,6 +85,18 @@ class SessionDisplayTest { assertFalse(SessionDisplay.unfoldedControlsWanted(true, true, true, true, true, false, 0, 1848, 700)) } + @Test fun portraitControlsWorkOnHandheldsAndPhonesWithoutAHinge() { + fun wanted(width: Int = 1080, height: Int = 1920, controller: Boolean = false, + keep: Boolean = false, pad: Boolean = true, pip: Boolean = false) = + SessionDisplay.unfoldedControlsWanted(true, false, controller, keep, pad, pip, width, height, 393) + assertTrue(wanted()) + assertFalse(wanted(width = 1920, height = 1080)) + assertFalse(wanted(controller = true)) + assertTrue(wanted(controller = true, keep = true)) + assertFalse(wanted(pad = false)) + assertFalse(wanted(pip = true)) + } + @Test fun followScreenKeepsTheWindowShapeAndSkipsTinyWindows() { assertEquals(2520 to 1080, SessionDisplay.resolveChoice(1080 to 2520, SessionDisplay.FOLLOW_SCREEN)) @@ -75,6 +105,13 @@ class SessionDisplayTest { assertNull(SessionDisplay.followSize(640, 360)) } + @Test fun aPhoneCanFollowTheShortGameAreaAboveItsControls() { + assertNull(SessionDisplay.followSize(720, 404)) + assertEquals(720 to 404, SessionDisplay.followSize(720, 404, controlsBelow = true)) + assertNull(SessionDisplay.followSize(320, 180, controlsBelow = true)) + assertNull(SessionDisplay.followSize(720, 0, controlsBelow = true)) + } + @Test fun resolutionCapsPreserveTheSelectedShapeWithoutExceedingPanelHeight() { assertEquals(1280 to 720, SessionDisplay.resolve(1920 to 1080, 720, SessionPrefs.SHAPE_AUTO)) assertEquals(960 to 720, SessionDisplay.resolve(1440 to 1080, 720, SessionPrefs.SHAPE_EXACT)) diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionScalingPrefsTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionScalingPrefsTest.kt index 03a3243910..de082c7fe9 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionScalingPrefsTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionScalingPrefsTest.kt @@ -13,6 +13,16 @@ import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) @Config(sdk = [28], manifest = Config.NONE) class SessionScalingPrefsTest { + @Test fun legacyAutomaticResolutionsRemainRotatablePresets() { + val context = RuntimeEnvironment.getApplication() + val prefs = context.getSharedPreferences("session", Context.MODE_PRIVATE) + prefs.edit().putString("shape", SessionPrefs.SHAPE_AUTO).putInt("resolutionCap.steam", 900).commit() + assertEquals("900p", SessionPrefs.resolutionChoice(context, "steam", 1920 to 1080)) + val desktop = SessionPrefs.resolutionChoice(context, "lxqt", 1920 to 1080) + assertEquals("720p", desktop) + assertEquals(720 to 1280, SessionDisplay.resolveChoice(1920 to 1080, desktop, portrait = true)) + } + @Before fun clearSettings() { RuntimeEnvironment.getApplication().getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit() } diff --git a/app/src/test/java/com/droiddeck/launcher/ui/GamepadGeometryTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/GamepadGeometryTest.kt index e60f12f444..06f4dedfd7 100644 --- a/app/src/test/java/com/droiddeck/launcher/ui/GamepadGeometryTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ui/GamepadGeometryTest.kt @@ -13,6 +13,9 @@ class GamepadGeometryTest { } private val panels = listOf( + Panel("Thor portrait", 1080, 1920, 369 / 160f), + Panel("720p phone portrait", 720, 1280, 2f), + Panel("Phone portrait", 1080, 2400, 2.75f), Panel("Fold 8 upright", 1848, 2448, 2.625f), Panel("Fold 8 as a tablet", 2448, 1848, 2.625f), Panel("Pixel Fold upright", 1840, 2208, 2.625f), @@ -26,10 +29,15 @@ class GamepadGeometryTest { private fun boxes(panel: Panel) = GamepadGeometry.layout(panel.width.toFloat(), panel.controlsHeight.toFloat(), panel.density) + private val grips = setOf(Slot.L4, Slot.L5, Slot.R5, Slot.R4) + private val portraitPanels get() = panels.take(3) + Panel("312dp phone portrait", 720, 1280, 369 / 160f) + private fun portraitBoxes(panel: Panel) = + GamepadGeometry.layout(panel.width.toFloat(), panel.controlsHeight.toFloat(), panel.density, portraitDock = true) + @Test fun everyControlIsPlacedAndPanelsOnlyWhenUpright() { for (panel in panels) { val upright = panel.height > panel.width - val expected = Slot.values().toSet() - if (upright) emptySet() else setOf(Slot.PANELS) + val expected = Slot.values().toSet() - grips - if (upright) emptySet() else setOf(Slot.PANELS) assertEquals(panel.name, expected, boxes(panel).keys) } } @@ -81,4 +89,56 @@ class GamepadGeometryTest { assertTrue(panel.name, before(Slot.STEAM, Slot.QAM)) } } + + @Test fun portraitDockPlacesAllControlsWithinThePanel() { + for (panel in portraitPanels) { + val b = portraitBoxes(panel) + assertEquals(panel.name, Slot.values().toSet(), b.keys) + for ((slot, box) in b) { + val where = "${panel.name}: $slot $box" + assertTrue(where, box.left >= 0f && box.top >= 0f) + assertTrue(where, box.right <= panel.width && box.bottom <= panel.controlsHeight) + assertTrue(where, box.width >= 44 * panel.density - 1 && box.height >= 44 * panel.density - 1) + } + } + } + + @Test fun portraitDockControlsDoNotOverlap() { + for (panel in portraitPanels) { + val placed = portraitBoxes(panel).entries.toList() + for (i in placed.indices) for (j in i + 1 until placed.size) { + assertFalse("${panel.name}: ${placed[i].key} overlaps ${placed[j].key}", + placed[i].value.overlaps(placed[j].value)) + } + } + } + + @Test fun portraitDockUsesMoreSpaceForTheThumbSurfaces() { + for (panel in portraitPanels) { + val old = boxes(panel) + val b = portraitBoxes(panel) + for (slot in listOf(Slot.LEFT_MAIN, Slot.RIGHT_MAIN, Slot.LEFT_SECOND, Slot.RIGHT_SECOND)) { + assertTrue("${panel.name}: $slot", b.getValue(slot).width >= old.getValue(slot).width * 1.2f) + } + assertEquals(panel.name, b.getValue(Slot.LEFT_MAIN).cx, b.getValue(Slot.LEFT_SECOND).cx, 0.5f) + assertEquals(panel.name, panel.width - b.getValue(Slot.LEFT_MAIN).cx, b.getValue(Slot.RIGHT_MAIN).cx, 0.5f) + } + } + + @Test fun portraitDockMovesUtilitiesAndGripsAboveTheGamepad() { + for (panel in portraitPanels) { + val b = portraitBoxes(panel) + assertEquals(panel.name, 8 * panel.density, b.getValue(Slot.VIEW).top, 0.5f) + assertTrue(panel.name, b.getValue(Slot.MENU).bottom < b.getValue(Slot.L4).top) + assertTrue(panel.name, b.getValue(Slot.L4).bottom < b.getValue(Slot.LEFT_OUTER_SHOULDER).top) + assertTrue(panel.name, b.getValue(Slot.LEFT_OUTER_SHOULDER).bottom < b.getValue(Slot.LEFT_SECOND).top) + } + } + + @Test fun shortPanelsKeepTheExistingLayoutEvenWhenPortraitDockIsRequested() { + for ((width, height, density) in listOf(Triple(1920f, 1080f, 2f), Triple(720f, 600f, 2.3f))) { + assertEquals(GamepadGeometry.layout(width, height, density), + GamepadGeometry.layout(width, height, density, portraitDock = true)) + } + } }