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

+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),
};
}