Skip to content

MACBOX_VIEW_SWITCH: move the VM's window between desktop and stream without a restart (Reims 0036) - #20

Merged
0xdaniell merged 1 commit into
mainfrom
atlas/view-switch
Nov 14, 2026
Merged

0xdaniell merged 1 commit into
mainfrom
atlas/view-switch

Conversation

@0xdaniell

@0xdaniell 0xdaniell commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What

A restart-free view switch. With MACBOX_VIEW_SWITCH=on, macbox view local|stream moves the running VM's window between the host's Wayland desktop and the browser stream (headless sway behind Selkies) while macOS runs. Off by default; with the flag off nothing changes.

  • Reims 0036 (REIMS_VGPU_WINDOW_COMPOSITOR_FILE=<path>). The file names a Wayland socket.
    • Reims's UI thread connects to the socket itself and hands SDL the connection (SDL_PROP_GLOBAL_VIDEO_WAYLAND_WL_DISPLAY_POINTER). It holds SDL's events apart from its video, so the threads that wake it can push their events at any time.
    • It looks at the file once a second, inside the wait it already makes. When the file names another socket:
      1. Each window lets its input go and hides.
      2. Its render thread lets the swapchain and Vulkan surface go. This is a new detach handshake beside close/released, posted and never waited on.
      3. Once the last SDL window is gone, SDL's video restarts on the new connection and the windows open there as they first opened.
    • The displays, their sinks and the guest are untouched.
    • If the new compositor can't be reached, the windows go back to the old one.
    • <file>.on says where the windows are.
  • macbox
    • With the flag on, the container mounts the host's socket whatever the view, sway runs too, and up sets the variable.
    • view rewrites run/compositor and waits for run/compositor.on.
    • status reads where the window is.
    • Docs: setup (config table), architecture, patches README.

Tested

  • SDL3 in isolation, off the GPU in a container without /dev/dri: Reims's SDL 3.4.18, two headless sway 1.12 (pixman) and lavapipe, with the same thread shape as Reims (one Vulkan instance and device for the process, the surface and presents on a render thread). Over 100 moves in one process:
    • every move landed on the right compositor;
    • 61.4–61.8 presents/s;
    • first present 2–18 ms after the move starts;
    • file descriptors constant, RSS flat after warm-up;
    • wake events pushed from another thread every 1 ms through the moves: 35k pushes, none refused.
  • Reims: cargo test -p reims-vgpu-window --lib gives 111 passed, including new tests for the detach handshake and the socket file. cargo clippy --all-targets is clean for the crate. The patch applies on 7198fe6 + 0001–0035.
  • bash -n and shellcheck show nothing new.

Verified on Atlas (2026-11-14)

Hardware: Arrow Lake iGPU, Mesa ANV, macOS 26.7.1. Production build plus this patch; Atlas's own view script has the same logic as macbox view.

  • Moves: 3 round trips stream ↔ local, 6 moves, all landed.
    • Reims's own move took 2–21 ms (qemu.log). The whole command took 1.6–2.0 s, including macOS's mode change over ssh.
  • Uptime: the guest's boottime didn't change. A leased iOS Simulator stayed booted throughout (same launchd_sim).
  • Stream after the moves, 2560x1440, through the remote probe: 59.6 distinct frames/s, p95 19.7 ms, p99 27.2 ms. That matches before the switch (59.6–60.0/s, p99 22–23 ms at 1920x1080).
  • Guest during a 12 s drag: 97–147 presents/s in each view after every move. Window draws were 201–227/s.
  • Input after the moves: clicked and typed through the Selkies page; Spotlight opened and showed the typed "abc".
  • Not verified: local fps with the monitor on (the run was at night). macbox view end to end on a fresh macbox install. The macbox CLI side was checked with bash -n and shellcheck only.

Atlas deployment note

Atlas production will run this on its sched1desk build, which also carries the local REIMS_VGPU_STATS_FRAMES stats patch (not part of this PR). Its REIMS_VGPU_STATS_FRAMES line in vm.toml stays until the next natural VM restart. Drop it then.

@0xdaniell
0xdaniell marked this pull request as ready for review November 14, 2026 20:55
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T20:58:13.253330Z 5c6969b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@0xdaniell
0xdaniell merged commit b685f0c into main Nov 14, 2026
2 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c6969b08a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread macbox
qemu_pid() { $DOCKER top "$C" -eo pid,args 2>/dev/null | awk '/qemu-system-x86_64/ {print $1; exit}'; }
view() { cat "$RUN/view" 2>/dev/null || echo stream; }
stream_socket() { # sway's socket in the container, the stream's (display-up.sh starts it if needed)
echo "/tmp/xdg/$(in_c "$REPO/src/container/display-up.sh" | sed -n 's/^WAYLAND_DISPLAY=//p')"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Propagate display-stack startup failures from stream_socket

With MACBOX_VIEW_SWITCH=on, if display-up.sh fails (for example, while installing Selkies on first use), the enclosing echo masks the failed pipeline and successfully returns /tmp/xdg/ instead of a socket. Consequently, cmd_up writes that directory into run/compositor, starts the VM without a usable display, and reports success; previously, the direct assignment propagated the failure and stopped startup. This was reproduced with a failing in_c stub under set -euo pipefail. Capture and check the pipeline's result separately before printing the socket path.

Useful? React with 👍 / 👎.

Comment thread macbox
to=/tmp/host-wayland/wayland-0 ;;
stream) to=$(stream_socket) ;;
esac
[ "$(cat "$RUN/compositor.on" 2>/dev/null)" = "$to" ] && { echo "$1" >"$RUN/view"; say "view: $1 (already)"; return 0; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Replace pending compositor requests before returning already

If a user interrupts macbox view stream before Reims processes its request and then runs macbox view local, compositor.on can still name the local socket while compositor requests the stream. This early return reports local (already) and updates run/view without replacing the pending stream request, so Reims subsequently moves the window to the stream despite the successful local command. The same race occurs with overlapping opposite-view commands. Write the requested socket even when the acknowledgement already matches, so a previous pending request cannot override the latest selection.

Useful? React with 👍 / 👎.

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.

1 participant