From d3b0b8e51c2aa1a0d952a9128b678f153e84dfb5 Mon Sep 17 00:00:00 2001 From: asdf17128 Date: Thu, 15 Oct 2026 19:01:01 +0800 Subject: [PATCH] Add top, bottom, and centered picture positions for Steam sessions (#871) --- app/src/main/cpp/waylandcomp/src/compositor.c | 14 ++++ app/src/main/cpp/waylandcomp/src/vk_present.c | 24 +++++- app/src/main/cpp/waylandcomp/src/vk_present.h | 3 +- .../cpp/waylandcomp/src/waylandcomp_jni.c | 12 ++- .../com/droiddeck/launcher/MainActivity.kt | 4 + .../com/droiddeck/launcher/SessionActivity.kt | 34 +++++++++ .../launcher/session/SessionPrefs.kt | 9 +++ .../launcher/session/SettingsReset.kt | 2 +- .../launcher/ui/ModeSettingsDialog.kt | 9 +++ .../launcher/wayland/WaylandCompositor.java | 2 + app/src/main/res/values-zh-rCN/strings.xml | 4 + app/src/main/res/values-zh-rHK/strings.xml | 4 + app/src/main/res/values-zh-rTW/strings.xml | 4 + app/src/main/res/values/strings.xml | 4 + docs/development/steam-display-scaling.md | 8 ++ tools/tests/test_picture_position_mapping.py | 74 +++++++++++++++++++ 16 files changed, 207 insertions(+), 4 deletions(-) create mode 100644 tools/tests/test_picture_position_mapping.py diff --git a/app/src/main/cpp/waylandcomp/src/compositor.c b/app/src/main/cpp/waylandcomp/src/compositor.c index 3b218ee86f..bff3f3959d 100644 --- a/app/src/main/cpp/waylandcomp/src/compositor.c +++ b/app/src/main/cpp/waylandcomp/src/compositor.c @@ -2933,12 +2933,26 @@ static int on_input_readable(int fd, uint32_t mask, void *data) { case 6: pointer_delta(m.p1 / 256.0, m.p2 / 256.0); break; case 7: deliver_touch(&m); break; case 8: output_resized(); break; + case 9: + vk_present_set_scale_mode(m.p1, m.p2); + schedule_render(); + break; default: deliver_pointer(&m); break; } } return 0; } +void droiddeck_wayland_set_scale_mode(int mode, int alignment) { + if (g_input_pipe[1] < 0) { + vk_present_set_scale_mode(mode, alignment); + return; + } + struct input_msg m = { 9, mode, alignment, 0, 0 }; + ssize_t n = write(g_input_pipe[1], &m, sizeof(m)); + (void)n; +} + void droiddeck_wayland_send_pointer(int action, int x, int y) { if (g_input_pipe[1] < 0) return; struct input_msg m = { 0, action, x, y, 0 }; diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.c b/app/src/main/cpp/waylandcomp/src/vk_present.c index 29db4f0001..832521468f 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.c +++ b/app/src/main/cpp/waylandcomp/src/vk_present.c @@ -130,6 +130,9 @@ static struct { int rx, ry, rw, rh; int valid; } g_map; +static pthread_mutex_t g_game_picture_lock = PTHREAD_MUTEX_INITIALIZER; +static float g_game_picture_rect[4]; +static int g_game_picture_top; static int64_t g_swap_retry_at_ns; static int g_swap_fail_logged; @@ -244,7 +247,7 @@ int vkp_device_lost(void) { return g_dev_state == -2; } void vk_present_set_scale_mode(int mode, int alignment) { if (mode < VKP_MODE_OFF || mode > VKP_MODE_INTEGER) mode = VKP_MODE_FIT; - if (alignment < VKP_ALIGN_CENTER || alignment > VKP_ALIGN_BOTTOM) alignment = VKP_ALIGN_CENTER; + if (alignment < VKP_ALIGN_CENTER || alignment > VKP_ALIGN_PICTURE_BOTTOM) alignment = VKP_ALIGN_CENTER; g_mode = mode; g_align = alignment; } @@ -263,6 +266,8 @@ static const char *align_name(int a) { switch (a) { case VKP_ALIGN_TOP: return "top"; case VKP_ALIGN_BOTTOM: return "bottom"; + case VKP_ALIGN_PICTURE_TOP: return "picture top"; + case VKP_ALIGN_PICTURE_BOTTOM: return "picture bottom"; default: return "center"; } } @@ -298,13 +303,30 @@ static void update_map(int scene_w, int scene_h) { g_map.off_x = (float)(g_map.rx + (int)((g_map.rw - scene_w * aspect) * 0.5f)); g_map.off_y = (float)(g_map.ry + (int)((g_map.rh - scene_h * aspect) * 0.5f)); } + if (align == VKP_ALIGN_PICTURE_TOP) g_map.off_y = 0; + else if (align == VKP_ALIGN_PICTURE_BOTTOM) g_map.off_y = H - scene_h * g_map.ky; g_map.valid = 1; + pthread_mutex_lock(&g_game_picture_lock); + g_game_picture_top = align == VKP_ALIGN_PICTURE_TOP || align == VKP_ALIGN_PICTURE_BOTTOM; + g_game_picture_rect[0] = g_map.off_x; + g_game_picture_rect[1] = g_map.off_y; + g_game_picture_rect[2] = g_map.off_x + scene_w * g_map.kx; + g_game_picture_rect[3] = g_map.off_y + scene_h * g_map.ky; + pthread_mutex_unlock(&g_game_picture_lock); droiddeck_log("screen", "%s, %s: %dx%d scene shown %dx%d at %d,%d on the %dx%d output", mode_name(mode), align_name(align), scene_w, scene_h, (int)(scene_w * g_map.kx + 0.5f), (int)(scene_h * g_map.ky + 0.5f), (int)g_map.off_x, (int)g_map.off_y, W, H); } +int vkp_game_picture_rect(float rect[4]) { + pthread_mutex_lock(&g_game_picture_lock); + int active = g_game_picture_top; + if (active) memcpy(rect, g_game_picture_rect, sizeof(g_game_picture_rect)); + pthread_mutex_unlock(&g_game_picture_lock); + return active; +} + int vkp_output_to_scene(double ox, double oy, double *sx, double *sy) { if (!g_map.valid || g_map.kx <= 0 || g_map.ky <= 0) return 0; *sx = (ox - g_map.off_x) / g_map.kx; diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.h b/app/src/main/cpp/waylandcomp/src/vk_present.h index 5b050d4798..18a976e213 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.h +++ b/app/src/main/cpp/waylandcomp/src/vk_present.h @@ -10,8 +10,9 @@ int vkp_apply_window_request(void); enum vkp_scale_mode { VKP_MODE_OFF = 0, VKP_MODE_FIT = 1, VKP_MODE_STRETCH = 2, VKP_MODE_FILL = 3, VKP_MODE_INTEGER = 4 }; -enum vkp_align { VKP_ALIGN_CENTER = 0, VKP_ALIGN_TOP = 1, VKP_ALIGN_BOTTOM = 2 }; +enum vkp_align { VKP_ALIGN_CENTER = 0, VKP_ALIGN_TOP = 1, VKP_ALIGN_BOTTOM = 2, VKP_ALIGN_PICTURE_TOP = 3, VKP_ALIGN_PICTURE_BOTTOM = 4 }; void vk_present_set_scale_mode(int mode, int alignment); +int vkp_game_picture_rect(float rect[4]); int vkp_output_to_scene(double ox, double oy, double *sx, double *sy); void vkp_output_size(int *w, int *h); diff --git a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c index b1125ce385..207c52cd5d 100644 --- a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c +++ b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c @@ -18,6 +18,7 @@ #include "droiddeck_color.h" extern int droiddeck_wayland_run(void); +extern void droiddeck_wayland_set_scale_mode(int mode, int alignment); extern void droiddeck_wayland_send_pointer(int action, int x, int y); extern void droiddeck_wayland_send_touch(int action, int pointer_id, int x, int y); extern int droiddeck_cursor_snapshot(int *out, int cap); @@ -354,11 +355,20 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeResizeOutput(JNIEnv JNIEXPORT void JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetScaleMode(JNIEnv *env, jclass clazz, jint mode, jint alignment) { - vk_present_set_scale_mode(mode, alignment); + droiddeck_wayland_set_scale_mode(mode, alignment); __android_log_print(ANDROID_LOG_INFO, TAG, "scale mode %d alignment %d", mode, alignment); } +JNIEXPORT jboolean JNICALL +Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeGamePictureRect(JNIEnv *env, jclass clazz, jfloatArray out) { + if (!out || (*env)->GetArrayLength(env, out) < 4) return JNI_FALSE; + float rect[4]; + if (!vkp_game_picture_rect(rect)) return JNI_FALSE; + (*env)->SetFloatArrayRegion(env, out, 0, 4, rect); + return JNI_TRUE; +} + JNIEXPORT void JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetUpscaler(JNIEnv *env, jclass clazz, jint mode) { vkp_effects_set_scaling(mode); diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index d72953db8f..cf563015b0 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -150,6 +150,7 @@ class MainActivity : ComponentActivity() { private var phantomProcessStatus by mutableStateOf(PhantomProcessStatus.NOT_APPLICABLE) private var showPhantomGate by mutableStateOf(false) private var directAudio by mutableStateOf(false) + private var picturePosition by mutableStateOf("center") private var stretch16x9 by mutableStateOf(false) private var orientation by mutableStateOf(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) private var launcherFullscreen by mutableStateOf(true) @@ -1246,6 +1247,7 @@ class MainActivity : ComponentActivity() { oscMode = if (mode == SessionService.MODE_STEAM) oscMode else null, backActionsInverted = backActionsInverted, directAudio = if (mode == SessionService.MODE_STEAM) directAudio else null, + picturePosition = if (mode == SessionService.MODE_STEAM) picturePosition else null, stretch16x9 = if (mode == SessionService.MODE_STEAM) stretch16x9 else null, mic = if (mode == SessionService.MODE_STEAM) mic else null, gameStorage = if (mode == SessionService.MODE_STEAM) gameStorage else null, @@ -1306,6 +1308,7 @@ class MainActivity : ComponentActivity() { backActionsInverted = inverted }, onDirectAudio = { on -> SessionPrefs.setDirectAudio(this, on); directAudio = on }, + onPicturePosition = { value -> SessionPrefs.setPicturePosition(this, value); picturePosition = value }, onStretch16x9 = { on -> SessionPrefs.setStretch16x9(this, on); stretch16x9 = on }, onMic = { on -> SessionPrefs.setMicEnabled(this, on) @@ -1465,6 +1468,7 @@ class MainActivity : ComponentActivity() { oscMode = SessionPrefs.oscMode(this) backActionsInverted = SessionPrefs.backActionsInverted(this) directAudio = SessionPrefs.directAudio(this) + picturePosition = SessionPrefs.picturePosition(this) stretch16x9 = SessionPrefs.stretch16x9(this) mic = SessionPrefs.micEnabled(this) refreshWifiDiscovery() diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 0c921c80cf..bdd3fc1319 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -120,6 +120,19 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private var pipUi by mutableStateOf(false) private var pipAutoEnter by mutableStateOf(false) private var unfoldedControls by mutableStateOf(false) + private var picturePosition by mutableStateOf("center") + + private fun applyGameAlignment() { + if (!CompositorHost.isStarted) return + val active = SessionState.mode == SessionService.MODE_STEAM && + !pipUi && !isInPictureInPictureMode && !cardboard.enabled + val alignment = if (!active) ALIGN_CENTER else when (picturePosition) { + "top" -> ALIGN_PICTURE_TOP + "bottom" -> ALIGN_PICTURE_BOTTOM + else -> ALIGN_CENTER + } + WaylandCompositor.nativeSetScaleMode(SCALE_FIT, alignment) + } private var unfoldedPanel: com.droiddeck.launcher.ui.DeckControlsPanel? = null private lateinit var sessionRoot: FrameLayout private val guestKeysDown = mutableSetOf() @@ -463,6 +476,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { defaultFocusHighlightEnabled = false setContent { androidx.compose.runtime.LaunchedEffect(drawerOpen, pcKeyboardOpen, achievementsOpen, pipUi) { updatePointerCapture() } + androidx.compose.runtime.LaunchedEffect(picturePosition, SessionState.running, pipUi, cardboard.enabled) { applyGameAlignment() } DroidDeckTheme { if (pipUi) { if (SessionState.suspended) androidx.compose.foundation.layout.Box( @@ -1056,6 +1070,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private fun readPrefs() { pipAutoEnter = SessionPrefs.pipAutoEnter(this) unfoldedControls = SessionPrefs.unfoldedControls(this) + picturePosition = SessionPrefs.picturePosition(this) hudOn = SessionPrefs.hudEnabled(this) upscaler = SessionPrefs.upscaler(this) upscaleSharpness = SessionPrefs.upscaleSharpness(this) @@ -1291,6 +1306,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { ) } applyFrameGen() + applyGameAlignment() } private var surfaceW = 0 @@ -1960,9 +1976,15 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { else -> SessionState.mode != SessionService.MODE_STEAM || SessionState.steamUi == "desktop" } + private val gamePictureBounds = FloatArray(4) + private var topPictureMapped = false + private fun drawnRect(): android.graphics.RectF? { val width = surfaceView.width.takeIf { it > 0 } ?: return null val height = surfaceView.height.takeIf { it > 0 } ?: return null + topPictureMapped = CompositorHost.isStarted && WaylandCompositor.nativeGamePictureRect(gamePictureBounds) + if (topPictureMapped) return android.graphics.RectF( + gamePictureBounds[0], gamePictureBounds[1], gamePictureBounds[2], gamePictureBounds[3]) val out = SessionState.outputSize val scale = minOf(width / out.first.toFloat(), height / out.second.toFloat()) val drawnW = out.first * scale @@ -1972,6 +1994,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { return android.graphics.RectF(left, top, left + drawnW, top + drawnH) } + private var ignoreGameTouch = false + override fun onTouchEvent(event: MotionEvent): Boolean { if (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE)) return onMouse(event) if (routedTouchMode == SessionPrefs.TOUCH_OFF) return true @@ -1985,6 +2009,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { return touchpad.onTouch(event) } val rect = drawnRect() ?: return false + if (event.actionMasked == MotionEvent.ACTION_DOWN) + ignoreGameTouch = topPictureMapped && !rect.contains(event.x, event.y) + if (ignoreGameTouch) { + if (event.actionMasked == MotionEvent.ACTION_DOWN) + WaylandCompositor.nativeSendTouch(3, -1, 0, 0) + if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) ignoreGameTouch = false + return true + } fun sendTouch(action: Int, index: Int) { val x = event.getX(index).coerceIn(rect.left, rect.right) val y = event.getY(index).coerceIn(rect.top, rect.bottom) @@ -2533,6 +2565,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private const val DRAWER_REPEAT_ACCELERATION_MS = 1_400L private const val SCALE_FIT = 1 private const val ALIGN_CENTER = 0 + private const val ALIGN_PICTURE_TOP = 3 + private const val ALIGN_PICTURE_BOTTOM = 4 private val RUNTIME_LINES = PackageLines( R.string.session_runtime_downloading, R.string.session_runtime_downloading_mb, R.string.session_runtime_checking, R.string.session_runtime_unpacking, 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 9ed3ec8189..1afb4fcfcd 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -195,6 +195,15 @@ object SessionPrefs { } + fun picturePosition(context: Context): String = + prefs(context).getString("picturePosition", "center") + ?.takeIf { it in listOf("top", "bottom", "center") } ?: "center" + + fun setPicturePosition(context: Context, position: String) { + prefs(context).edit().putString("picturePosition", + position.takeIf { it in listOf("top", "bottom", "center") } ?: "center").apply() + } + fun stretch16x9(context: Context): Boolean = prefs(context).getBoolean("stretch16x9", false) fun setStretch16x9(context: Context, on: Boolean) { diff --git a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt index 1d4e6aec14..a819bca215 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt @@ -13,7 +13,7 @@ object SettingsReset { "orientation", "launcherFullscreen", "animations", "theme", "runSteamAtStartup", "addedGamesArt", "gameStoresEnabled", "gameStoresSpeedTier", "gameStoresParallel", "storesOpenTab", "storesShowMature", "hud", "hudDeck", "backActionsInverted", "touch", "osc", "shape", "steamController", - "gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "stretch16x9", + "gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "stretch16x9", "picturePosition", "gpuDriverMode", "androidDriver", "linuxDriver", "linuxDriver.steam", "linuxDriver.desktop", "tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus", 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 35c7a17651..89471658ef 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt @@ -77,6 +77,7 @@ class ModeSettings( val fexPreset: String? = null, val forceSsbs: Boolean = false, val syncBackend: String? = null, + val picturePosition: String? = null, val stretch16x9: Boolean? = null, val steamRepairQueued: Boolean = false, val mangoapp: Boolean = true, @@ -120,6 +121,7 @@ class ModeSettingsActions( val onFexPreset: (String) -> Unit = {}, val onForceSsbs: (Boolean) -> Unit = {}, val onSyncBackend: (String) -> Unit = {}, + val onPicturePosition: (String) -> Unit = {}, val onStretch16x9: (Boolean) -> Unit = {}, val onSteamRepair: () -> Unit = {}, val onMangoapp: (Boolean) -> Unit = {}, @@ -167,6 +169,13 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras: val displaySize = com.droiddeck.launcher.session.SessionDisplay.resolveChoice(s.panelSize, s.resolution) SettingsGroup(stringResource(R.string.display_session)) { ResolutionRow(host, s.resolution, s.panelSize, a.onResolution) + s.picturePosition?.let { position -> + ChoiceRow(host, "picture-position", stringResource(R.string.display_picture_position), null, + listOf("top" to stringResource(R.string.display_position_top), + "bottom" to stringResource(R.string.display_position_bottom), + "center" to stringResource(R.string.display_position_center)), + position, onPick = a.onPicturePosition) + } if (s.stretch16x9 != null && (com.droiddeck.launcher.session.SessionDisplay.canStretch16x9(s.panelSize) || com.droiddeck.launcher.session.SessionDisplay.canStretch16x9(displaySize))) { val canStretch = com.droiddeck.launcher.session.SessionDisplay.canStretch16x9(displaySize) diff --git a/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java b/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java index 97cfcf3c44..85f9464c1e 100644 --- a/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java +++ b/app/src/main/java/com/droiddeck/launcher/wayland/WaylandCompositor.java @@ -197,6 +197,8 @@ public final class WaylandCompositor { public static native void nativeSetOutputSize(int width, int height); + public static native boolean nativeGamePictureRect(float[] out); + public static native void nativeResizeOutput(int width, int height); public static native void nativeResetFirstFrame(); diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 13767c0d44..ab860a284d 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -2215,4 +2215,8 @@ 下载组件 下载内容与“组件”页面共享。在上方选择已下载的版本,即可在下次启动游戏时使用。 选择要下载的版本 + 画面位置 + 置顶 + 置底 + 居中(默认) diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 52bc387fd3..824c20e182 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -2215,4 +2215,8 @@ 下載元件 下載內容與「元件」頁面共用。在上方選擇已下載的版本,即可在下次啟動遊戲時使用。 選擇要下載的版本 + 畫面位置 + 置頂 + 置底 + 置中(預設) diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 07687eac42..cb3ded0de0 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -2215,4 +2215,8 @@ 下載元件 下載內容與「元件」頁面共用。在上方選擇已下載的版本,即可在下次啟動遊戲時使用。 選擇要下載的版本 + 畫面位置 + 置頂 + 置底 + 置中(預設) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 883bc0c339..8a79cbc1d1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2260,4 +2260,8 @@ Couldn\'t reach GOG Could not read your GOG library Registering with Steam… + Picture position + Top + Bottom + Center (default) diff --git a/docs/development/steam-display-scaling.md b/docs/development/steam-display-scaling.md index 299f4b188b..9551de73a1 100644 --- a/docs/development/steam-display-scaling.md +++ b/docs/development/steam-display-scaling.md @@ -228,3 +228,11 @@ flag for an experiment. Device check (Thor): Alan Wake's American Nightmare with its 1280x720 Game Resolution runs on `:1` at 1280x720 with no `--force-windows-fullscreen` in the session, 2 frame-size changes, no crash in logcat. The Games tab and the drawer render without the switch. + +## Steam picture position + +The launcher's Execute Steam settings, under Display, offer Picture position: Top, Bottom, Center (default). The selection applies to the entire Steam session, including menus and games, and is loaded again on resume. No focus-based switching or in-game toggle is used. PiP and VR retain their own presentation. + +Positioning keeps the selected resolution, fit scale, aspect ratio and full surface intact. It distributes outer letterboxing above or below the picture; it does not crop game-authored black bars inside the surface. A surface that already fills the panel has no vertical space to move. Use a 16:9 resolution for fixed-16:9 games when a separate controls area is desired. + +The compositor publishes actual bounds for touch mapping and ignores touches starting outside the picture. The mapping harness covers top, bottom and center across tall, 16:9 and wide surfaces, including inverse input mapping and legacy half-screen mode compatibility. diff --git a/tools/tests/test_picture_position_mapping.py b/tools/tests/test_picture_position_mapping.py new file mode 100644 index 0000000000..597fec9384 --- /dev/null +++ b/tools/tests/test_picture_position_mapping.py @@ -0,0 +1,74 @@ +"""Test the renderer's actual map and inverse map without a Vulkan device.""" +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + +REPO = Path(__file__).resolve().parents[2] + + +class GameTopMappingTest(unittest.TestCase): + def test_letterbox_alignment_and_touch_inverse(self): + cc = shutil.which(os.environ.get('CC', 'cc')) + if not cc: + self.skipTest('A host C compiler is required') + source = (REPO / 'app/src/main/cpp/waylandcomp/src/vk_present.c').read_text() + header = (REPO / 'app/src/main/cpp/waylandcomp/src/vk_present.h').read_text() + enums = header[header.index('enum vkp_scale_mode'):header.index('void vk_present_set_scale_mode')] + state = source[source.index('static volatile int g_mode'):source.index('static int64_t g_swap_retry_at_ns')] + def function(signature): + start = source.index(signature) + return source[start:source.index('\n}\n', start) + 3] + funcs = '\n'.join(function(name) for name in ['static const char *mode_name(', + 'static const char *align_name(', 'static void update_map(', 'int vkp_output_to_scene(', 'int vkp_game_picture_rect(']) + with tempfile.TemporaryDirectory() as tmp: + tmp = Path(tmp) + code = '#include \n#include \n#include \n#include \n#include \n' + code += '#define droiddeck_log(...) ((void)0)\nstatic struct { unsigned width, height; } g_extent;\n' + code += enums + state + funcs + code += r''' +static void near(double a, double b) { assert(fabs(a - b) < 0.01); } +static void check(int sw, int sh, int ow, int oh, int alignment) { + g_extent.width = ow; g_extent.height = oh; + g_mode = VKP_MODE_FIT; g_align = alignment; + update_map(sw, sh); + float rect[4]; + assert(vkp_game_picture_rect(rect)); + double top = alignment == VKP_ALIGN_PICTURE_TOP ? 0 : oh - sh * g_map.ky; + near(rect[0], g_map.off_x); near(rect[1], top); + near(rect[2], g_map.off_x + sw * g_map.kx); + near(rect[3], top + sh * g_map.ky); + near(g_map.off_y, top); + double sx, sy; + assert(vkp_output_to_scene(g_map.off_x + sw * g_map.kx / 2, + top + sh * g_map.ky / 2, &sx, &sy)); + near(sx, sw / 2.0); near(sy, sh / 2.0); + near(g_map.kx, g_map.ky); + assert(sh * g_map.ky <= oh + 0.01); + g_align = VKP_ALIGN_CENTER; update_map(sw, sh); + assert(!vkp_game_picture_rect(rect)); + near(g_map.off_y, (int)((oh - sh * g_map.ky) * 0.5)); +} +int main(void) { + for (int alignment = VKP_ALIGN_PICTURE_TOP; alignment <= VKP_ALIGN_PICTURE_BOTTOM; alignment++) { + check(1240, 1100, 2480, 2200, alignment); + check(1280, 720, 2480, 2200, alignment); + check(1024, 768, 2480, 2200, alignment); + check(1920, 1080, 2400, 1080, alignment); + check(1240, 1100, 2480, 1394, alignment); + } + g_align = VKP_ALIGN_TOP; update_map(1280, 720); + assert(g_map.rh == 697 && g_map.ry == 0); + puts("PASS"); +} +''' + (tmp / 'map.c').write_text(code) + subprocess.run([cc, '-std=c11', str(tmp / 'map.c'), '-lm', '-o', str(tmp / 'map')], check=True, capture_output=True, text=True) + result = subprocess.run([str(tmp / 'map')], capture_output=True, text=True) + self.assertEqual(result.returncode, 0, result.stderr) + + +if __name__ == '__main__': + unittest.main()