Crop screenshots

This commit is contained in:
James Babcock committed 2026-08-02 19:36:16 -07:00
1 parent 0f4adb0e86
commit 1ec6b3ff83
5 files changed
+85 -10

No files matched your search

+21 -4
View File
@@ -25,6 +25,24 @@ const ICON_MARGIN_X = ((SIDEBAR_COLUMN_WIDTH - ICON_SIZE) / 2) | 0;
/** Column index of the rightmost sidebar column (the one that fills first). */
const FIRST_COLUMN = SIDEBAR_COLUMNS - 1;
const ICON_SPACING = 8;
const ICON_STRIDE = ICON_SIZE + ICON_SPACING;
/** Icon list top/bottom margins within the sidebar band, below the top bar. */
const LIST_MARGIN = 10;
/** Icon rows that fit in one sidebar column. */
const ROWS_PER_COLUMN = Math.max(
1,
((MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 2 * LIST_MARGIN + ICON_SPACING) / ICON_STRIDE) | 0,
);
/**
* Whether the sidebar's left (overflow) column holds any icons. Icons fill
* the right column first; scrolling never shows fewer than a full right
* column, so the left column is populated exactly when there are more
* windows than one column holds.
*/
export function sidebarLeftColumnUsed(windowCount: number): boolean {
return windowCount > ROWS_PER_COLUMN;
}
const NOTIFICATION_ICON_SIZE = 24;
const BORDER_VALUE = 40;
const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
@@ -128,10 +146,9 @@ export class ShellChromeLayer implements Layer {
// windows off-screen above/below. Icons fill the right column top to
// bottom, then overflow into the left one, so a visible slot's column is
// decided by its position within the scrolled window.
const listTop = bandTop + TOP_BAR_HEIGHT + 10;
const itemStride = ICON_SIZE + ICON_SPACING;
const listHeight = bandBottom - listTop - 10;
const rowsPerColumn = Math.max(1, ((listHeight + ICON_SPACING) / itemStride) | 0);
const listTop = bandTop + TOP_BAR_HEIGHT + LIST_MARGIN;
const itemStride = ICON_STRIDE;
const rowsPerColumn = ROWS_PER_COLUMN;
const visibleCount = rowsPerColumn * SIDEBAR_COLUMNS;
const count = state.windows.length;
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, visibleCount, count);
+27 -2
View File
@@ -24,11 +24,19 @@ import {
timeFormatSetting,
wakeWordActionSetting,
} from "../dashboard-settings";
import { ShellChromeLayer, type ShellChromeState, type ShellChromeWindow } from "./chrome-layer";
import { ShellChromeLayer, sidebarLeftColumnUsed, type ShellChromeState, type ShellChromeWindow } from "./chrome-layer";
import { ShellModalLayer } from "./modal-layer";
import { ToolDebugMenuLayer } from "./tool-debug-layer";
import { toolRegistry } from "../../assistant/tool-registry";
import { minWindowTop, SIDEBAR_WIDTH, TOP_BAR_HEIGHT, type WindowHeightMode } from "./geometry";
import {
MIN_WINDOW_HEIGHT,
minWindowTop,
SIDEBAR_COLUMN_WIDTH,
SIDEBAR_WIDTH,
TOP_BAR_HEIGHT,
windowTop,
type WindowHeightMode,
} from "./geometry";
/**
* The shell: owns the window registry, focus, screen on/off, and the shell
@@ -573,6 +581,23 @@ class Shell {
return this.windows[this.selectedIndex] ?? this.windows[0];
}
/**
* Screen rect actually occupied by content, for cropping screenshots: the
* foreground window's band (full screen for a max-height window, the
* vertical-position-dependent 288px band otherwise), minus the sidebar's
* left column when no icons have overflowed into it.
*/
screenshotCropRect(): { x: number; y: number; width: number; height: number } {
const heightMode = this.foregroundWindow()?.heightMode ?? "min";
const x = sidebarLeftColumnUsed(this.windows.length) ? 0 : SIDEBAR_COLUMN_WIDTH;
return {
x,
y: windowTop(heightMode),
width: G2_LENS_WIDTH - x,
height: heightMode === "max" ? G2_LENS_HEIGHT : MIN_WINDOW_HEIGHT,
};
}
/** Whether a window is the current input target (foreground + focus in-window). */
isWindowFocused(windowId: string): boolean {
return this.screenOn && this.focus === "window" && this.foregroundWindow()?.windowId === windowId;