Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(glyphgrid): opaque xterm viewport, font-change cell drift, plate under-cover, respawn transparency

enesf1f018d94916
diff --git a/src/renderer/lib/glyphGridNode.test.ts b/src/renderer/lib/glyphGridNode.test.ts
index 0fe98733a..e6a4afe69 100644
--- a/src/renderer/lib/glyphGridNode.test.ts
+++ b/src/renderer/lib/glyphGridNode.test.ts
@@ -23,17 +23,23 @@ describe('bodyWorldRect', () => {
})
describe('platePadPx', () => {
- it('takes the MINIMUM side, so the plate can never spill past the body box', () => {
- // .term-node__xterm's real padding: 4px 2px 2px 6px.
- expect(platePadPx({ top: 4, right: 2, bottom: 2, left: 6 })).toBe(2)
+ it('takes the MAXIMUM side, so no padded strip is left uncovered', () => {
+ // .term-node__xterm's real padding: 4px 2px 2px 6px. The node body is transparent under
+ // `.term-node--glyphgrid`, so a strip the plate misses shows raw canvas while one it
+ // over-covers hides under the node's own opaque chrome — the max leaves nothing bare.
+ expect(platePadPx({ top: 4, right: 2, bottom: 2, left: 6 })).toBe(6)
})
it('passes a symmetric padding through', () => {
expect(platePadPx({ top: 8, right: 8, bottom: 8, left: 8 })).toBe(8)
})
- it('collapses a negative side to 0 rather than shrinking the rect', () => {
- expect(platePadPx({ top: 4, right: -2, bottom: 2, left: 6 })).toBe(0)
+ it('is 0 for a zero padding — the plate is then exactly the grid rect', () => {
+ expect(platePadPx({ top: 0, right: 0, bottom: 0, left: 0 })).toBe(0)
+ })
+
+ it('collapses negative sides to 0 rather than growing the rect off a bad parse', () => {
+ expect(platePadPx({ top: -4, right: -2, bottom: -2, left: -6 })).toBe(0)
})
it('collapses an unparseable (NaN) side to 0', () => {
diff --git a/src/renderer/lib/glyphGridNode.ts b/src/renderer/lib/glyphGridNode.ts
index 7b734f25a..11633cba1 100644
--- a/src/renderer/lib/glyphGridNode.ts
+++ b/src/renderer/lib/glyphGridNode.ts
@@ -46,22 +46,27 @@ export function bodyWorldRect(nodePos: Vec2, bodyOffset: Vec2): Vec2 {
* resolved from the terminal host's CSS padding, which is NOT symmetric (`.term-node__xterm` is
* `4px 2px 2px 6px`).
*
- * The MINIMUM is the only safe reduction. The plate is an opaque scissored clear: too small and
- * the node's own opaque body background covers the difference (invisible), too large and it
- * paints over whatever sits beside the node — chrome, a neighbour, the canvas background — which
- * is a visible artefact nothing else corrects. Under-covering is free; over-covering is a bug.
+ * The MAXIMUM is the safe reduction, and WHICH end is safe is decided by the node's background. A
+ * glyph-attached terminal is a transparent WINDOW onto the shared canvas (`.term-node--glyphgrid`
+ * drops the background from the node root and its body), so the plate IS the terminal's
+ * background: ground the plate does not cover shows raw canvas, while ground it over-covers is
+ * hidden under the node's own opaque DOM chrome, which paints above the canvas. Under-covering is
+ * the visible failure; over-covering is free.
+ *
+ * This was the MINIMUM while the plan still called for an opaque node body — the reasoning
+ * inverted with it. Do not restore the minimum without restoring that opaque body too.
*
* Negative/NaN inputs (a computed style that failed to parse) collapse to 0 rather than
* propagating into the engine's rect math.
*/
export function platePadPx(pad: Insets): number {
const sides = [pad.top, pad.right, pad.bottom, pad.left]
- let min = Infinity
+ let max = 0
for (const v of sides) {
if (!Number.isFinite(v)) return 0
- if (v < min) min = v
+ if (v > max) max = v
}
- return min > 0 ? min : 0
+ return max
}
/** Fallback background — the colour `TerminalNode` builds every xterm with. Used when the theme
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 60533b522..0ae4f73c6 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -528,6 +528,10 @@ export function TerminalNode({
// `selected`/`unread`/`working`/… on many renders and React rewrites the whole attribute when it
// changes, so a class added behind React's back would be wiped by the next selection change.
const [glyphMounted, setGlyphMounted] = useState(false)
+ // Bumped whenever the shared context was dropped and this node owes a re-registration. It exists
+ // to move the RE-SETUP out of the (synchronous) generation notification and into an effect that
+ // runs after the font options have reached xterm — see the participation effect below.
+ const [glyphEpoch, setGlyphEpoch] = useState(0)
const [mdHtml, setMdHtml] = useState('')
const [editingTitle, setEditingTitle] = useState(false)
const hoveredRef = useRef(false)
@@ -1081,9 +1085,13 @@ export function TerminalNode({
glyphGrid = null
if (glyphGridRef.current === grid) glyphGridRef.current = null
if (!attach && !grid) return true
- // The node goes opaque again in the same commit the rows come back — skipped on the unmount
- // path, where there is no component left to render it.
- if (!disposed) setGlyphMounted(false)
+ // INVARIANT: `glyphMounted` is true exactly while a grid is attached — teardown always clears
+ // it, `setupGlyph` sets it on success, and nothing else writes it. UNCONDITIONAL, never gated
+ // on `disposed`: that flag is also set for a RESPAWN, where the component SURVIVES and only
+ // this effect run ends. Gating left a respawned node whose fresh setup then failed showing
+ // its DOM text over a transparent body — i.e. over the canvas dot grid. On a real unmount
+ // this is a no-op (React 18 drops a setState on an unmounted component silently).
+ setGlyphMounted(false)
term.element?.classList.remove('glyphgrid-mode')
const restored = attach ? attach.dispose() : true
grid?.dispose()
@@ -1172,6 +1180,10 @@ export function TerminalNode({
// device-metric chain — and corrects itself here if the two ever disagree (an xterm bump
// changing that chain is exactly the drift this catches). Once, and never from a corrected
// pass, so a persistent disagreement cannot loop.
+ //
+ // This does NOT cover a FONT CHANGE: there both renderers agree, they are simply both still
+ // reporting the pre-change cell. That case is handled by WHEN this function is called — see
+ // the participation effect's ordering note — not by the check below.
if (forcedCell) return
const actual = cssCellOf(term)
if (!actual) return
@@ -1798,9 +1810,17 @@ export function TerminalNode({
setupGlyph()
// Only the ACTIVE path subscribes, and only once: a session that never turned the shared
// renderer on holds no store subscription at all. `generation` is bumped for every context
- // disposal — font change, mode off, session failure — and re-running the setup is how each
- // of those resolves: a new context re-registers, a null one leaves the terminal on the DOM
- // renderer (unbudgeted, which is xterm's own default and always correct).
+ // disposal — font change, mode off, session failure.
+ //
+ // This handler TEARS DOWN ONLY. The re-setup is deferred to the participation effect via
+ // `glyphEpoch`, and the reason is the font-change case: this notification is SYNCHRONOUS
+ // inside `useSettings.setState` (settings change → the layer's settings subscription disposes
+ // the context and bumps the generation → we run), which is BEFORE React has committed the
+ // render that applies `term.options.fontSize` to xterm. Re-registering here would read a
+ // stale `dimensions.css.cell` and pin the grid to the OLD cell size while the rebuilt atlas
+ // rasterizes at the new one — and a grid's cell size cannot be changed afterwards, so the
+ // drift would be permanent until the node remounted. Tearing down early is always safe: the
+ // context these handles belong to is already gone.
let lastGen = useSharedGlyph.getState().generation
glyphGenUnsub = useSharedGlyph.subscribe((s) => {
if (disposed || s.generation === lastGen) return
@@ -1809,7 +1829,7 @@ export function TerminalNode({
escalateRespawn('glyphgrid could not restore the DOM renderer')
return
}
- setupGlyph()
+ setGlyphEpoch((n) => n + 1)
})
}
let wasVisible = false
@@ -1943,16 +1963,6 @@ export function TerminalNode({
grid.setOrigin(origin.x, origin.y)
}, [positionAbsoluteX, positionAbsoluteY])
- // The two states in which this node's terminal is NOT on screen even though it is mounted:
- // collapsed (the body is `display: none`) and the ⌘M markdown/chat view (an opaque panel over
- // the body). Both drop the grid — and re-register on the way back — for the same reason a parked
- // terminal drops its WebGL context: there is nothing to draw, and a grid left registered keeps
- // painting its last frame at the node's world rect with nothing of ours in front of it. No-op
- // unless this node participates in the shared canvas.
- useEffect(() => {
- glyphSyncRef.current?.(!collapsed && !mdMode)
- }, [collapsed, mdMode])
-
// Live-apply font/cursor/scrollback settings to the running terminal, so a Settings change
// reaches the terminals already on the canvas instead of only the next fresh one.
//
@@ -1971,6 +1981,29 @@ export function TerminalNode({
applyFitRef.current?.()
}, [fontSize, fontFamily, cursorBlink, tmuxScrollback])
+ // glyphgrid participation — whether this node should hold a grid RIGHT NOW.
+ //
+ // ORDERING IS THE POINT, and it is why this effect is declared HERE, immediately after the one
+ // that writes `term.options.fontFamily/fontSize`. React runs a commit's effects in declaration
+ // order, so by the time this runs xterm has already re-measured its character cell and its
+ // renderer's `dimensions.css.cell` — the number `setupGlyph` registers the grid with — is the
+ // NEW one. A font change reaches us as a `glyphEpoch` bump raised synchronously from the
+ // generation notification, i.e. BEFORE that commit; re-registering there would pin the grid to
+ // the old cell size forever (a grid's cell size cannot be changed after `register`). The font
+ // settings are in the deps as well as the epoch, so the re-setup still lands after the options
+ // even if the two ever arrive in separate renders. Do not move this effect above the one above.
+ //
+ // It also owns the two states in which the terminal is NOT on screen although it is mounted:
+ // collapsed (the body is `display: none`) and the ⌘M markdown/chat view (an opaque panel over
+ // the body). Both drop the grid — and re-register on the way back — for the same reason a parked
+ // terminal drops its WebGL context: there is nothing to draw, and a grid left registered keeps
+ // painting its last frame at the node's world rect with nothing of ours in front of it.
+ //
+ // No-op (one ref null check) unless this node participates in the shared canvas.
+ useEffect(() => {
+ glyphSyncRef.current?.(!collapsed && !mdMode)
+ }, [collapsed, mdMode, glyphEpoch, fontSize, fontFamily])
+
// Kanban board opened/closed: re-evaluate our size vote. Open → applyFit reports null (yield the
// grid to a card-modal viewer); close → it re-reports the real fit. On the first run boardOpen
// matches the ref's init value, and applyFit is guarded (no-op when nothing changed), so this
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index b5bbd20fe..678bf5d0f 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -1629,18 +1629,35 @@ body,
`.term-node__find` #2a2a2a, and the body's own overlays). The selection ring and the unread glow
are border-color + box-shadow, both independent of the background.
- TWO accepted degradations, both plate GEOMETRY, both Phase 2's call (a rounded / stencilled
- plate) and both judged on the device checklist:
+ Accepted degradations, all plate GEOMETRY, all Phase 2's call (a rounded / stencilled plate, or
+ a plate sized to the BODY rect instead of the grid rect) and all judged on the device checklist.
+ `padPx` is ONE symmetric scalar taken from the LARGEST side of the host's `4px 2px 2px 6px`
+ padding (= 6; see `lib/glyphGridNode.ts` `platePadPx`), which covers the left and top insets
+ completely — over-covering them is free, since the node's own opaque chrome paints above the
+ canvas. What is left:
1. the plate is a square rect while the node has border-radius 10px, so the body's corners read
- square in shared mode;
- 2. the plate covers the grid plus padPx, and a fit leaves up to one cell of slack at the right
- and bottom of the body — that slack shows the canvas behind the node rather than the
- terminal background. */
+ square in shared mode (the node's `overflow: hidden` clips DOM children, and the canvas is
+ not one);
+ 2. the right/bottom edges do not land exactly: a fit leaves up to one cell of slack there, so
+ when the slack EXCEEDS 6px a strip of that slack shows the canvas behind the node instead of
+ the terminal background, and when it is under 6px the plate reaches up to ~4px past the
+ node's outer edge — visible only against the canvas, since a neighbouring node's DOM paints
+ over it. */
.term-node--glyphgrid,
.term-node--glyphgrid .term-node__body {
background: transparent;
}
+/* xterm paints its own opaque background on the SCROLL VIEWPORT — `.xterm-viewport` in its
+ stylesheet, and `Viewport._handleThemeChange` re-asserts it as an INLINE
+ `style.backgroundColor = theme.background.css` on every theme change. Inline beats any selector,
+ which is the only reason `!important` appears here: a stylesheet rule cannot otherwise win, and
+ without it the viewport covers the whole transparent body and the shared canvas is invisible
+ again — the exact failure this whole Option-B change exists to fix. */
+.term-node__xterm .xterm.glyphgrid-mode .xterm-viewport {
+ background-color: transparent !important;
+}
+
/* …and xterm's own text layers must not paint over the canvas now showing through. This class is
added to the `.xterm` element only while a glyph grid is actually attached, and removed
the moment it detaches — no default renderer mode ever matches this rule.