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

@@ -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() {
@@ -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))
@@ -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()
}
@@ -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))
}
}
}