Skip to content

feat(viewer): mirror the picture to every display on Wayland boards - #3527

Open
vpetersson-bot wants to merge 3 commits into
masterfrom
feat/wayland-display-mirroring
Open

vpetersson-bot wants to merge 3 commits into
masterfrom
feat/wayland-display-mirroring

Conversation

@vpetersson-bot

@vpetersson-bot vpetersson-bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds an opt-in Mirror to all displays setting for the boards whose viewer runs under the cage Wayland compositor (Pi 5, x86, generic arm64). With it on, every connected display shows the same content, for example both micro-HDMI ports on a Pi 5.

Requested on the forum: Twin HDMI Outputs. This covers mirroring only. Separate playlists per output and spanning one canvas across screens are out of scope.

Why it doesn't work today

bin/lib/viewer/platform_wayland.sh launches cage with -m last, which enables a single output on purpose so that a display on the "wrong" port isn't left black. As a result, a second display never lights up.

How

  • Boot (platform_wayland.sh): reads display_mirroring from anthias.conf with configparser (same getboolean semantics as the viewer), launches cage with -m extend when it is on, and exports ANTHIAS_CAGE_MIRRORING so the viewer knows which mode this cage runs in.
  • Viewer (anthias_viewer/display_mirroring.py): reads wlr-randr --json and stacks every enabled output at the layout origin in one atomic wlr-randr call. Cage sizes its fullscreen view to the layout bounding box, so every screen shows the whole canvas.
    • If the screens share a mode, or offer a common one, all of them switch to the largest common mode for a pixel-exact mirror. The preferred mode wins; otherwise the highest refresh.
    • Otherwise each screen keeps its mode and is scaled to the smallest logical width.
    • Already-mirrored layouts produce no call, so there's no modeset flicker.
    • The call is retried on every asset-loop tick until cage answers, the same way the rotation retry works.
  • Confirmation: because a change restarts the display, Save opens a confirmation dialog (styled like the Reboot/Shutdown one) whenever the mirroring toggle changed. Cancel saves nothing; Save and restart display submits. Saves that leave the toggle alone never prompt. API clients (PATCH) are not prompted.
  • Toggling: cage only picks -m last / -m extend at startup. On reload, when the setting differs from the running cage's mode, the viewer exits from the main thread and restart: always relaunches the container in the new mode. Unrelated reloads and rotation changes never restart.
  • Overlapping outputs: a connector that cage enumerates while disconnected is harmless here, because all outputs overlap.
  • Rotation keeps working: _apply_wlr_transform already iterates over every output.
  • Server: display_mirroring is added to settings defaults (off), the Settings page (toggle shown only when DEVICE_TYPE is a cage board, via anthias_common.board.supports_display_mirroring), and the v2 device settings GET/PATCH as an additive optional field. No existing API field changes.

Testing

  • tests/test_display_mirroring.py covers:
    • parsing wlr-randr --json, including disabled heads and garbage input;
    • the layout planner: single output, already mirrored, side-by-side, largest common mode, preferred vs refresh, and the scaling fallback;
    • apply_mirror success and failure paths;
    • the board gate;
    • the viewer latch/retry and the restart-on-toggle logic.
  • Full unit suite passes locally (pytest -m "not integration"), along with ruff check, ruff format --check and mypy.
  • On a real Pi 5 (vc4, cage 0.2.0, wlroots 0.18.2, wlr-randr 0.4.1), with both HDMI connectors forced on at different resolutions (1920x1080 and 1280x720):
    • Before: only HDMI-A-2 is enabled and HDMI-A-1 is disabled (dark).
    • Setting off with this branch: identical to before (cage -m last).
    • PATCH display_mirroring: true: the viewer restarts once, cage runs -m extend, and both outputs sit at 0,0 on the common 1024x768 mode. Both vc4 CRTCs are active, and grim captures of the two outputs are byte-identical.
    • Rotation 90 while mirrored: applied live to both outputs with no restart, and the captures are still identical.
    • PATCH display_mirroring: false: one restart back to the single-output layout, with no restart loop.
  • Settings dialog, Pi 5 in headless Chromium (Playwright):
    • An unrelated save doesn't prompt.
    • Toggle + Save shows "Turn on mirroring?", and Cancel leaves display_mirroring false.
    • Confirming saves it, and the display restarts once into the mirrored layout (both CRTCs active at the common mode).
    • Turning it off shows "Turn off mirroring?" and returns to one output.
    • The container restart count stayed at one per change, with no loop.
  • Pi 4, regression check (eglfs, both HDMI ports forced on):
    • The toggle isn't rendered.
    • Forcing display_mirroring: true through the API does nothing to the viewer: no restart, same webview process, and DRM state identical to the stock-image baseline.
  • A headless wlroots run with mismatched virtual outputs (1080p + 4K) confirmed the scaling fallback renders the full canvas on both.

Not covered

  • Hotplugging a second screen after boot: the viewer container has no udev, so cage won't see it. Connect the screens before the device starts, or toggle the setting to restart. The UI hint says so.
  • Video performance on two 4K outputs at once on a Pi 5 wasn't measured. The testbeds are headless, so the forced outputs were at most 1080p.

🤖 Generated with Claude Code

Pi 5, x86 and generic arm64 run the viewer under cage with `-m last`,
so only one HDMI output is ever lit; a second screen on the other port
stays dark. Add an opt-in "Mirror to all displays" setting for these
boards.

With it on, start_viewer launches cage with `-m extend` so every
output is enabled, and the viewer stacks all outputs at the layout
origin with one atomic wlr-randr call. When the screens share a
resolution (or offer a common mode) they are switched to the largest
common one for a pixel-exact mirror; otherwise each keeps its mode and
is scaled to the smallest logical width. Rotation keeps working on all
outputs. Cage only picks its output mode at startup, so toggling the
setting makes the viewer exit and the container restart cage.

The setting is exposed in Settings (only on cage boards) and as
`display_mirroring` in the v2 device settings API. Off by default, so
existing installs keep today's behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
@vpetersson-bot
vpetersson-bot requested a review from a team as a code owner November 27, 2026 08:45
Copilot AI lite review requested due to automatic review settings November 27, 2026 08:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

Saving a changed "Mirror to all displays" restarts the viewer so cage
comes back in the other output mode. Ask first, the same way Reboot
and Shutdown do: Save opens a dialog only when the toggle changed,
Cancel saves nothing, and "Save and restart display" submits the form.
Saves that leave the toggle alone never prompt.

The hint now also says a screen plugged in after boot needs a restart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
Copilot AI lite review requested due to automatic review settings November 27, 2026 08:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

Co-authored-by: multica-agent <github@multica.ai>
Copilot AI lite review requested due to automatic review settings November 27, 2026 09:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants