feat(session): add portrait sessions and controls below the game (#1612)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-26 12:01:44 -04:00
1 parent d65912f0c5
commit eaaecf0661
16 files changed
+359 -91

No files matched your search

@@ -17,12 +17,13 @@ object SessionDisplay {
fun screenSize(panel: Pair<Int, Int>): Pair<Int, Int> =
(maxOf(panel.first, panel.second) and 1.inv()) to (minOf(panel.first, panel.second) and 1.inv())
fun resolveChoice(panel: Pair<Int, Int>, choice: String): Pair<Int, Int> {
if (choice == MATCH_SCREEN || choice == FOLLOW_SCREEN) return screenSize(panel)
presetHeight(choice)?.let { return resolve(panel, it, SessionPrefs.SHAPE_AUTO) }
fun resolveChoice(panel: Pair<Int, Int>, choice: String, portrait: Boolean = false): Pair<Int, Int> {
fun orient(size: Pair<Int, Int>) = 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<Int, Int>): List<String> {
@@ -31,8 +32,10 @@ object SessionDisplay {
.filter { resolveChoice(panel, it) != screenSize(panel) } + MATCH_SCREEN + FOLLOW_SCREEN
}
fun followSize(width: Int, height: Int): Pair<Int, Int>? =
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<Int, Int>? =
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<Int, Int> {
@@ -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()
}
@@ -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")