diff --git a/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt b/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt index 26ffb499cc..53f152a60b 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt @@ -49,6 +49,16 @@ object GameEnvironment { return withScopeValue(config, scope, NO_STEAM, if (on) "1" else null) } + const val GAME_RESOLUTION = "DROIDDECK_GAME_RESOLUTION" + + fun gameResolution(config: Config, scope: String): GameResolution.Choice? = + if (scope.isEmpty()) null else GameResolution.parse(config.games[scope]?.get(GAME_RESOLUTION)) + + fun withGameResolution(config: Config, scope: String, choice: GameResolution.Choice?): Config { + require(scope.isNotEmpty() && validScope(scope)) + return withScopeValue(config, scope, GAME_RESOLUTION, choice?.let(GameResolution::format)) + } + fun effective(config: Config, preset: String, scope: String, forceSsbs: Boolean = false): Map = defaults(preset, forceSsbs) + config.shared + if (scope.isEmpty()) emptyMap() else config.games[scope].orEmpty() diff --git a/app/src/main/java/com/droiddeck/launcher/core/GameResolution.kt b/app/src/main/java/com/droiddeck/launcher/core/GameResolution.kt new file mode 100644 index 0000000000..0255d9616b --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/core/GameResolution.kt @@ -0,0 +1,70 @@ +package com.droiddeck.launcher.core + +object GameResolution { + sealed interface Choice + data class Fixed(val width: Int, val height: Int) : Choice + data class Scaled(val scale: Float) : Choice + + data class Aspect(val label: String, val sizes: List) + + val aspects = listOf( + Aspect("16:9", listOf(Fixed(960, 540), Fixed(1280, 720), Fixed(1600, 900), Fixed(1920, 1080), Fixed(2560, 1440))), + Aspect("16:10", listOf(Fixed(1280, 800), Fixed(1440, 900), Fixed(1680, 1050), Fixed(1920, 1200), Fixed(2560, 1600))), + Aspect("4:3", listOf(Fixed(640, 480), Fixed(800, 600), Fixed(1024, 768), Fixed(1280, 960), Fixed(1440, 1080))), + ) + + val scales = listOf(1.5f, 2f, 3f) + + const val MIN_WIDTH = 320 + const val MIN_HEIGHT = 240 + const val MAX_SIDE = 7680 + private const val SCALED_PREFIX = "/" + + fun parse(value: String?): Choice? { + val text = value?.trim().orEmpty() + if (text.startsWith(SCALED_PREFIX)) { + return text.removePrefix(SCALED_PREFIX).toFloatOrNull()?.takeIf { it > 1f && it <= 8f }?.let(::Scaled) + } + val parts = text.split('x', 'X', '×').map { it.trim().toIntOrNull() } + if (parts.size != 2) return null + val (w, h) = parts + return if (w != null && h != null && valid(w, h)) Fixed(w and 1.inv(), h and 1.inv()) else null + } + + fun valid(width: Int, height: Int) = width in MIN_WIDTH..MAX_SIDE && height in MIN_HEIGHT..MAX_SIDE + + fun format(choice: Choice): String = when (choice) { + is Fixed -> "${choice.width}x${choice.height}" + is Scaled -> SCALED_PREFIX + formatScale(choice.scale) + } + + fun formatScale(scale: Float): String = + (Math.round(scale * 10) / 10f).let { if (it % 1f == 0f) it.toInt().toString() else it.toString() } + + fun resolve(choice: Choice, output: Pair): Pair = when (choice) { + is Fixed -> choice.width to choice.height + is Scaled -> (Math.round(output.first / choice.scale).coerceAtLeast(MIN_WIDTH) and 1.inv()) to + (Math.round(output.second / choice.scale).coerceAtLeast(MIN_HEIGHT) and 1.inv()) + } + + fun aspectLabel(width: Int, height: Int): String { + if (width <= 0 || height <= 0) return "" + val ratio = width.toFloat() / height + aspects.firstOrNull { a -> + val (w, h) = a.label.split(':').map(String::toFloat) + kotlin.math.abs(ratio - w / h) < 0.02f + }?.let { return it.label } + if (kotlin.math.abs(ratio - 64f / 27f) < 0.04f || kotlin.math.abs(ratio - 21f / 9f) < 0.04f) return "21:9" + val g = gcd(width, height) + return if (width / g <= 32) "${width / g}:${height / g}" else String.format(java.util.Locale.ROOT, "%.2f:1", ratio) + } + + fun sizesFor(aspect: Aspect, panel: Pair): List { + val long = maxOf(panel.first, panel.second) + val short = minOf(panel.first, panel.second) + val fit = aspect.sizes.filter { it.width <= long && it.height <= short } + return fit.ifEmpty { aspect.sizes.take(1) } + } + + private tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b) +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt b/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt index 2a19f39abc..81dc109d67 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt @@ -79,6 +79,13 @@ object GameEnvironmentStore { return config } + @Synchronized + fun setGameResolution(context: Context, scope: String, choice: com.droiddeck.launcher.core.GameResolution.Choice?): GameEnvironment.Config { + val config = GameEnvironment.withGameResolution(read(context), scope, choice) + save(context, config) + return config + } + @Synchronized fun setDefault(context: Context, scope: String, name: String, value: String): Boolean { val config = read(context) diff --git a/app/src/main/java/com/droiddeck/launcher/session/NoSteamLaunch.kt b/app/src/main/java/com/droiddeck/launcher/session/NoSteamLaunch.kt index 8d8070f875..a1f39ae470 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/NoSteamLaunch.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/NoSteamLaunch.kt @@ -30,6 +30,25 @@ object NoSteamLaunch { GameEnvironment.gameNoSteam(GameEnvironmentStore.read(context), (appId and 0xFFFFFFFFL).toString()) }.getOrDefault(false) + fun scopeOf(program: String?, args: List, battleNetTitle: (String) -> String? = { null }): String? = when (program) { + EPIC -> EpicClient.shortcutAppId.toString() + BATTLENET -> args.getOrNull(args.indexOf("launch") + 1)?.takeIf { args.contains("launch") }?.let(battleNetTitle) + ?: com.droiddeck.launcher.runtime.BattleNet.APP_ID.toString() + PROTON_RUN -> args.getOrNull(args.indexOf("--app") + 1)?.takeIf { args.contains("--app") } + else -> null + }?.takeIf { it.isNotEmpty() && GameEnvironment.validScope(it) } + + fun battleNetTitleScope(context: Context, code: String): String? = + AddedGames.scan(context).firstOrNull { game -> + game.source == com.droiddeck.launcher.stores.Store.BATTLENET.id && + game.storeId?.let(com.droiddeck.launcher.runtime.BattleNet::title)?.code == code + }?.let { settingsId(it).toString() } + + fun resolution(config: GameEnvironment.Config, scope: String?, output: Pair): Pair? { + val choice = scope?.let { GameEnvironment.gameResolution(config, it) } ?: return null + return com.droiddeck.launcher.core.GameResolution.resolve(choice, output) + } + fun command(game: Library.SteamGame, added: AddedGames.Game?): Command? = when { game.library == Library.EPIC_LAUNCHER -> Command(EPIC, listOf("run"), game.name) game.library == Library.ADDED && game.source == com.droiddeck.launcher.stores.Store.BATTLENET.id -> diff --git a/app/src/main/java/com/droiddeck/launcher/session/SelectedGameProfile.kt b/app/src/main/java/com/droiddeck/launcher/session/SelectedGameProfile.kt index cdcc617a61..c3df4a97c4 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SelectedGameProfile.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SelectedGameProfile.kt @@ -59,7 +59,7 @@ data class SelectedGameProfile( ) } val otherEnvironment = environment.games[game.profileKey].orEmpty().keys - FexPreset.environmentKeys - - GameEnvironment.NO_STEAM + GameEnvironment.NO_STEAM - GameEnvironment.GAME_RESOLUTION return SelectedGameProfile( appId = selectedAppId, name = game.name, 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 232eaf0c6d..3e7f30b15f 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -588,6 +588,14 @@ class SessionService : Service() { guest.add("BL_WIDTH=" + size.first) guest.add("BL_HEIGHT=" + size.second) + if (noSteamGame()) runCatching { + val scope = NoSteamLaunch.scopeOf(SessionState.program, SessionState.programArgs) { NoSteamLaunch.battleNetTitleScope(this, it) } + NoSteamLaunch.resolution(GameEnvironmentStore.read(this), scope, size) + }.onFailure { Log.w(TAG, "game resolution", it) }.getOrNull()?.let { (w, h) -> + guest.add("BL_GAME_WIDTH=$w") + guest.add("BL_GAME_HEIGHT=$h") + Log.i(TAG, "game resolution: ${w}x$h on a ${size.first}x${size.second} output") + } if (SessionState.followScreen || size.first < size.second || SessionPrefs.orientation(this) == android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER) guest.add("BL_FOLLOW_OUTPUT=1") diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index 0e22804a63..3655ec0959 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -918,12 +918,37 @@ internal fun GameSettingsMenus(host: MenuHost, game: com.droiddeck.launcher.fron val custom = stringResource(R.string.comp_game_fex_custom) val customSync = stringResource(R.string.game_sync_custom) val resetDone = stringResource(R.string.comp_game_reset_done, game.name) + val resKey = "game-settings-res" + val resolution = current?.let { com.droiddeck.launcher.core.GameEnvironment.gameResolution(it, scope) } + val screen = remember { com.droiddeck.launcher.session.SessionDisplay.screenSize(com.droiddeck.launcher.session.SessionDisplay.panelSize(appContext)) } + val matchScreen = stringResource(R.string.display_match_screen, screen.first, screen.second) + val scaledLabels = com.droiddeck.launcher.core.GameResolution.scales.associateWith { + stringResource(R.string.display_follow_screen_scaled, com.droiddeck.launcher.core.GameResolution.formatScale(it)) + } + fun sizeLabel(size: Pair) = "${size.first}×${size.second} · ${com.droiddeck.launcher.core.GameResolution.aspectLabel(size.first, size.second)}" + fun resolutionLabel(choice: com.droiddeck.launcher.core.GameResolution.Choice?): String = when (choice) { + null -> matchScreen + is com.droiddeck.launcher.core.GameResolution.Scaled -> (scaledLabels[choice.scale] + ?: "÷" + com.droiddeck.launcher.core.GameResolution.formatScale(choice.scale)) + + " · " + sizeLabel(com.droiddeck.launcher.core.GameResolution.resolve(choice, screen)) + is com.droiddeck.launcher.core.GameResolution.Fixed -> sizeLabel(choice.width to choice.height) + } + fun pickResolution(choice: com.droiddeck.launcher.core.GameResolution.Choice?) { + host.open = key + save { com.droiddeck.launcher.session.GameEnvironmentStore.setGameResolution(it, scope, choice) } + } + var editResolution by remember(scope) { mutableStateOf(false) } AnchoredMenu(host.open == key, onDismiss = { if (host.open == key) host.open = null }, title = stringResource(R.string.game_settings_menu_title, game.name)) { first -> MenuItem(stringResource(R.string.game_no_steam_title), checked = noSteam, enabled = ready, detail = stringResource(R.string.game_no_steam_detail), focusRequester = first) { val on = !noSteam save { com.droiddeck.launcher.session.GameEnvironmentStore.setGameNoSteam(it, scope, on) } } + if (noSteam) MenuItem( + stringResource(R.string.game_res_title), checked = false, enabled = ready, + detail = resolutionLabel(resolution), + trailing = { Text("›", fontSize = 16.sp, color = colors.onSurfaceVariant) }, + ) { host.open = resKey } if (!launcher) { val chosen = com.droiddeck.launcher.core.FexPreset.all.firstOrNull { it.id == fex } MenuItem( @@ -960,6 +985,45 @@ internal fun GameSettingsMenus(host: MenuHost, game: com.droiddeck.launcher.fron } } } + AnchoredMenu(host.open == resKey, onDismiss = { if (host.open == resKey) host.open = null }, title = stringResource(R.string.game_res_title)) { first -> + MenuItem(matchScreen, checked = resolution == null, enabled = ready, focusRequester = first) { pickResolution(null) } + com.droiddeck.launcher.core.GameResolution.scales.forEach { scale -> + val choice = com.droiddeck.launcher.core.GameResolution.Scaled(scale) + MenuItem(scaledLabels.getValue(scale), checked = resolution == choice, enabled = ready, + detail = sizeLabel(com.droiddeck.launcher.core.GameResolution.resolve(choice, screen))) { pickResolution(choice) } + } + com.droiddeck.launcher.core.GameResolution.aspects.forEach { aspect -> + val sizes = com.droiddeck.launcher.core.GameResolution.sizesFor(aspect, screen) + MenuItem(aspect.label, checked = resolution in aspect.sizes, enabled = ready, + detail = sizes.joinToString(" · ") { "${it.width}×${it.height}" }, + trailing = { Text("›", fontSize = 16.sp, color = colors.onSurfaceVariant) }, + ) { host.open = "$resKey-${aspect.label}" } + } + val fixed = resolution as? com.droiddeck.launcher.core.GameResolution.Fixed + val customValue = fixed?.takeIf { f -> com.droiddeck.launcher.core.GameResolution.aspects.none { f in it.sizes } } + MenuItem( + if (customValue == null) stringResource(R.string.mode_res_custom) else stringResource(R.string.mode_res_custom_value, customValue.width, customValue.height), + checked = customValue != null, enabled = ready, + detail = customValue?.let { com.droiddeck.launcher.core.GameResolution.aspectLabel(it.width, it.height) }, + ) { editResolution = true } + } + com.droiddeck.launcher.core.GameResolution.aspects.forEach { aspect -> + val aspectKey = "$resKey-${aspect.label}" + AnchoredMenu(host.open == aspectKey, onDismiss = { if (host.open == aspectKey) host.open = null }, title = aspect.label) { first -> + com.droiddeck.launcher.core.GameResolution.sizesFor(aspect, screen).forEachIndexed { index, size -> + MenuItem("${size.width}×${size.height}", checked = resolution == size, enabled = ready, + focusRequester = if (index == 0) first else null) { pickResolution(size) } + } + } + } + if (editResolution) CustomResolutionDialog( + (resolution as? com.droiddeck.launcher.core.GameResolution.Fixed)?.let { it.width to it.height }, + onSave = { value -> + editResolution = false + pickResolution(com.droiddeck.launcher.core.GameResolution.Fixed(value.first, value.second)) + }, + onDismiss = { editResolution = false }, + ) AnchoredMenu(host.open == fexKey, onDismiss = { if (host.open == fexKey) host.open = null }, title = stringResource(R.string.fex_preset_title)) { first -> MenuItem(useDefault, checked = fex == null, enabled = ready, detail = stringResource(generalFex.label), focusRequester = first) { host.open = key diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 7c2811030a..36d31630f5 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -488,6 +488,7 @@ تشغيل يبدأ مع Steam يبدأ بدون Steam + دقة اللعبة الإعدادات إعدادات %1$s الافتراضي diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index 078d972636..d9ef13c8b1 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -482,6 +482,7 @@ Activado Se inicia con Steam Se inicia sin Steam + Resolución del juego Ajustes Ajustes de %1$s Predeterminado diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index dc02c0948f..55449ac2f4 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -480,6 +480,7 @@ Включено Стартира със Steam Стартира без Steam + Резолюция на играта Настройки Настройки на %1$s По подразбиране diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 691da1a73c..35282822a5 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -484,6 +484,7 @@ Zapnuto Spouští se se Steamem Spouští se bez Steamu + Rozlišení hry Nastavení Nastavení %1$s Výchozí diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index f1b55c9650..7a5aa072ef 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -480,6 +480,7 @@ Til Starter med Steam Starter uden Steam + Spilopløsning Indstillinger Indstillinger for %1$s Standard diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 7d5ded3548..1d15db3d88 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -480,6 +480,7 @@ An Startet mit Steam Startet ohne Steam + Spielauflösung Einstellungen Einstellungen für %1$s Standard diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index e31df6b602..27692a1325 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -480,6 +480,7 @@ Ενεργό Ξεκινά με το Steam Ξεκινά χωρίς το Steam + Ανάλυση παιχνιδιού Ρυθμίσεις Ρυθμίσεις %1$s Προεπιλογή diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index c4639709ad..adea64b8f4 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -482,6 +482,7 @@ Activado Se inicia con Steam Se inicia sin Steam + Resolución del juego Ajustes Ajustes de %1$s Predeterminado diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 9dcb88f402..481ed7ca5c 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -480,6 +480,7 @@ Päällä Käynnistyy Steamin kanssa Käynnistyy ilman Steamia + Pelin resoluutio Asetukset %1$s – asetukset Oletus diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 412575e608..61accc73a6 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -482,6 +482,7 @@ Activé Démarre avec Steam Démarre sans Steam + Résolution du jeu Paramètres Paramètres de %1$s Par défaut diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index c6042223f0..72f0917b03 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -480,6 +480,7 @@ चालू Steam के साथ शुरू होता है Steam के बिना शुरू होता है + गेम रिज़ॉल्यूशन सेटिंग %1$s सेटिंग डिफ़ॉल्ट diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 4d86e51f7e..409a9e72f8 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -480,6 +480,7 @@ Be Steammel indul Steam nélkül indul + Játék felbontása Beállítások %1$s beállításai Alapértelmezett diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index cecc8289f0..81ded51384 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -478,6 +478,7 @@ Aktif Dimulai dengan Steam Dimulai tanpa Steam + Resolusi game Setelan Setelan %1$s Default diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 58b65563ea..f8f6c7866c 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -482,6 +482,7 @@ Attivo Si avvia con Steam Si avvia senza Steam + Risoluzione del gioco Impostazioni Impostazioni di %1$s Predefinito diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 0cdcc111bd..fe43ef5ee0 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -478,6 +478,7 @@ オン Steam と一緒に起動 Steam なしで起動 + ゲームの解像度 設定 %1$s の設定 デフォルト diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index fc352bcc37..e00a044135 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -478,6 +478,7 @@ 켜짐 Steam과 함께 시작 Steam 없이 시작 + 게임 해상도 설정 %1$s 설정 기본값 diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index 7135bd5457..58caf14b83 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -478,6 +478,7 @@ Hidup Bermula dengan Steam Bermula tanpa Steam + Resolusi permainan Tetapan Tetapan %1$s Lalai diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index f1a5b47fae..f56b734f56 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -480,6 +480,7 @@ På Starter med Steam Starter uten Steam + Spilloppløsning Innstillinger Innstillinger for %1$s Standard diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index eff91dd724..4240b47aee 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -480,6 +480,7 @@ Aan Start met Steam Start zonder Steam + Spelresolutie Instellingen Instellingen voor %1$s Standaard diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 1267e54be9..2c789b65d2 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -484,6 +484,7 @@ Wł. Uruchamia się ze Steam Uruchamia się bez Steam + Rozdzielczość gry Ustawienia Ustawienia: %1$s Domyślne diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 2db4dbb6ec..dde7bf233f 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -482,6 +482,7 @@ Ativado Inicia com o Steam Inicia sem o Steam + Resolução do jogo Definições Definições de %1$s Predefinição diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 643b20e847..1bf1feb07a 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -482,6 +482,7 @@ Ativado Inicia com o Steam Inicia sem o Steam + Resolução do jogo Configurações Configurações de %1$s Padrão diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index 3838347619..a2e10057d6 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -482,6 +482,7 @@ Activat Pornește cu Steam Pornește fără Steam + Rezoluția jocului Setări Setări %1$s Implicit diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 41cbd27d7c..88dbfbc2fd 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -503,6 +503,7 @@ Включено Запускается со Steam Запускается без Steam + Разрешение игры Настройки Настройки %1$s По умолчанию diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 5a6c222004..e0754fe02b 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -480,6 +480,7 @@ På Startar med Steam Startar utan Steam + Spelupplösning Inställningar Inställningar för %1$s Standard diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 1e4d92cbf1..e483bfead0 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -478,6 +478,7 @@ เปิด เริ่มพร้อม Steam เริ่มโดยไม่ใช้ Steam + ความละเอียดของเกม การตั้งค่า การตั้งค่า %1$s ค่าเริ่มต้น diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 906d04d13b..479e767c1b 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -480,6 +480,7 @@ Açık Steam ile başlar Steam olmadan başlar + Oyun çözünürlüğü Ayarlar %1$s Ayarları Varsayılan diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 5767ee73a2..ea4e958377 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -484,6 +484,7 @@ Увімкнено Запускається зі Steam Запускається без Steam + Роздільна здатність гри Налаштування Налаштування %1$s За замовчуванням diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index c21f685321..e6b9a21732 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -478,6 +478,7 @@ Bật Khởi động cùng Steam Khởi động không cần Steam + Độ phân giải trò chơi Thiết lập Thiết lập %1$s Mặc định diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 5e9acd782f..67e815130d 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -478,6 +478,7 @@ 开 随 Steam 启动 不通过 Steam 启动 + 游戏分辨率 设置 %1$s 设置 默认 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 64f8133583..f97f66c3a1 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -478,6 +478,7 @@ 開 隨 Steam 啟動 不經 Steam 啟動 + 遊戲解像度 設定 %1$s 設定 預設 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 30ef0996e5..ee48c655e2 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -478,6 +478,7 @@ 開 隨 Steam 啟動 不經 Steam 啟動 + 遊戲解析度 設定 %1$s 設定 預設 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e4611630b9..f1a5dcf3f3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -528,6 +528,7 @@ On Starts with Steam Starts without Steam + Game resolution Settings %1$s Settings Default diff --git a/app/src/test/java/com/droiddeck/launcher/core/GameResolutionTest.kt b/app/src/test/java/com/droiddeck/launcher/core/GameResolutionTest.kt new file mode 100644 index 0000000000..5a76e0525e --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/core/GameResolutionTest.kt @@ -0,0 +1,60 @@ +package com.droiddeck.launcher.core + +import com.droiddeck.launcher.session.NoSteamLaunch +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Test + +class GameResolutionTest { + @Test + fun choicesRoundTripThroughTheStoredValue() { + for (choice in listOf(GameResolution.Fixed(1280, 720), GameResolution.Scaled(1.5f), GameResolution.Scaled(2f))) { + assertEquals(choice, GameResolution.parse(GameResolution.format(choice))) + } + assertEquals("1280x720", GameResolution.format(GameResolution.Fixed(1280, 720))) + assertEquals("/1.5", GameResolution.format(GameResolution.Scaled(1.5f))) + } + + @Test + fun invalidValuesAreIgnored() { + for (value in listOf(null, "", "abc", "100x100", "1280", "1280x720x2", "/1", "/0.5", "/9")) { + assertNull(value, GameResolution.parse(value)) + } + } + + @Test + fun aScaleDividesTheOutputToEvenSides() { + assertEquals(1706 to 1066, GameResolution.resolve(GameResolution.Scaled(1.5f), 2560 to 1600)) + assertEquals(1280 to 800, GameResolution.resolve(GameResolution.Scaled(2f), 2560 to 1600)) + assertEquals(1280 to 720, GameResolution.resolve(GameResolution.Fixed(1280, 720), 2560 to 1600)) + } + + @Test + fun aspectRatiosAreNamed() { + assertEquals("16:9", GameResolution.aspectLabel(1920, 1080)) + assertEquals("16:10", GameResolution.aspectLabel(2560, 1600)) + assertEquals("4:3", GameResolution.aspectLabel(1024, 768)) + assertEquals("21:9", GameResolution.aspectLabel(2560, 1080)) + assertEquals("20:9", GameResolution.aspectLabel(2400, 1080)) + } + + @Test + fun presetsLargerThanThePanelAreLeftOut() { + val wide = GameResolution.aspects.first { it.label == "16:9" } + assertEquals(listOf(960 to 540, 1280 to 720, 1600 to 900, 1920 to 1080), + GameResolution.sizesFor(wide, 1920 to 1200).map { it.width to it.height }) + } + + @Test + fun theSessionFindsTheResolutionOfTheGameItStarts() { + val config = GameEnvironment.withGameResolution(GameEnvironment.Config(), "570", GameResolution.Fixed(1280, 800)) + val scope = NoSteamLaunch.scopeOf(NoSteamLaunch.PROTON_RUN, listOf("--app", "570")) + assertEquals("570", scope) + assertEquals(1280 to 800, NoSteamLaunch.resolution(config, scope, 2560 to 1600)) + assertNull(NoSteamLaunch.resolution(config, "440", 2560 to 1600)) + assertEquals("123", NoSteamLaunch.scopeOf(NoSteamLaunch.BATTLENET, listOf("launch", "WTCG")) { if (it == "WTCG") "123" else null }) + assertEquals(com.droiddeck.launcher.runtime.BattleNet.APP_ID.toString(), + NoSteamLaunch.scopeOf(NoSteamLaunch.BATTLENET, listOf("launch", "Pro"))) + assertNull(GameEnvironment.withGameResolution(config, "570", null).games["570"]) + } +} diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 8bb519db52..fbea003241 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -511,6 +511,12 @@ if [ -z "${BL_INSIDE:-}" ]; then echo "== gamescope: games at ${nested}x${nested_h} stretched to the ${width}x${height} output" fi fi + if [ "$mode" = run ] && [ "${BL_GAME_WIDTH:-0}" -gt 0 ] && [ "${BL_GAME_HEIGHT:-0}" -gt 0 ]; then + nested=$BL_GAME_WIDTH + nested_h=$BL_GAME_HEIGHT + game_size=1 + echo "== gamescope: the game runs at ${nested}x${nested_h}, scaled to the ${width}x${height} output with its proportions kept" + fi backend=${BL_GAMESCOPE_BACKEND:-wayland} case "$backend" in wayland) ;; @@ -528,7 +534,7 @@ if [ -z "${BL_INSIDE:-}" ]; then echo "== gamescope: composites every frame (Mali bridge: the Steam UI flickers on separate planes)" fi args=(--backend "$backend" --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$nested_h") - if [ "$nested" != "$width" ] || [ "$nested_h" != "$height" ]; then + if [ "${game_size:-0}" != 1 ] && { [ "$nested" != "$width" ] || [ "$nested_h" != "$height" ]; }; then args+=(-S stretch) export BL_STRETCHED=1 fi diff --git a/tools/tests/test_game_resolution.py b/tools/tests/test_game_resolution.py new file mode 100644 index 0000000000..78c5fb3d98 --- /dev/null +++ b/tools/tests/test_game_resolution.py @@ -0,0 +1,53 @@ +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + + +SESSION = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-session' + + +class GameResolutionTest(unittest.TestCase): + def launch(self, mode, **overrides): + source = SESSION.read_text() + start = source.index(' width=${BL_WIDTH:-1280}') + end = source.index('\nfi\n\nbl_displays()', start) + block = source[start:end].replace('/usr/local/bin/droiddeck-pipewire', 'pipewire_stub') + with tempfile.TemporaryDirectory() as directory: + env = dict(os.environ, XDG_RUNTIME_DIR=directory, BL_REFRESH='60', BL_MANGOAPP='0', + BL_WIDTH='2560', BL_HEIGHT='1600') + for name in ('BL_GAME_WIDTH', 'BL_GAME_HEIGHT', 'BL_FOLLOW_OUTPUT', 'BL_GAMESCOPE_STRETCH_16X9'): + env.pop(name, None) + env.update(overrides) + fake = Path(directory) / 'gamescope' + fake.write_text('#!/bin/bash\nprintf "ARG:%s\\n" "$@"\n') + fake.chmod(0o755) + env['PATH'] = directory + os.pathsep + env['PATH'] + script = f''' +set -u +mode={mode} +pipewire_stub() {{ return 1; }} +run_gamescope() {{ printf 'ARG:%s\n' "$@"; }} +''' + block + result = subprocess.run(['bash', '-c', script], env=env, capture_output=True, text=True, timeout=5) + self.assertEqual(0, result.returncode, result.stderr) + return [line.removeprefix('ARG:') for line in result.stdout.splitlines() if line.startswith('ARG:')] + + def test_a_game_started_without_steam_runs_at_its_resolution_with_proportions_kept(self): + args = self.launch('run', BL_GAME_WIDTH='1280', BL_GAME_HEIGHT='720') + self.assertEqual(['2560', '1600'], [args[args.index('-W') + 1], args[args.index('-H') + 1]]) + self.assertEqual(['1280', '720'], [args[args.index('-w') + 1], args[args.index('-h') + 1]]) + self.assertNotIn('-S', args) + + def test_without_a_game_resolution_the_game_matches_the_output(self): + args = self.launch('run') + self.assertEqual(['2560', '1600'], [args[args.index('-w') + 1], args[args.index('-h') + 1]]) + + def test_steam_ignores_the_game_resolution(self): + args = self.launch('steam', BL_GAME_WIDTH='1280', BL_GAME_HEIGHT='720') + self.assertEqual(['2560', '1600'], [args[args.index('-w') + 1], args[args.index('-h') + 1]]) + + +if __name__ == '__main__': + unittest.main()