From baa475355b0c271d865011ab2483ab8fab0aec4b Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 26 Nov 2026 15:51:13 -0500 Subject: [PATCH] docs: expand bottom screen region mirror, guides and companion API --- .../bottom-screen-companion-api.md | 137 ++++++++++++++++++ docs/development/bottom-screen-guides.md | 118 +++++++++++++++ .../bottom-screen-region-mirror.md | 107 ++++++++++++++ ...m-screen-companion.md => bottom-screen.md} | 21 +-- 4 files changed, 369 insertions(+), 14 deletions(-) create mode 100644 docs/development/bottom-screen-companion-api.md create mode 100644 docs/development/bottom-screen-guides.md create mode 100644 docs/development/bottom-screen-region-mirror.md rename docs/development/{bottom-screen-companion.md => bottom-screen.md} (88%) diff --git a/docs/development/bottom-screen-companion-api.md b/docs/development/bottom-screen-companion-api.md new file mode 100644 index 0000000000..cd9dfe850a --- /dev/null +++ b/docs/development/bottom-screen-companion-api.md @@ -0,0 +1,137 @@ +# Bottom screen: companion API for PC games + +Part of the [bottom screen research](bottom-screen.md). Researched 2026-11-26 against `main` at `d788afc12`. Not implemented. + +Let games and mods running in the Linux and Proton session drive pages on DroidDeck's bottom screen: live state (health, money, map position, inventory, quests) and touch commands back into the game. + +## Use cases + +- **RPGs**: a Pip-Boy for Fallout 4, inventory and quests for Skyrim and Fallout: New Vegas, equipment swaps by touch. +- **Sims and management**: Stardew Valley's day, bag, bundles and calendar; RimWorld colonists and alerts; Project Zomboid's status. +- **Open world**: GTA's radio, weapons, wanted level and GPS-to-blip. +- **Racing and flight**: the telemetry dashboards DroidDeck already has. +- **Speedrunning**: LiveSplit splits for any game with an auto-splitter. + +## Companions people already use + +Several Thor companions already run against PC games in Wine, and two document DroidDeck as a supported launcher. Each is a separate Android app paired with a game-side mod that serves state on loopback. + +| Companion | Game-side piece | Transport | +| --- | --- | --- | +| [Thor Pip-Boy](https://github.com/harmssi/thor-pipboy) (Fallout 4, **targets DroidDeck**) | F4SE plugin | WebSocket on `127.0.0.1:8767`, protocol copied from SkyrimWebSocket; commands `toggle`, `equip`, `use`, `radio`; raw access to the game's Pip-Boy data | +| [Grand Theft Companion](https://github.com/BrianJr03/GrandTheftCompanion) (GTA IV and V, **documents DroidDeck setup**) | `.asi` via Ultimate ASI Loader (IV) or ScriptHookV (V); needs `WINEDLLOVERRIDES=dinput8=n,b` in Steam launch options | JSON on `127.0.0.1:47801` at 20 Hz with a hello frame; radio, weapon, GPS and cheat commands. Its map page is a crop of the minimap | +| [AYN Thor dual-screen mods](https://github.com/JoeCorrell/AYN-Thor-Dualscreen-Mods) (Stardew Valley, for WEMU) | SMAPI mod | Hand-written RFC 6455 WebSocket on `127.0.0.1:7786` (".NET's WebSocket server wraps Windows components Wine does not implement"). No auth. Replays the latest message of each kind on connect, computes nothing without a client, hides the game HUD while one is attached. Sprites sent once as base64 PNG with nine-patch insets. Commands: `select_slot`, `move_item`, `eat_slot`, `sort_bag`, `shift_toolbar`, `craft_recipe` and others. Optional UDP beacon on 7787. The [Barry client](https://github.com/project-barry/stardew-dual-screen/blob/main/docs/protocol.md) documents the schema and ships a mock server | +| [SkyrimWebSocket](https://github.com/andreyvelsk/SkyrimWebSocket) + SkyrimWebMonitor | SKSE plugin | WebSocket on `127.0.0.1:8765`. Client-driven `subscribe` with frequency, send-on-change and aliased fields; `query`, `heartbeat`, `command` → `commandResult` ([protocol](https://github.com/andreyvelsk/SkyrimWebSocket/blob/main/PROTOCOL.md)). Client is a web app | +| [SkyrimSE-DualScreen](https://github.com/Plus-Cloud/SkyrimSE-DualScreen) | `SkyrimAYN.dll` | A 384 KiB memory-mapped file with a seqlock header ([layout](https://github.com/Plus-Cloud/SkyrimSE-DualScreen/blob/main/native/shared-memory.md)). Only works with its own bundled Wine | +| FNVDS (Fallout: New Vegas) | xNVSE plugin | TCP on `127.0.0.1:47888` | +| FFXII Companion | LUA Script Loader script reading memory, gated on the game build | JSON files in shared storage; commands as request files | +| [ZomboidDS](https://github.com/Space001000/ZomboidDS) (Project Zomboid on a Java port) | Lua and Java mod | WebSocket `ws://127.0.0.1:7786/ws` (**the same port as the Stardew mod**), envelope `{v,type,seq,data}`, hello first, full-state topics replayed on connect, `command_result`, `capabilities[]`, icons over HTTP ([protocol](https://github.com/Space001000/ZomboidDS/blob/main/protocol/PROTOCOL.md)) | + +Lessons: + +- Every project invents its own port and schema; two already collide on 7786. +- Each needs its own Android app on the bottom screen. Thor Pip-Boy warns that bringing it to the front "lowers DroidDeck's priority and could get the game killed" while Fallout 4 is loading. Pages drawn inside DroidDeck's own bottom-screen Presentation avoid that. +- The good protocols share a shape: hello with capabilities, complete state per topic replayed on connect, commands with ids and results, assets sent once and cached. +- Mods should do no work while nobody is watching (the Stardew mod and SkyrimWebSocket both do this). + +## Game-side APIs a companion could consume + +| Source | Protocol | Works in Proton on ARM? | +| --- | --- | --- | +| SKSE, F4SE, xNVSE plugins | Any socket from a Windows DLL | Yes, proven by the companions above | +| ScriptHookV / ASI plugins | Any socket | Yes, proven | +| [RIMAPI](https://github.com/IlyaChichkov/RIMAPI) (RimWorld) | REST and SSE on `localhost:8765`, 120+ endpoints, extensible by other mods | Likely (Unity, Mono) | +| [Hollow Knight tracker](https://github.com/kingkiller39/HollowKnightRandomizerTracker2.8) | WebSocket on `localhost:11420` | Likely | +| [Ficsit Remote Monitoring](https://docs.ficsit.app/ficsitremotemonitoring/latest/webserver.html) (Satisfactory) | HTTP and WebSocket on 8080 | The game is heavy for ARM | +| [Valheim WebMap](https://github.com/kylepaulsen/ValheimWebMap) | BepInEx, HTTP and WebSocket on 3000 | Server-side mod | +| Cyberpunk 2077 | CET plus RedSocket, used by [Crowd Control](https://crowdcontrol.live/guides/cyberpunk2077/) | Unknown; heavy | +| Fallout 4 Pip-Boy app protocol | UDP 28000 discovery, binary stream on TCP 27000 ([reverse-engineered](https://github.com/luckydonald/JavaPipBoyServer/blob/master/PROTOCOL.md)) | Broken in the current game build per Thor Pip-Boy | +| CS2 / Dota 2 Game State Integration | The game POSTs JSON to a URI declared in a cfg file | Protocol is a good model; the games are unrealistic on ARM | +| ETS2 / ATS telemetry SDK | Shared memory; needs an in-Wine relay such as [Funbit's server](https://github.com/Funbit/ets2-telemetry-server) | With a relay | +| [LiveSplit server](https://github.com/LiveSplit/LiveSplit.Server) | Text commands on TCP 16834 | Yes | +| Discord Rich Presence | Named pipe `\\.\pipe\discord-ipc-0` with JSON frames | A Wine-side pipe sink would give presence data for any game that integrates Discord | +| Racing UDP, War Thunder, Elite Dangerous | Already consumed by DroidDeck (below) | Yes | + +Generic memory readers that publish JSON are another model: [tosu](https://github.com/KotRikD/tosu) serves osu! state on a WebSocket, and LiveSplit's ASL and [WASM auto-splitters](https://github.com/alexknauth/hollowknight-autosplit-wasm) are per-game pointer descriptions that a Rust runtime (livesplit-core) evaluates. + +## What DroidDeck already has + +Paths are under [`app/src/main/java/com/droiddeck/launcher/`](../../app/src/main/java/com/droiddeck/launcher/). + +- **Shared loopback.** proot creates no network namespace and the bwrap shim ignores `--unshare-net`, so the guest's `127.0.0.1` is the app's `127.0.0.1` ([`core/NetworkReport.kt`](../../app/src/main/java/com/droiddeck/launcher/core/NetworkReport.kt), `tools/linuxfs/overlay/usr/local/bin/droiddeck-bwrap`). A Windows game in Proton can connect to a socket the app opens, and the app can connect to a socket a mod opens. +- **Telemetry template.** [`session/GameTelemetry.kt`](../../app/src/main/java/com/droiddeck/launcher/session/GameTelemetry.kt) parses Codemasters (UDP 20777), Forza (5300) and OutGauge (4444) packets, War Thunder's `http://127.0.0.1:8111/state` and Elite Dangerous's `Status.json` read straight from the Proton prefix. [`ui/BottomTelemetryPage.kt`](../../app/src/main/java/com/droiddeck/launcher/ui/BottomTelemetryPage.kt) runs one listener per source, marks data stale after 3 s, reports busy ports and unknown formats, and draws dashboards. [`session/TelemetryOutput.kt`](../../app/src/main/java/com/droiddeck/launcher/session/TelemetryOutput.kt) edits a game's config in its prefix (with a backup) to turn telemetry on. This is the first version of the companion API: built-in adapters for known games. +- **Agent channel.** `droiddeck-agent` in the guest and [`agent/AgentGuest.kt`](../../app/src/main/java/com/droiddeck/launcher/agent/AgentGuest.kt) talk through request and response files in a shared directory, plus watched state files (`focus.json` and others). `steamEval` reaches Steam's UI over the DevTools port. +- **Installing mods.** [`session/WinComponents.kt`](../../app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt) installs per-game components from the [DroidDeck-Components](https://github.com/Droid-Deck/DroidDeck-Components) catalog: download, extract, copy DLLs and files, DLL overrides, registration. That is exactly what SKSE, F4SE, ScriptHookV, ASI Loader and BepInEx need. Per-game environment overrides ([`session/GameEnvironmentStore.kt`](../../app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt)) reach the game through the `steam-compatibility` wrapper, including `WINEDLLOVERRIDES`. There is no SMAPI or BepInEx installer yet. +- **A second guest on the bottom screen.** The bottom KDE desktop is a second compositor in its own process with its own `/run/droiddeck`, so the main guest cannot see its Wayland socket. A debug-gated run queue in [`droiddeck-desktop`](../../tools/linuxfs/desktop/droiddeck-desktop) runs scripts there with `WAYLAND_DISPLAY=wayland-1 DISPLAY=:1`, which is a seed for a "run on bottom" command. + +## Proposed design + +### Phase 1: adapters for existing companions + +DroidDeck connects as a client to the servers mods already open and draws their pages natively in the bottom-screen Presentation: + +- Stardew (port 7786, WEMU protocol), Skyrim and Fallout 4 (SkyrimWebSocket protocol on 8765 and Thor Pip-Boy on 8767), GTA (47801), RIMAPI, the Hollow Knight tracker, LiveSplit. +- Probe only the ports known for the focused app id, so a busy port never confuses two games. +- Offer the mod itself through the components catalog, so setup is one toggle in the game's settings. + +This gives working showcases without writing any mods, and a reason to define the shared state model first. + +### Phase 2: DroidDeck's own protocol + +For new mods, DroidDeck is the server and mods are clients: + +- **Transport.** WebSocket at `ws://127.0.0.1:/companion/v1`, and newline-delimited JSON over raw TCP on the same port (detected from the first bytes). Clients are trivial under Wine; servers inside Wine are not (the Stardew mod had to hand-write one). Several mods or games can attach at once. +- **Discovery.** DroidDeck sets `DROIDDECK_COMPANION_URL`, `DROIDDECK_COMPANION_TOKEN` (random per launch) and `DROIDDECK_APPID` in the game's environment through the existing game-environment path, and writes the same values to a known file in the prefix for processes that lose the environment. +- **Security.** Any Android app can reach loopback, so the token is required in `hello` within about 2 s or the connection closes. No remote bind. Commands that change the game need a per-mod user toggle. Limits on frame and asset sizes. +- **Envelope.** `{"v":1,"type":…,"seq":n,…}`. + +| Direction | Message | Purpose | +| --- | --- | --- | +| game → DroidDeck | `hello{token, game{appid, build}, mod{id, version}, capabilities[]}` | Identify and authenticate | +| | `declare{states{key: {type, unit, min, max}}}` | Describe the state keys the mod publishes | +| | `state{topic, data}` | Complete value of a topic, never a diff; DroidDeck keeps the latest and replays it when a page opens | +| | `asset{id: sha256, mime, nine_patch, filter}` + binary frame | Art sent once and cached across sessions by content hash | +| | `event{toast \| haptic \| sound}` | Notifications | +| | `result{id, ok, error}` | Command outcome | +| DroidDeck → game | `welcome{session, screen{w, h}}` | Accept the connection | +| | `visibility{visible, topics[], hz}` | Tell the mod what is on screen so it computes nothing else | +| | `command{id, name, args}` | Touch actions | +| | `input{button}` | Pass L/R or similar when a page claims them | +| | `ping` | Liveness | + +A small C header and a C# client file would let SKSE, F4SE, ASI and BepInEx/SMAPI authors adopt it in an afternoon. + +### Phase 3: pages + +- **Declarative pages** in a `.ddpage` zip (`manifest.json` plus assets), modelled on Eden Duo's [package format](https://github.com/igawa6/eden-duo-companions/blob/main/docs/PACKAGE_FORMAT.md) but drawn with DroidDeck's own components: + - `pages[]` of widgets (`label`, `value`, `bar`, `grid`, `list`, `image`, `map`, `button`) bound to state keys, with `repeat` over arrays; + - actions `command`, `page` and `input` on tap, hold and swipe; + - a settings page backed by the mod's options; + - host values (`@device.*`, `@perf.*`) so pages can mix game and device data. +- **Normalized core keys**, the lesson from SimHub, whose dashboards work across many games because readers map them onto one property tree: `player.health`, `player.money`, `location.name`, `map.{x,y,heading}`, `inventory[]`, `quests[]`, `game.time`. A generic RPG page then works for any mod that provides them. +- **WebView escape hatch** for richer pages, in the style of EmuLnk's [theme API](https://github.com/EmuLnk/emulnk-repo/wiki/Theme-API): `window.droiddeck.onState` and `.send`. This also hosts existing web clients like SkyrimWebMonitor unchanged. +- Pages ship inside the mod, or from a catalog repository like the components catalog. + +### Phase 4: run on bottom + +A `droiddeck-run-bottom -- ` command, like Armada's `armada-run-bottom`, that opens a guest program on the bottom screen with touch. Kanto Gear's separate-window mode and second-monitor mods would then work as they are. Unity games could render to `Display.displays[1]` (the Silksong Android approach) if the bottom panel is exposed as a second output to the guest. Builds on the bottom desktop's run queue, or on binding its runtime directory into the main guest. + +### Phase 5: memory profiles (only if demand) + +Per-game JSON pointer profiles, gated on the Steam build id, evaluated on the Android side against the game process, in the style of Eden Duo or LiveSplit's auto-splitters. Strict version gating with a "needs build X" page, as Eden Duo does. Highest maintenance cost; only for popular games without mod support. + +## Open questions + +- Whether a single port and token for every game is enough, or each session gets its own port. +- How pages and mods are versioned together, and what happens when a mod is newer than the page. +- Which component installs belong in the catalog (SKSE, F4SE, ScriptHookV, ASI Loader, SMAPI, BepInEx) and how they interact with Steam updates of the game. +- Asking the authors of Thor Pip-Boy, Grand Theft Companion and the Stardew mod whether they would also speak DroidDeck's protocol. +- Touch commands that change game state while the game is paused or loading. + +## Milestones + +1. Stardew adapter (port 7786) with a native page, and the SMAPI mod offered through components. +2. Skyrim and Fallout 4 adapters (SkyrimWebSocket protocol), GTA adapter. +3. DroidDeck protocol server, C and C# clients, `.ddpage` renderer, normalized keys. +4. Run on bottom. +5. Memory profiles. diff --git a/docs/development/bottom-screen-guides.md b/docs/development/bottom-screen-guides.md new file mode 100644 index 0000000000..53df254583 --- /dev/null +++ b/docs/development/bottom-screen-guides.md @@ -0,0 +1,118 @@ +# Bottom screen: guides tab + +Part of the [bottom screen research](bottom-screen.md). Researched 2026-11-26 against `main` at `d788afc12`. Not implemented. + +A dashboard tab that follows the running game and shows its guides, achievements, maps and fixes, reopens where the user left off, and saves pages for offline use. + +## Use cases + +- Stuck on a puzzle or boss: the walkthrough for this game is already open on the bottom screen at the last section read. +- Achievement hunting: a checklist of locked achievements with missable ones flagged, spoilers blurred until tapped. +- Collectibles: a map image pinned with pan and zoom, markers saved per map. +- Fixes: PCGamingWiki and ProtonDB notes for the game when it misbehaves. +- Offline play on a plane with guides saved earlier. + +## Prior art + +| Project | Matching | Offline | Reader and extras | Complaints and requests | +| --- | --- | --- | --- | --- | +| [Game Twin](https://github.com/alpha-minus/game-twin) (GPL-3, 157★) | Bundled catalogs (GameFAQs, StrategyWiki, VGMaps, Steam guides) rebuilt offline; Jaccard title match at 0.6 with a sequel guard (numbers must match); hand-mapped series sites (Zelda Dungeon, Bulbapedia); site search URLs for the rest | `WebView.saveWebArchive` after forcing lazy images to load; MHT split into HTML and assets served via `shouldInterceptRequest`; scripts stripped; OkHttp with WebView cookies for side downloads. Also imports PDF, TXT, EPUB | Reading mode with per-host cleanup, auto table of contents, find, bookmarks. Resume by the text at the top of the viewport plus its occurrence, so it survives reflow. Maps with markers, checklists, RetroAchievements and Steam achievements, folder sync, optional Gemini with a screenshot | Battery and fan noise from live pages left running ([#12](https://github.com/alpha-minus/game-twin/issues/12), [#24](https://github.com/alpha-minus/game-twin/issues/24)); saved guides unreadable in dark mode ([#9](https://github.com/alpha-minus/game-twin/issues/9)); cookie banners ([#2](https://github.com/alpha-minus/game-twin/issues/2)); requests for notes ([#28](https://github.com/alpha-minus/game-twin/issues/28)) and a visible capture indicator for AI ([#22](https://github.com/alpha-minus/game-twin/issues/22)) | +| [Pixel Guide](https://github.com/rexmont/Pixel-Guide-Android) (closed source) | Manual | TXT, single-file HTML, multi-page Neoseeker | ASCII reflow with auto table of contents, per-guide font, resume, find, controller scrolling, 14 themes, manuals, translation, AI | Ads in saved pages ([#46](https://github.com/rexmont/Pixel-Guide-Android/issues/46)), very large guides fail ([#58](https://github.com/rexmont/Pixel-Guide-Android/issues/58)); requests for stick scrolling ([#35](https://github.com/rexmont/Pixel-Guide-Android/issues/35)), prev/next ([#27](https://github.com/rexmont/Pixel-Guide-Android/issues/27)), checklists ([#44](https://github.com/rexmont/Pixel-Guide-Android/issues/44)), remembering the game association ([#20](https://github.com/rexmont/Pixel-Guide-Android/issues/20)) | +| [WalkThor](https://github.com/nerf-herder-29/WalkThor) (MIT) | Fuzzy match of ROM name to local files | Local PDF and TXT only | Position stored as a character offset; 80-column pages for ASCII tables; L1/R1 page turns. Bottom window is non-focusable while a game runs because taking focus "can halve its frame rate" | n/a | +| Steam Deck overlay Guides (SteamOS 3.3) | Exact app id | No | Favourites and popular guides; later fixes for oversized images and spoiler tags. Gone from the desktop overlay, where the 2023 overlay instead added pinned windows and Game Notes ([PC Gamer](https://pcgamer.com/new-steam-feature-lets-you-pin-windows-over-games-including-guides-notes-and-web-pages)) | n/a | + +DroidDeck's advantage: we know the exact Steam app id of the focused game, so we need no title matching for Steam games. + +## Sources + +| Source | Access | Terms | Use | +| --- | --- | --- | --- | +| **Steam Community guides** | Listing: `steamcommunity.com/app//guides/?browsefilter=toprated\|trend&requiredtags[]=Walkthroughs`. API: `IPublishedFileService/QueryFiles` with `filetype=11` needs a key or the signed-in user's token. Guide pages (`sharedfiles/filedetails/?id=`) are server-rendered; sections are `div.subSection` with numeric ids | Authors own their guides under the Steam Subscriber Agreement. Cache per user, never redistribute | First source. Native section reader with stable anchors for chapter jumps and resume | +| **Steam achievements** | `IPlayerService/GetGameAchievements/v1/?appid=&language=` needs no key and returns names, icons, the hidden flag, global unlock percentage, and descriptions even for hidden achievements (checked on Elden Ring, Hollow Knight, Baldur's Gate 3). It is undocumented. `GetGlobalAchievementPercentagesForApp` also needs no key. The player's unlocks should come from the local client (`SteamClient.Apps` through CDP, or the client's stats cache); not yet tested | Valve | Achievement checklist with spoiler blur and difficulty from unlock % | +| **Wikidata** | SPARQL by Steam app id (P1733), or Epic (P6278) or GOG (P2725) id, returns the Fandom wiki (P4073), PCGamingWiki (P6337), GameFAQs (P4769), IGN (P5385), HowLongToBeat (P2816) and speedrun.com ids | CC0 | Crosswalk from the running game to every other site, including non-Steam games | +| **StrategyWiki** | MediaWiki API | CC BY-SA 4.0 | Full offline caching allowed | +| **Fandom wikis** | MediaWiki `api.php` per wiki | CC BY-SA (media excluded) | Per-game wiki pages, found through Wikidata | +| **PCGamingWiki** | `pcgamingwiki.com/api/appid.php?appid=` redirects to the page; MediaWiki API (anonymous Cargo queries are refused now) | CC BY-NC-SA 3.0 | Fixes and settings, in a "Fixes" section | +| **ProtonDB** | `protondb.com/api/v1/reports/summaries/.json`, no key | ProtonDB | A tier badge next to fixes | +| **GameFAQs, Neoseeker, IGN** | No API. GameFAQs terms forbid unauthorized scraping; its robots signals allow reference use but not AI training | Authors' copyright; Ziff Davis bans automated retrieval including AI use without permission | Browse in a WebView; save a page only when the user asks; never prefetch or send to AI | +| **VGMaps, Map Genie** | Images; Map Genie is an interactive site (Ziff Davis) | Maps belong to the games' owners; Map Genie bans automated retrieval | Save VGMaps images on request into the map viewer; Map Genie only as a live WebView | +| **YouTube** | Search URL (free) or Data API (100 quota units per search) | YouTube | Search link and embedded player, no downloads | +| **HowLongToBeat, TrueSteamAchievements** | No stable API ([unofficial library breaks often](https://github.com/ScrappyCocco/HowLongToBeat-PythonAPI/issues)) | Ziff Davis / site owners | Links only | + +Recommended order for the tab: Steam guides → achievements → StrategyWiki or the game's Fandom wiki (via Wikidata) → PCGamingWiki and ProtonDB → curated series sites → GameFAQs, Neoseeker and IGN in a WebView → maps → YouTube. + +## What DroidDeck already has + +Paths are under [`app/src/main/java/com/droiddeck/launcher/`](../../app/src/main/java/com/droiddeck/launcher/). + +- **Game identity.** `AgentGuest.activeSteamAppId` from gamescope focus (ignoring the Steam client, 769), passed to bottom pages as `runningGame`. Non-Steam store games are Steam shortcuts; `resolveAchievementsInFront` already maps the focused id to the store and store id through the library cache. +- **WebView base.** [`ui/BottomChatPage.kt`](../../app/src/main/java/com/droiddeck/launcher/ui/BottomChatPage.kt) loads Steam Community with a host allow-list, desktop user agent, fit-to-screen CSS and crash recovery. [`session/SteamWebLogin.kt`](../../app/src/main/java/com/droiddeck/launcher/session/SteamWebLogin.kt) imports the Steam client's own `steamcommunity.com` cookies, so guides load signed in without another login. +- **Achievements.** [`stores/StoreAchievements.kt`](../../app/src/main/java/com/droiddeck/launcher/stores/StoreAchievements.kt) is a provider base with a per-game cache; GOG and Epic implement it. [`ui/StoreAchievementsUi.kt`](../../app/src/main/java/com/droiddeck/launcher/ui/StoreAchievementsUi.kt) has the rows, tab and session panel. A Steam provider plugs in as source `steam`. +- **Per-game storage.** `SessionPrefs` already keys settings by game (for example `fpsLimit.game.`); the guide workspace fits the same pattern. +- **Game frame without MediaProjection.** `SessionActivity.copyGameFrame` and `AgentAttachments.gameFrame` capture the game image directly, which an optional AI helper could use with no capture permission. +- **Controller.** The dashboard forwards controller input to the game and has no D-pad focus today. The docked session menu has focus handling (`SecondScreenPresentation.dispatchMenuKey`, the `dockedMenuController` setting) and is the pattern to follow. + +## Design + +**Workspace per game.** One workspace per Steam app id (or store key): open guide, section, text anchor, recent searches, pinned maps, checklist ticks. Restored when the game gains focus. Cleared with the game profile. + +**Home of the tab** for the running game: + +1. Continue: the last guide at the last section. +2. Steam guides, top rated and trending, filterable by tag (Walkthroughs, Achievements, Secrets, Maps). +3. Achievements: locked first, missable flagged, hidden descriptions blurred. +4. Wiki: StrategyWiki or Fandom, from Wikidata. +5. Fixes: PCGamingWiki and the ProtonDB tier. +6. Saved: offline pages and maps for this game. +7. Search the web: GameFAQs, Neoseeker, IGN and YouTube with the game name prefilled. + +**Reader.** + +- Steam guides and MediaWiki pages are rendered natively from their HTML (sections, images, spoilers), not as a full web page: smaller, dark by default, and reflowed for the panel. +- Other sites open in a WebView with cleanup CSS, forced dark mode and a cookie-banner dismiss. +- Resume by text anchor (Game Twin's approach), falling back to scroll ratio. +- Table of contents from Steam section ids or the MediaWiki outline; find in page. +- Spoiler-safe by default: Steam `[spoiler]` spans and hidden achievements blurred until tapped. + +**Offline.** + +- Steam guides and wiki pages: save the parsed HTML and images per user. +- Other sites: MHT saved on request, with scripts stripped. +- Saved pages are listed per game and work without network. + +**Controller.** + +- The guide never takes focus or priority from the game (WalkThor's lesson). +- A dedicated chord or the docked-menu controller mode gives it the pad: right stick scrolls, L1/R1 change section, D-pad moves through links and the contents, B returns the pad to the game. +- Touch always works. + +**Battery.** Pause or destroy WebViews when the tab is not visible; the top complaint about Game Twin is a live page draining the battery behind the game. + +## Progress-aware help (later) + +Signals we can use without reading game memory: + +- Steam achievement unlocks with timestamps, matched to guide section titles. +- Steam rich presence (`steam_display`) and, for games that report it, [Steam Timeline](https://partner.steamgames.com/doc/api/ISteamTimeline) game phases and tooltips. Whether the client exposes these to CDP needs checking. + +An optional AI helper ("Where am I, what next?") would send the game frame plus those signals. Rules from Game Twin's feedback and the criticism of Xbox Gaming Copilot ([Tom's Hardware](https://www.tomshardware.com/video-games/pc-gaming/microsoft-says-gaming-copilot-uses-screenshots-to-understand-in-game-events-not-for-training-ai-models-optional-feature-can-be-turned-off-but-not-easily-uninstalled)): + +- opt-in, user's own key; +- one frame per question, with a visible indicator; +- crop out notifications and overlays; +- never send cached text from sources that forbid AI use. + +## Open questions + +- The most reliable way to read the player's Steam unlocks locally (CDP versus the client's stats cache). +- Whether Steam guide listings load reliably without the web API key, using the signed-in cookies. +- How much of a Steam guide's formatting (tables, embedded video) the native reader must support. +- Where the tab lives in swapped mode (it follows the panel to the top screen). + +## Milestones + +1. Steam guides list and WebView reader for the running app id, with a per-game last page. +2. Steam achievements provider and checklist with spoiler blur. +3. Native section reader, offline saving and the controller mode. +4. Wikidata crosswalk, wiki and fixes sections, maps viewer. +5. Progress-aware suggestions and the optional AI helper. diff --git a/docs/development/bottom-screen-region-mirror.md b/docs/development/bottom-screen-region-mirror.md new file mode 100644 index 0000000000..1b9d68397d --- /dev/null +++ b/docs/development/bottom-screen-region-mirror.md @@ -0,0 +1,107 @@ +# Bottom screen: region mirror + +Part of the [bottom screen research](bottom-screen.md). Researched 2026-11-26 against `main` at `d788afc12`. Not implemented. + +Show live crops of the game image (minimap, HUD, ability bar, dialogue box) scaled up on the bottom screen, and optionally remove them from the top screen. Regions are saved per game. + +## Use cases + +- **Minimaps** in open-world and action games (GTA, Monster Hunter, The Witcher, Elden Ring's compass): bigger on the bottom, gone from the top. +- **MMO and ARPG bars**: ability, health and buff bars moved off a crowded 6" screen. Megingiard users asked for 90° rotation for a Guild Wars 2 ability bar and for very thin crops for visual-novel text. +- **Racing**: rear-view mirror or track map on the bottom while the top shows only the road. +- **Strategy**: the minimap of an RTS or a city builder, where it is the main navigation tool. +- **Clean top screen**: hide every HUD element on top and keep them all on the bottom. + +## Prior art + +| Project | Capture | Notes | +| --- | --- | --- | +| [Megingiard](https://github.com/stormpanda/megingiard) (Thor) | A privileged shell helper creates a mirror display (hidden `SurfaceControl.createDisplay` on API 33; `AUTO_MIRROR` virtual display through `mirrorSurface` on API 34+), then SurfaceTexture → GLES → TextureView. Falls back to MediaProjection with a consent prompt on every start | Up to 10 cutouts. Crop box edited on the top screen, placement on the bottom. Edge handles, 1 px gamepad steps, snap guides, aspect lock (free, source-locked, destination-locked), rotation and flips, pinch zoom, circle shape, edge blending, temporal smoothing. Variance masks cut moving background out of HUD art. "Visual anchors" (a 256-point colour signature checked at 60 Hz) switch layout or freeze cutouts when a menu covers the HUD. FPS cap 10–120. Complaints: black mirror, consent prompts, helper pairing, DRM blanking ([docs](https://github.com/stormpanda/megingiard/tree/main/docs/features/mirror)) | +| [Heimdall](https://github.com/mastercook777/Heimdall-AYN-Thor-Assistant) (Thor) | MediaProjection into one virtual display, fanned out on the GPU: one EGL surface per "Portal", crop in the texture matrix | Two Portals. Per-Portal zoom, shape, fps, and an "Interactive" mode that sends one-finger touch back to the region. Curated [community profiles](https://github.com/mastercook777/heimdall-community-profiles) keyed by app, checked by SHA-256 | +| [WalkThor](https://github.com/nerf-herder-29/WalkThor) (Thor) | MediaProjection at half resolution into an `ImageReader`, drawn with Compose | Four regions per game stored as fractions of the screen and keyed by game title. Pick box keeps the bottom screen's aspect by default. About 30 fps. Its bottom window is non-focusable so the game keeps top-app priority | +| [OnTopReplica](https://github.com/LorenzCK/OnTopReplica) (Windows) | DWM thumbnails (`DwmRegisterThumbnail` with source and destination rectangles): a crop done by the compositor, with no copy | The usual way to put an MMO minimap on a second monitor. SteamDeckHQ's [AYANEO Flip DS review](https://steamdeckhq.com/news/ayaneo-flip-ds-review/) used it for a Monster Hunter: World minimap on the bottom screen | +| [wl-mirror](https://github.com/Ferdi265/wl-mirror) (Linux) | wlr-screencopy or dmabuf export with `--region` | Scaling modes fit, cover, exact, linear and nearest, plus freeze | +| gamescope PipeWire stream | An extra composite pass of the whole output, used by Steam for recording | Full output only, no regions. Still a precedent for a second output rendered inside the compositor | + +None of the Android tools can hide the region on the top screen: they capture the final display output, so any mask they drew would be captured too. Each also adds at least one composition cycle of latency and needs MediaProjection or a privileged helper. + +## Why DroidDeck can do better + +The game is composited by our own Wayland compositor in the app process. We have the game image as a Vulkan image before it reaches the display, so we can: + +- crop without screen capture, a consent prompt or a privileged helper; +- avoid the extra SurfaceFlinger round trip; +- mask the region on the top screen in the same pass; +- know the game's own resolution and our letterbox or stretch transform, so regions can be stored in game coordinates. + +## Current pipeline + +Paths are under [`app/src/main/cpp/waylandcomp/src/`](../../app/src/main/cpp/waylandcomp/src/). + +- gamescope runs nested in our compositor with its Wayland backend (`tools/linuxfs/overlay/usr/local/bin/droiddeck-session`). Client buffers arrive as dma-bufs or AHardwareBuffers and are imported as `VkImage`s ([`vk_present.c`](../../app/src/main/cpp/waylandcomp/src/vk_present.c)). +- `render_scene()` in [`compositor.c`](../../app/src/main/cpp/waylandcomp/src/compositor.c) builds a draw list; `vkp_render()` composites it, runs the effects chain ([`effects_chain.c`](../../app/src/main/cpp/waylandcomp/src/effects_chain.c): FSR, NIS, SGSR, CAS, CRT and others) and blits into one swapchain on one `ANativeWindow`. +- There is exactly one output window. Swapping the game to the bottom screen ([`BottomGameScreen.kt`](../../app/src/main/java/com/droiddeck/launcher/ui/BottomGameScreen.kt), `SessionActivity.putGameOnBottom`) re-targets that window to the Presentation's `SurfaceView`; it does not feed two surfaces. +- A gated zero-copy path ([`sc_layer.c`](../../app/src/main/cpp/waylandcomp/src/sc_layer.c), [`ZERO_COPY_SPIKE.md`](../../app/src/main/cpp/waylandcomp/ZERO_COPY_SPIKE.md)) posts the game's AHardwareBuffer straight to an `ASurfaceControl` child layer, with no composited image. +- `update_map()` holds the scene-to-output transform for each scale mode (letterbox, fit, stretch, fill, integer); `vkp_output_to_scene` and `vkp_scene_to_output` convert between them. `vkp_blit_image()` already blits into AHB-backed images. +- Screenshots use `PixelCopy` on the active `SurfaceView` (`SessionActivity.copyGameFrame`). +- The bottom-screen Presentation ([`SecondScreenPresentation.kt`](../../app/src/main/java/com/droiddeck/launcher/ui/SecondScreenPresentation.kt)) lives in the same process as the compositor, so a new JNI call can hand it a surface. The bottom KDE desktop runs a second compositor in another process and cannot share images without AHB IPC. + +## Technical options + +### A. Second output from the compositor (recommended first) + +Add a second, optional output to `vk_present`: its own `ANativeWindow` and swapchain, fed by a `nativeSetMirrorSurface` JNI call from a `SurfaceView` in the bottom Presentation. + +- After compositing the top frame, blit each region's source rectangle from the scene image into the mirror swapchain image with `vkCmdBlitImage` (or a small shader pass), and present it. +- The copy is small: a 1240×1080 target at 60 Hz is about 0.3 GB/s against roughly 60 GB/s of memory bandwidth on the Thor's SoC (an estimate, not measured). The real costs are an extra queue submit competing with a GPU-bound game, and pacing a second display. +- A shader pass makes nearest or integer scaling (pixel-art HUDs), masks, circles, rounded corners and colour keys possible. An existing upscaler (FSR EASU or SGSR) could scale a small minimap cleanly. +- The mirror runs at its own rate (default 30 fps, options 15 and 60) and skips frames when the bottom panel is behind. +- The top pass can fill, blur or dim the same rectangles to hide them. + +### B. Zero-copy layers + +Composite the top frame into compositor-owned AHardwareBuffers, then attach the same buffer to one `ASurfaceControl` child per region under the bottom `SurfaceView`, with `setCrop`, `setPosition`, `setScale` and `setBufferTransform`. + +- The NDK documents that each layer holding a buffer counts as its own reference, and that all of them must be released before the buffer is reused ([`surface_control.h`](https://cs.android.com/android/platform/superproject/main/+/main:frameworks/native/include/android/surface_control.h)). +- On API 33 (the Thor) the NDK `setBuffer` has no per-buffer release callback; release comes as a per-surface fence in the completion callback. All region fences must be merged before reuse, and the pool needs one or two extra buffers because the 60 Hz bottom panel holds buffers longer than the 120 Hz top panel. +- Avoid the Java `Transaction.setBuffer` release callback here: callbacks are keyed by buffer and per-layer frame number, so two layers showing the same buffer can collide. This is inferred from AOSP source, not tested. +- `ASurfaceControl_fromJava` needs API 34; on API 33 parent through `ASurfaceControl_createFromWindow` on the bottom `SurfaceView`'s window. +- Scaling is done by the display hardware with a fixed vendor filter (no nearest neighbour), and the number of hardware planes is limited. If they run out, SurfaceFlinger composites on the GPU instead, which still works. +- This only makes sense once the top screen itself is presented through AHB layers. Option A first. + +### C. PixelCopy prototype + +Crop a `PixelCopy` of the top `SurfaceView` at 5–10 fps into a bitmap. Useful for testing the editor UX and region presets quickly, but too slow for a real minimap, and it probably returns nothing when the zero-copy path puts the game on a child layer. + +## Coordinates and presets + +- Store rectangles in game-surface coordinates (gamescope's output, `DD_WIDTH`×`DD_HEIGHT`), not display pixels, so they survive changes to scale mode, FSR and output size. The compositor converts them each frame. +- Fractions of the screen alone break when the aspect ratio changes, because engines anchor HUD widgets to corners and scale by height or DPI ([Unreal anchors](https://dev.epicgames.com/documentation/en-us/unreal-engine/umg-anchors-in-unreal-engine-ui)). Store an anchor (one of nine corners, edges or centre), an offset and a size in units of the game's height. +- Key presets by Steam app id, aspect bucket (16:9, 16:10, 4:3, other) and an optional UI-scale tag set by the user. +- Later: a community preset catalog keyed by app id, curated and hashed like Heimdall's, offered as "Suggested regions" for the running game. + +## UX + +- **Editing on both screens.** The top screen shows the frozen frame with a crop box: edge and corner handles, D-pad nudge by 1 px and shoulder buttons by 10. The bottom screen shows placement with snap guides, aspect lock, rotation, flip, filter (smooth or sharp) and shape. +- **Limits.** Up to four regions per game. Long-press freezes a region; tap opens its options. +- **Hide on top.** Per region: off, fill, blur or dim. +- **Auto-hide.** Later, Megingiard-style colour anchors that hide or freeze regions when a menu covers the HUD. +- **Place in the panel system.** A new "Mirror" bottom-screen mode next to the dashboard and control modes, remembered per game (see per-game panel memory in the overview). Regions can also be shown in a corner of the dashboard. +- **Swapped mode.** With the game on the bottom screen, the mirror output goes to the top screen. +- Reuse DroidDeck's own settings components; no generic dialogs. + +## Open questions + +- Pacing and fencing of a second swapchain on a different display without stalling the top present. +- Interaction with glasses output, which already re-targets the single window. +- Whether regions apply before or after effects (a CRT shader on a minimap is probably unwanted). +- Battery and thermal cost, measured on the Thor and Duo with a GPU-bound game. +- Touch forwarding into a region (Heimdall's "Interactive"), mapped back to game coordinates. + +## Milestones + +1. PixelCopy prototype of the editor and per-game storage. +2. Second output in `vk_present` with one region and smooth scaling. +3. Multiple regions, shader filters, hide on top. +4. Presets keyed by aspect, suggested regions, anchors. +5. Zero-copy layers once the top screen uses AHB presentation. diff --git a/docs/development/bottom-screen-companion.md b/docs/development/bottom-screen.md similarity index 88% rename from docs/development/bottom-screen-companion.md rename to docs/development/bottom-screen.md index 1c9599e1e7..d31a544d66 100644 --- a/docs/development/bottom-screen-companion.md +++ b/docs/development/bottom-screen.md @@ -1,6 +1,6 @@ # Bottom screen: research and proposals -Researched 2026-11-26 against `main` at `d788afc12` (0.7.11). Implementation is not scheduled yet. This document records what other dual-screen Android projects put on the second screen, how they get their data, where DroidDeck stands, and the features we want to build. +Researched 2026-11-26 against `main` at `d788afc12` (0.7.11). Implementation is not scheduled yet. This document records what other dual-screen Android projects put on the second screen, how they get their data, where DroidDeck stands, and the features we want to build. Three proposals have their own documents: [region mirror](bottom-screen-region-mirror.md), [guides tab](bottom-screen-guides.md) and [companion API](bottom-screen-companion-api.md). The starting point was WULFF DEN's survey video [Dual screen Android apps are getting crazy](https://youtu.be/dAiuG2A-wkc) (2026-11-26). It covers the AYN Thor and Retroid Pocket Duo, and most of its apps come from the [GAFT list](https://andreyvelsk.github.io/GAFT) of Thor apps. @@ -131,28 +131,21 @@ Rearrangeable tiles on the dashboard: FPS limit, 60/120 Hz, per-screen brightnes ### 6. Region mirror from our compositor -Crop rectangles of the game image (minimap, HUD, inventory) and show them scaled on the bottom panel, saved per game. +Crop rectangles of the game image (minimap, HUD, ability bars) onto the bottom screen, saved per game, optionally hidden on the top screen. Other Thor tools need MediaProjection or a privileged helper and cannot hide the original; our compositor has the game image before display, so it can do both with no permission prompt. Recommended path: a second output in `vk_present` that blits region sub-rectangles, with zero-copy layers later. -- We own the game's output surface, so we can sample it on the GPU without screen capture, a permission prompt, or capture latency. Megingiard, WalkThor and Heimdall all need MediaProjection for this. -- Editing: drag a rectangle on a frozen frame on the bottom screen, pinch to zoom. Optionally hide the region on the top screen. -- Needs a design for how the crop reaches the bottom `Presentation`: a second output of the compositor, or a shared texture. +Details: [bottom-screen-region-mirror.md](bottom-screen-region-mirror.md). ### 7. Guides tab -A per-game guides tab: Steam Community guides for the running app id, pinned pages, and the last page reopened when the game returns. Save pages for offline use. +A per-game tab with Steam Community guides for the exact app id, Steam achievements as a spoiler-safe checklist, the game's wiki and fixes (found through Wikidata), saved pages for offline use, and a workspace that reopens at the last section. It must never take focus from the game, and pauses pages it is not showing. -- The chat WebView and its cookies are the starting point. -- Later: maps, and ProtonDB or DroidDeck compatibility notes for the game. +Details: [bottom-screen-guides.md](bottom-screen-guides.md). ### 8. Companion API for PC games -Let games and mods drive the bottom screen. In order of effort: +Let mods running in Proton drive native bottom-screen pages over loopback. Thor Pip-Boy (Fallout 4) and Grand Theft Companion (GTA) already run against DroidDeck as separate apps, and the Stardew, Skyrim and RimWorld ecosystems have servers we can adapt to. Plan: adapters for those first, then DroidDeck's own token-authenticated protocol with declarative pages and normalized state keys, then "run on bottom", then memory profiles only if needed. The existing racing, War Thunder and Elite Dangerous telemetry is the first set of built-in adapters. -1. **Loopback channel.** Mods inside the container (SMAPI, BepInEx, MelonLoader) publish JSON or WebSocket state that a bottom-screen page renders. First target: compatibility with the existing Stardew mod on `127.0.0.1:7786`, which gives a full showcase without writing a mod. Needs a check that loopback in the container reaches the app, or a relay through `droiddeck-agent`. -2. **Run on bottom.** A command like Armada's `armada-run-bottom` that opens a guest window on the bottom panel with touch, building on the KDE desktop mode. This lets a game's second window or a companion process (Kanto Gear's separate mode, second-monitor mods) appear there. Unity games could use `Display.displays[1]` if the bottom panel is exposed as a second X output. -3. **Declarative packages.** Eden Duo-style per-game packages: a UI manifest plus a data source (loopback, file tail, or memory reads locked to the Steam build ID). Distributed from a catalog repo and fetched in-app. Only after 1 and 2 show demand. - -The existing racing, War Thunder and Elite Dangerous telemetry follows the same idea and becomes the first set of built-in companions. +Details: [bottom-screen-companion-api.md](bottom-screen-companion-api.md). ## Related fixes