Add screen-size setting to Navigate and Terminal apps

This commit is contained in:
James Babcock committed 2026-09-05 10:45:39 -07:00
1 parent 50f2041eea
commit 1524766996
15 files changed
+501 -56

No files matched your search

+11 -11
View File
@@ -69,8 +69,8 @@ function slotPosition(variant: SidebarVariant, listTop: number, position: number
}
/** Top y of the sidebar's icon list (below the band's top bar). */
function sidebarListTop(): number {
return minWindowTop() + TOP_BAR_HEIGHT + LIST_MARGIN;
function sidebarListTop(appId?: string): number {
return minWindowTop(appId) + TOP_BAR_HEIGHT + LIST_MARGIN;
}
/**
@@ -100,6 +100,7 @@ export type ShellChromeState = {
focus: "sidebar" | "window";
/** Height mode of the foreground window; decides where its top bar sits. */
foregroundHeightMode: WindowHeightMode;
foregroundAppId?: string;
battery: { headset: number | null; headsetCharging: boolean | null };
/** App-provided tray images, drawn between notification icons and batteries. */
trayIcons: GrayImage[];
@@ -191,7 +192,7 @@ export class ShellChromeLayer implements Layer {
const state = this.getState();
// Full-panel mode: the strip is an overlay, present only while the user
// is in it (the window underneath keeps its full width the rest of the time).
if (sidebarStripVisible(state.focus)) {
if (sidebarStripVisible(state.focus, state.foregroundAppId)) {
this.drawSidebar(image, state);
}
this.drawTopBar(image, state);
@@ -212,7 +213,7 @@ export class ShellChromeLayer implements Layer {
windowIndexAt(x: number, y: number, windowCount: number): number | null {
if (x < 0 || x >= SIDEBAR_WIDTH || windowCount === 0) return null;
const variant = sidebarVariant(windowCount);
const listTop = sidebarListTop();
const listTop = sidebarListTop(this.getState().foregroundAppId);
const lastVisible = Math.min(windowCount, this.scrollRow + rowsPerColumn(variant) * variant.columns);
for (let index = this.scrollRow; index < lastVisible; index++) {
const { column, y: slotY } = slotPosition(variant, listTop, index - this.scrollRow);
@@ -225,10 +226,9 @@ export class ShellChromeLayer implements Layer {
}
private drawSidebar(image: GrayImage, state: ShellChromeState): void {
// 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();
// Align the sidebar with the app's preferred band. Legacy tall terminal
// sessions keep the sidebar at the global band position.
const bandTop = minWindowTop(state.foregroundAppId);
const bandBottom = bandTop + MIN_WINDOW_HEIGHT;
image.fillRect(0, bandTop, SIDEBAR_WIDTH, MIN_WINDOW_HEIGHT, SHELL_OPAQUE_BLACK);
@@ -242,7 +242,7 @@ export class ShellChromeLayer implements Layer {
const iconMarginX = ((variant.columnWidth - iconSize) / 2) | 0;
// Column index of the rightmost column (the one that fills first).
const firstColumn = variant.columns - 1;
const listTop = sidebarListTop();
const listTop = sidebarListTop(state.foregroundAppId);
const visibleCount = rowsPerColumn(variant) * variant.columns;
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, visibleCount, count);
const lastVisible = Math.min(count, this.scrollRow + visibleCount);
@@ -304,10 +304,10 @@ export class ShellChromeLayer implements Layer {
// The bar sits at the top edge of the foreground window's band, wherever
// its height mode puts that (screen top for max height). It moves when
// the foreground switches to a window of a different height.
const barTop = windowTop(state.foregroundHeightMode);
const barTop = windowTop(state.foregroundHeightMode, state.foregroundAppId);
// The bar spans the app viewport; with the sidebar overlaid (full-panel
// mode, sidebar focused) it still starts past the strip.
const barLeft = sidebarStripVisible(state.focus) ? SIDEBAR_WIDTH : 0;
const barLeft = sidebarStripVisible(state.focus, state.foregroundAppId) ? SIDEBAR_WIDTH : 0;
image.fillRect(barLeft, barTop, G2_LENS_WIDTH - barLeft, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK);
image.drawLine(barLeft, barTop + TOP_BAR_HEIGHT - 1, G2_LENS_WIDTH - 1, barTop + TOP_BAR_HEIGHT - 1, BORDER_VALUE);
+42 -26
View File
@@ -1,5 +1,13 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../../graphics/image";
import { displayModeSetting, type DisplayModeSetting, verticalPositionSetting } from "../dashboard-settings";
import {
displayModeSetting,
type DisplayModeSetting,
verticalPositionSetting,
navigateDisplayModeSetting,
navigateVerticalPositionSetting,
terminalDisplayModeSetting,
terminalVerticalPositionSetting,
} from "../dashboard-settings";
/** Top bar: 24px notification icons plus a little padding. */
export const TOP_BAR_HEIGHT = 28;
@@ -13,8 +21,14 @@ export const TOP_BAR_HEIGHT = 28;
export const SIDEBAR_WIDTH = 64;
/** The Display > Display mode setting (see dashboard-settings.ts). */
export function displayMode(): DisplayModeSetting {
return displayModeSetting.get();
function appDisplayMode(appId?: string) {
return appId === "navigate" ? navigateDisplayModeSetting.get()
: appId === "terminal" ? terminalDisplayModeSetting.get() : "default";
}
export function displayMode(appId?: string): DisplayModeSetting {
const mode = appDisplayMode(appId);
return mode === "global" || mode === "default" ? displayModeSetting.get() : mode;
}
/**
@@ -22,24 +36,24 @@ export function displayMode(): DisplayModeSetting {
* the strip, or nothing in the full-panel mode (where the chrome paints the
* strip over the window while the sidebar has focus).
*/
export function sidebarWidth(): number {
return displayMode() === "640x480" ? 0 : SIDEBAR_WIDTH;
export function sidebarWidth(appId?: string): number {
return displayMode(appId) === "640x480" ? 0 : SIDEBAR_WIDTH;
}
/**
* Whether the sidebar strip is on screen: always when it reserves width; in
* the full-panel mode (where it overlays the window) only while it has focus.
*/
export function sidebarStripVisible(focus: "sidebar" | "window"): boolean {
return sidebarWidth() > 0 || focus === "sidebar";
export function sidebarStripVisible(focus: "sidebar" | "window", appId?: string): boolean {
return sidebarWidth(appId) > 0 || focus === "sidebar";
}
/**
* The height an app's requested mode actually gets: the band mode honours
* it, the taller modes give every window the whole screen.
* Explicit app sizes (including Use global) replace the requested height.
* The default keeps legacy per-window heights, such as tall terminal sessions.
*/
export function effectiveHeightMode(mode: WindowHeightMode): WindowHeightMode {
return displayMode() === "576x288" ? mode : "max";
export function effectiveHeightMode(mode: WindowHeightMode, appId?: string): WindowHeightMode {
return displayMode(appId) === "576x288" ? (appDisplayMode(appId) === "default" ? mode : "min") : "max";
}
/**
@@ -74,8 +88,8 @@ export const MIN_WINDOW_HEIGHT = 288;
export const MIN_WINDOW_MAX_TOP = G2_LENS_HEIGHT - MIN_WINDOW_HEIGHT;
/** Total height (top bar + content) of a window's band in the given mode. */
export function windowBandHeight(mode: WindowHeightMode): number {
switch (effectiveHeightMode(mode)) {
export function windowBandHeight(mode: WindowHeightMode, appId?: string): number {
switch (effectiveHeightMode(mode, appId)) {
case "max":
return G2_LENS_HEIGHT;
case "medium":
@@ -90,8 +104,10 @@ export function windowBandHeight(mode: WindowHeightMode): number {
* position setting: each band height distributes its own free space by the
* same fraction, so all heights sit consistently within the screen.
*/
function verticalPositionFraction(): number {
switch (verticalPositionSetting.get()) {
function verticalPositionFraction(appId?: string): number {
const position = appId === "navigate" ? navigateVerticalPositionSetting.get()
: appId === "terminal" ? terminalVerticalPositionSetting.get() : "global";
switch (position === "global" ? verticalPositionSetting.get() : position) {
case "top":
return 0;
case "upper":
@@ -109,33 +125,33 @@ function verticalPositionFraction(): number {
* Top edge (y) of a min-height window. The sidebar and shell overlays always
* align to this band, even while a taller window is foreground.
*/
export function minWindowTop(): number {
return windowTop("min");
export function minWindowTop(appId?: string): number {
return windowTop("min", appId);
}
/** Top edge (y) of a window's top bar; max-height windows pin to the screen top. */
export function windowTop(mode: WindowHeightMode): number {
return Math.round((G2_LENS_HEIGHT - windowBandHeight(mode)) * verticalPositionFraction());
export function windowTop(mode: WindowHeightMode, appId?: string): number {
return Math.round((G2_LENS_HEIGHT - windowBandHeight(mode, appId)) * verticalPositionFraction(appId));
}
/** App-content viewport size for a height mode (independent of vertical position). */
export function appViewportSize(mode: WindowHeightMode): { width: number; height: number } {
export function appViewportSize(mode: WindowHeightMode, appId?: string): { width: number; height: number } {
return {
width: G2_LENS_WIDTH - sidebarWidth(),
height: windowBandHeight(mode) - TOP_BAR_HEIGHT,
width: G2_LENS_WIDTH - sidebarWidth(appId),
height: windowBandHeight(mode, appId) - TOP_BAR_HEIGHT,
};
}
/** Screen rect of a window's app-content viewport (below its top bar). */
export function appViewportRect(mode: WindowHeightMode): {
export function appViewportRect(mode: WindowHeightMode, appId?: string): {
x: number;
y: number;
width: number;
height: number;
} {
return {
x: sidebarWidth(),
y: windowTop(mode) + TOP_BAR_HEIGHT,
...appViewportSize(mode),
x: sidebarWidth(appId),
y: windowTop(mode, appId) + TOP_BAR_HEIGHT,
...appViewportSize(mode, appId),
};
}
+6 -4
View File
@@ -115,7 +115,7 @@ export type ShellWindow = {
requestRender: () => void;
/**
* Re-measure against the current display mode (viewport size / band) and
* repaint. Windows without it (workers, whose canvas is fixed at open) are
* repaint. Windows without it (workers with a canvas fixed at open) are
* closed and relaunched by the controller instead.
*/
relayout?: () => void;
@@ -784,13 +784,14 @@ class Shell {
* strip left of the icon columns when the one-column variant is active.
*/
screenshotCropRect(): { x: number; y: number; width: number; height: number } {
const appId = this.foregroundWindow()?.appId;
const heightMode = this.foregroundWindow()?.heightMode ?? "min";
const x = sidebarContentLeft(this.windows.length);
const x = sidebarWidth(appId) === 0 ? 0 : sidebarContentLeft(this.windows.length);
return {
x,
y: windowTop(heightMode),
y: windowTop(heightMode, appId),
width: G2_LENS_WIDTH - x,
height: windowBandHeight(heightMode),
height: windowBandHeight(heightMode, appId),
};
}
@@ -1397,6 +1398,7 @@ class Shell {
selectedIndex: this.selectedIndex,
focus: this.focus,
foregroundHeightMode: this.foregroundWindow()?.heightMode ?? "min",
foregroundAppId: this.foregroundWindow()?.appId,
battery: this.battery,
trayIcons: Array.from(this.trayIcons.keys())
.sort()
+6 -1
View File
@@ -14,6 +14,7 @@ import { shell, type ShellWindow } from "./shell";
*/
export type WorkerAppMessage =
| { type: "open-window"; windowId: string; surfaceId: string; title: string; viewport: { width: number; height: number } }
| { type: "resize-window"; windowId: string; viewport: { width: number; height: number } }
| { type: "close-window"; windowId: string }
| { type: "input"; windowId: string; event: unknown; frameId: number; focused: boolean }
| { type: "text-input"; windowId: string; text: string }
@@ -338,7 +339,7 @@ export class WorkerAppHost {
windowId: spec.windowId,
surfaceId,
title: spec.title,
viewport: appViewportSize(heightMode),
viewport: appViewportSize(heightMode, this.options.appId),
});
const window: ShellWindow = {
appId: this.options.appId,
@@ -348,6 +349,10 @@ export class WorkerAppHost {
closeable: true,
acceptsDirectional: spec.acceptsDirectional,
heightMode,
// These apps can resize their live content without losing route/session state.
relayout: this.options.appId === "navigate" || this.options.appId === "terminal"
? () => this.post({ type: "resize-window", windowId: spec.windowId, viewport: appViewportSize(heightMode, this.options.appId) })
: undefined,
hasAppMenu: () => this.windowGestures.get(spec.windowId)?.hasAppMenu ?? false,
claimsLongPress: () => this.windowGestures.get(spec.windowId)?.claimsLongPress ?? false,
close: () => {