From 7d2a41bd569c43cea9e7d5fcc95d8682215d5208 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Fri, 31 Jul 2026 14:52:51 -0700 Subject: [PATCH] Apps are variable height; add vertical position setting --- README | 2 + app/g2/dashboard-controller.ts | 56 ++++++++++++++++---- app/ui/dashboard-settings.ts | 21 ++++++++ app/ui/dashboard/settings-menus.ts | 4 ++ app/ui/menu.ts | 8 +-- app/ui/shell/chrome-layer.ts | 59 +++++++++++++-------- app/ui/shell/debug-tests-app.ts | 4 +- app/ui/shell/geometry.ts | 67 +++++++++++++++++++++--- app/ui/shell/in-process-window.ts | 8 ++- app/ui/shell/modal-layer.ts | 36 ++++++++----- app/ui/shell/shell.ts | 23 ++++++--- app/ui/shell/tool-debug-layer.ts | 25 +++++---- app/ui/shell/worker-window.ts | 15 ++++-- app/workers/terminal-app.worker.ts | 82 +++++++++++++++++++----------- 14 files changed, 301 insertions(+), 109 deletions(-) diff --git a/README b/README index 8caf0f34..50c95d68 100644 --- a/README +++ b/README @@ -44,6 +44,8 @@ To install, run to queries and commands using an Anthropic or OpenAI model (requires an API key). * Multitasking, with an app-switcher sidebar and app launcher + * Supports full-screen apps using the full 640x480 display area (rather than + the 576x288 that EvenHub apps can use) * Integration with Android notifications: A top-bar that shows the same icons your phone does, popups when notifications arrive, and menu items to dismiss or use Android-app-provided custom actions like mark as diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index 51777e46..34cfc66c 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -79,7 +79,7 @@ import { TRANSCRIBE_WINDOW_ID, } from "../ui/shell/transcribe-app"; import { type InProcessAppOptions, type InProcessWindow } from "../ui/shell/in-process-window"; -import { APP_VIEWPORT } from "../ui/shell/geometry"; +import { appViewportRect, type WindowHeightMode } from "../ui/shell/geometry"; import { type LayerActions } from "../ui/layers"; import { brightnessSetting, @@ -95,6 +95,7 @@ import { screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, systemCardNameSetting, + verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString, @@ -318,6 +319,34 @@ class DashboardController { this.pushFirmwareDebugFlags(); this.pushBrightness(); this.syncEvenHubScreenOffSetting(); + this.applyVerticalPositionIfChanged(); + }); + } + + // Vertical-position changes move every window surface (and the chrome that + // aligns with them); the value is tracked so unrelated setting changes + // don't trigger a full reposition. + private lastVerticalPosition = verticalPositionSetting.get(); + + private applyVerticalPositionIfChanged(): void { + const position = verticalPositionSetting.get(); + if (position === this.lastVerticalPosition) return; + this.lastVerticalPosition = position; + const foregroundWindowId = shell.foregroundWindow()?.windowId; + void (async () => { + for (const window of shell.getWindows()) { + await this.configureWindowSurface( + window.surfaceId, + window.windowId === foregroundWindowId, + window.heightMode, + ); + } + // Repaint after the surfaces have moved: window content is unchanged + // but the moved surfaces need a recomposite, and the chrome band moved. + shell.foregroundWindow()?.requestRender(); + this.requestShellRender(); + })().catch((error) => { + this.appendLog(`vertical reposition failed: ${this.formatError(error)}`); }); } @@ -846,7 +875,11 @@ class DashboardController { }); const foregroundWindowId = shell.foregroundWindow()?.windowId; for (const window of shell.getWindows()) { - await this.configureWindowSurface(window.surfaceId, window.windowId === foregroundWindowId); + await this.configureWindowSurface( + window.surfaceId, + window.windowId === foregroundWindowId, + window.heightMode, + ); } await communicator.start(); this.syncEvenHubScreenOffSetting(); @@ -1219,7 +1252,7 @@ class DashboardController { shell.registerWindow(settingsApp.window); // Configure the surface before foregrounding so the first frame has // somewhere to land. - await this.configureWindowSurface(SETTINGS_SURFACE_ID, false); + await this.configureWindowSurface(SETTINGS_SURFACE_ID, false, settingsApp.window.heightMode); shell.focusWindow(SETTINGS_WINDOW_ID); this.requestShellRender(); this.appendLog("launched settings"); @@ -1251,7 +1284,7 @@ class DashboardController { }); this.inProcessApps.set(windowId, app); shell.registerWindow(app.window); - await this.configureWindowSurface(surfaceId, false); + await this.configureWindowSurface(surfaceId, false, app.window.heightMode); shell.focusWindow(windowId); this.requestShellRender(); this.appendLog(`launched ${windowId}`); @@ -1283,8 +1316,8 @@ class DashboardController { const host = new WorkerAppHost({ appId, worker, - viewport: { width: APP_VIEWPORT.width, height: APP_VIEWPORT.height }, - configureSurface: (surfaceId, visible) => this.configureWindowSurface(surfaceId, visible), + configureSurface: (surfaceId, visible, heightMode) => + this.configureWindowSurface(surfaceId, visible, heightMode), setSurfaceVisible: (surfaceId, visible) => this.setWindowSurfaceVisible(surfaceId, visible), removeSurface: (surfaceId) => this.removeWindowSurface(surfaceId), requestShellRender: () => this.requestShellRender(), @@ -1464,14 +1497,15 @@ class DashboardController { } /** Create/refresh a window surface on the compositor, if connected. */ - private async configureWindowSurface(surfaceId: string, visible: boolean): Promise { + private async configureWindowSurface( + surfaceId: string, + visible: boolean, + heightMode: WindowHeightMode = "min", + ): Promise { const communicator = this.communicator; if (!communicator) return; await communicator.configureSurface(surfaceId, { - x: APP_VIEWPORT.x, - y: APP_VIEWPORT.y, - width: APP_VIEWPORT.width, - height: APP_VIEWPORT.height, + ...appViewportRect(heightMode), zOrder: 0, transparency: "opaque", }); diff --git a/app/ui/dashboard-settings.ts b/app/ui/dashboard-settings.ts index eae077ea..3a86faad 100644 --- a/app/ui/dashboard-settings.ts +++ b/app/ui/dashboard-settings.ts @@ -255,6 +255,27 @@ export const screenTimeoutSetting = new ConfigSettingEnum( description: "How long the display stays on after the last input before turning itself off. \"Never\" keeps it on until turned off manually.", }); +export type VerticalPosition = "top" | "upper" | "middle" | "lower" | "bottom"; + +const VERTICAL_POSITION_LABELS: Record = { + top: "Top", + upper: "Upper", + middle: "Middle", + lower: "Lower", + bottom: "Bottom", +}; + +export const verticalPositionSetting = new ConfigSettingEnum({ + id: "vertical-position", + label: "Vertical position", + storageKey: "display.verticalPosition", + defaultValue: "middle", + values: ["top", "upper", "middle", "lower", "bottom"], + formatValue: (value) => VERTICAL_POSITION_LABELS[value] ?? value, + description: + "Where standard (reduced-height) windows sit vertically within the display area, to position them within your field of view. Full-height windows such as terminal views always use the whole screen.", +}); + export const voiceControlEnabledSetting = new ConfigSettingBoolean({ id: "voice-control-enabled", label: "Enable", diff --git a/app/ui/dashboard/settings-menus.ts b/app/ui/dashboard/settings-menus.ts index 452392f6..90a05627 100644 --- a/app/ui/dashboard/settings-menus.ts +++ b/app/ui/dashboard/settings-menus.ts @@ -24,6 +24,7 @@ import { timeFormatSetting, toggleSettingMenuItem, uiFontSetting, + verticalPositionSetting, voiceProviderSetting, screenTimeoutSetting, wakeWordActionSetting, @@ -48,6 +49,9 @@ function settingsSections(): SettingsSection[] { shell.noteUserActivity(); }, }), + // Where min-height windows (and the sidebar) sit vertically on the + // screen; the dashboard controller repositions surfaces on change. + enumSettingMenuItem(verticalPositionSetting), // Controls the top-bar battery indicators (icon vs percentage). enumSettingMenuItem(batteryDisplayModeSetting), // Controls the top-bar clock (24-hour vs 12-hour). diff --git a/app/ui/menu.ts b/app/ui/menu.ts index db09e3e8..475da3a6 100644 --- a/app/ui/menu.ts +++ b/app/ui/menu.ts @@ -192,12 +192,15 @@ export class MenuLayer implements Layer { paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage { const font = getDefaultSmallFont(); + const image = paintBelow(); const { x, y, width } = this.layout; const chromeTop = (this.title ? MENU_TITLE_HEIGHT : 0) + MENU_BODY_PADDING; const minHeight = this.layout.minHeight ?? DEFAULT_MENU_MIN_HEIGHT; + // Cap to the surface being painted on: a window's stack image may be much + // shorter than the full screen (min-height windows). const maxHeight = Math.min( - this.layout.maxHeight ?? G2_LENS_HEIGHT - y - DEFAULT_MENU_Y, - G2_LENS_HEIGHT - y, + this.layout.maxHeight ?? image.height - y - DEFAULT_MENU_Y, + image.height - y, ); const contentHeight = chromeTop + this.items.length * MENU_ROW_HEIGHT + MENU_BODY_PADDING; const height = clamp(contentHeight, Math.min(minHeight, maxHeight), maxHeight); @@ -209,7 +212,6 @@ export class MenuLayer implements Layer { this.items.length, ); - const image = paintBelow(); // Fill 1, not 0: identical after 4bpp quantization, but 0 is the // transparent color key when a menu paints on the shell surface. image.fillRoundedRect(x, y, width, height, 1); diff --git a/app/ui/shell/chrome-layer.ts b/app/ui/shell/chrome-layer.ts index 24178685..75d65de5 100644 --- a/app/ui/shell/chrome-layer.ts +++ b/app/ui/shell/chrome-layer.ts @@ -8,7 +8,15 @@ import { renderIcon, renderIconWithGlyph, type IconName } from "../../graphics/i import { batteryDisplayModeSetting, timeFormatSetting } from "../dashboard-settings"; import { Layer } from "../layers"; import { scrollToKeepSelectionVisible } from "../menu"; -import { SHELL_OPAQUE_BLACK, SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry"; +import { + MIN_WINDOW_HEIGHT, + minWindowTop, + SHELL_OPAQUE_BLACK, + SIDEBAR_WIDTH, + TOP_BAR_HEIGHT, + windowTop, + type WindowHeightMode, +} from "./geometry"; const ICON_SIZE = 32; const ICON_MARGIN_X = ((SIDEBAR_WIDTH - ICON_SIZE) / 2) | 0; @@ -30,6 +38,8 @@ export type ShellChromeState = { windows: ShellChromeWindow[]; selectedIndex: number; focus: "sidebar" | "window"; + /** Height mode of the foreground window; decides where its top bar sits. */ + foregroundHeightMode: WindowHeightMode; battery: { headset: number | null; headsetCharging: boolean | null }; /** App-provided tray images, drawn between notification icons and batteries. */ trayIcons: GrayImage[]; @@ -103,13 +113,18 @@ export class ShellChromeLayer implements Layer { } private drawSidebar(image: GrayImage, state: ShellChromeState): void { - image.fillRect(0, 0, SIDEBAR_WIDTH, G2_LENS_HEIGHT, SHELL_OPAQUE_BLACK); + // The sidebar always occupies the min-height window band at the preferred + // vertical position: it never moves when the foreground window's height + // changes, and it lines up exactly with a min-height window's chrome. + const bandTop = minWindowTop(); + const bandBottom = bandTop + MIN_WINDOW_HEIGHT; + image.fillRect(0, bandTop, SIDEBAR_WIDTH, MIN_WINDOW_HEIGHT, SHELL_OPAQUE_BLACK); // Scroll the icon list to keep the selection visible; chevrons mark // windows off-screen above/below. - const listTop = TOP_BAR_HEIGHT + 10; + const listTop = bandTop + TOP_BAR_HEIGHT + 10; const itemStride = ICON_SIZE + ICON_SPACING; - const listHeight = G2_LENS_HEIGHT - listTop - 10; + const listHeight = bandBottom - listTop - 10; const visibleCount = Math.max(1, ((listHeight + ICON_SPACING) / itemStride) | 0); const count = state.windows.length; this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, visibleCount, count); @@ -125,10 +140,10 @@ export class ShellChromeLayer implements Layer { const selTabTop = selVisible ? listTop + (state.selectedIndex - this.scrollRow) * itemStride - 2 : 0; const selTabBottom = selTabTop + ICON_SIZE + 4; if (selVisible) { - image.drawLine(sep, 0, sep, selTabTop, BORDER_VALUE); - image.drawLine(sep, selTabBottom, sep, G2_LENS_HEIGHT - 1, BORDER_VALUE); + image.drawLine(sep, bandTop, sep, selTabTop, BORDER_VALUE); + image.drawLine(sep, selTabBottom, sep, bandBottom - 1, BORDER_VALUE); } else { - image.drawLine(sep, 0, sep, G2_LENS_HEIGHT - 1, BORDER_VALUE); + image.drawLine(sep, bandTop, sep, bandBottom - 1, BORDER_VALUE); } for (let index = this.scrollRow; index < lastVisible; index++) { @@ -147,27 +162,31 @@ export class ShellChromeLayer implements Layer { } if (this.scrollRow > 0) { - drawChevron(image, SIDEBAR_WIDTH / 2, TOP_BAR_HEIGHT + 6, -1); + drawChevron(image, SIDEBAR_WIDTH / 2, bandTop + TOP_BAR_HEIGHT + 6, -1); } if (lastVisible < count) { - drawChevron(image, SIDEBAR_WIDTH / 2, G2_LENS_HEIGHT - 6, 1); + drawChevron(image, SIDEBAR_WIDTH / 2, bandBottom - 6, 1); } } private drawTopBar(image: GrayImage, state: ShellChromeState): void { const font = getDefaultMediumFont(); - image.fillRect(SIDEBAR_WIDTH, 0, G2_LENS_WIDTH - SIDEBAR_WIDTH, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK); - image.drawLine(SIDEBAR_WIDTH, TOP_BAR_HEIGHT - 1, G2_LENS_WIDTH - 1, TOP_BAR_HEIGHT - 1, BORDER_VALUE); + // The bar sits at the top edge of the foreground window: the screen top + // for a max-height window, the min-height band otherwise. It moves when + // the foreground switches to a window of a different height. + const barTop = windowTop(state.foregroundHeightMode); + image.fillRect(SIDEBAR_WIDTH, barTop, G2_LENS_WIDTH - SIDEBAR_WIDTH, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK); + image.drawLine(SIDEBAR_WIDTH, barTop + TOP_BAR_HEIGHT - 1, G2_LENS_WIDTH - 1, barTop + TOP_BAR_HEIGHT - 1, BORDER_VALUE); const now = new Date(); const clock = `${WEEKDAYS[now.getDay()]} ${now.getDate()} ${MONTHS[now.getMonth()]} ` + formatClockTime(now); const clockX = SIDEBAR_WIDTH + 10; - const textY = Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0); + const textY = barTop + Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0); image.drawText(font, clockX, textY, clock, 210); - const batteryLeft = this.drawTopBarBatteries(image, state); - const trayLeft = drawTrayIcons(image, state.trayIcons, batteryLeft); + const batteryLeft = this.drawTopBarBatteries(image, state, barTop); + const trayLeft = drawTrayIcons(image, state.trayIcons, batteryLeft, barTop); const iconsX = clockX + font.measureText(clock) + 16; const maxIcons = Math.max(0, ((trayLeft - 8 - iconsX) / (NOTIFICATION_ICON_SIZE + 4)) | 0); @@ -176,7 +195,7 @@ export class ShellChromeLayer implements Layer { if (stale) { noteStaleDataUsed(); } - const iconY = ((TOP_BAR_HEIGHT - NOTIFICATION_ICON_SIZE) / 2) | 0; + const iconY = barTop + (((TOP_BAR_HEIGHT - NOTIFICATION_ICON_SIZE) / 2) | 0); for (let index = 0; index < icons.length; index++) { image.bitBlt(icons[index]!, iconsX + index * (NOTIFICATION_ICON_SIZE + 4), iconY, { transparentZero: true, @@ -190,7 +209,7 @@ export class ShellChromeLayer implements Layer { * the top bar, following the dashboard card's icon/percentage setting. * Returns the left edge of the battery block. */ - private drawTopBarBatteries(image: GrayImage, state: ShellChromeState): number { + private drawTopBarBatteries(image: GrayImage, state: ShellChromeState, barTop: number): number { const font = getDefaultSmallFont(); const percentageMode = batteryDisplayModeSetting.get() === "percentage"; type BatteryItem = { label: string; percent: number; charging: boolean }; @@ -206,7 +225,7 @@ export class ShellChromeLayer implements Layer { const labelGap = 5; const itemGap = 12; - const textY = Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0); + const textY = barTop + Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0); let x = G2_LENS_WIDTH - 8; for (let index = items.length - 1; index >= 0; index--) { const item = items[index]!; @@ -226,7 +245,7 @@ export class ShellChromeLayer implements Layer { } } else { const icon = drawBattery(item.percent, item.charging); - image.bitBlt(icon, valueX, Math.max(0, ((TOP_BAR_HEIGHT - icon.height) / 2) | 0), { + image.bitBlt(icon, valueX, barTop + Math.max(0, ((TOP_BAR_HEIGHT - icon.height) / 2) | 0), { transparentZero: true, }); } @@ -240,12 +259,12 @@ export class ShellChromeLayer implements Layer { * Draw app tray icons right-to-left, ending just left of the battery block; * returns the left edge of the tray region. */ -function drawTrayIcons(image: GrayImage, trayIcons: GrayImage[], rightEdge: number): number { +function drawTrayIcons(image: GrayImage, trayIcons: GrayImage[], rightEdge: number, barTop: number): number { let x = rightEdge; for (let index = trayIcons.length - 1; index >= 0; index--) { const icon = trayIcons[index]!; x -= icon.width + 10; - image.bitBlt(icon, x, Math.max(0, ((TOP_BAR_HEIGHT - icon.height) / 2) | 0), { + image.bitBlt(icon, x, barTop + Math.max(0, ((TOP_BAR_HEIGHT - icon.height) / 2) | 0), { transparentZero: true, }); } diff --git a/app/ui/shell/debug-tests-app.ts b/app/ui/shell/debug-tests-app.ts index f23f10d6..084af82c 100644 --- a/app/ui/shell/debug-tests-app.ts +++ b/app/ui/shell/debug-tests-app.ts @@ -2,7 +2,7 @@ import { MenuLayer } from "../menu"; import { ScreenTestLayer } from "../apps/screen-test"; import { BuzzerDemoLayer } from "../apps/buzzer-demo"; import { AccelerometerDemoLayer } from "../apps/accelerometer-demo"; -import { APP_VIEWPORT } from "./geometry"; +import { appViewportSize } from "./geometry"; import { createInProcessWindow, YieldAtRootLayer, @@ -42,7 +42,7 @@ export function createDebugTestsAppWindow(options: InProcessAppOptions): InProce y: 8, width: 272, minHeight: 0, - maxHeight: APP_VIEWPORT.height - 16, + maxHeight: appViewportSize("min").height - 16, }, ); return createInProcessWindow({ diff --git a/app/ui/shell/geometry.ts b/app/ui/shell/geometry.ts index 8313041e..2b3580de 100644 --- a/app/ui/shell/geometry.ts +++ b/app/ui/shell/geometry.ts @@ -1,4 +1,5 @@ import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../../graphics/image"; +import { verticalPositionSetting } from "../dashboard-settings"; /** Top bar: 24px notification icons plus a little padding. */ export const TOP_BAR_HEIGHT = 28; @@ -12,10 +13,62 @@ export const SIDEBAR_WIDTH = 36; */ export const SHELL_OPAQUE_BLACK = 1; -/** Screen region belonging to the foreground app window (compile-time fixed). */ -export const APP_VIEWPORT = { - x: SIDEBAR_WIDTH, - y: TOP_BAR_HEIGHT, - width: G2_LENS_WIDTH - SIDEBAR_WIDTH, - height: G2_LENS_HEIGHT - TOP_BAR_HEIGHT, -} as const; +/** + * Windows come in two heights. "min" covers the same 288px band the stock + * firmware uses, leaving most of the field of view clear; "max" uses the + * whole 480px screen (terminal views). Both include a top bar drawn by the + * shell at the window's top edge. + */ +export type WindowHeightMode = "min" | "max"; + +/** Total height (top bar + content) of a min-height window. */ +export const MIN_WINDOW_HEIGHT = 288; +/** Farthest down a min-height window can start. */ +export const MIN_WINDOW_MAX_TOP = G2_LENS_HEIGHT - MIN_WINDOW_HEIGHT; + +/** + * Top edge (y) of a min-height window, from the Display > Vertical position + * setting. The sidebar and shell overlays always align to this band, even + * while a max-height window is foreground. + */ +export function minWindowTop(): number { + switch (verticalPositionSetting.get()) { + case "top": + return 0; + case "upper": + return Math.round(MIN_WINDOW_MAX_TOP * 0.25); + case "lower": + return Math.round(MIN_WINDOW_MAX_TOP * 0.75); + case "bottom": + return MIN_WINDOW_MAX_TOP; + default: + return Math.round(MIN_WINDOW_MAX_TOP * 0.5); + } +} + +/** Top edge (y) of a window's top bar; max-height windows pin to the screen top. */ +export function windowTop(mode: WindowHeightMode): number { + return mode === "max" ? 0 : minWindowTop(); +} + +/** App-content viewport size for a height mode (independent of vertical position). */ +export function appViewportSize(mode: WindowHeightMode): { width: number; height: number } { + return { + width: G2_LENS_WIDTH - SIDEBAR_WIDTH, + height: (mode === "max" ? G2_LENS_HEIGHT : MIN_WINDOW_HEIGHT) - TOP_BAR_HEIGHT, + }; +} + +/** Screen rect of a window's app-content viewport (below its top bar). */ +export function appViewportRect(mode: WindowHeightMode): { + x: number; + y: number; + width: number; + height: number; +} { + return { + x: SIDEBAR_WIDTH, + y: windowTop(mode) + TOP_BAR_HEIGHT, + ...appViewportSize(mode), + }; +} diff --git a/app/ui/shell/in-process-window.ts b/app/ui/shell/in-process-window.ts index 5f29d0fd..aee16a9d 100644 --- a/app/ui/shell/in-process-window.ts +++ b/app/ui/shell/in-process-window.ts @@ -6,7 +6,7 @@ import { type MenuItem } from "../menu"; import { WindowMenuLayer } from "../window-menu"; import { windowIcon } from "./chrome-layer"; import { type IconName } from "../../graphics/icons"; -import { APP_VIEWPORT } from "./geometry"; +import { appViewportSize, type WindowHeightMode } from "./geometry"; import { shell, type ShellWindow } from "./shell"; /** @@ -24,6 +24,8 @@ export type InProcessWindowOptions = { /** Lucide icon name for the sidebar indicator; falls back to iconLetter. */ icon?: IconName; closeable: boolean; + /** Window height: the standard 288px band ("min", default) or full screen ("max"). */ + heightMode?: WindowHeightMode; /** * App-specific entries for the window's long-press menu, listed ahead of * the default Voice input / Close window entries. Called at open time, so @@ -60,10 +62,11 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces console.error(`${options.windowId} render failed: ${error}`); }); }; + const heightMode = options.heightMode ?? "min"; const stack = new LayerStack( options.baseLayer, { ...options.actions, requestRender }, - { width: APP_VIEWPORT.width, height: APP_VIEWPORT.height }, + appViewportSize(heightMode), () => shell.isWindowFocused(options.windowId), ); @@ -124,6 +127,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces title: options.title, surfaceId: `window:${options.windowId}`, closeable: options.closeable, + heightMode, close: () => { closed = true; // Fire onRemoved for any pushed layers so they release resources (e.g. a diff --git a/app/ui/shell/modal-layer.ts b/app/ui/shell/modal-layer.ts index ad02dcfe..37b0539d 100644 --- a/app/ui/shell/modal-layer.ts +++ b/app/ui/shell/modal-layer.ts @@ -1,23 +1,30 @@ import { GrayImage } from "../../graphics/image"; import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, PaintBelow } from "../layers"; -import { APP_VIEWPORT, SHELL_OPAQUE_BLACK } from "./geometry"; +import { appViewportRect, appViewportSize, SHELL_OPAQUE_BLACK } from "./geometry"; -// The modal covers most of the app viewport, leaving a little of the -// foreground app visible around the edges. +// The modal covers most of the min-height app viewport, leaving a little of +// the foreground app visible around the edges. Its size is fixed (min-height +// windows have a fixed viewport size); its position follows the vertical +// position setting, so it is computed per paint. const MODAL_MARGIN = 14; const MODAL_PADDING = 4; -export const MODAL_RECT = { - x: APP_VIEWPORT.x + MODAL_MARGIN, - y: APP_VIEWPORT.y + MODAL_MARGIN, - width: APP_VIEWPORT.width - 2 * MODAL_MARGIN, - height: APP_VIEWPORT.height - 2 * MODAL_MARGIN, -} as const; export const MODAL_INTERIOR = { - width: MODAL_RECT.width - 2 * MODAL_PADDING, - height: MODAL_RECT.height - 2 * MODAL_PADDING, + width: appViewportSize("min").width - 2 * MODAL_MARGIN - 2 * MODAL_PADDING, + height: appViewportSize("min").height - 2 * MODAL_MARGIN - 2 * MODAL_PADDING, } as const; +/** Screen rect of the modal box, aligned to the min-height window band. */ +export function modalRect(): { x: number; y: number; width: number; height: number } { + const viewport = appViewportRect("min"); + return { + x: viewport.x + MODAL_MARGIN, + y: viewport.y + MODAL_MARGIN, + width: viewport.width - 2 * MODAL_MARGIN, + height: viewport.height - 2 * MODAL_MARGIN, + }; +} + /** * A shell overlay hosting an inner layer stack in a bordered box over the * app viewport (used for new-notification popups). The inner stack paints at @@ -37,9 +44,10 @@ export class ShellModalLayer implements Layer { paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage { const image = paintBelow(); const inner = this.stack.paint(); - image.fillRoundedRect(MODAL_RECT.x, MODAL_RECT.y, MODAL_RECT.width, MODAL_RECT.height, SHELL_OPAQUE_BLACK, 8); - image.drawRoundedRect(MODAL_RECT.x, MODAL_RECT.y, MODAL_RECT.width, MODAL_RECT.height, 110, 8); - image.bitBlt(inner, MODAL_RECT.x + MODAL_PADDING, MODAL_RECT.y + MODAL_PADDING, { transparentZero: true }); + const rect = modalRect(); + image.fillRoundedRect(rect.x, rect.y, rect.width, rect.height, SHELL_OPAQUE_BLACK, 8); + image.drawRoundedRect(rect.x, rect.y, rect.width, rect.height, 110, 8); + image.bitBlt(inner, rect.x + MODAL_PADDING, rect.y + MODAL_PADDING, { transparentZero: true }); return image; } diff --git a/app/ui/shell/shell.ts b/app/ui/shell/shell.ts index aa79a892..a1570b9a 100644 --- a/app/ui/shell/shell.ts +++ b/app/ui/shell/shell.ts @@ -24,7 +24,7 @@ import { ShellChromeLayer, type ShellChromeState, type ShellChromeWindow } from import { ShellModalLayer } from "./modal-layer"; import { ToolDebugMenuLayer } from "./tool-debug-layer"; import { toolRegistry } from "../../assistant/tool-registry"; -import { SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry"; +import { minWindowTop, SIDEBAR_WIDTH, TOP_BAR_HEIGHT, type WindowHeightMode } from "./geometry"; /** * The shell: owns the window registry, focus, screen on/off, and the shell @@ -49,6 +49,12 @@ export type ShellWindow = { surfaceId: string; /** Whether close menu entries (app menu default, shell escape menu) apply (the launcher is pinned). */ closeable: boolean; + /** + * Window height: the standard 288px band ("min") or the full screen + * ("max", terminal views). Decides the surface rect and where the shell + * draws this window's top bar. + */ + heightMode: WindowHeightMode; /** App-side cleanup when the shell closes the window (worker notification, surface removal). */ close?: () => void; drawIcon: ShellChromeWindow["drawIcon"]; @@ -97,9 +103,11 @@ const LONG_PRESS_ESCAPE_MENU_MS = 4000; /** Shell-surface overlay menu (the escape menu); closing it returns focus to the sidebar. */ class ShellOverlayMenuLayer extends MenuLayer { constructor(items: MenuItem[], private readonly onClosed: () => void) { + // Aligned to the min-height window band (like the sidebar), wherever the + // vertical position setting currently puts it. super(null, items, { x: SIDEBAR_WIDTH + 8, - y: TOP_BAR_HEIGHT + 8, + y: minWindowTop() + TOP_BAR_HEIGHT + 8, width: 272, minHeight: 0, }); @@ -135,13 +143,15 @@ class ShellAlertLayer implements Layer { paint(_ctx: LayerContext, paintBelow: () => GrayImage): GrayImage { const image = paintBelow(); const font = getDefaultSmallFont(); - image.fillRoundedRect(ALERT_X, ALERT_Y, ALERT_W, ALERT_H, 1, 10); - image.drawRoundedRect(ALERT_X, ALERT_Y, ALERT_W, ALERT_H, 90, 10); - image.drawText(font, ALERT_X + 16, ALERT_Y + 12, "Assistant", 200); + // Positioned within the min-height window band, like the other shell overlays. + const alertY = minWindowTop() + ALERT_Y; + image.fillRoundedRect(ALERT_X, alertY, ALERT_W, ALERT_H, 1, 10); + image.drawRoundedRect(ALERT_X, alertY, ALERT_W, ALERT_H, 90, 10); + image.drawText(font, ALERT_X + 16, alertY + 12, "Assistant", 200); image.drawTextWrapped({ font, x: ALERT_X + 16, - y: ALERT_Y + 34, + y: alertY + 34, width: ALERT_W - 32, text: this.text, value: 235, @@ -911,6 +921,7 @@ class Shell { })), selectedIndex: this.selectedIndex, focus: this.focus, + foregroundHeightMode: this.foregroundWindow()?.heightMode ?? "min", battery: this.battery, trayIcons: Array.from(this.trayIcons.keys()) .sort() diff --git a/app/ui/shell/tool-debug-layer.ts b/app/ui/shell/tool-debug-layer.ts index 69e4aece..ec1b0e86 100644 --- a/app/ui/shell/tool-debug-layer.ts +++ b/app/ui/shell/tool-debug-layer.ts @@ -1,11 +1,11 @@ -import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image"; +import { G2_LENS_WIDTH, GrayImage } from "../../graphics/image"; import { getDefaultSmallFont } from "../../graphics/bdffont"; import { wrapText } from "../../graphics/textwrap"; import { clamp } from "../../util/numeric-util"; import type { ToolDebugEntry } from "../../assistant/tool-registry"; import { DashboardInputEvent, Layer, LayerContext, PaintBelow } from "../layers"; import { MenuLayer, drawListScrollbar, type MenuItem } from "../menu"; -import { SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry"; +import { MIN_WINDOW_HEIGHT, minWindowTop, SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry"; /** * Shell-overlay debug dialog (escape menu > Debug): lists the voice assistant @@ -15,10 +15,16 @@ import { SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry"; */ const DIALOG_X = SIDEBAR_WIDTH + 8; -const DIALOG_Y = TOP_BAR_HEIGHT + 8; const DIALOG_WIDTH = 420; const DETAIL_WIDTH = G2_LENS_WIDTH - DIALOG_X - 8; -const DETAIL_HEIGHT = G2_LENS_HEIGHT - DIALOG_Y - 8; +// Shell overlays align to the min-height window band; the detail box fills +// the band below the top bar with an 8px margin on each side. +const DETAIL_HEIGHT = MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 16; + +/** Dialog top edge, aligned to the min-height band's content area. */ +function dialogY(): number { + return minWindowTop() + TOP_BAR_HEIGHT + 8; +} const DETAIL_PADDING = 14; const DETAIL_LINE_HEIGHT = 14; @@ -26,7 +32,7 @@ export class ToolDebugMenuLayer extends MenuLayer { constructor(appId: string | null, entries: ToolDebugEntry[], private readonly onClosed: () => void) { super(appId ? `Assistant tools: ${appId}` : "Assistant tools", buildItems(appId, entries), { x: DIALOG_X, - y: DIALOG_Y, + y: dialogY(), width: DIALOG_WIDTH, minHeight: 0, }); @@ -72,8 +78,9 @@ class ToolDetailLayer implements Layer { paint(_ctx: LayerContext, paintBelow: PaintBelow): GrayImage { const image = paintBelow(); const font = getDefaultSmallFont(); - image.fillRoundedRect(DIALOG_X, DIALOG_Y, DETAIL_WIDTH, DETAIL_HEIGHT, 1, 10); - image.drawRoundedRect(DIALOG_X, DIALOG_Y, DETAIL_WIDTH, DETAIL_HEIGHT, 72, 10); + const top = dialogY(); + image.fillRoundedRect(DIALOG_X, top, DETAIL_WIDTH, DETAIL_HEIGHT, 1, 10); + image.drawRoundedRect(DIALOG_X, top, DETAIL_WIDTH, DETAIL_HEIGHT, 72, 10); const textX = DIALOG_X + DETAIL_PADDING; const textWidth = DETAIL_WIDTH - 2 * DETAIL_PADDING - 8; @@ -84,14 +91,14 @@ class ToolDetailLayer implements Layer { const lastVisibleRow = Math.min(lines.length, this.scrollRow + visibleRowCount); for (let index = this.scrollRow; index < lastVisibleRow; index++) { const line = lines[index]!; - const y = DIALOG_Y + DETAIL_PADDING + (index - this.scrollRow) * DETAIL_LINE_HEIGHT; + const y = top + DETAIL_PADDING + (index - this.scrollRow) * DETAIL_LINE_HEIGHT; image.drawText(font, textX, y, line.text, line.value); } if (lines.length > visibleRowCount) { drawListScrollbar( image, DIALOG_X + DETAIL_WIDTH - 7, - DIALOG_Y + DETAIL_PADDING, + top + DETAIL_PADDING, DETAIL_HEIGHT - 2 * DETAIL_PADDING, this.scrollRow, visibleRowCount, diff --git a/app/ui/shell/worker-window.ts b/app/ui/shell/worker-window.ts index b910be6e..45d9c49f 100644 --- a/app/ui/shell/worker-window.ts +++ b/app/ui/shell/worker-window.ts @@ -2,6 +2,7 @@ import { GrayImage } from "../../graphics/image"; import { windowIcon } from "./chrome-layer"; import { type IconName } from "../../graphics/icons"; import { toolRegistry, type ToolResult, type ToolSpec } from "../../assistant/tool-registry"; +import { appViewportSize, type WindowHeightMode } from "./geometry"; import { shell, type ShellWindow } from "./shell"; /** @@ -46,6 +47,8 @@ export type WorkerAppReply = icon?: IconName; iconGlyph?: string; focus?: boolean; + /** Window height: the standard 288px band ("min", default) or full screen ("max"). */ + heightMode?: WindowHeightMode; } | { type: "set-title"; windowId: string; title: string } | { type: "set-attention"; windowId: string; attention: boolean } @@ -100,14 +103,15 @@ export type WorkerWindowSpec = { iconGlyph?: string; /** Foreground and focus the window once its surface exists. */ focus?: boolean; + /** Window height: the standard 288px band ("min", default) or full screen ("max"). */ + heightMode?: WindowHeightMode; }; export type WorkerAppHostOptions = { appId: string; worker: Worker; - viewport: { width: number; height: number }; /** Create/refresh a window surface on the compositor (no-op when disconnected). */ - configureSurface: (surfaceId: string, visible: boolean) => Promise; + configureSurface: (surfaceId: string, visible: boolean, heightMode: WindowHeightMode) => Promise; setSurfaceVisible: (surfaceId: string, visible: boolean) => void; removeSurface: (surfaceId: string) => void; requestShellRender: () => void; @@ -174,6 +178,7 @@ export class WorkerAppHost { icon: message.icon, iconGlyph: message.iconGlyph, focus: message.focus, + heightMode: message.heightMode, }); break; case "set-attention": @@ -242,12 +247,13 @@ export class WorkerAppHost { /** Open a window of this app and register it with the shell. */ openWindow(spec: WorkerWindowSpec): ShellWindow { const surfaceId = `window:${spec.windowId}`; + const heightMode = spec.heightMode ?? "min"; this.openWindows.add(spec.windowId); this.post({ type: "open-window", windowId: spec.windowId, surfaceId, - viewport: this.options.viewport, + viewport: appViewportSize(heightMode), }); const window: ShellWindow = { appId: this.options.appId, @@ -255,6 +261,7 @@ export class WorkerAppHost { title: spec.title, surfaceId, closeable: true, + heightMode, close: () => { this.openWindows.delete(spec.windowId); // Withdraw this window's tools and fail any in-flight calls to it. @@ -301,7 +308,7 @@ export class WorkerAppHost { // Configure the surface before any foregrounding so the worker's first // frame has somewhere to land. void this.options - .configureSurface(surfaceId, false) + .configureSurface(surfaceId, false, heightMode) .then(() => { if (spec.focus) { shell.focusWindow(spec.windowId); diff --git a/app/workers/terminal-app.worker.ts b/app/workers/terminal-app.worker.ts index 285d5f57..b4129a00 100644 --- a/app/workers/terminal-app.worker.ts +++ b/app/workers/terminal-app.worker.ts @@ -41,17 +41,26 @@ import { type MenuItem, } from "../ui/menu"; import { defaultWindowMenuItems, WindowMenu } from "../ui/window-menu"; +import { appViewportSize } from "../ui/shell/geometry"; import type { WorkerAppMessage, WorkerAppReply } from "../ui/shell/worker-window"; import type { ToolResult, ToolSpec } from "../assistant/tool-registry"; declare const global: any; declare const com: any; -// Terminus-12 has a 6x12 cell; the grid size is derived from the viewport at -// the first open-window and declared in each websocket init handshake. +// Terminus-12 has a 6x12 cell; each window derives its grid from the +// viewport in its open-window message (the hub is min-height, session views +// full-height). The websocket init handshake declares the view grid. const terminalFont = getFont("terminus12"); const CELL_WIDTH = 6; const CELL_HEIGHT = 12; +// Grid of a session view window (full-height); also declared on the control +// connection so sessions launched from presets come up at view size. +const VIEW_VIEWPORT = appViewportSize("max"); +const VIEW_GRID = { + cols: Math.floor(VIEW_VIEWPORT.width / CELL_WIDTH), + rows: Math.floor(VIEW_VIEWPORT.height / CELL_HEIGHT), +}; const DEVICE_NAME = "Faceclaw G2"; const HUB_ROW_HEIGHT = 20; const RENDER_COALESCE_MS = 33; @@ -60,6 +69,11 @@ const HISTORY_PAGE = 200; type BaseWindow = { windowId: string; surfaceId: string; + /** Content viewport from the shell's open-window message; grid = viewport / cell. */ + viewportWidth: number; + viewportHeight: number; + gridCols: number; + gridRows: number; foreground: boolean; /** * Whether this window is the shell's input target (vs. the sidebar having @@ -174,10 +188,6 @@ const TERMINAL_TOOLS: ToolSpec[] = [ timeoutMs: 15_000, }, ]; -let viewportWidth = 0; -let viewportHeight = 0; -let gridCols = 0; -let gridRows = 0; let screenOn = true; // Control connection: session listing for the hub, plus unsolicited @@ -277,21 +287,17 @@ onSettingsStoreChanged((key) => { if (!key.startsWith("terminal.")) return; // Settings that don't affect the connection; no reconnect needed. if (key === "terminal.launchPresets" || key === "terminal.wakeOnBell") return; - if (gridCols > 0) { + // (Re)start only once the app has actually been opened. + if (controlClient || windows.size > 0) { startControlClient(); } }); function openWindow(windowId: string, surfaceId: string, viewport: { width: number; height: number }): void { - viewportWidth = viewport.width; - viewportHeight = viewport.height; - gridCols = Math.floor(viewportWidth / CELL_WIDTH); - gridRows = Math.floor(viewportHeight / CELL_HEIGHT); - const pendingView = pendingViews.get(windowId); if (pendingView) { pendingViews.delete(windowId); - windows.set(windowId, createViewWindow(windowId, surfaceId, pendingView)); + windows.set(windowId, createViewWindow(windowId, surfaceId, viewport, pendingView)); renderHubWindows(); return; } @@ -299,6 +305,10 @@ function openWindow(windowId: string, surfaceId: string, viewport: { width: numb kind: "hub", windowId, surfaceId, + viewportWidth: viewport.width, + viewportHeight: viewport.height, + gridCols: Math.floor(viewport.width / CELL_WIDTH), + gridRows: Math.floor(viewport.height / CELL_HEIGHT), foreground: false, focused: false, renderScheduled: false, @@ -337,8 +347,8 @@ function clientOptions() { port: parseInt(terminalPortSetting.get(), 10) || 8737, authToken: terminalAuthTokenSetting.get(), deviceName: DEVICE_NAME, - cols: gridCols, - rows: gridRows, + cols: VIEW_GRID.cols, + rows: VIEW_GRID.rows, }; } @@ -425,14 +435,21 @@ function renderHubWindows(): void { function createViewWindow( windowId: string, surfaceId: string, + viewport: { width: number; height: number }, view: { socket: string; label: string; glyph: string }, ): ViewWindow { const { socket, label, glyph } = view; - const client = new G2MirrorClient(clientOptions()); + const gridCols = Math.floor(viewport.width / CELL_WIDTH); + const gridRows = Math.floor(viewport.height / CELL_HEIGHT); + const client = new G2MirrorClient({ ...clientOptions(), cols: gridCols, rows: gridRows }); const window: ViewWindow = { kind: "view", windowId, surfaceId, + viewportWidth: viewport.width, + viewportHeight: viewport.height, + gridCols, + gridRows, foreground: false, focused: false, renderScheduled: false, @@ -504,7 +521,7 @@ function createViewWindow( function windowMenu(window: TerminalWindow): WindowMenu { if (!window.menu) { window.menu = new WindowMenu({ - size: { width: viewportWidth, height: viewportHeight }, + size: { width: window.viewportWidth, height: window.viewportHeight }, paintBase: () => paintContent(window), isFocused: () => window.focused, }); @@ -603,11 +620,11 @@ function handleInput(window: TerminalWindow, event: DashboardInputEvent, frameId /** Top visible absolute line index when following the live bottom. */ function followTop(window: ViewWindow): number { - return window.historyNext + window.emulator.bufferLength() - gridRows; + return window.historyNext + window.emulator.bufferLength() - window.gridRows; } function handleViewScroll(window: ViewWindow, direction: -1 | 1, frameId: number): void { - const page = Math.max(1, gridRows - 1); + const page = Math.max(1, window.gridRows - 1); const bottomTop = followTop(window); const minTop = window.archiveStart; const currentTop = window.scrollTop ?? bottomTop; @@ -623,7 +640,7 @@ function maybePrefetchHistory(window: ViewWindow): void { if (window.historyFetchInFlight) return; if (window.archiveStart <= window.historyOldest) return; // nothing older retained const top = window.scrollTop ?? followTop(window); - if (window.archive.length === 0 || top - window.archiveStart <= gridRows) { + if (window.archive.length === 0 || top - window.archiveStart <= window.gridRows) { window.historyFetchInFlight = true; window.client.requestHistory(window.archiveStart, HISTORY_PAGE); } @@ -779,6 +796,9 @@ function openViewWindow(socket: string, label: string): void { icon: "terminal", iconGlyph: glyph || undefined, focus: true, + // Terminal views are the one full-height window kind: more rows matter + // more than a small on-screen footprint. + heightMode: "max", }); } @@ -812,7 +832,7 @@ function paintContent(window: TerminalWindow): GrayImage { } function paintHub(window: HubWindow): GrayImage { - const image = new GrayImage(viewportWidth, viewportHeight, 0); + const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0); // No border box: the shell chrome (top bar + sidebar) already frames the app. image.drawText(terminalFont, 18, 10, "Terminal", 220); image.drawText(terminalFont, 24, 30, hubStatusLine(), 170); @@ -826,7 +846,7 @@ function paintHub(window: HubWindow): GrayImage { const items = hubItems(window); window.selectedIndex = Math.max(0, Math.min(window.selectedIndex, items.length - 1)); - const visibleRowCount = Math.max(1, ((viewportHeight - 30 - listTop) / HUB_ROW_HEIGHT) | 0); + const visibleRowCount = Math.max(1, ((window.viewportHeight - 30 - listTop) / HUB_ROW_HEIGHT) | 0); window.scrollRow = scrollToKeepSelectionVisible(window.scrollRow, window.selectedIndex, visibleRowCount, items.length); const lastVisibleRow = Math.min(items.length, window.scrollRow + visibleRowCount); for (let index = window.scrollRow; index < lastVisibleRow; index++) { @@ -835,14 +855,14 @@ function paintHub(window: HubWindow): GrayImage { if (selected) { // Match the shell convention: fill only when this window has focus, so // an outline-only selection signals the sidebar owns input. - drawSelectionHighlight(image, 20, y - 2, viewportWidth - 40, HUB_ROW_HEIGHT - 1, window.focused, 8); + drawSelectionHighlight(image, 20, y - 2, window.viewportWidth - 40, HUB_ROW_HEIGHT - 1, window.focused, 8); } image.drawText(terminalFont, 32, y + 2, items[index]!.label, selected ? 255 : 200); } if (items.length > visibleRowCount) { drawListScrollbar( image, - viewportWidth - 10, + window.viewportWidth - 10, listTop, visibleRowCount * HUB_ROW_HEIGHT - 4, window.scrollRow, @@ -851,7 +871,7 @@ function paintHub(window: HubWindow): GrayImage { ); } - image.drawText(terminalFont, 24, viewportHeight - 24, `${GESTURE_DOUBLE_CLICK} back`, 110); + image.drawText(terminalFont, 24, window.viewportHeight - 24, `${GESTURE_DOUBLE_CLICK} back`, 110); return image; } @@ -863,14 +883,14 @@ function hubStatusLine(): string { } function paintView(window: ViewWindow): GrayImage { - const image = new GrayImage(viewportWidth, viewportHeight, 0); + const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0); if (!window.receivedData) { image.drawText(terminalFont, 24, 110, window.status, 170); image.drawText(terminalFont, 24, 130, `${GESTURE_DOUBLE_CLICK} back`, 110); return image; } - const rows = gridRows; + const rows = window.gridRows; const historyNext = window.historyNext; const bufferLength = window.emulator.bufferLength(); const bottomTop = historyNext + bufferLength - rows; @@ -903,11 +923,11 @@ function paintView(window: ViewWindow): GrayImage { /** Right-edge scrollbar showing the view position within the scrollback. */ function drawScrollIndicator(image: GrayImage, top: number, minTop: number, maxTop: number): void { - const trackX = viewportWidth - 3; - image.fillRect(trackX, 0, 3, viewportHeight, 30); + const trackX = image.width - 3; + image.fillRect(trackX, 0, 3, image.height, 30); const fraction = clamp((top - minTop) / Math.max(1, maxTop - minTop), 0, 1); const thumbHeight = 24; - const thumbY = Math.round((viewportHeight - thumbHeight) * fraction); + const thumbY = Math.round((image.height - thumbHeight) * fraction); image.fillRect(trackX, thumbY, 3, thumbHeight, 150); } @@ -1031,7 +1051,7 @@ function toolReadScreen(): ToolResult { const view = resolveActiveView(); if (!view) return { ok: false, error: "No terminal session is open." }; const length = view.emulator.bufferLength(); - const start = Math.max(0, length - gridRows); + const start = Math.max(0, length - view.gridRows); const lines: string[] = []; for (let index = start; index < length; index++) { lines.push(view.emulator.lineAt(index));