feat(session): split the display resolution into landscape and portrait (#2990)

## Summary

Splits the session resolution setting into two: **Landscape resolution**
and **Portrait resolution**. Each has the same options as the old
Resolution row, plus a Follow option so one orientation can mirror the
other.

## Why

A single resolution has to serve both orientations. Presets and Match
screen flip automatically in portrait, but a custom size is used exactly
as typed, so a landscape size in a portrait session is wrong. Users who
play in both orientations couldn't pick a good size for each.

## Behavior

- The Display tab shows **Landscape resolution** and, underneath it,
**Portrait resolution**. Both offer the full existing list: presets,
Match screen, Follow screen, scaled follow options and Custom.
- Each row has an extra option at the top. **Follow portrait** (on the
landscape row) and **Follow landscape** (on the portrait row) use the
other orientation's choice, so someone can set one resolution and let
the other mirror it. The label shows the size it resolves to.
- A session picks the landscape or portrait choice from its orientation.
This uses the same orientation check as the output size, so the
unfolded-controls layout still counts as landscape.
- Custom WxH sizes are flipped to match the target orientation when
followed, e.g. portrait following 1280x720 uses 720x1280.
- If both rows would follow each other, the other row is set to the
concrete size it currently resolves to, so there is never a loop and
nothing visibly changes.
- The glasses output keeps using the landscape resolution.
- Applies to the Steam and Desktop Display tabs, which share the same
row.

## Compatibility

- The existing saved choice (`displayResolution.<mode>`) is now the
landscape resolution, so existing users keep their setting.
- The portrait choice is stored as `displayResolution.portrait.<mode>`
and defaults to Follow landscape, so portrait sessions behave as before
until it is changed. The settings reset covers it through the existing
`displayResolution.` prefix.
- One visible difference: a typed landscape custom size, used as typed
in portrait before, now flips to portrait while portrait follows
landscape.

## Known limitation

"Follow screen" is still decided once when the session starts, not on
every rotation. Re-evaluating it on rotation could make the window
orientation flip repeatedly when no orientation is pinned.

## Changes

- `SessionDisplay`: `LINK_LANDSCAPE` / `LINK_PORTRAIT`, `isLink`,
`orientCustom`, `effectiveChoice`
- `SessionPrefs`: `resolutionStored` (raw value per orientation),
`resolutionChoice(..., portrait)`, `setResolutionChoice(..., portrait)`
with the loop guard, `resolutionChosen(..., portrait)`
- `SessionActivity`: `portraitOutput()` drives the output size,
follow-screen choice and follow scale; the Match-screen default for
programs that draw at the panel size checks the matching orientation
- `ResolutionRow`, `ModeSettingsDialog`, `FrontEndActivity`: two rows,
the Follow option, state and actions
- `DeviceReport`: logs landscape and portrait separately
- Strings: `display_resolution_landscape`,
`display_resolution_portrait`, `display_follow_landscape`,
`display_follow_portrait` in all 33 locales; the unused
`display_resolution` is removed
- Tests: `PortraitResolutionTest`

## Testing

- Unit tests added for the preference logic, follow resolution, loop
guard and reset.
This commit is contained in:
FX1922 authored and GitHub committed 2026-11-22 08:03:03 +03:00
commit aefa5a3c0d
42 files changed
+388 -103

No files matched your search

@@ -12,6 +12,9 @@ object SessionDisplay {
const val FOLLOW_SCALE_MAX = 8f
private const val FOLLOW_SCALED_PREFIX = "follow/"
const val LINK_LANDSCAPE = "link/landscape"
const val LINK_PORTRAIT = "link/portrait"
const val DEFAULT_RESOLUTION = "720p"
private val PRESET_HEIGHTS = listOf(720, 900, 1080)
@@ -35,6 +38,23 @@ object SessionDisplay {
else -> null
}
fun isLink(choice: String): Boolean = choice == LINK_LANDSCAPE || choice == LINK_PORTRAIT
fun orientCustom(choice: String, portrait: Boolean): String {
val parts = choice.split('x').map { it.toIntOrNull() }
if (parts.size != 2 || parts.any { it == null || it <= 0 }) return choice
val width = parts[0]!!
val height = parts[1]!!
return if ((portrait && width > height) || (!portrait && height > width)) "${height}x$width" else choice
}
fun effectiveChoice(landscape: String, portrait: String, forPortrait: Boolean): String {
val own = if (forPortrait) portrait else landscape
if (!isLink(own)) return own
val other = if (forPortrait) landscape else portrait
return if (isLink(other)) DEFAULT_RESOLUTION else orientCustom(other, forPortrait)
}
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())
@@ -69,8 +89,12 @@ object SessionDisplay {
const val UNFOLDED_MIN_DP = 600
fun unfoldedGameHeight(width: Int, height: Int, tabRow: Int = 0): Int =
(minOf(width * 9 / 16, (height * UNFOLDED_MAX_GAME_SHARE).toInt()) - tabRow.coerceAtLeast(0)).coerceAtLeast(0) and 1.inv()
fun unfoldedGameHeight(width: Int, height: Int, tabRow: Int = 0, aspect: Float = 0f): Int {
val row = tabRow.coerceAtLeast(0)
val cap = (height * UNFOLDED_MAX_GAME_SHARE).toInt()
if (aspect > 0f && aspect < 16f / 9f) return minOf((width / aspect).toInt(), cap - row).coerceAtLeast(0) and 1.inv()
return (minOf(width * 9 / 16, cap) - row).coerceAtLeast(0) and 1.inv()
}
fun unfoldedControlsWanted(
enabled: Boolean,
@@ -1314,14 +1314,31 @@ object SessionPrefs {
private fun resolutionCap(context: Context, mode: String): Int = prefs(context).getInt("resolutionCap.$mode", 720)
fun resolutionChosen(context: Context, mode: String): Boolean =
fun resolutionChosen(context: Context, mode: String, portrait: Boolean = false): Boolean =
prefs(context).contains("displayResolution.$mode") ||
prefs(context).contains("resolutionCap.$mode") || customResolution(context, mode) != null
prefs(context).contains("resolutionCap.$mode") || customResolution(context, mode) != null ||
(portrait && prefs(context).contains("displayResolution.portrait.$mode"))
fun resolutionChoice(context: Context, mode: String, panel: Pair<Int, Int>): String {
fun resolutionChoice(context: Context, mode: String, panel: Pair<Int, Int>, portrait: Boolean = false): String =
SessionDisplay.effectiveChoice(
resolutionStored(context, mode, panel, false), resolutionStored(context, mode, panel, true), portrait)
fun resolutionStored(context: Context, mode: String, panel: Pair<Int, Int>, portrait: Boolean): String {
if (!portrait) return landscapeResolutionStored(context, mode, panel)
val value = prefs(context).getString("displayResolution.portrait.$mode", null) ?: return SessionDisplay.LINK_LANDSCAPE
if (value == SessionDisplay.LINK_LANDSCAPE || value == SessionDisplay.MATCH_SCREEN || SessionDisplay.isFollow(value) ||
SessionDisplay.presetHeight(value) != null) return value
return parseOrientedResolution(value)?.let { "${it.first}x${it.second}" } ?: SessionDisplay.LINK_LANDSCAPE
}
fun parseOrientedResolution(text: String): Pair<Int, Int>? =
parseResolution(text) ?: text.trim().split('x', 'X', '×', '*').takeIf { it.size == 2 }
?.let { parseResolution("${it[1]}x${it[0]}") }?.let { it.second to it.first }
private fun landscapeResolutionStored(context: Context, mode: String, panel: Pair<Int, Int>): String {
val saved = prefs(context)
saved.getString("displayResolution.$mode", null)?.let { value ->
if (value == SessionDisplay.MATCH_SCREEN || SessionDisplay.isFollow(value) ||
if (value == SessionDisplay.MATCH_SCREEN || value == SessionDisplay.LINK_PORTRAIT || SessionDisplay.isFollow(value) ||
SessionDisplay.presetHeight(value) != null) return value
parseResolution(value)?.let { return "${it.first}x${it.second}" }
}
@@ -1333,13 +1350,22 @@ object SessionPrefs {
else "${legacy.first}x${legacy.second}"
}
fun setResolutionChoice(context: Context, mode: String, choice: String) {
val value = if (choice == SessionDisplay.MATCH_SCREEN || SessionDisplay.isFollow(choice) ||
fun setResolutionChoice(context: Context, mode: String, choice: String, portrait: Boolean = false) {
val link = if (portrait) SessionDisplay.LINK_LANDSCAPE else SessionDisplay.LINK_PORTRAIT
val value = if (choice == link || choice == SessionDisplay.MATCH_SCREEN || SessionDisplay.isFollow(choice) ||
SessionDisplay.presetHeight(choice) != null) choice else {
val size = requireNotNull(parseResolution(choice)) { "Invalid resolution" }
val size = requireNotNull(if (portrait) parseOrientedResolution(choice) else parseResolution(choice)) { "Invalid resolution" }
"${size.first}x${size.second}"
}
prefs(context).edit().putString("displayResolution.$mode", value).apply()
val panel = SessionDisplay.panelSize(context)
val landscapeStored = resolutionStored(context, mode, panel, false)
val portraitStored = resolutionStored(context, mode, panel, true)
val edit = prefs(context).edit()
if (value == link && SessionDisplay.isLink(if (portrait) landscapeStored else portraitStored)) {
val concrete = SessionDisplay.effectiveChoice(landscapeStored, portraitStored, !portrait)
edit.putString(if (portrait) "displayResolution.$mode" else "displayResolution.portrait.$mode", concrete)
}
edit.putString(if (portrait) "displayResolution.portrait.$mode" else "displayResolution.$mode", value).apply()
}
fun fexPreset(context: Context): String = prefs(context).getString("fexPreset", DEFAULT_FEX_PRESET) ?: DEFAULT_FEX_PRESET
@@ -1978,7 +2004,7 @@ object SessionPrefs {
fun displayMode(context: Context, mode: String, program: String?): String =
if (mode == SessionService.MODE_RUN && com.droiddeck.launcher.runtime.UserApps.launches(program) &&
resolutionChosen(context, SessionService.MODE_DESKTOP)) SessionService.MODE_DESKTOP
(resolutionChosen(context, SessionService.MODE_DESKTOP) || resolutionChosen(context, SessionService.MODE_DESKTOP, true))) SessionService.MODE_DESKTOP
else prefMode(mode)
fun pipAutoEnter(context: Context): Boolean = prefs(context).getBoolean("pipAutoEnter", true)