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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
perf(glass): rebuild glass terminals once a slider drag settles
iceclatterWT2eb5911f575a
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex 360912288..d422b774d 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -3,7 +3,7 @@ import { FIND_DECORATIONS } from '../lib/palette'import { ptyRefusal } from '@shared/pty-refusal'import { patchImeModeSwitch } from '../terminal/ime-mode-switch'-import { installGlassCellBackgrounds, setGlassCellAlpha } from '../terminal/glass-cell-backgrounds'+import { installGlassCellBackgrounds, scheduleGlassCellAlpha, setGlassCellAlpha } from '../terminal/glass-cell-backgrounds'import { deliverRelayInitialLaunch } from '../terminal/relay-initial-launch'import { commitLaunch } from '../terminal/launch-attempt'@@ -4854,6 +4854,19 @@ export function TerminalNode({// focus / visibilitychange listeners now provide.}, [positionAbsoluteX, positionAbsoluteY])+ // Glass cell backgrounds follow the node's tint alpha (slider, Reduce Transparency). Backgrounds+ // are only recomputed for CHANGED cells, so an alpha change rebuilds the WebGL model — debounced+ // while the slider is dragged (scheduleGlassCellAlpha); the shared glyph grid stands glass down,+ // and so does this. Declared ABOVE the applyLiveOptions effect: the glyphgrid effect below that+ // one must stay immediately after it (see its comment).+ const glassCellAlpha = tint && !glyphMounted ? tint.alpha : null+ useEffect(() => {+ glassCellAlphaRef.current = glassCellAlpha+ const term = termRef.current+ if (!term) return+ return scheduleGlassCellAlpha(term, glassCellAlpha, () => term.clearTextureAtlas())+ }, [glassCellAlpha])+// Live-apply the appearance settings to the running terminal, so a Settings change reaches the// terminals already on the canvas instead of only the next fresh one.//@@ -4875,16 +4888,6 @@ export function TerminalNode({if (themeChanged) fullRepaintRef.current?.()}, [visual, glass])- // Glass cell backgrounds follow the node's tint alpha (slider, Reduce Transparency). Backgrounds- // are only recomputed for CHANGED cells, so an alpha change rebuilds the WebGL model; the shared- // glyph grid stands glass down, and so does this.- const glassCellAlpha = tint && !glyphMounted ? tint.alpha : null- useEffect(() => {- glassCellAlphaRef.current = glassCellAlpha- const term = termRef.current- if (term && setGlassCellAlpha(term, glassCellAlpha)) term.clearTextureAtlas()- }, [glassCellAlpha])-// 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 onediff --git a/src/renderer/terminal/glass-cell-backgrounds.test.ts b/src/renderer/terminal/glass-cell-backgrounds.test.tsindex 75ad1e5e1..b1d28f006 100644--- a/src/renderer/terminal/glass-cell-backgrounds.test.ts+++ b/src/renderer/terminal/glass-cell-backgrounds.test.ts@@ -1,4 +1,4 @@-import { describe, expect, it } from 'vitest'+import { describe, expect, it, vi } from 'vitest'import fs from 'fs'import path from 'path'import type { Terminal } from '@xterm/xterm'@@ -7,7 +7,9 @@ import {classifyRun,glassPanelFill,installGlassCellBackgrounds,+ GLASS_CELL_REBUILD_MS,oklab,+ scheduleGlassCellAlpha,setGlassCellAlpha} from './glass-cell-backgrounds'import {@@ -173,6 +175,31 @@ it('setGlassCellAlpha reports only real changes', () => {expect(setGlassCellAlpha(t, null)).toBe(false)})+it('a slider drag rebuilds once it settles; glass on/off rebuilds at once', () => {+ vi.useFakeTimers()+ try {+ const t = {} as Terminal+ const rebuild = vi.fn()+ scheduleGlassCellAlpha(t, 0.675, rebuild) // glass on: immediate+ expect(rebuild).toHaveBeenCalledTimes(1)+ // A drag: every step's effect cleanup cancels the previous step's pending rebuild.+ let cancel = () => {}+ for (const a of [0.68, 0.69, 0.7, 0.71]) {+ cancel()+ cancel = scheduleGlassCellAlpha(t, a, rebuild)+ vi.advanceTimersByTime(GLASS_CELL_REBUILD_MS / 3)+ }+ expect(rebuild).toHaveBeenCalledTimes(1)+ vi.advanceTimersByTime(GLASS_CELL_REBUILD_MS)+ expect(rebuild).toHaveBeenCalledTimes(2)+ expect(setGlassCellAlpha(t, 0.71)).toBe(false) // the last step landed+ scheduleGlassCellAlpha(t, null, rebuild) // glass off: immediate+ expect(rebuild).toHaveBeenCalledTimes(3)+ } finally {+ vi.useRealTimers()+ }+})+type FakeCell = { bg: number; fg?: number; ch?: string }/** A structural fake of the addon's RectangleRenderer, doing what the real `_updateRectangle`diff --git a/src/renderer/terminal/glass-cell-backgrounds.ts b/src/renderer/terminal/glass-cell-backgrounds.tsindex e3ec7a270..1cd8aac37 100644--- a/src/renderer/terminal/glass-cell-backgrounds.ts+++ b/src/renderer/terminal/glass-cell-backgrounds.ts@@ -201,6 +201,28 @@ const panelVerdicts = new WeakMap<Terminal, PanelVerdicts>()/** The colour part of a packed fg/bg word (mode + palette index or RGB), flags stripped. */const COLOR_BITS = CM_MASK | 0xffffff+/** How long a slider drag must pause before the terminals rebuild (see `scheduleGlassCellAlpha`). */+export const GLASS_CELL_REBUILD_MS = 150++/**+ * `setGlassCellAlpha` + the rebuild it owes, for a React effect (returns its cleanup). A rebuild is+ * `term.clearTextureAtlas()`, which wipes the SHARED glyph atlas and redraws every glass terminal —+ * and a Glass-slider drag streams an alpha per 0.01 step. So a change between two glass alphas+ * waits until the drag has been still for `GLASS_CELL_REBUILD_MS`; switching glass on or off is+ * immediate (the theme changes with it, and a stale alpha would paint panels over an opaque bg).+ */+export function scheduleGlassCellAlpha(term: Terminal, alpha: number | null, rebuild: () => void): () => void {+ const apply = (): void => {+ if (setGlassCellAlpha(term, alpha)) rebuild()+ }+ if (alpha === null || !cellAlpha.has(term)) {+ apply()+ return () => {}+ }+ const id = setTimeout(apply, GLASS_CELL_REBUILD_MS)+ return () => clearTimeout(id)+}+type Vertices = { attributes: Float32Array }type UpdateRectangle = (v: Vertices,