How It Works
Why Native mutter D-Bus APIs
Section titled “Why Native mutter D-Bus APIs”Most “tablet as second screen” tools on Linux mirror an existing display, require X11, or rely on DisplayLink drivers / EVDI kernel modules to create a new Wayland output.
Mutter can already do this natively:
org.gnome.Mutter.ScreenCastprovidesRecordVirtual, which creates a real virtual monitor with no backing physical hardware.org.gnome.Mutter.RemoteDesktopinjects multi-touch events whose coordinates are relative to that PipeWire stream, so input lands on the right monitor with no geometry maths at all.
mutter Session Startup Sequence
Section titled “mutter Session Startup Sequence”The exact sequence is not obvious from mutter’s interface XML and must happen in this order:
- Call
RemoteDesktop.CreateSession()and read itsSessionId. - Call
ScreenCast.CreateSession({"remote-desktop-session-id": id}). Linking the two sessions is what makes injected input land on the virtual monitor. - Call
ScreenCast.Session.RecordVirtual({ modes, is-platform, cursor-mode }):is-platform: truemakes it a real monitor in Settings → Displays rather than a shared surface.modespins it to an exact resolution on GNOME 50+ so PipeWire cannot renegotiate it (GNOME 46–49 pins it via PipeWire caps negotiation).
- Subscribe to
PipeWireStreamAddedbefore starting, or the signal is missed. - Call
RemoteDesktop.Session.Start()— notScreenCast.Session.Start(), which mutter rejects for a linked session with “Must be started from remote desktop session”. Teardown is symmetric.
Zero-Reorder Video Pipeline
Section titled “Zero-Reorder Video Pipeline”Once the PipeWire node ID arrives, the host runs a zero-reorder GStreamer pipeline.
When VA-API hardware acceleration is available (AMD / Intel gst-plugin-va):
pipewiresrc → videorate → vapostproc (VAMemory NV12) → vah264enc → h264parse → appsink → USB / TCPWhen VA-API is absent, it falls back cleanly to CPU encoding:
pipewiresrc → videorate → videoconvert → videoscale → x264enc / openh264enc → h264parse → appsink → USB / TCPZero-Reorder SPS VUI Rewrite & RFI Recovery
Section titled “Zero-Reorder SPS VUI Rewrite & RFI Recovery”- In-flight SPS VUI rewriting: Keyframes have their H.264 SPS VUI rewritten (
max_num_reorder_frames = 0,max_dec_frame_buffering = 1) so Android’sMediaCodecoutputs decoded frames immediately without reorder buffering — even on OMX decoders lackingKEY_LOW_LATENCY. - Rolling Intra Refresh + RFI (Reference Frame Invalidation): Keeps steady-state streaming free of periodic full-screen IDR spikes while recovering from dropped or overwritten frames within a single round trip (~1 ms over USB).
- Adaptive Bitrate Control: Periodic
Statsreports from the tablet (decode_queue_depth, decoded/dropped frame counters, render timestamps) drive bitrate probing upward on healthy links and back off immediately if the decoder queue grows.
Four-Socket Transport Architecture
Section titled “Four-Socket Transport Architecture”Bulk video is never allowed to head-of-line block latency-critical touch input or power events. Extraspace opens four dedicated sockets (forwarded over adb on USB, or directly over LAN TCP):
| Stream | Port | Direction | Purpose |
|---|---|---|---|
| Control / Touch | 27183 |
Bidirectional | Handshake, video config, pings, RFI, adaptive bitrate stats, and high-rate touch events |
| Video | 27184 |
Host → Tablet | H.264 desktop video stream |
| Camera | 27185 |
Tablet → Host | H.264 camera stream decoded into /dev/video10 |
| Power | 27186 |
Bidirectional | Dedicated lock/unlock/suspend/wake sync (systemd-logind + org.gnome.ScreenSaver) |
Display Layout Persistence
Section titled “Display Layout Persistence”Because mutter assigns a fresh serial to every RecordVirtual monitor, GNOME cannot remember its position across reconnects on its own. xs-mutter watches org.gnome.Mutter.DisplayConfig, records the virtual monitor’s edge attachment, offset, rotation, and scale relative to its neighbouring physical display, and restores it automatically on reconnect.