diff --git a/app/src/main/java/com/droiddeck/launcher/session/SteamQam.kt b/app/src/main/java/com/droiddeck/launcher/session/SteamQam.kt index 578f1c5cb4..c50fc9fff3 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SteamQam.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SteamQam.kt @@ -10,9 +10,20 @@ import java.io.File // browser view placed outside the Big Picture window, composition capped at "notification" so gamescope keeps the game // focused, and gamepad focus on the main UI. The hold is a lease the app renews, so Steam recovers if the app goes away. object SteamQam { - data class Target(val port: Int, val path: String) + /** [mainPath] is Steam's main menu page, shown beside the quick access menu in the split layout. */ + data class Target(val port: Int, val path: String, val mainPath: String? = null) + const val MAIN_MENU = 1 const val QUICK_ACCESS = 2 + + /** Height in CSS pixels both menus are laid out at in the split layout, so they show at one scale. */ + const val SPLIT_CSS_HEIGHT = 480 + + /** Steam's own width for the main menu; quick access takes the rest of the panel. */ + const val MAIN_CSS_WIDTH = 240 + + private const val MAIN_PARKED_CSS = + ".BasicUI > .Panel { transform: none !important; width: 100% !important; height: 100% !important; margin: 0 !important; }" const val LEASE_MS = 5_000 private const val TAG = "SteamQam" private const val EVAL_MS = 6_000L @@ -26,21 +37,54 @@ object SteamQam { * Takes or renews the lease for [owner], or releases it. A live lease held by a newer panel is never taken back by an * older one, so a late request from a panel being torn down cannot end its replacement's lease or change its layout. */ - internal fun leaseScript(on: Boolean, owner: Long, aspect: Float = 0f): String = + internal fun leaseScript(on: Boolean, owner: Long, aspect: Float = 0f, split: Boolean = false): String = if (on) "if (!(g.__ddQamUntil > Date.now()) || !(g.__ddQamOwner > $owner)) { g.__ddQamOwner = $owner; g.__ddQamUntil = Date.now() + $LEASE_MS;" + - (if (aspect > 0f) " g.__ddQamAspect = $aspect;" else "") + " }" + (if (aspect > 0f) " g.__ddQamAspect = $aspect;" else "") + " g.__ddQamSplit = $split; }" else "if (g.__ddQamOwner === $owner) g.__ddQamUntil = 0;" - /** [aspect] is the panel's width over height: the menu is laid out at that shape so every tab shows at one scale. */ - internal fun script(on: Boolean, aspect: Float = 0f, owner: Long = 0): String = """(() => { - const g = globalThis, QAM = 2; + /** + * [aspect] is the panel's width over height: the menu is laid out at that shape so every tab shows at one scale. With + * [split], Steam's main menu is kept rendered at its own width beside the quick access menu, which gets the rest. + */ + internal fun script(on: Boolean, aspect: Float = 0f, owner: Long = 0, split: Boolean = false): String = """(() => { + const g = globalThis, QAM = 2, MAIN = 1; const W = SteamUIStore.WindowStore.SteamUIWindows[0]; const m = W.MenuStore, c = W.m_CompositionStateStore; const nav = W.m_FocusNavContext; const popup = g_PopupManager.GetExistingPopup("SP BPM_uid0"); const held = () => g.__ddQamUntil > Date.now(); - const ours = () => held() && m.m_eOpenSideMenu === QAM && !g.__ddQamTop; + const split = () => held() && g.__ddQamSplit === true; + // Steam's views carry no names: the main menu's is the one Steam focuses while the main menu is open. Until Steam + // has shown it, the main menu is opened once with its view parked like the quick access menu's. + const probing = () => g.__ddMainProbe > Date.now(); + const ours = () => held() && !g.__ddQamTop && (m.m_eOpenSideMenu === QAM || (probing() && m.m_eOpenSideMenu === MAIN)); const width = (h) => g.__ddQamAspect > 0 ? Math.round(h * g.__ddQamAspect) : 0; + const parkX = () => popup.m_popup.innerWidth + 64; + const mainSize = () => [$MAIN_CSS_WIDTH, $SPLIT_CSS_HEIGHT]; + const qamSplitSize = () => [Math.max(Math.round($SPLIT_CSS_HEIGHT * (g.__ddQamAspect > 0 ? g.__ddQamAspect : 1)) - $MAIN_CSS_WIDTH, 320), $SPLIT_CSS_HEIGHT]; + const size = (w, h) => split() ? qamSplitSize() : [width(h) || w, h]; + const mainView = () => views().find(v => v.__ddMain); + // Only the quick access view is parked: the one Steam focuses while quick access is open. Before Steam has + // focused it, any view but the main menu's and the header's web page (Store and other pages) may be it. + const headerView = () => W.m_HeaderStore?.m_currentBrowserAndBackstack?.m_browserView; + const isQam = (v) => !v.__ddMain && v !== headerView() && + (!!v.__ddQamView || !views().some(o => o.__ddQamView) || (probing() && m.m_eOpenSideMenu === MAIN)); + const mainParked = () => split() && (m.m_eOpenSideMenu !== MAIN || probing()); + const mainDoc = () => { + for (const s of SteamUIStore.m_GamepadNavigationManager?.m_rgGamepadInputSources || []) { + try { const d = s.m_targetWindow?.document; if (d?.title?.startsWith("MainMenu")) return d; } catch (e) {} + } + return null; + }; + // Steam slides the main menu out whenever it is not the open side menu; parked, it stays in place and fills its view. + const mainStyle = (on) => { + const d = mainDoc(); + let s = d?.getElementById("dd-main-split"); + if (!on) { s?.remove(); return; } + if (!d?.head) return; + if (!s) { s = d.createElement("style"); s.id = "dd-main-split"; d.head.appendChild(s); } + if (s.textContent !== "$MAIN_PARKED_CSS") s.textContent = "$MAIN_PARKED_CSS"; + }; if (!c.__ddQam) { c.__ddQam = c.ComputeOverallMinimumRequestedComposition; m.__ddQam = m.OnMenuDeactivated; @@ -59,6 +103,18 @@ object SteamQam { return without >= 2 ? v : 1; }; } + // Steam frosts its Store page while a side menu is open; a parked menu is not over it. + const inst = m.m_Instance; + if (inst?.SetStoreBrowserGlass && !inst.__ddQamGlass) { + inst.__ddQamGlass = inst.SetStoreBrowserGlass; + inst.SetStoreBrowserGlass = function (e) { return inst.__ddQamGlass.call(this, ours() ? 0 : e); }; + } + const glass = () => { + const on = !ours() && m.m_eOpenSideMenu !== 0; + if (g.__ddQamGlassOn === on) return; + g.__ddQamGlassOn = on; + inst?.SetStoreBrowserGlass?.(m.m_eOpenSideMenu); + }; const views = () => popup?.m_rgChildBrowserViews || []; const backdrop = (hide) => { const doc = popup?.m_popup?.document; @@ -75,16 +131,61 @@ object SteamQam { }; const keep = () => { for (const v of views()) { - if (v.__ddQam) continue; - v.__ddQam = v.SetBounds; + if (!v.__ddQam) v.__ddQam = v.SetBounds; + if (v.__ddQamW === 4) continue; + v.__ddQamW = 4; + v.__ddQamVis = v.__ddQamVis || v.SetVisible; + v.__ddQamFocus = v.__ddQamFocus || v.SetFocus; v.SetBounds = function (x, y, w, h, ...r) { + if (v.__ddMain && mainParked()) { + if (w > 0) v.__ddMainAsked = [x, y, w, h]; + [w, h] = mainSize(); + v.__ddMainOn = true; v.__ddMainW = w; v.__ddMainH = h; + return v.__ddQam.call(this, parkX(), 0, w, h, ...r); + } + if (v.__ddMain && w > 0) mainStyle(false); v.__ddAsked = [x, y, w, h]; - if (w > 0 && ours()) { x = popup.m_popup.innerWidth + 64; w = width(h) || w; } + if (w > 0 && ours() && isQam(v)) { x = parkX(); [w, h] = size(w, h); } v.__ddAt = x; v.__ddW = w; + v.__ddH = h; return v.__ddQam.call(this, x, y, w, h, ...r); }; + v.SetVisible = function (on, ...r) { + return v.__ddQamVis.call(this, on || (!!v.__ddMain && mainParked()), ...r); + }; + v.SetFocus = function (on, ...r) { + if (on && m.m_eOpenSideMenu === MAIN && v !== headerView()) { + for (const o of views()) if (o !== v) delete o.__ddMain; + v.__ddMain = true; + delete v.__ddQamView; + } + if (on && m.m_eOpenSideMenu === QAM && !v.__ddMain && v !== headerView()) { + for (const o of views()) if (o !== v) delete o.__ddQamView; + v.__ddQamView = true; + } + return v.__ddQamFocus.call(this, on, ...r); + }; } + if (g.__ddMainProbe && !probing()) { g.__ddMainProbe = 0; g.__ddMainProbed = true; } + if (probing() && mainView()) { g.__ddMainProbe = 0; g.__ddMainProbed = true; } + const mv = mainView(); + if (mv && !probing()) { + if (mainParked()) { + const [w, h] = mainSize(); + if (!mv.__ddMainOn || mv.__ddMainW !== w || mv.__ddMainH !== h) { + mv.__ddQam.call(mv, parkX(), 0, w, h); + mv.__ddQamVis.call(mv, true); + mv.__ddMainOn = true; mv.__ddMainW = w; mv.__ddMainH = h; + } + } else if (mv.__ddMainOn) { + mv.__ddMainOn = false; + if (m.m_eOpenSideMenu !== MAIN) { mv.__ddQamVis.call(mv, false); mv.__ddQam.call(mv, 0, 0, 0, 0); } + else if (mv.__ddMainAsked) mv.__ddQam.call(mv, ...mv.__ddMainAsked); + } + } + mainStyle(!!mv && mainParked() && !probing()); + glass(); if (!held()) { const parked = !g.__ddQamTop; g.__ddQamTop = false; @@ -124,6 +225,20 @@ object SteamQam { } g.__ddQamTop = false; } + if (split() && !mv) { + if (probing()) return; + if ((g.__ddMainProbes || 0) < 3 && m.m_eOpenSideMenu !== MAIN) { + g.__ddMainProbes = (g.__ddMainProbes || 0) + 1; + g.__ddMainProbe = Date.now() + 1500; + m.OpenMainMenu(); + c.EnsureCorrectComposition?.(); + return; + } + } + if (g.__ddMainProbed) { + g.__ddMainProbed = false; + if (m.m_eOpenSideMenu === MAIN) m.OpenQuickAccessMenu(g.__ddQamTab ?? undefined); + } const decky = !!g.DeckyPluginLoader?.tabsHook?.qamBrowserViewPatch; // Decky hooks the menu after Steam starts; the menu has to unmount for its tab to appear, so reopen on the next tick. if (m.m_eOpenSideMenu === QAM && decky && !g.__ddQamDecky) { g.__ddQamDecky = true; m.CloseSideMenus(); return; } @@ -136,18 +251,26 @@ object SteamQam { if (m.m_eQuickAccessTab != null) g.__ddQamTab = m.m_eQuickAccessTab; if (!g.__ddQamOn) { g.__ddQamOn = true; c.EnsureCorrectComposition?.(); } for (const v of views()) { + if (v.__ddMain) continue; + if (!isQam(v)) { + // A view parked before the quick access view was known goes back where Steam asked for it. + const a = v.__ddAsked; + if (a?.[2] > 0 && v.__ddAt >= popup.m_popup.innerWidth) { v.__ddQam.call(v, ...a); v.__ddAt = a[0]; v.__ddW = a[2]; v.__ddH = a[3]; } + continue; + } if (!v.__ddAsked) { const b = v.GetBounds?.(); - if (b && b.width > 0) { v.__ddAsked = [b.x, b.y, b.width, b.height]; v.__ddAt = b.x; v.__ddW = b.width; } + if (b && b.width > 0) { v.__ddAsked = [b.x, b.y, b.width, b.height]; v.__ddAt = b.x; v.__ddW = b.width; v.__ddH = b.height; } } const a = v.__ddAsked; - if (a?.[2] > 0 && (v.__ddAt < popup.m_popup.innerWidth || (width(a[3]) && v.__ddW !== width(a[3])))) v.SetBounds(...a); + const [w, h] = a?.[2] > 0 ? size(a[2], a[3]) : [0, 0]; + if (a?.[2] > 0 && (v.__ddAt < popup.m_popup.innerWidth || v.__ddW !== w || v.__ddH !== h)) v.SetBounds(...a); } const main = nav?.m_rgGamepadNavigationTrees?.find(t => t.m_ID === "GamepadUI_Full_Root"); - if (main && nav.m_LastActiveNavTree?.m_ID?.startsWith("QuickAccess")) nav.SetActiveNavTree(main); + if (main && /^(QuickAccess|MainMenu)/.test(nav.m_LastActiveNavTree?.m_ID ?? "")) nav.SetActiveNavTree(main); backdrop(true); }; - ${leaseScript(on, owner, aspect)} + ${leaseScript(on, owner, aspect, split)} keep(); if (held() && !g.__ddQamTimer) { g.__ddQamTimer = setInterval(() => { @@ -161,7 +284,8 @@ object SteamQam { /** [open] is Steam's open side menu; [top] is true while the menu is shown on the top screen. */ data class Hold(val open: Int, val top: Boolean) - fun hold(context: Context, aspect: Float, owner: Long): Hold? = eval(context, script(true, aspect, owner))?.let(::parseHold) + fun hold(context: Context, aspect: Float, owner: Long, split: Boolean = false): Hold? = + eval(context, script(true, aspect, owner, split))?.let(::parseHold) internal fun parseHold(text: String): Hold? = runCatching { val a = JSONArray(text) @@ -181,7 +305,9 @@ object SteamQam { fun target(context: Context): Target? = runCatching { val devtools = File(AgentGuest.dir(context), "cdp-port").readText().trim().toInt() val (relay, secret) = parseRelay(helper(context, "start", devtools.toString())) ?: return null - val found = runCatching { parseTarget(relay, get(relay, "/$secret/json"))?.let { it.copy(path = "/$secret${it.path}") } } + val found = runCatching { + parseTarget(relay, get(relay, "/$secret/json"))?.let { t -> t.copy(path = "/$secret${t.path}", mainPath = t.mainPath?.let { "/$secret$it" }) } + } if (found.getOrNull() == null) helper(context, "stop", relay.toString()) found.getOrThrow() }.onFailure { android.util.Log.e(TAG, "no quick access target: $it") }.getOrNull() @@ -232,14 +358,16 @@ object SteamQam { internal fun parseTarget(port: Int, json: String): Target? { val list = JSONArray(json) - for (i in 0 until list.length()) { - val t = list.optJSONObject(i) ?: continue - if (!t.optString("title").startsWith("QuickAccess")) continue - val ws = t.optString("webSocketDebuggerUrl") - val path = Regex("^ws://[^/]+(/devtools/page/[A-Za-z0-9-]+)$").find(ws)?.groupValues?.get(1) ?: continue - return Target(port, path) + fun page(prefix: String): String? { + for (i in 0 until list.length()) { + val t = list.optJSONObject(i) ?: continue + if (!t.optString("title").startsWith(prefix)) continue + val ws = t.optString("webSocketDebuggerUrl") + Regex("^ws://[^/]+(/devtools/page/[A-Za-z0-9-]+)$").find(ws)?.groupValues?.get(1)?.let { return it } + } + return null } - return null + return page("QuickAccess")?.let { Target(port, it, page("MainMenu")) } } private fun eval(context: Context, expression: String): String? = runCatching { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BottomSteamQamPanel.kt b/app/src/main/java/com/droiddeck/launcher/ui/BottomSteamQamPanel.kt index d2630fa7b7..2b5de80b8f 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomSteamQamPanel.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomSteamQamPanel.kt @@ -8,11 +8,14 @@ import androidx.compose.foundation.Canvas import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.AlignHorizontalCenter import androidx.compose.material.icons.outlined.AlignHorizontalLeft import androidx.compose.material.icons.outlined.AlignHorizontalRight +import androidx.compose.material.icons.outlined.VerticalSplit import androidx.compose.material.icons.outlined.WidthFull import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -72,7 +75,8 @@ internal enum class QamFit(val id: String, @StringRes val label: Int, val icon: FULL("full", R.string.bottom_qam_layout_full, Icons.Outlined.WidthFull, 0), LEFT("left", R.string.bottom_qam_layout_left, Icons.Outlined.AlignHorizontalLeft, -1), CENTER("center", R.string.bottom_qam_layout_center, Icons.Outlined.AlignHorizontalCenter, 0), - RIGHT("right", R.string.bottom_qam_layout_right, Icons.Outlined.AlignHorizontalRight, 1); + RIGHT("right", R.string.bottom_qam_layout_right, Icons.Outlined.AlignHorizontalRight, 1), + SPLIT("split", R.string.bottom_qam_layout_split, Icons.Outlined.VerticalSplit, 0); val next: QamFit get() = entries[(ordinal + 1) % entries.size] @@ -117,17 +121,89 @@ private const val TICK_MS = 1_000L private const val FAST_TICK_MS = 150L private const val MAX_RETRY_MS = 4_000L -/** The last frame shown, so returning to the panel shows the menu at once while the live stream reconnects. */ +/** One of Steam's menu pages streamed to the panel; the last frame is kept so returning to the panel shows it at once. */ +internal class MenuStream { + @Volatile var page: CdpPage? = null + val live = java.util.concurrent.atomic.AtomicBoolean(false) + val image = mutableStateOf(null) + val shape = mutableStateOf(null) + + fun show(frame: ImageBitmap) { + image.value = frame + live.set(true) + } + + /** Connects to [path] and starts its screencast; false when the page cannot be reached. */ + fun connect(port: Int, path: String): Boolean { + page?.close() + live.set(false) + val p = runCatching { + CdpPage(port, path) { method, params -> + if (method == "Page.screencastFrame") { + page?.send("Page.screencastFrameAck", JSONObject().put("sessionId", params.optInt("sessionId"))) + decodeFrame(params.optString("data"))?.let(::show) + } + } + }.onFailure { android.util.Log.w("SteamQam", "devtools connect: $it") }.getOrNull() ?: return false + page = p + p.send("Page.enable") + val started = p.call("Page.startScreencast", JSONObject().put("format", "jpeg").put("quality", 85) + .put("maxWidth", 1920).put("maxHeight", 1440)) + if (started == null || started.has("error") || !started.has("result")) { + p.close() + page = null + return false + } + return true + } + + /** Runs [script], which returns the page's [width, height, pixel ratio, content right], and refreshes a still page. */ + fun refresh(script: String) { + val p = page ?: return + // The screencast sends frames only when the menu repaints, so a still menu needs one screenshot. + if (!live.get()) { + p.call("Page.captureScreenshot", JSONObject().put("format", "jpeg").put("quality", 85)) + ?.optJSONObject("result")?.optString("data")?.let(::decodeFrame)?.let(::show) + } + (p.evaluate(script) as? String)?.let { text -> + runCatching { + val a = JSONArray(text) + val layout = FloatArray(4) { a.getDouble(it).toFloat() } + if (!layout.contentEquals(shape.value)) shape.value = layout + } + } + } + + /** Stops the stream and runs [restore] on the page, which outlives this connection. */ + fun stop(restore: String) { + val p = page ?: return + page = null + runCatching { p.send("Page.stopScreencast") } + runCatching { p.evaluate(restore) } + p.close() + } + + fun frame(): QamFrame? { + val img = image.value + val l = shape.value + return if (img != null && l != null && l[0] > 0f) QamFrame(img, l[0], l[1], l[3].coerceIn(l[0] * 0.25f, l[0])) else null + } +} + +/** Steam's main menu beside the quick access menu; Steam's side of the hold keeps it in place and filling its view. */ +internal object MainMenuLayout { + const val CONTENT_SCRIPT = "JSON.stringify([innerWidth, innerHeight, devicePixelRatio, innerWidth])" +} + +/** Panel streams kept across visits to the panel. */ private object QamCache { - @Volatile var image: ImageBitmap? = null - @Volatile var shape: FloatArray? = null + val qam = MenuStream() + val main = MenuStream() } @Composable internal fun SteamQamPanel() { val context = LocalContext.current.applicationContext - var image by remember { mutableStateOf(QamCache.image) } - var shape by remember { mutableStateOf(QamCache.shape) } var failed by remember { mutableStateOf(false) } var slow by remember { mutableStateOf(false) } LaunchedEffect(Unit) { @@ -135,78 +211,56 @@ internal fun SteamQamPanel() { slow = true } val fit = QamFit.current(context) - val holder = remember { arrayOfNulls(1) } + val qam = QamCache.qam + val mainMenu = QamCache.main val owner = remember { SteamQam.newOwner() } val relay = remember { intArrayOf(0) } - val live = remember { java.util.concurrent.atomic.AtomicBoolean(false) } + val mainPath = remember { arrayOfNulls(1) } val aspect = remember { floatArrayOf(0f) } val measure = Modifier.fillMaxSize().onSizeChanged { if (it.height > 0) aspect[0] = it.width.toFloat() / it.height } - val show = { frame: ImageBitmap -> image = frame; QamCache.image = frame; live.set(true) } LaunchedEffect(Unit) { withContext(Dispatchers.IO) { var misses = 0 + fun split() = QamFit.current(context) == QamFit.SPLIT // The lease is renewed on its own, so slow discovery or a retry backoff never lets the held menu lapse. val renew = launch { while (isActive) { - if (SessionState.phase == SessionPhase.READY && aspect[0] > 0f) SteamQam.hold(context, aspect[0], owner) + if (SessionState.phase == SessionPhase.READY && aspect[0] > 0f) SteamQam.hold(context, aspect[0], owner, split()) delay(TICK_MS) } } try { while (isActive) { // Holding the menu before Steam's first frame keeps gamescope from presenting it. - if (SessionState.phase != SessionPhase.READY) { + if (SessionState.phase != SessionPhase.READY || aspect[0] == 0f) { delay(FAST_TICK_MS) continue } - if (aspect[0] == 0f) { - delay(FAST_TICK_MS) - continue - } - val held = SteamQam.hold(context, aspect[0], owner) + val split = split() + val held = SteamQam.hold(context, aspect[0], owner, split) ensureActive() var reached = held != null if (held?.open == SteamQam.QUICK_ACCESS) { - var page = holder[0] - if (page == null || page.closed) { - page?.close() - live.set(false) - page = SteamQam.target(context)?.let { t -> + if (qam.page?.closed != false) { + val t = SteamQam.target(context) + if (t != null) { if (relay[0] != 0 && relay[0] != t.port) SteamQam.stopRelay(context, relay[0]) relay[0] = t.port - runCatching { - CdpPage(t.port, t.path) { method, params -> - if (method == "Page.screencastFrame") { - holder[0]?.send("Page.screencastFrameAck", JSONObject().put("sessionId", params.optInt("sessionId"))) - decodeFrame(params.optString("data"))?.let(show) - } - } - }.onFailure { android.util.Log.w("SteamQam", "devtools connect: $it") }.getOrNull() + mainPath[0] = t.mainPath + qam.connect(t.port, t.path) + mainMenu.stop(MainMenuLayout.CONTENT_SCRIPT) } - holder[0] = page ensureActive() - page?.send("Page.enable") - val started = page?.call("Page.startScreencast", JSONObject().put("format", "jpeg").put("quality", 85) - .put("maxWidth", 1920).put("maxHeight", 1440)) - if (page != null && (started == null || started.has("error") || !started.has("result"))) { - page.close() - page = null - holder[0] = null - } } - // The screencast sends frames only when the menu repaints, so a still menu needs one screenshot. - if (!live.get()) { - page?.call("Page.captureScreenshot", JSONObject().put("format", "jpeg").put("quality", 85)) - ?.optJSONObject("result")?.optString("data")?.let(::decodeFrame)?.let(show) - } - reached = page != null - val wide = !held.top && QamFit.current(context) == QamFit.FULL - (page?.evaluate(QamLayout.contentScript(wide)) as? String)?.let { text -> - runCatching { - val a = JSONArray(text) - val layout = floatArrayOf(a.getDouble(0).toFloat(), a.getDouble(1).toFloat(), a.getDouble(2).toFloat(), a.getDouble(3).toFloat()) - if (!layout.contentEquals(shape)) { shape = layout; QamCache.shape = layout } - } + reached = qam.page != null + val wide = !held.top && (QamFit.current(context) == QamFit.FULL || split) + qam.refresh(QamLayout.contentScript(wide)) + val path = mainPath[0] + if (split && path != null) { + if (mainMenu.page?.closed != false) mainMenu.connect(relay[0], path) + mainMenu.refresh(MainMenuLayout.CONTENT_SCRIPT) + } else if (!split) { + mainMenu.stop(MainMenuLayout.CONTENT_SCRIPT) } } failed = !reached @@ -214,7 +268,7 @@ internal fun SteamQamPanel() { misses = if (reached) 0 else misses + 1 val wait = when { !reached -> minOf(TICK_MS shl minOf(misses - 1, 2), MAX_RETRY_MS) - live.get() -> TICK_MS + qam.live.get() && (!split || mainMenu.live.get()) -> TICK_MS else -> FAST_TICK_MS } val used = QamFit.current(context) @@ -225,35 +279,46 @@ internal fun SteamQamPanel() { } finally { withContext(NonCancellable) { renew.cancelAndJoin() - val page = holder[0] - holder[0] = null - runCatching { page?.send("Page.stopScreencast") } - // The page outlives this connection, so the widened layout would otherwise stay on the top screen. - runCatching { page?.evaluate(QamLayout.contentScript(wide = false)) } - page?.close() + // The pages outlive these connections, so the widened layouts would otherwise stay on the top screen. + qam.stop(QamLayout.contentScript(wide = false)) + mainMenu.stop(MainMenuLayout.CONTENT_SCRIPT) SteamQam.release(context, relay[0], owner) } } } } - val img = image - val l = shape - val f = remember(img, l) { - if (img != null && l != null && l[0] > 0f) QamFrame(img, l[0], l[1], l[3].coerceIn(l[0] * 0.25f, l[0])) else null - } - if (f == null) { + val qamFrame = qam.frame() + if (qamFrame == null) { Box(measure) { if (slow) PanelNote(stringResource(if (failed) R.string.bottom_qam_unavailable else R.string.achievements_reading)) } return } - BoxWithConstraints(measure.background(f.fill)) { + if (fit != QamFit.SPLIT) { + MenuCanvas(qamFrame, fit.align, measure) { qam.page } + return + } + // Each side is as wide as its menu at the shared scale, so neither is shrunk nor padded with empty space. + val mainFrame = mainMenu.frame() + val mainWidth = mainFrame?.cssWidth ?: SteamQam.MAIN_CSS_WIDTH.toFloat() + Row(measure) { + val left = Modifier.weight(mainWidth).fillMaxHeight() + if (mainFrame != null) MenuCanvas(mainFrame, -1, left) { mainMenu.page } + else Box(left.background(qamFrame.fill)) + MenuCanvas(qamFrame, -1, Modifier.weight(qamFrame.cssWidth).fillMaxHeight()) { qam.page } + } +} + +/** Draws [f] scaled into the box, placed by [align], and forwards touches on it to [page]. */ +@Composable +private fun MenuCanvas(f: QamFrame, align: Int, modifier: Modifier, page: () -> CdpPage?) { + BoxWithConstraints(modifier.background(f.fill)) { val density = LocalDensity.current val boxW = with(density) { maxWidth.toPx() } val boxH = with(density) { maxHeight.toPx() } - val (scale, left) = QamLayout.fit(boxW, boxH, f.contentRight, f.cssHeight, fit.align) + val (scale, left) = QamLayout.fit(boxW, boxH, f.contentRight, f.cssHeight, align) Canvas( - Modifier.fillMaxSize().pointerInput(f.cssWidth, f.contentRight, boxW, boxH, fit) { + Modifier.fillMaxSize().pointerInput(f.cssWidth, f.contentRight, boxW, boxH, align) { var touching = false var target: CdpPage? = null try { @@ -268,7 +333,7 @@ internal fun SteamQamPanel() { PointerEventType.Release -> "touchEnd" else -> null }?.takeIf { it == "touchStart" || touching } ?: continue - if (type == "touchStart") target = holder[0] + if (type == "touchStart") target = page() touching = type != "touchEnd" val points = if (type == "touchEnd") JSONArray() else JSONArray().put(JSONObject().put("x", x.toDouble()).put("y", y.toDouble())) diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 022f589826..a6e775b724 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -2236,6 +2236,7 @@ يسار وسط يمين + مقسّم قائمة الوصول السريع في Steam غير متاحة بعد. إحصاءات داخل اللعبة مؤشرات الشاشة السفلية 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 33a0f918e1..8736030aef 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -2231,6 +2231,7 @@ Izquierda Centro Derecha + Dividido El menú de acceso rápido de Steam aún no está disponible. Estadísticas del juego HUD de la pantalla inferior diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 8cf8a2002a..f31d5d345d 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -2136,6 +2136,7 @@ Вляво В центъра Вдясно + Разделено Менюто за бърз достъп на Steam още не е налично. Статистика в играта HUD на долния екран diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 60b90ae035..a6dc786834 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -2186,6 +2186,7 @@ Vlevo Na střed Vpravo + Rozděleno Nabídka rychlého přístupu Steamu zatím není k dispozici. Statistiky ve hře HUD na spodní obrazovce diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index c316cfc229..ff8edf9e72 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -2136,6 +2136,7 @@ Venstre Midte Højre + Delt Steams menu til hurtig adgang er ikke tilgængelig endnu. Statistik i spillet HUD på nederste skærm diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index de3e9c377d..6fadfcf213 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -2128,6 +2128,7 @@ Links Mitte Rechts + Geteilt Das Schnellzugriffsmenü von Steam ist noch nicht verfügbar. Spielstatistiken HUD für den unteren Bildschirm diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 655da001c1..948fe204bc 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -2136,6 +2136,7 @@ Αριστερά Κέντρο Δεξιά + Διαιρεμένο Το μενού γρήγορης πρόσβασης του Steam δεν είναι ακόμη διαθέσιμο. Στατιστικά παιχνιδιού HUD κάτω οθόνης diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 6a5d9622da..6929481163 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -2161,6 +2161,7 @@ Izquierda Centro Derecha + Dividido El menú de acceso rápido de Steam aún no está disponible. Estadísticas del juego HUD de la pantalla inferior diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 80c90ff817..07a4f05b14 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -2136,6 +2136,7 @@ Vasen Keskellä Oikea + Jaettu Steamin pikavalikko ei ole vielä käytettävissä. Pelinsisäiset tilastot Alanäytön HUD diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index db54af05d4..3879851004 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -2160,6 +2160,7 @@ Gauche Centre Droite + Partagé Le menu d’accès rapide de Steam n’est pas encore disponible. Statistiques en jeu HUD de l\'écran du bas diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 47b15821d3..afecaa38e7 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -2136,6 +2136,7 @@ बाएँ बीच में दाएँ + विभाजित Steam का क्विक एक्सेस मेनू अभी उपलब्ध नहीं है। इन-गेम आंकड़े निचली स्क्रीन HUD diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index edc23c97ca..f8b706073a 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -2136,6 +2136,7 @@ Balra Középen Jobbra + Osztott A Steam gyorselérési menüje még nem érhető el. Játékon belüli statisztikák HUD az alsó képernyőn diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 67f801c7bb..d24a21aa8c 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -2112,6 +2112,7 @@ Kiri Tengah Kanan + Terbagi Menu Akses Cepat Steam belum tersedia. Statistik dalam gim HUD layar bawah diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 19021c75bf..66461063e7 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -2152,6 +2152,7 @@ Sinistra Centro Destra + Diviso Il menu di accesso rapido di Steam non è ancora disponibile. Statistiche di gioco HUD dello schermo inferiore diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 199f44f302..036443dd3a 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -2112,6 +2112,7 @@ 左 中央 右 + 分割 Steam のクイックアクセスメニューはまだ使えません。 ゲーム内統計 下部画面の HUD diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 7d139b289b..3c02c76b1f 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -2112,6 +2112,7 @@ 왼쪽 가운데 오른쪽 + 분할 Steam 빠른 메뉴를 아직 사용할 수 없습니다. 게임 내 통계 하단 화면 HUD diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index 73ba644c82..16285afb92 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -2112,6 +2112,7 @@ Kiri Tengah Kanan + Terbahagi Menu Akses Pantas Steam belum tersedia. Statistik dalam permainan HUD skrin bawah diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 96e5da88c7..3ad30c77b6 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -2136,6 +2136,7 @@ Venstre Midten Høyre + Delt Steams hurtigtilgangsmeny er ikke tilgjengelig ennå. Statistikk i spillet HUD på bunnskjermen diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 0b15dff90d..5876c31aa5 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -2136,6 +2136,7 @@ Links Midden Rechts + Gesplitst Het menu Snelle toegang van Steam is nog niet beschikbaar. In-game statistieken HUD op het onderste scherm diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 80ca1f1c4b..1d8cd1e91e 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -2186,6 +2186,7 @@ Do lewej Na środku Do prawej + Podzielony Menu szybkiego dostępu Steam nie jest jeszcze dostępne. Statystyki w grze HUD dolnego ekranu diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 9121642799..9f06da10cb 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -2167,6 +2167,7 @@ Esquerda Centro Direita + Dividido O menu de acesso rápido do Steam ainda não está disponível. Estatísticas no jogo HUD do ecrã inferior diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 4ab1890f2a..96df3e3e8d 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -2175,6 +2175,7 @@ Esquerda Centro Direita + Dividido O menu de acesso rápido do Steam ainda não está disponível. Estatísticas no jogo HUD da tela inferior diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index fe0a3ab63c..0b54f68343 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -2161,6 +2161,7 @@ Stânga Centru Dreapta + Împărțit Meniul de acces rapid Steam nu este încă disponibil. Statistici în joc HUD pe ecranul de jos diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 11939be52a..7eceacdda3 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -2187,6 +2187,7 @@ Слева По центру Справа + Разделённый Меню быстрого доступа Steam пока недоступно. Игровая статистика HUD нижнего экрана diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 66a76edda1..0ee2b4d932 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -2136,6 +2136,7 @@ Vänster Mitten Höger + Delad Steams snabbåtkomstmeny är inte tillgänglig än. Statistik i spelet HUD på nedre skärmen diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 7e2004c609..993064a0b9 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -2112,6 +2112,7 @@ ซ้าย กึ่งกลาง ขวา + แบ่งครึ่ง เมนูเข้าถึงด่วนของ Steam ยังไม่พร้อมใช้งาน สถิติในเกม HUD หน้าจอล่าง diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 6b7b4ce7b0..164b2aa8ba 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -2128,6 +2128,7 @@ Sol Orta Sağ + Bölünmüş Steam Hızlı Erişim menüsü henüz kullanılamıyor. Oyun içi istatistikler Alt ekrandaki HUD diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 6a0d3b607d..09beecb05e 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -2186,6 +2186,7 @@ Ліворуч По центру Праворуч + Розділений Меню швидкого доступу Steam ще недоступне. Ігрова статистика HUD на нижньому екрані diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 9353281a09..12baabb6a5 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -2112,6 +2112,7 @@ Trái Giữa Phải + Chia đôi Menu Truy cập nhanh của Steam chưa sẵn sàng. Thông số trong game HUD màn hình dưới diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 58bbf19378..e6e63aa9dd 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -2189,6 +2189,7 @@ 左侧 居中 右侧 + 分屏 Steam 快速访问菜单暂不可用。 游戏内数据 下屏 HUD diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index f0a26a39a9..648863b9a5 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -2111,6 +2111,7 @@ 左側 置中 右側 + 分割 Steam 快速存取選單暫時無法使用。 遊戲內數據 下方螢幕 HUD diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 621d47e5c6..7f8fdeea10 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -2111,6 +2111,7 @@ 左側 置中 右側 + 分割 Steam 快速存取選單暫時無法使用。 遊戲內數據 下螢幕 HUD diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 29d2b8d03b..098129e055 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2419,6 +2419,7 @@ Left Center Right + Split Steam\'s Quick Access menu is not available yet. In-game stats Bottom screen HUD diff --git a/app/src/test/java/com/droiddeck/launcher/session/SteamQamTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SteamQamTest.kt index 5e16af444f..38eb32bfcd 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SteamQamTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SteamQamTest.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.session +import com.droiddeck.launcher.ui.MainMenuLayout import com.droiddeck.launcher.ui.QamFit import com.droiddeck.launcher.ui.QamLayout import org.junit.Assert.assertEquals @@ -51,6 +52,7 @@ class SteamQamTest { val program = "const g = {};\n" + steps.joinToString("\n") { step -> when (step) { is Triple<*, *, *> -> SteamQam.leaseScript(step.first as Boolean, step.second as Long, step.third as Float) + is SplitStep -> SteamQam.leaseScript(true, step.owner, 0.5f, step.split) is Pair<*, *> -> if (step.second == EXPIRE) "g.__ddQamUntil = Date.now() - 1;" else SteamQam.leaseScript(step.first as Boolean, step.second as Long) else -> error("unknown step $step") } @@ -85,14 +87,14 @@ class SteamQamTest { @Test fun theQuickAccessButtonTogglesTheTopScreenAndTheWideLayoutFollows() { val script = SteamQam.script(true) - assertTrue(script.contains("const ours = () => held() && m.m_eOpenSideMenu === QAM && !g.__ddQamTop;")) + assertTrue(script.contains("const ours = () => held() && !g.__ddQamTop && (m.m_eOpenSideMenu === QAM || (probing() && m.m_eOpenSideMenu === MAIN));")) assertTrue(script.contains("if (press !== g.__ddQamPress) {")) assertTrue(QamLayout.contentScript(true).contains("max-width: none !important")) assertFalse(QamLayout.contentScript(false).contains("max-width: none")) } @Test fun theMenuIsLaidOutAtThePanelsShapeOnlyWhileHeld() { - assertTrue(SteamQam.script(true, 1.5f, owner = 3).contains("g.__ddQamOwner = 3; g.__ddQamUntil = Date.now() + ${SteamQam.LEASE_MS}; g.__ddQamAspect = 1.5; }")) + assertTrue(SteamQam.script(true, 1.5f, owner = 3).contains("g.__ddQamOwner = 3; g.__ddQamUntil = Date.now() + ${SteamQam.LEASE_MS}; g.__ddQamAspect = 1.5; g.__ddQamSplit = false; }")) assertFalse(SteamQam.script(true).contains("g.__ddQamAspect =")) assertFalse(SteamQam.script(false, 1.5f).contains("g.__ddQamAspect =")) } @@ -114,8 +116,8 @@ class SteamQamTest { @Test fun whileHeldTheMenuStaysOffTheTopScreenAndOutOfTheGamesWay() { val script = SteamQam.script(true) assertTrue(script.contains("return without >= 2 ? v : 1;")) - assertTrue(script.contains("if (w > 0 && ours()) { x = popup.m_popup.innerWidth + 64; w = width(h) || w; }")) - assertTrue(script.contains("nav.m_LastActiveNavTree?.m_ID?.startsWith(\"QuickAccess\")")) + assertTrue(script.contains("if (w > 0 && ours() && isQam(v)) { x = parkX(); [w, h] = size(w, h); }")) + assertTrue(script.contains("/^(QuickAccess|MainMenu)/.test(nav.m_LastActiveNavTree?.m_ID ?? \"\")")) assertTrue(script.contains("if (m.m_eOpenSideMenu === QAM) m.CloseSideMenus();")) } @@ -134,8 +136,9 @@ class SteamQamTest { assertEquals(0f, QamLayout.fit(1280f, 832f, 1280f, 640f, 1).second, 0.001f) } - @Test fun theLayoutButtonCyclesFullLeftCenterRight() { - assertEquals(listOf(QamFit.LEFT, QamFit.CENTER, QamFit.RIGHT, QamFit.FULL), QamFit.entries.map { it.next }) + @Test fun theLayoutButtonCyclesFullLeftCenterRightSplit() { + assertEquals(listOf(QamFit.LEFT, QamFit.CENTER, QamFit.RIGHT, QamFit.SPLIT, QamFit.FULL), QamFit.entries.map { it.next }) + assertEquals(QamFit.SPLIT, QamFit.from("split")) assertEquals(QamFit.FULL, QamFit.from(null)) assertEquals(QamFit.RIGHT, QamFit.from("right")) assertEquals(QamFit.FULL, QamFit.from("sideways")) @@ -147,6 +150,55 @@ class SteamQamTest { assertEquals(0f, left, 0.001f) } + @Test fun findsTheMainMenuPageBesideQuickAccess() { + val json = """[ + {"title":"MainMenu_uid2","webSocketDebuggerUrl":"ws://127.0.0.1:8080/devtools/page/M41N"}, + {"title":"QuickAccess_uid2","webSocketDebuggerUrl":"ws://127.0.0.1:8080/devtools/page/0F3A-b9"} + ]""" + assertEquals(SteamQam.Target(4321, "/devtools/page/0F3A-b9", "/devtools/page/M41N"), SteamQam.parseTarget(4321, json)) + assertNull(SteamQam.parseTarget(1, """[{"title":"MainMenu_uid2","webSocketDebuggerUrl":"ws://127.0.0.1:1/devtools/page/A"}]""")) + } + + @Test fun theSplitLayoutIsPartOfTheLease() { + assertEquals("true", runLease(listOf(SplitStep(1L, true)), "g.__ddQamSplit")) + // A rejected hold from an older panel leaves the newer panel's split choice alone. + assertEquals("true", runLease(listOf(SplitStep(2L, true), SplitStep(1L, false)), "g.__ddQamSplit")) + assertTrue(SteamQam.script(true, 0.5f, owner = 3, split = true).contains("g.__ddQamSplit = true; }")) + } + + @Test fun onlyTheQuickAccessViewIsParked() { + val script = SteamQam.script(true, 1.3f, owner = 3) + // Store and other web pages live in the header's view, which keeps the bounds Steam gives it. + assertTrue(script.contains("const isQam = (v) => !v.__ddMain && v !== headerView() &&")) + assertTrue(script.contains("if (on && m.m_eOpenSideMenu === QAM && !v.__ddMain && v !== headerView()) {")) + assertTrue(script.contains("if (!isQam(v)) {")) + // A parked menu leaves the Store page unfrosted. + assertTrue(script.contains("inst.__ddQamGlass.call(this, ours() ? 0 : e)")) + } + + @Test fun theMainMenuStaysInPlaceOnlyWhileParked() { + val script = SteamQam.script(true, 0.5f, owner = 3, split = true) + assertTrue(script.contains("transform: none !important")) + assertTrue(script.contains("mainStyle(!!mv && mainParked() && !probing());")) + // Steam sizing the main menu for the top screen drops the parked style at once. + assertTrue(script.contains("if (v.__ddMain && w > 0) mainStyle(false);")) + } + + @Test fun theScriptsParse() { + val node = runCatching { ProcessBuilder("node", "--version").start().waitFor() == 0 }.getOrDefault(false) + org.junit.Assume.assumeTrue("node is not installed", node) + val scripts = listOf(SteamQam.script(true, 0.5f, 3, split = true), SteamQam.script(false, owner = 3), + QamLayout.contentScript(true), MainMenuLayout.CONTENT_SCRIPT) + val program = scripts.joinToString(";") { "new Function(" + org.json.JSONObject.quote(it) + ")" } + // Passed on stdin: Windows argument quoting would mangle the quotes in the scripts. + val p = ProcessBuilder("node").redirectErrorStream(true).start() + p.outputStream.use { it.write(program.toByteArray()) } + val out = p.inputStream.bufferedReader().readText() + assertEquals(out, 0, p.waitFor()) + } + + private data class SplitStep(val owner: Long, val split: Boolean) + private companion object { /** A lease step that lets the current lease run out. */ const val EXPIRE = -1L diff --git a/docs/development/bottom-screen.md b/docs/development/bottom-screen.md index ba0ce9d065..6872063f6b 100644 --- a/docs/development/bottom-screen.md +++ b/docs/development/bottom-screen.md @@ -181,8 +181,10 @@ Plugin loaders expose Steam's CEF DevTools so the menu can be viewed in a deskto - The menu's browser view is placed just outside the Big Picture window through its own `SetBounds`, so it keeps rendering but never shows on top, including while Steam slides it wider for Friends and chat. The view is also given the panel's shape (about 712 × 463 instead of Steam's 856 × 463), so every tab shows at one scale. In Full width, a style on the menu page also lifts Steam's 300 px cap on each tab, so every tab fills the panel and Friends shows its list and chat side by side. - A timer inside Steam keeps this state every 250 ms, so the menu comes back, on the tab it was showing, as soon as Steam's main menu or a full-screen page such as Decky's store closes. It runs on a 5 s lease that the panel renews each second: if the app stops, Steam returns to normal by itself. - The hold starts only once the session is ready: holding the menu before Steam's first frame kept gamescope from presenting anything. -- `droiddeck-qam-relay` relays the app to the DevTools port, which only answers clients inside the guest. The panel streams the menu with `Page.startScreencast`, scales its content to the panel and fills the rest with the menu's own background, and forwards touches on the menu with `Input.dispatchTouchEvent`. A layout button in the panel's bar cycles Full width (every tab stretched to the panel), Left, Center and Right (Steam's own narrow tabs, placed on that side); the choice is kept. Returning to the panel shows the last frame at once while the stream reconnects, and the first frame after a cold start takes about 1.4 s. +- `droiddeck-qam-relay` relays the app to the DevTools port, which only answers clients inside the guest. The panel streams the menu with `Page.startScreencast`, scales its content to the panel and fills the rest with the menu's own background, and forwards touches on the menu with `Input.dispatchTouchEvent`. A layout button in the panel's bar cycles Full width (every tab stretched to the panel), Left, Center and Right (Steam's own narrow tabs, placed on that side) and Split (below); the choice is kept. Returning to the panel shows the last frame at once while the stream reconnects, and the first frame after a cold start takes about 1.4 s. - The Quick Access button still shows the menu on the top screen, in Steam's own layout and with the controller; closing it there (B or the button again) returns it to the bottom screen on the same tab. +- The Split layout puts Steam's main menu (the Steam button's menu) on the left and Quick Access on the right. Both are laid out 480 CSS pixels tall so they show at one scale: the main menu at Steam's own 240 px width, Quick Access across the rest. Steam keeps one side menu open at a time and slides the other out, so the main menu's view is kept visible, parked beside Quick Access's, and a style on its page holds it in place. Steam's views carry no names: the main menu's is the one Steam focuses while the main menu is open, so after Steam starts the panel opens it once, parked before it is drawn. Taps on either half go to that menu; in a game, the running game's card at the top of the main menu returns to it. The Steam button still shows the main menu on the top screen in Steam's own layout, and closing it returns both menus to the bottom. Checked on the AYN Thor in Big Picture and in Bomb Rush Cyberfunk, with the game keeping focus. +- Only Quick Access's own view is parked: the one Steam focuses while Quick Access is open. Store and other web pages live in another view, which keeps the bounds Steam gives it, and Steam's frosted glass over the Store page is left off while the menu is parked rather than over it. - Leaving the panel closes the menu and turns the patches off; the Steam button and the normal Quick Access button then work as before. Opening Steam's main menu replaces the Quick Access menu for as long as it is open, as on a Deck. Checked with Decky Loader 3.3.1 enabled: its tab renders and takes touch, and its store opens full screen on top with the controller, then returns to the Decky tab below. Decky hooks the menu after Steam starts, so the panel reopens it once when that happens. @@ -201,6 +203,10 @@ Limits: it relies on Steam's minified UI stores and method names, so a client up | --- | --- | | ![Quick Access in the centred layout](evidence/bottom-screen-qam-center-2026-11-27.png) | ![Quick Access in the right-aligned layout](evidence/bottom-screen-qam-right-2026-11-27.png) | +| Layout: Split | Split, in a game | +| --- | --- | +| ![Steam's main menu and Quick Access side by side on the bottom screen](evidence/bottom-screen-qam-split-2026-11-30.png) | ![The split layout during a game, with the game's card at the top of the main menu](evidence/bottom-screen-qam-split-ingame-2026-11-30.png) | + The top screen during that game, with the menu open on the bottom: ![Top screen during the game, with nothing drawn over it](evidence/bottom-screen-qam-top-ingame-2026-11-27.png) ## Related fixes diff --git a/docs/development/evidence/bottom-screen-qam-split-2026-11-30.png b/docs/development/evidence/bottom-screen-qam-split-2026-11-30.png new file mode 100644 index 0000000000..dda6f288d2 Binary files /dev/null and b/docs/development/evidence/bottom-screen-qam-split-2026-11-30.png differ diff --git a/docs/development/evidence/bottom-screen-qam-split-ingame-2026-11-30.png b/docs/development/evidence/bottom-screen-qam-split-ingame-2026-11-30.png new file mode 100644 index 0000000000..76c0efb63d Binary files /dev/null and b/docs/development/evidence/bottom-screen-qam-split-ingame-2026-11-30.png differ