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
fix(terminal): watch the ratio like the glyph layer, and skip hysteresis on a display change (#986)
Erik Zwepd63d3b05dabe
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex a5e16e8c2..aec147a25 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -61,6 +61,7 @@ import {} from './canvas-image-import'import {SharedGlyphLayer,+ createPixelRatioWatcher,flushOpaqueNodeIds,gestureTerminalIds,hasActiveGesture,@@ -82,7 +83,7 @@ import { terminalKey } from '../terminal/terminal-config'import {setWebglGesture,setWebglZoom,- watchWebglDevicePixelRatio,+ setWebglDevicePixelRatio,releaseAllHiddenGrants,WEBGL_GESTURE_SETTLE_MS} from '../terminal/webgl-budget'@@ -13544,8 +13545,25 @@ export function Canvas() {}, [])// The crisp gate's zoom threshold depends on the display (issue #986): report the device-pixel- // ratio now and whenever the window moves to a display with a different one.- useEffect(() => watchWebglDevicePixelRatio(window), [])+ // ratio now and whenever it changes. Same two triggers as the shared glyph layer: the re-arming+ // media-query watcher, plus `resize` for ratios an exact `dppx` query can miss (fractional+ // browser-zoom steps in the Server Edition).+ useEffect(() => {+ const report = (): void => setWebglDevicePixelRatio(window.devicePixelRatio)+ report()+ const watch = createPixelRatioWatcher(+ {+ dpr: () => window.devicePixelRatio || 1,+ match: (query) => (typeof window.matchMedia === 'function' ? window.matchMedia(query) : null)+ },+ report+ )+ window.addEventListener('resize', report)+ return () => {+ watch.stop()+ window.removeEventListener('resize', report)+ }+ }, [])// Safety net for a lost Stop POST / crashed CLI: decay working entries that saw no hook// event at all for STALE_WORKING_MS (the sweep itself is cheap; see agentStatus.ts).diff --git a/src/renderer/terminal/webgl-budget.test.ts b/src/renderer/terminal/webgl-budget.test.tsindex dada08460..8550d5881 100644--- a/src/renderer/terminal/webgl-budget.test.ts+++ b/src/renderer/terminal/webgl-budget.test.ts@@ -10,7 +10,6 @@ import {setWebglGesture,setWebglZoom,setWebglDevicePixelRatio,- watchWebglDevicePixelRatio,WEBGL_LOW_DPI_CRISP_ABOVE_ZOOM,WEBGL_LOW_DPI_GPU_RESUME_BELOW_ZOOM,WEBGL_ACQUIRE_DEBOUNCE_MS,@@ -500,33 +499,17 @@ describe('webgl-budget coordinator', () => {expect(a.rec.held).toBe(true)})- it('watchWebglDevicePixelRatio reports the ratio now and on every display change, then unsubscribes', () => {- const listeners = new Set<() => void>()- const queries: string[] = []- const win = {- devicePixelRatio: 2,- matchMedia(q: string) {- queries.push(q)- return {- addEventListener: (_: 'change', fn: () => void) => listeners.add(fn),- removeEventListener: (_: 'change', fn: () => void) => listeners.delete(fn)- }- }- }+ it('a display change decides on the entry threshold of the NEW display, not the hysteresis band', () => {+ // Crisp at 170% on the 1x display; 170% is inside the retina band (160–175%) but never+ // crossed the retina entry line, so on the retina display it must go back to the GPU.+ setWebglDevicePixelRatio(1)const a = fakeClient('a')- const stop = watchWebglDevicePixelRatio(win)grant(a)- zoomTo(1.25)- expect(a.rec.held).toBe(true)- win.devicePixelRatio = 1- ;[...listeners].forEach((fn) => fn())- vi.advanceTimersByTime(WEBGL_DRAIN_MS * 10)+ zoomTo(1.7)expect(a.rec.held).toBe(false)- // The query is ratio-specific, so each change re-subscribes against the NEW ratio.- expect(queries).toEqual(['(resolution: 2dppx)', '(resolution: 1dppx)'])- expect(listeners.size).toBe(1)- stop()- expect(listeners.size).toBe(0)+ setWebglDevicePixelRatio(2)+ vi.advanceTimersByTime(WEBGL_DRAIN_MS * 10)+ expect(a.rec.held).toBe(true)})it('ignores a non-finite or non-positive ratio', () => {diff --git a/src/renderer/terminal/webgl-budget.ts b/src/renderer/terminal/webgl-budget.tsindex fb561fd72..7e7f230f7 100644--- a/src/renderer/terminal/webgl-budget.ts+++ b/src/renderer/terminal/webgl-budget.ts@@ -168,45 +168,16 @@ let lastZoom = 1let devicePixelRatio = Number.POSITIVE_INFINITY/**- * Report the window's devicePixelRatio (it changes when the window moves between displays).- * Re-evaluates the current zoom against the thresholds for the new ratio.+ * Report the window's devicePixelRatio (it changes when the window moves between displays, and+ * with browser zoom in the Server Edition). Re-evaluates the current zoom against the ENTRY+ * threshold of the new display only: hysteresis guards a pinch hovering at one boundary, and a+ * display change is not that — at 170% on a 1x display the terminals are crisp, and 170% on a+ * retina display never crossed its 175% line, so they belong back on the GPU.*/export function setWebglDevicePixelRatio(dpr: number): void {if (!Number.isFinite(dpr) || dpr <= 0 || dpr === devicePixelRatio) returndevicePixelRatio = dpr- applyZoomCrisp(lastZoom)-}--interface DprMediaQuery {- addEventListener(type: 'change', listener: () => void): void- removeEventListener(type: 'change', listener: () => void): void-}--/**- * Report `win.devicePixelRatio` now, and again whenever it changes (a window dragged between a- * retina and a low-DPI display). A `(resolution: Ndppx)` query only fires when the ratio LEAVES N,- * so every change re-subscribes against the new ratio. Returns the unsubscribe.- */-export function watchWebglDevicePixelRatio(win: {- devicePixelRatio: number- matchMedia?: (query: string) => DprMediaQuery-}): () => void {- let query: DprMediaQuery | null = null- const subscribe = (): void => {- setWebglDevicePixelRatio(win.devicePixelRatio)- if (typeof win.matchMedia !== 'function') return- query = win.matchMedia(`(resolution: ${win.devicePixelRatio}dppx)`)- query.addEventListener('change', onChange)- }- function onChange(): void {- query?.removeEventListener('change', onChange)- subscribe()- }- subscribe()- return () => {- query?.removeEventListener('change', onChange)- query = null- }+ applyZoomCrisp(lastZoom, true)}/**@@ -223,11 +194,11 @@ export function setWebglZoom(zoom: number): void {applyZoomCrisp(zoom)}-function applyZoomCrisp(zoom: number): void {+function applyZoomCrisp(zoom: number, displayChanged = false): void {const lowDpi = devicePixelRatio < LOW_DPI_BELOWconst crispAbove = lowDpi ? WEBGL_LOW_DPI_CRISP_ABOVE_ZOOM : WEBGL_CRISP_ABOVE_ZOOMconst resumeBelow = lowDpi ? WEBGL_LOW_DPI_GPU_RESUME_BELOW_ZOOM : WEBGL_GPU_RESUME_BELOW_ZOOM- const next = zoomCrisp ? zoom > resumeBelow : zoom > crispAbove+ const next = zoomCrisp && !displayChanged ? zoom > resumeBelow : zoom > crispAboveif (next === zoomCrisp) returnzoomCrisp = nextif (zoomCrisp) {