55 kB 829 lines
7e68a437
⋯
compositor/XR.md
download raw history
at main Markdown

cont8nuum: second screen and XR #

Part of the compositor's notes (CLAUDE.md beside this file), kept apart for their size. The shell's side of XR (the charms bar's surface, cards) is in desktop/shell/PANELS.md, the toasts' row in desktop/shell/CLAUDE.md.

  • Second screen and XR (output.c, glasses.c, tracker.c, imu.c, math3d.h): [display] project = auto, pc, duplicate, second or xr, chosen from the shell's Second screen flyout (project.c, Super+P/XF86Display, the shell protocol's project action and project/project_choices appearance keys) or PC settings' Displays. Outputs have a role: NORMAL, MIRROR (Duplicate: the built-in panel's frames letterboxed, drawn in c8_xr_sink_frame), GLASSES and VIRTUAL. Glasses are told by EDID (make MRG, or XREAL in make/model; C8_GLASSES=NAME forces one, C8_BUILTIN=NAME the built-in panel), and get "Broadcast RGB" = Full (full_range: 1920x1080 is a TV mode, so i915's Automatic sent black as grey and the whole display glowed). In XR a headless output of our own (XR-1, [glasses] screen, on a headless backend added to the multi one) is the primary that the shell lays out on; its frames are kept (xr.picture, its texture xr.picture_texture with it; a scanned-out client buffer, Start alone on XR-1, is drawn from wlroots' own texture of it, wlr_client_buffer_get: importing its shm buffer read what the shell was redrawing, and Start flickered) and each glasses frame draws them in our own GLES2 inside a wlroots render pass, as a slate distance m ahead (1:1 pixels at the default), once per eye when the mode is 32:9 (SBS, ±ipd/2). Sinks stay out of the layout; the panel is off. Needs the GLES2 renderer. C8_XR_DUMP=FILE.png writes a glasses frame a second (headless can't grim a sink); C8_XR_DUMP_MS sets how often and a %d in FILE numbers them, to see an animation (each costs ~70 ms at 1920x1080, so 30 gives about every fifth frame). Tracking: c8_tracker_pose is all the drawing asks (a full pose, so 6DoF slots in); c8_tracker_update at the start of each glasses frame has c8_imu_read take what the stream has brought (its fd is watched only while connecting; a reader timer reads every READ_MS, 100, when no frames come, and the watchdog reads before calling the stream silent); imu.c reads the glasses' stream, TCP 169.254.2.1:52998 (frame layout at its top; kind 11 is motion at 1 kHz, kind 4's NaNs are another sensor), bound to the interface holding 169.254.2.x because Tailscale (an exit node without LAN access) routes link-local into tailscale0; Mahony fusion, gyro bias from quarter seconds where it barely wavers, i.e. while the glasses rest (a worn head sways ~0.01 rad/s, ten times the bias), and worn from whole seconds of a head held about still (WORN_*: spread under 0.03 rad/s, within 0.006 of the bias known, 5 % a time; the desk's bias went stale as the glasses warmed and everything drifted right), kept in ~/.local/state/cont8nuum/glasses-bias for the next session, and by temperature (the stream's, offset 70; TEMP_STEP 2 C bins, lines t BIN x y z rest worn after the first): one bias saved warm was wrong for the next cold start, always the same way, which is why it drifted right. thermal() once a second: a connection starts from the table's bias for its temperature, warming follows the table where both sides were measured at rest (TABLE_TRUSTED seconds; worn values waver too much to follow) with a slight pull to it, and the table takes the bias in use (fast at rest, slowly worn). Saved when the stream ends too. So the glasses want leaving plugged in, in XR, at rest from cold until warm once (10-15 min). A mock that warms 30 to 44 C with the bias moving 0.004 rad/s (scratch imu-warm.py, not kept): 17 degrees of drift in 90 s worn before, within 1 after one such rest. Untested in the glasses; whether the real bias repeats with temperature is unknown until the table of a real rest is read. Worn, following a drifting window with your head hides the drift from the worn learning (the mean it sees is the bias it has): only rest measurements, or a compass (kind 4's field, unused), can fix that. "Only gravity pushing" (the tilt pull and bias learning both need it) is within G_LEVEL of what the accelerometer has read lately (imu->g, G_TAU), not of 9.81. Every 10 s health() logs a "Glasses: tracking:" line (gaps, clock against theirs, how far ahead poses were predicted, frame gaps, g, bias, temperature) to the session log, ~/.local/share/sddm/wayland-session.log: read it first when tracking is said to go bad after a while (2026-11-26: wobbly after a few minutes worn, cause not found; never open a second connection to the stream while they're worn). A mock worn head (imu-sway: 0.003 rad/s bias on up, sway and noise, never still) drifted 16° in 90 s before, 4° and then held after; prediction by [glasses] latency (ms as at 90 Hz, scaled by the refresh, LATENCY_AT_MS: it is about a refresh and a half, and the 3D mode's 60 Hz with 90's number trailed turns, "everything further away"; untested in the glasses) from the refresh a frame starts in (frame_start: the last present on the display's beat, not the moment drawing began, which varied and shook the picture as the head turned) to the middle row (the glasses light rows top down over scanout ms, auto = a refresh, so the vertex shader places each vertex between a top-row and a bottom-row pose by its row, else a turn makes a window's bottom trail its top); a neck model in tracker.c ([glasses] neck = up, forward in m: the eyes swing round the neck's pivot, so a head tilt or turn moves them); the sensor sits ~40° tilted up in the frame ([glasses] tilt, measured as the axis of a head tilt, which is the line of sight: without it tilting the head turned the view sideways), applied after fusion (to_eyes); a fresh fix recentres (the world turns by heading only so it stays level, else turning the head tilts the slate; the slate goes to the pitch looked at, facing you), as does glasses-recentre (Super+Ctrl+Space). The axis map is x,-y,-z (head x,y,z from sensor axes on the 1 Pro+; up from gravity and a turn, the right/back sign only from wearing them: a recording can't tell it from a half turn about up); C8_XR_AXES tries another, tools/xreal-axes.py measures it worn. C8_XR_IMU=HOST:PORT reads a mock stream. Prediction turns by the gyro averaged over GYRO_TAU (6 ms), not one sample; [glasses] steady (default on) shows the fused orientation through a 1€ filter (imu->shown: 1 Hz cutoff held still, +100 Hz per rad/s, so a turn is never more than ~0.1° behind). Untested in the glasses. PC settings' XR page sets every [glasses] key (the snapshot sends them all; neck's two sliders write the one key; "Reset all to defaults" at the foot asks, then removes every one, outlines too). c8ui sliders can show their value (c8ui_slider_set_format). Recording (OBS through the ScreenCast portal): out of the layout the glasses had no wl_output, so only XR-1 (the shell's screen, no windows) could be captured. c8_xr_sink_frame gives them one (after XR-1's, so portal-wlr without a picker shares it; dropped when they leave XR) and wlroots' output capture copies their frames. With Monado the glasses are leased and c8 draws nothing on them, so that was gone (sharing had no screen, 2026-12-02): XR-VIEW (C8_OUTPUT_VIEW, glasses.c view_update), a headless output of one eye's size, out of the layout, portal-only like the above, described (under its name in the share picker) by the headset's own name: the OpenXR system name less Monado's "Monado: " (c8_xr_headset_named, from xrclient.c's connect; "Headset" until then; our driver's is "XREAL glasses"; tested nested: "Qwerty HMD"). Its pictures are Monado's own (2026-12-03): the left eye with every layer put together, the game too, read back by Monado's debug-mirror path and sent over a socket (our Monado commit's sharing; c8's end is xrruntime.c share_readable → glasses.c c8_xr_share_frame → view_commit, fitted into the view's size, black round it: a mode changed under a capture failed it). Monado reads back only while asked ('S' streams every 3rd frame, 's' stops, '1' one frame, 'R' after each one c8 took). Who asks: needs_frame is no sign of a capture (every wlr_output_schedule_frame fires it, and screencopy fires it before taking its lock; wlroots 0.20.2's source), so the view's frame (c8_xr_sink_frame) streams when its attach_render_locks is held, which a capture keeps until it has its picture; 10 of Monado's frames with no lock end it (a stream lets go between frames). Without Monado's frames (its socket not up) the view is drawn by us (draw_space, no game). Its xdg_output (xdgoutput.c) is past the layout's right edge: at 0,0 grim -o XR-VIEW composited XR-1 over it, all black. Tested nested (qwerty head, hello_xr): grim of XR-VIEW gives Monado's composite; untested on the glasses and through the portal. Only xdg-desktop-portal-wlr sees it (c8_output_global_visible, by /proc exe, in the global filter; capture_global, set before it's made, as making it announces it, and the filter goes by the global's data, not wlr_output.global, set only after). Every other output out of the layout has its global destroyed (output.c layout_remove): hiding the glasses' layout global behind the filter as they left the layout entering XR killed any client that bound it meanwhile ("global wl_output is unavailable": apps, possibly Xwayland or the shell), which left windows missing after switching. Tested headless: desktop, XR, desktop, XR, desktop with a foot and the gallery from each, none lost, Alt+Tab to each. And xdgoutput.c replaces wlroots' xdg-output manager, which asserts an output is in the layout (c8 crashed). Layer surfaces asking for an output out of the layout get the primary. [glasses] outlines (PC settings' XR page) draws the space for such recordings: a floor grid FLOOR_M under the eyes, a frame round every slate and a line from each to the floor. Start opens at [glasses] start_distance (2.5 m, as the windows' distance; both chosen in the glasses) and the shell's screen widens to Start's tiles while it's up (the shell protocol's set_start_width, sent from relayout; c8_xr_shell_size, also for a changed [glasses] screen, 8192 at most), so nothing scrolls sideways there. Its pose puts its top left corner in from the view's by its real size at that distance (atan(w/2 m / d)), so a wide or far Start doesn't start off to the left. Tested headless with a mock IMU (a still head, tilt = 0): 1280x720 widening to 2068 and back as Start closes and opens (start the app with c8 -s foot, then Super taps), the glasses' view at 3 m. The shell's screen is drawn over the windows, so it's drawn nearer than any window that may be under it (shell_front in hologram.c, every frame: within SHELL_NEAR_DEG of its middle, SHELL_AHEAD in front), its pixels smaller by as much (xr.shell_drawn/shell_m, c8_holo_shell_pose; picking uses them too), so one eye sees no change and in 3D it's never further than what it covers. shell_pose stays where it was placed. Tested headless in SBS: Start's shift between the eyes went from 51 px (2.5 m) to 83 px with a window carried to ~1.55 m, its size unchanged. Start closing in the glasses sweeps away (the shell's closed_at, CLOSE_MS, the opening in reverse) while the compositor keeps its layer up START_CLOSE_MS (450, room for the shell's first frames being late; start_close timer; node_at skips Start whenever !start_visible), then recentres the shell's screen. XR-1 runs at the glasses' refresh (c8_xr_shell_size; at headless's 60 the shell's animations stepped unevenly in the glasses' 90). A toast after 10 s without motion. A real session's sound moves to the glasses' USB card while they're in XR and back after (xr_audio, pactl). Frames (2026-11-26): on battery in the balanced power mode (cores at 800 MHz, the GPU at its slowest) the glasses got 70-95 of 120 frames a second with a video playing, 84 of 90 at 90 Hz, 119 of 120 in performance mode: that was "wobbly after a few minutes" and "low framerate turning my head". The cause was the GPU: i915 left it at 300 MHz of 1100 and a frame took 4-7 ms of it. data/udev/70-cont8nuum-xreal.rules holds gt_min_freq_mhz at 650 while the glasses are plugged in and puts it back on unplug (by hand, 650 gave 88 of 90 with the video for about 1.3 W, 1100 a little better, 89.5, for 2.7 W more; the rule seen working on a replug). What a glasses frame costs was cut too: the shell's screen is drawn only where something is on it (shown_box walks the scene for XR-1 at each of its frames, xr.picture_shown; nothing at all with Start closed, where it was a full keyed layer every frame), the floor grid of outlines is one draw of vertices made once (make_floor, the lines program; it was ~400 draws), and nothing waits for the GPU (a glFinish tried for i915's boost didn't boost and held the loop ~3 ms a frame): its time comes from a timer query (GL_EXT_disjoint_timer_query through eglGetProcAddress, answered a frame or two later). pace_frame logs a "Glasses: frames:" line every 1000: a second, how many late, then average/most ms from the refresh to our turn (wait), sensors, drawing, handing over (the commit) and GPU. Tested headless (the floor, Start up and gone, the line); untested in the glasses. Not tried: a high-priority GPU context (needs CAP_SYS_NICE on c8), so a video's GPU work can still get in front of a frame. The user won't have performance mode held for XR; their config.ini has [output DP-1] mode = 1920x1080@90 (the glasses came as DP-2 one day and ran at 120: [output glasses], output.c's output_config, applies to glasses with no section of their port's name; tested headless, 2026-12-02). hidraw needs data/udev/70-cont8nuum-xreal.rules. Holograms (hologram.c, c8_xr_active = the virtual output exists): each window is a slate of its own. arrange_holograms (view.c) gives it a slot of the layout far off every output (SLOT_ORIGIN, 8192 px each, the window 2048 in so popups fit; popups are unconstrained to the slot), its own size (1280x800 new, or its flat size), every one on; the desktop rect is off. Poses are in the recentred world, a new window where you look (cascading 8° on from another), a dialog just in front of its window and moving with it. glasses.c draws each window's surfaces from their textures (wlr_scene_node_for_each_buffer), furthest first, an accent frame round the focused one (edges soft: each quad grows AA_MARGIN px in the vertex shader and cover() fades the sides that are a slate's edge over a screen pixel by fwidth, GL_OES_standard_derivatives, hard without it; sides where pieces of a window meet stay hard, and the frame tucks a pixel under the window so no seam shows; the pointer's dot too), and sends their frame callbacks itself (no output shows them; the glasses draw every frame in XR). A window wholly out of view (out_of_view) isn't drawn and gets its frame callbacks every OUT_OF_VIEW_MS (200) instead; the focused window and ones being shared are always drawn; then the shell's screen in front, keyed so black is clear, Start opening with its top left START_INSET_PX in from the view's (c8_holo_start_shown; back centred on your gaze when it closes) and else drifting after your gaze. The shell gets the xr appearance key (v7): Start then draws no background (clear, so the room shows through) and the windows dim under it (xr.dim, eased). A tile's launch splash is a slate of a new window's size in a slot of its own (c8_holo_splash_box, configured by shell.c) where the window will open (free_pose); Start goes as it shows, and the next window (within 10 s) takes its pose. The shell grows it from its middle. A frame of it can be a scanned-out client buffer covering part of it (a lone toast): picture_src/dst keep where. XR-1 locks software cursors, so the pointer is always in its frames (else a scanned-out Start or charms bar left it out). The pointer is a ray (xr.aim): mouse motion turns it, the head carries it along at the edge of the view; pick finds the nearest slate it meets (the shell's screen first, where something is there: c8_node_exists_at), and the cursor is put at that point of the slot (cursor->x/y set by hand, wlr_cursor won't leave the layout) or of XR-1, then c8_pointer_motion does the rest. There's no cursor image anywhere in XR, the shell's screen too (client requests are ignored, c8_holo_cursor_hidden), and glasses.c draws a dot. While a button is held the ray keeps to the pressed slate's plane. For SCROLL_HOLD_MS after a scroll (xr.scrolled_ms) the head's sway doesn't move the pointer within SCROLL_SLOP_PX: Chromium ends a touchpad scroll on any motion, and every glasses frame re-aimed the ray. Super+drag carries a window, Super+wheel moves it nearer/further. Tested headless (mono, no IMU: C8_XR_IMU=127.0.0.1:9, wlrctl pointer for the mouse): one and two windows, Start, a toast, pointing, clicking, Super+wheel. Live in the glasses: pointing, Super+drag, right-click menus. X11 windows: X coordinates are 16-bit and Xwayland's pointer is kept on its root window (the layout), so in a slot an X app never saw the pointer; X is told every X window is at XR-1's corner (x_origin, xwayland.c), and the one the pointer enters goes on top in X (x_raise_pointed, on the seat's pointer focus change), since X picks the window by its stacking, not the surface. Crossing from one X window to another can give the new one a motion at the old one's last point first (Xwayland sees the restack and the enter on two sockets). A slate bigger than XR-1 loses the pointer past XR-1's size. Tested headless (two love windows, SDL_EVENT_LOGGING=2). Untested: X11 menus (placed by the client in X coordinates, so on the shell's screen, not by the slot). The charms bar: in XR the shell makes a surface of shell protocol's bar role (panels.c bar_update: clock and status, Switch/Start/Settings (no Search: from the bar it only opened Start's search behind it), Volume and Brightness, the tray two high; only its size is the shell's) and shell.c puts it in a slot of its own (BAR_SLOT, c8_holo_bar_box), its node enabled only while it shows. bar_frame (hologram.c) brings it up when the gaze goes BAR_DOWN_DEG (18°; 30° wasn't comfortable) down, BAR_DIST (0.8 m) away, a little under the gaze and level with your heading, at the windows' pixel size (c8_holo_bar_m). It's placed by the charms, not the surface's middle (bar_place: BAR_ROW_PX, the shell's bar height, at the foot of the box): with a card already on it the middle went under the gaze and the charms below the view. It sinks as you look lower, but not while a card is on it (bar_grabbed): looking from the card down to the charms sank them out of view, again and again. Sinking is measured from bar_sink_from (the charms' pitch, or lower: the lowest you looked while a card was up), so a card closing doesn't make it catch up with a jump. It turns with you past 20° until it's back in front of you (bar_turning, within BAR_CENTRED_DEG: stopping at 20° left it off to one side) and goes above BAR_UP_DEG (not while a press on it is held; with a card on it, BAR_UP_OVER_DEG over the card's top instead, bar_up_pitch: a card can reach higher than 10°). Coming up it fades in and rises BAR_RISE_M into place over BAR_IN_MS (260), going it fades over BAR_OUT_MS, both in time (bar_t, bar_fade eased, drawn at bar_drawn; picking keeps bar_pose): the old per-frame step was over in ~10 frames at 90-120 Hz and read as appearing at once. It curves round you: drawn in CURVE_STRIP_PX strips on a cylinder C8_BAR_CURVE_R (= C8_BAR_DIST, 0.8 m, so the axis runs through your eyes and all of it is as near and faces you; at 1.2 m it looked flat) round an axis along its up (glasses.c curve_strip), picked on the same cylinder (ray_curved). A taller surface grows upwards (bar_h): the charms stay put. The shell's surface is clear but for the bar and what's above it (panels.c bar_above_set, centred over the bar, BAR_ABOVE_GAP apart): the switcher as a row of pictures, every card and flyout (show_on_bar), and room for the quick tiles' level The switcher and cards take the keyboard (grab_keyboard on the bar, c8_holo_bar_grab, bar_grabbed): with the bar down (Alt+Tab) it comes up where you look, pinned until let go (bar_grab_pinned); up from looking down (a button on it) it isn't pinned, so looking up puts it and the card away; pinned by Super+C it stays pinned after the card goes. The bar going from view or a press elsewhere sends dismissed (c8_shell_bar_dismiss). Tested headless (no IMU, Super+C, wlrctl): centred and curved, Alt+Tab's row and its release, the Power card and Escape closing it. It's picked before anything else; the ray goes to its middle when it comes up and moves with it after. The charms binding (Super+C, a swipe in from the right) pins it where you look (c8_holo_charms) until pressed again, a press elsewhere, Start or a panel. While it's up from looking down, what opens (Start, panels, new windows) goes ahead at centre_pitch, not down there (look()), and a press on it doesn't just dismiss an open panel (c8_shell_dismiss). Tested headless with a mock IMU (gravity alone, pitch from a file; fusion takes ~15 s to settle there): showing, sinking, hover, the Start charm opening Start ahead, Super+C pin and unpin, looking up hiding it. Untested: the tray in it, the glasses, bar_place and the no-sink rule with a moving head (headless the card opening left the bar where it was). The quick settings tiles are on it too (see c8-shell). The HUD: in XR the shell's osd surfaces (toasts, the level box) aren't on XR-1 but in a slot of their own as big as it (HUD_SLOT, c8_holo_hud_box; place_panel in shell.c puts them there), drawn as one slate whose bottom edge eases after a line HUD_LOW (0.6) of half the view under its middle (at the very bottom they were out of sight in the glasses), but HUD_OVER_BAR_DEG above the charms bar's top (and what's above it) while it's up, middle after middle (hud_frame: HUD_RATE, HUD_DIST 1 m or in front of the nearest window, its pixels scaled to look the same size), held still while the ray is on it so a toast can be clicked; picked after the bar (hit_hud, c8_node_exists_at), the cursor set by hand like a window's. The shell lays them out along its screen's bottom. Beacons: a window that maps out of view (c8_holo_view_mapped from c8_view_mapped, decided once it's placed) shows its icon towards the edge of the view on its side (its middle at BEACON_REACH, 0.6 of half the view: at 0.85 the icon and chevron, nearer than the windows, fell out of one eye's view and into the glasses' blurry edge; 0.6 untested worn), with a chevron pointing the way (c8_holo_beacon, glasses.c draw_beacon; the tile in its tile colour from c8_slatebar_beacon, its first letter when no icon loads), for BEACON_MS (3 s, fading over the last quarter) or until it's in view. Tested headless (mock IMU, wlrctl): toasts side by side and the level box above them, clicking a toast, the beacon for a window opening at a kept place 60° off and its fade. Headless XR tests must set XDG_STATE_HOME to a scratch dir: c8 writes the gyro bias and placements there, and a mock IMU's still head overwrote the real bias once. The slate bar (slatebar.c draws it into a texture per window, kept until how it looks changes; hologram.c takes its input; glasses.c draw_chrome): a row of tiles C8_SLATEBAR_H px high, C8_SLATEBAR_GAP under the slate on its plane, from its left edge (c8_slatebar_width), on the focused window, the one pointed at last (xr.chrome_view) and one being moved or resized; never under Start or locked. Accent tiles on the focused one, dark on others: icon and title (TITLE_MIN-TITLE_MAX wide), then Follow me, Move, Minimise, Maximise, Close each a tile of its own (Resize was one too, gone as the corner does it); and an L-shaped handle round the bottom right corner. A theatre's controls show with the ray within THEATRE_REVEAL_PX of its bottom. The ray on it puts the cursor nowhere (the app gets a leave). Dragging the title carries the window (as Super+drag), the corner resizes it (held only); Move does the same until the next click (move_sticky, that click's release swallowed), the wheel alone moves a carried one nearer/further. Buttons act on release over them (press_view). A resize sets holo.width/height from the ray's travel on the plane and re-arranges; the top left corner stays put (holo.anchor, kept ANCHOR_MS after so a late app doesn't jump). Follow me (holo.follow) drifts the window after your gaze once it's FOLLOW_ME_DEG off. c8_pointer_motion unsets the cursor image whenever c8_holo_cursor_hidden (a rebase used to leave an arrow on the shell's screen). Tested headless (no IMU, wlrctl): hover, Move with the wheel, Resize, Follow me drifting back, Close. Tried in the glasses (2026-11-23): "feels pretty decent", sizes and thresholds kept. Dragging the title or the corner isn't confirmed (wlrctl can't hold a button). Minimising is XR's only (flat, chrome.c's title bar has just Close: an app out of the way is one you switched from, and c8_view_minimize, which window lists can still ask for, only sends it behind the others). The slate bar's Minimise sets holo.minimised on the root (c8_holo_minimise, its dialogs go with it): not drawn (glasses.c ranks it as unseen, and it gets no frame callbacks at all, as a hidden window flat: the switcher shows what it last drew; one being shared keeps the OUT_OF_VIEW_MS ones), not picked, and c8_top_view skips it, so it never has the keyboard and with none left Start comes up. c8_focus_view restores it, so picking it anywhere does (switcher, a Start tile, activation, a new dialog of its own); leaving XR restores all (c8_holo_restore_all). Each one's icon tile (c8_slatebar_beacon's, C8_MINI_PX) is drawn by the compositor in a row over the charms bar's surface, round its cylinder (glasses.c draw_minimised, hit_mini in hologram.c picks them after the bar; xr.aim_mini/press_mini), in the order they were put away; the one pointed at has a white frame and its title above (c8_slatebar_label), and a click (c8_view_activate) brings it back where it was, flying to you if that's out of view. The HUD keeps above the row. Tested headless (mock IMU, wlrctl): the button, Start with none left, the icon, its hover and click, wlrctl toplevel minimize and focus; flat, the title bar with Close alone. Untested: the glasses, several icons, the row with a card or the switcher above the bar, the row while Start is up (a still head can't look down). Windows going and coming back (glasses.c): minimised, a slate shrinks to AWAY_SCALE, drops AWAY_DROP_M towards the bar's row and fades over MINIMISE_MS; restored (holo.restored_at, set by c8_holo_restore only for one that was minimised) it comes back the same way over RESTORE_MS (away(), no frame or slate bar meanwhile). Closing, c8_xr_window_closing (first thing in c8_view_unmapped, while geo is still there) locks each surface's last buffer as a ghost (ghosts, 8 at most, 16 surfaces each) and it shrinks to CLOSE_SCALE and fades over CLOSE_MS where the window was. Its scene nodes are disabled by the time the unmap reaches us, so ghost_walk goes into disabled nodes; wlr_scene_node_for_each_buffer found nothing. Ghosts go when XR does. Tested headless (frames every ~20 ms, wlrctl toplevel minimize/focus/close): all three. Untested: the glasses, a closing window with popups open. A press off Start (on a window round it or on nothing: c8_holo_button, none of the shell's screen, the bar or the HUD under the ray) puts it away and focuses a window pressed; with no window Start stays. Tested headless: a press above Start, foot focused after. Placements (placement.c): where you leave an app's window is kept by app id in ~/.local/state/cont8nuum/holograms.ini (yaw/pitch in degrees in the recentred world, distance, width, height, follow; c8_state_path in util.c, also the gyro bias's), written 1 s after the last change and at exit (c8_placement_flush), 256 apps at most. Saved on put down, resize (where it will be at its new size), Follow me, the wheel, and on close, but only for a window you placed or that opened from a kept place (holo.kept), so an untouched second window closing last doesn't undo the first. An app's first window opens there (place_remembered, over the splash's spot), size and follow too; a kept place more than REMEMBERED_DEG (70°) from where you look opens where you look at its distance. Tested headless: kept across closing (with an untouched second window closing last) and a restart of c8. Untested: the glasses; the launch splash still shows at a fresh spot. Theatre: a window asking for fullscreen (wants_fullscreen, noticed in c8_holo_window_box, which now says fullscreen to view.c's configure) gets a slate THEATRE_FILL (90%) of the view where you look at the default distance (so its pixels are the glasses' own), Follow me off; its pose, size and follow are kept (holo.before_*) and come back when it leaves fullscreen, and placements save those, never the theatre. While it's the focused window (c8_holo_theatre) the others dim to DIM_BY_THEATRE and it has no accent frame; its bar shows only with the ray within THEATRE_REVEAL_PX of its top (xr.reveal_view) or on the bar. Maximise puts any window there and takes it out again, an app's own fullscreen too (holo.theatre_ask, 1 or -1 over what the app asks, cleared by its next fullscreen request: one we put there is told it's fullscreen, so its own key for that brings it back; the button shows two boxes meanwhile). Tested headless: foot maximised and back by the button. Untested: maximising mpv and leaving with its f, X11. Tested headless with mpv --fs (--vo=gpu; --vo=wlshm dies with a viewport error in a plain window too, not looked into): the theatre, the bar revealed, f back to a window. Untested: the glasses, X11 fullscreen. Summoning (c8_holo_summon, through c8_view_activate = focus + summon; plain c8_focus_view never summons): a window picked from elsewhere (the shell's activate: switcher, a Start tile of a running app, a toast; xdg-activation; the foreign-toplevel lists; X11 activate; Super+; PC settings launched again) whose centre is more than SUMMON_VIEW of half the view from where you look flies there (holo.summon, SUMMON_RATE of the way a frame, keeping its distance); one in view stays. Clicks and focus passing on close don't summon. Tested headless: Alt+Tab to a window in view (stays), back to one carried out of view (flies in). Untested: the glasses. Background ([glasses] background, a picture's path; the skyin glasses.c): a 360 picture round you behind everything, on a sphereSKY_M (50 m) round the head, dimming with the windows (xr.dim), not drawn locked. 2:1 is the whole sphere; a wider one is a strip all the way round, as high as its shape says, with its horizon where background_horizon (% down it, default 50) says, and the rest of the sphere filled from its edge colours (sky_edges: 64 averages round each edge going to their mean at the pole, the picture fading into them). c8 reads no pictures itself: c8-panorama FILE MAXW MAXH(panorama.c, libexec, gdk-pixbuf) writes RGB into a memfd, shrunk to the glasses' pixels per degree all round (or GL's biggest texture), its size written last, and a pipe on fd 3 closing says it's done; the rows then go to the textureSKY_UPLOAD(8 MB) a frame and it fades in.sky_updateat each glasses frame follows the config (a new path loads again, a new horizon only remakes the mesh);sky_dropfrees it leaving XR (it makes the renderer's context current for that). NASA's 20000x5389 Curiosity panorama: 6 s to decode, 13647x3677, 150 MB of texture, horizon at 9. PC settings' XR page has Background (Choose a picture through the portal, None, the horizon slider). Tested headless (mock IMU, a still head): that picture, a 2:1 one, changing and removing it live, the horizon, out of XR and back; the page wide and at 480. Untested: the glasses (what a bright background does to reading windows there), 3D, the frame time it costs, the picker choosing one. Plan (all of its phases 1-4 now done; 6DoF, hands, spatial sound later):~/.claude/plans/replicated-dreaming-frost.md`.
  • stereo.c serves cont8nuum-stereo-v1 (any client; c8-video uses it): a surface's object says its buffers hold both eyes' pictures (set_layout: side by side or top and bottom, which is first) or a sphere (set_projection: 360 or the front 180), applied as said, not with the commit. Only XR does anything with it, and the shows event says what (bits stereo: two eyes are drawn, the glasses in a 32:9 mode; surround: any XR; 0 flat, sent from c8_xr_update), from draw_space each frame. glasses.c: draw_surface gives a tagged surface's quad the eye's half of the buffer (stereo_src, the left eye's when one eye is drawn); the newest mapped sphere surface of a window that is up (c8_stereo_surround) isn't drawn on its window but on a sphere round the head in the background's place (draw_dome: the background's vertex shader and rings, a mesh of its own, SKY_M away, 2D and external textures; the half sphere discards what is behind), its window never counted out of view. Flat, a tagged surface is drawn like any other, so clients only tag while shows says. Captures of such a window (the switcher's picture, sharing) show the buffer whole. Tested headless (two headless outputs, the glasses' at 3840x1080, a still mock head): a side-by-side clip with LEFT in one eye and RIGHT in the other, a 360 one round the view with the window's controls over it. Untested: the glasses, top and bottom, 180, an external (dmabuf) texture on the sphere, leaving XR mid-video. Show as 3D (2026-12-02), for apps that don't speak the protocol (games, emulators, Xwayland): the slate bar's tile between Maximise and Close (C8_SLATEBAR_STEREO, stereo_glyph: "3D" flat, two boxes side by side or one over the other) steps view->holo.stereo round flat, side by side, top and bottom; glasses.c's slate_draw.main crops the window's own surface by it (stereo_src now takes the layout), a client's own tag with a layout winning. Each half is drawn over the whole window, so it suits half-width side by side (a full-width one looks squeezed: make the window narrower). Kept per app in holograms.ini as stereo = side-by-side|top-bottom (c8_placement_put_stereo; an entry can have it without a pose, has_pose) and given to every window of that app when placed (place_root). Tested headless (two outputs, the glasses' 3840x1080, no IMU, mpv showing a LEFT|RIGHT picture, wlrctl pointer move -84 430 from the window's middle onto the tile): remembered side by side at start, one eye each; clicks to top and bottom, then flat, saved. Untested: the glasses, an Xwayland game.

The Monado path: VR games (2026-12-02; on main since 2026-12-04) #

Plan and its reasons: MONADO-XR.md beside this file. [glasses] runtime = auto (default: Monado when ours is installed), monado or builtin (today's direct path, unchanged; also what runs while Monado is restarting and after it fails for good).

  • xrruntime.c: in XR with the glasses' output there and Monado wanted, c8_xr_update → c8_xr_runtime_update lets go of our IMU (c8_tracker_set_wanted false: the glasses take one connection, and the driver opens its own), offers the output for lease (lease.c; only DRM outputs, wlr_output_is_drm) and starts C8_BINDIR/monado-service through c8_spawn_client_child (util.c: one fork, so c8 has the pid; reaped by a pidfd) with XRT_COMPOSITOR_FORCE_WAYLAND_DIRECT=1 and XRT_COMPOSITOR_WAYLAND_CONNECTOR= the output's name (Monado's comp_window_direct_wayland.c takes the named connector, else the first). While it runs only it sees the lease global (c8_lease_global_visible in the global filter). The output is leasing meanwhile (role GLASSES, out of the layout, nothing of ours drawn: c8_xr_sink_frame returns). Granting destroys the wlr_output; lease_request sets xr.leased first when the glasses are among the connectors, so project_possible still counts them and XR stays; the wlr_drm_lease destroy signal clears it and the output returns through new_output. While leased the glasses count as an external screen too (project_possible), else "PC screen only" wasn't possible and leaving XR fell back to XR. And c8_xr_update runs again when called inside itself (update_again): stopping Monado ends its lease at once, from within the update, and that call was dropped, so the laptop's screen never came back (the real session went black, 2026-12-02; tested nested since, to PC screen and back to XR on builtin). Leaving XR or switching to builtin stops it (stopping: not counted as a failure) through its stdin, a pipe of ours (c8_spawn_client_child's stdin_out): Monado's main loop ends on anything there, its own way to stop. Not SIGTERM: something in it catches that (/proc: SIGTERM caught, SIGINT ignored, as SDL's quit handler leaves them) and it never stopped. Its connection isn't cut meanwhile (it closes it as it goes): cut, its compositor lost its surface mid-frame and crashed. And while it stops every window is told its frame is done (drain, every 16 ms): nested, its compositor presents into a window of ours that nobody draws once XR is left, and its teardown waited on that present for good (gdb: teardown_all joining the compositor thread, in vkQueuePresentKHR). Tested nested (2026-12-02): it ends with status 0 in ~40 ms, to PC screen (the laptop's screen back, Start opens) and to builtin XR (c8 drawing the glasses again). On the glasses, where it presents to the lease, untried. It exiting by itself: started again after 3 s, five times; then failed for the session, a notification, builtin. The same when it runs but the overlay can't join it 20 times (5 s; tested: a Monado built without GLES). Nested (no DRM, no lease manager) it is started all the same with the test's own XRT_* environment, for the overlay to be tested. The child has PR_SET_PDEATHSIG SIGKILL (util.c): a Monado that outlived a killed c8 held its pidfile and socket, and every later one quit "already running" (2026-12-02).
  • Leased or not, target is the output it was started for; another one there (the lease ended, the output came back) means it's going. Keyed on offered instead, a nested run (nothing to lease) took every later c8_xr_update for "after a lease": c8 drew the glasses beside Monado and turned its own IMU back on (2026-12-02). The output coming back while Monado runs (the glasses' 3D button replugs them as a new display) restarts Monado for it, and until it's back nobody draws and our IMU stays shut. Before (first real session, 2026-12-02) c8 drew them itself while Monado lived on without its display: two IMU connections, and the head still from the overlay's stale xrLocateSpace (c8_tracker_set_external), so the picture wobbled and the ray aimed left of what it hit. At spawn c8 gives the driver C8_GLASSES_MODE (the mode Monado's direct mode will pick: most pixels, then the highest refresh) and XRT_COMPOSITOR_SCALE_PERCENTAGE=100 (its 140% drew 2688x1512 an eye at 120 Hz on the UHD 620, a refresh late every frame) and XRT_COMPOSITOR_DESIRED_MODE (the index of the mode c8 set from [output NAME] mode, in the output's list, the kernel's order and Vulkan's): left alone Monado took 120 Hz where the user had 90 and missed nearly every frame by a refresh. The overlay draws OVERSCAN (1.15, in tangents) beyond the views and says so in each projection view's fov, so Monado's turning a late frame to the head has picture to show: without it the edges opened on every turn, "a rectangle, not a bubble" (2026-12-02). Each eye's rectangle is its own, VIEW_GAP clear columns apart (the right eye read the left's last columns when turned). maxImageRectWidth is an eye's, not the image's (Monado: twice the display's). Tested on the 1 Pro+ in the 2D mode: the head pose Monado hands the overlay turns as far as the head (a mock 90 degree turn read 90 nested too); the world swung against turns with the driver's scanout correction on and held still with it off (xr/CLAUDE.md). Asked to stop, then SIGKILL after 3 s (reaper; on c8's exit, after 2 s), should it hang all the same.
  • xrclient.c: once $XDG_RUNTIME_DIR/monado_comp_ipc exists and is newer than the spawn (before that the loader only prints errors; an older file is a dead Monado's), an OpenXR instance through the dlopened libopenxr_loader.so.1 (headers only at build time: openxr.pc from c8-xr, C8_HAVE_OPENXR; without them the file is stubs) with XR_EXTX_overlay, XR_MNDX_egl_enable and XR_KHR_opengl_es_enable; the GLES requirements asked (the spec wants it before the session); an overlay session (placement 1) bound to wlroots' own EGL display and context (config NULL: Mesa's no_config_context), LOCAL and VIEW spaces, one swapchain of both eyes side by side (recommended size), GL_SRGB8_ALPHA8 with sRGB writes off (GL_EXT_sRGB_write_control: our numbers are already sRGB's), else GL_RGBA8 (a little washed out). Monado shows an overlay even with no main session (checked in its ipc_server_process.c), so there's no handoff. xrWaitFrame runs on a thread (the spec only synchronises it against itself) which wakes the loop with an eventfd and waits until the main thread has begun the frame; begin, xrLocateViews + xrLocateSpace (the head → c8_tracker_set_external, so recentring, the ray and placing work unchanged), draw, end on the main thread. Events every 100 ms and after each frame: READY begins the session and the thread, STOPPING ends them, EXITING, LOSS_PENDING or a failed wait mark it lost and xrruntime's tick makes another. MAIN_SESSION_VISIBILITY_CHANGED_EXTX sets over_game. Traps, both found in the first real run (2026-12-02): the instance and xrGetSystem are made on a thread of their own (connect_thread, then finish_connect on the main thread). Monado's socket takes a connection before it is set up, and its setup waits on our Wayland server (its window nested, its lease for real) while our main thread waited on its answer: a deadlock, c8 frozen until Monado died. A thread still waiting when we give up is detached and frees itself; 15 s without an answer is giving up. And our context stays current through xrEndFrame: Monado fences the frame in whatever context is current then ("Failed to insert fence" and a glFinish every frame otherwise).
  • glasses.c: draw_space is now its wlr-render-pass shell around draw_space_frame (struct space_frame: head, eyes, m per px, fov, size, backdrop), which c8_xr_draw_views also calls with the runtime's views: asymmetric frusta (mat4_frustum), no Y flip (GL's images), no rolling-scanout or latency prediction (Monado reprojects), recentred as head_at does. Over a game (backdrop false) the clear is transparent and there's no sky, dome or floor; the windows, beacons and pointer are hidden (game_only) until Start or the charms bar is up. Its dumps (C8_XR_DUMP) are read back with glReadPixels.
  • Layers, not one picture (2026-12-02, the user's call after the first real sessions): c8's space goes onto Monado's own composition layers instead of one projection image Monado turns to the head (that image has edges, which showed on every turn, and blurs text twice). First done: the background as XR_KHR_composition_layer_equirect2 layers under ours (c8_xr_sky, c8_xr_sky_draw, xrclient.c's sky_*), the sky's own mesh drawn flat (sky.flat: x round, y the pitch) into two static swapchains, once per picture: the edge's colours as a whole sphere (1024x512) and the picture over it, in a band as high above the horizon as below. Monado v25.1.0's shader counts latitude from straight up (acos(y)), so an uneven upper/lower angle comes out mirrored; an even one is right under the spec and Monado alike. Radius 0 (infinite), pose xr.centre in LOCAL. Its fade-in and dimming are a third equirect layer over it, the veil: a 16x8 swapchain cleared to black at 1 - shown × dim (c8_xr_sky_veil, veil_draw; no color_scale_bias: off in Monado's build). It was first our projection's clear, but that sits over the windows' quads and dimmed them too. Without the extension, or if making them fails, ours draws it as before. Over a game or with an all-round video there's none. Trap: the swapchains are made and destroyed on the frame thread, between our frames (after xrEndFrame, before xrWaitFrame), with the main thread kept off the runtime meanwhile (no event polls: one connection, one lock). Made on the main thread, xrCreateSwapchain never returned, nested: Monado's queue is held by its compositor presenting (FIFO) to its window, a slate of ours, whose frame callbacks only come when we draw a frame. Meanwhile events_tick tells every window its frame is done (c8_xr_windows_done). Direct mode on the glasses presents to the lease, not to us, but the thread keeps c8 moving either way. Tested nested (2026-12-02, the harness below): made in 1 s for a 12800x2979 strip, 4 runs of 4; Monado's window (C8_XR_DUMP_RUNTIME) shows the panorama upright, filling the view, and a 90 degree mock turn shows another part of it filling the view. Not yet on the glasses. c8 keeps its own copy of the picture too (for the builtin path), so it's on the GPU twice. Windows next: each flat window is a quad layer (struct c8_xr_slates, draw_slate_layer; xrclient.c's slots). It is drawn by the same draw_frame/draw_surface/draw_chrome as ever, through a "slate eye": an orthographic camera over the slate's own plane (window, popups, frame and the bar under it, in pixels × the slate's metres per pixel), into its own swapchain, and handed in as an XrCompositionLayerQuad at the middle of what was drawn, its pose turned by xr.centre into LOCAL. Swapchains are rounded up to 128 px (at most 8192), made and dropped on the frame thread like the sky's, and freed after 90 frames unused; a window whose swapchain isn't made yet, or that won't fit in the 16 slots, is drawn in our projection as before. Stays in the projection too: a window shown in 3D, the all-round one, and windows away. Layers come in order (sky, veil, quads back to front as ranked sorts them, projection), with no depth between them: what's left in the projection (outlines, the floor, the ray) is always over the quads. Tested nested (2026-12-02): Files as a quad, sharp in Monado's window, the sky behind it dimmed and the window not; c8's projection dump held only the ray's dot. Windows are layers only while nothing solid is behind them in our projection (the background drawn there: no equirect, or not made yet; a video all round), which would cover them; and then the projection is cleared to nothing, not black. The shell next (struct plane, plane_begin/plane_end, the same slate eye): Start's picture, a launch's splash and the toasts as quads, the charms bar (with the minimised windows' row and the title over it) as an XR_KHR_composition_layer_cylinder layer: drawn flat, unrolled (curve_strip with r 0), since along the cylinder a pixel is as long as on the flat slate; the layer's pose is on the axis, C8_BAR_CURVE_R nearer than the bar's middle, centralAngle its width / r, aspect its width / height, the image as wide each side of the middle (minimised_extent). They go in a chain, in drawing order: one is a layer only while all under it are, so a window left in our projection (3D, no swapchain yet) or a closing one (ghosts_shown) puts Start, splash, toasts and bar back in ours over it. The pointer's dot is the chain's last layer (a 64 px disc drawn once, the quad sized to it). Still in ours whatever: beacons, the floor, outlines, and the dot when the chain broke. Trap: Monado v25.1.0's compute compositor made a cylinder's height angle × aspect, not angle / aspect as the spec (and its own graphics path): the bar came out ~900 times as tall, in streaks. Fixed upstream after the release; our Monado branch carries it, cherry-picked. Someone else's older Monado still has it. The veil's alpha is gamma-corrected (powf(..., 2.2)): Monado blends in linear light, and 0.3 of the sky came out as 0.56 of its sRGB value; with the power it's about 0.2, near ours. Tested nested (2026-12-02): Start (wtype -k Super_L) as a quad over the dimmed Files quad, the sky dimmed by the veil; the charms bar (Super+C) as a cylinder, sharp and right-sized, after the patch; in both c8's projection held only the dot. Not tested: toasts, the splash, the minimised row on the bar. On the glasses (1 Pro+, 2D, 120 Hz, UHD 620; 2026-12-02): text sharper, the edges gone, Start over the dimmed windows; but choppy, Monado "probably missed frame by ~25ms" about 24 times a second, and a window seemed to move up when its chrome came. Since (tested nested only):
    • A window's layer is drawn again only when what it shows changed (slate_sig: each surface's pointer, current.seq, texture and place, the alpha, frame colour, the chrome's look, its place in the image). Otherwise begin says C8_XR_SAME and the quad is given again without acquiring: the runtime shows the last image released (the spec's rule), and the slot's sig is only set once released. Frame callbacks go out only on a redraw, which is fine: a commit changes seq. Nested, an idle Files still committed ~10 times a second while loading (real redraws). Start's picture has one too (picture_seq, a count of the shell's pictures, and the part shown), the toasts and a splash theirs (tree_sig); the bar is drawn whenever it's up.
    • Monado is started with XRT_COMPOSITOR_COMPUTE=0 (unless set): v25.1.0's compute compositor runs every layer for every pixel of both eyes; the graphics one draws each layer where it is. Nested both gave the same picture, cylinder included.
    • A window's image always has room for its chrome, so the chrome coming doesn't change the layer's size or middle, or outgrow its swapchain (a new one takes frames, the window in our projection meanwhile). Nested the window didn't move either way; on the glasses that's the guess, unconfirmed.
    • They ran at 120 Hz because their 90 was set for another port: [output glasses] now (above). 90 or 60 gives Monado more time a frame; untried on them.
    • The pointer's dot is a layer (above): in our projection it was drawn at c8's rate and turned to the head by Monado, the windows placed by Monado itself, so it swam against them.
    • With nothing drawn in our projection (space_frame.drawn: a count of draw calls in its eye loop, or the black clear) it isn't handed to the runtime at all, two whole views less to blend. Nested, with Files, Start and the charms bar up, it held nothing and was left out; the pictures the same.
  • C8_XR_DUMP_RUNTIME=/path/r%d.png (every C8_XR_DUMP_MS): saves the runtime's own window, i.e. what Monado shows, in a nested test. grim can't: it's a slate in a space only the runtime draws.
  • Games: with ours wanted at start c8 sets XR_RUNTIME_JSON (unless the user has one), PRESSURE_VESSEL_IMPORT_OPENXR_1_RUNTIMES=1, PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/monado_comp_ipc (xrizer's README: Steam's container doesn't see the socket otherwise) and, with xrizer unpacked in ~/.local/share/xrizer or the prefix's share/xrizer, VR_OVERRIDE (and an openvrpaths.vrpath naming it if there's none: OpenVR wants one). session.c exports them to systemd and D-Bus.
  • Their 3D mode (glassesmode.c, [glasses] sbs_switch, off): Monado needs 3840x1080 and picks the mode when it leases, so before offering a 1920-wide output c8 sends set-input-mode (id 10274, body 1a 02 08 01) to 169.254.2.1:52999 on the glasses' link, as kevindurb/xreal-linux does for an XREAL 1S, notes was-2d in glasses-mode and waits 3 s for the display to change; leaving sends 08 00 back only with that note. Never sent to the 1 Pro+: untried, hence off.
  • The driver (xr/, its CLAUDE.md): imu.c builds into Monado too; what it needs of its host is imu.h's c8_imu_host (loop, changed, settings, silent) and <imu-host.h> (logging, clocks, c8_state_path; c8's in src/, the driver's in xr/driver/). Angle brackets on purpose: a quoted include would always find src/'s copy.
  • Tested headless: the builtin path after the refactor (Show as 3D's test, the same picture); auto without Monado logs what's missing and stays builtin; a stand-in monado-service that exits after a second (put in .prefix/bin with a dummy json, removed after): started, ended, restarted every 3 s, after five restarts the fallback. Untested, waiting on Monado's build packages: the overlay against a real Monado (simulated HMD, QWERTY_ENABLE=1, XRT_COMPOSITOR_FORCE_WAYLAND=1 in a nested c8), hello_xr as the main session under it, the EGL binding with wlroots' context, the sRGB handling. Untested on hardware: all of it (the lease, the driver's tracking against ours, xrizer, Proton, the 3D switch).