From b1493a353d355927ad5f62d30a0ea32106e2078b Mon Sep 17 00:00:00 2001 From: James Babcock Date: Tue, 1 Sep 2026 00:58:28 -0700 Subject: [PATCH] Context menus are centered and include window title --- CHANGELOG | 3 +++ app/apps/blocks/blocks-app.worker.ts | 3 +++ app/apps/freecell/freecell-app.worker.ts | 3 +++ app/apps/minesweeper/minesweeper-app.worker.ts | 3 +++ app/apps/navigate/navigate-app.worker.ts | 3 +++ app/apps/pinball/pinball-app.worker.ts | 3 +++ app/apps/roam/roam-app.worker.ts | 3 +++ app/apps/terminal/terminal-app.worker.ts | 12 +++++++++--- app/apps/timer/timer-app.worker.ts | 3 +++ app/ui/menu.ts | 6 ++++-- app/ui/shell/in-process-window.ts | 2 +- app/ui/shell/shell.ts | 14 ++++++++------ app/ui/shell/worker-window.ts | 3 ++- app/ui/window-menu.ts | 12 +++++++----- 14 files changed, 55 insertions(+), 18 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 82667b94..31043cf4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ # Changelog +## 0.6.4 - Future +* Context menus are centered and include window title + ## 0.6.3 - 2026-09-01 * Update custom firmware base version from 2.2.6 to 2.2.9 * Add support for the short-then-long-press gesture diff --git a/app/apps/blocks/blocks-app.worker.ts b/app/apps/blocks/blocks-app.worker.ts index 4c9b270e..9ac8da52 100644 --- a/app/apps/blocks/blocks-app.worker.ts +++ b/app/apps/blocks/blocks-app.worker.ts @@ -136,6 +136,7 @@ type GamePhase = "playing" | "paused" | "game-over"; type BlocksWindow = { windowId: string; surfaceId: string; + title: string; viewportWidth: number; viewportHeight: number; foreground: boolean; @@ -181,6 +182,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { const window: BlocksWindow = { windowId: message.windowId, surfaceId: message.surfaceId, + title: message.title, viewportWidth: message.viewport.width, viewportHeight: message.viewport.height, foreground: false, @@ -303,6 +305,7 @@ function openWindowMenu(window: BlocksWindow): void { function windowMenu(window: BlocksWindow): WindowMenu { if (!window.menu) { window.menu = new WindowMenu({ + title: () => window.title, size: { width: window.viewportWidth, height: window.viewportHeight }, paintBase: () => paintContent(window), isFocused: () => window.focused, diff --git a/app/apps/freecell/freecell-app.worker.ts b/app/apps/freecell/freecell-app.worker.ts index 2529c48d..5b45fa2e 100644 --- a/app/apps/freecell/freecell-app.worker.ts +++ b/app/apps/freecell/freecell-app.worker.ts @@ -100,6 +100,7 @@ type Snapshot = { type FreecellWindow = { windowId: string; surfaceId: string; + title: string; viewportWidth: number; viewportHeight: number; foreground: boolean; @@ -142,6 +143,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { const window: FreecellWindow = { windowId: message.windowId, surfaceId: message.surfaceId, + title: message.title, viewportWidth: message.viewport.width, viewportHeight: message.viewport.height, foreground: false, @@ -256,6 +258,7 @@ function openWindowMenu(window: FreecellWindow): void { function windowMenu(window: FreecellWindow): WindowMenu { if (!window.menu) { window.menu = new WindowMenu({ + title: () => window.title, size: { width: window.viewportWidth, height: window.viewportHeight }, paintBase: () => paintContent(window), isFocused: () => window.focused, diff --git a/app/apps/minesweeper/minesweeper-app.worker.ts b/app/apps/minesweeper/minesweeper-app.worker.ts index edc91513..797b0785 100644 --- a/app/apps/minesweeper/minesweeper-app.worker.ts +++ b/app/apps/minesweeper/minesweeper-app.worker.ts @@ -94,6 +94,7 @@ type GamePhase = "playing" | "paused" | "won" | "lost"; type MinesweeperWindow = { windowId: string; surfaceId: string; + title: string; viewportWidth: number; viewportHeight: number; foreground: boolean; @@ -146,6 +147,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { const window: MinesweeperWindow = { windowId: message.windowId, surfaceId: message.surfaceId, + title: message.title, viewportWidth: message.viewport.width, viewportHeight: message.viewport.height, foreground: false, @@ -285,6 +287,7 @@ function openWindowMenu(window: MinesweeperWindow): void { function windowMenu(window: MinesweeperWindow): WindowMenu { if (!window.menu) { window.menu = new WindowMenu({ + title: () => window.title, size: { width: window.viewportWidth, height: window.viewportHeight }, paintBase: () => paintContent(window), isFocused: () => window.focused, diff --git a/app/apps/navigate/navigate-app.worker.ts b/app/apps/navigate/navigate-app.worker.ts index 96404d6b..b0e051ad 100644 --- a/app/apps/navigate/navigate-app.worker.ts +++ b/app/apps/navigate/navigate-app.worker.ts @@ -59,6 +59,7 @@ type MapMode = "follow" | "overview"; type NavWindow = { windowId: string; surfaceId: string; + title: string; viewportWidth: number; viewportHeight: number; foreground: boolean; @@ -162,6 +163,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { window = { windowId: message.windowId, surfaceId: message.surfaceId, + title: message.title, viewportWidth: message.viewport.width, viewportHeight: message.viewport.height, foreground: false, @@ -612,6 +614,7 @@ function describeRouteStatus(): string { function windowMenu(win: NavWindow): WindowMenu { if (!win.menu) { win.menu = new WindowMenu({ + title: () => win.title, size: { width: win.viewportWidth, height: win.viewportHeight }, paintBase: () => paintContent(win), isFocused: () => win.focused, diff --git a/app/apps/pinball/pinball-app.worker.ts b/app/apps/pinball/pinball-app.worker.ts index b3598ecf..3f756b0c 100644 --- a/app/apps/pinball/pinball-app.worker.ts +++ b/app/apps/pinball/pinball-app.worker.ts @@ -242,6 +242,7 @@ type Flipper = { type PinballWindow = { windowId: string; surfaceId: string; + title: string; viewportWidth: number; viewportHeight: number; foreground: boolean; @@ -301,6 +302,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { const window: PinballWindow = { windowId: message.windowId, surfaceId: message.surfaceId, + title: message.title, viewportWidth: message.viewport.width, viewportHeight: message.viewport.height, foreground: false, @@ -469,6 +471,7 @@ function openWindowMenu(window: PinballWindow): void { function windowMenu(window: PinballWindow): WindowMenu { if (!window.menu) { window.menu = new WindowMenu({ + title: () => window.title, size: { width: window.viewportWidth, height: window.viewportHeight }, paintBase: () => paintContent(window), isFocused: () => window.focused, diff --git a/app/apps/roam/roam-app.worker.ts b/app/apps/roam/roam-app.worker.ts index d78ea93a..dbe293c9 100644 --- a/app/apps/roam/roam-app.worker.ts +++ b/app/apps/roam/roam-app.worker.ts @@ -64,6 +64,7 @@ const smallFont = getDefaultSmallFont(); type RoamWindow = { windowId: string; surfaceId: string; + title: string; viewportWidth: number; viewportHeight: number; foreground: boolean; @@ -168,6 +169,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { window = { windowId: message.windowId, surfaceId: message.surfaceId, + title: message.title, viewportWidth: message.viewport.width, viewportHeight: message.viewport.height, foreground: false, @@ -327,6 +329,7 @@ function maybeRefreshStalePage(): void { function windowMenu(win: RoamWindow): WindowMenu { if (!win.menu) { win.menu = new WindowMenu({ + title: () => win.title, size: { width: win.viewportWidth, height: win.viewportHeight }, paintBase: () => paintContent(win), isFocused: () => win.focused, diff --git a/app/apps/terminal/terminal-app.worker.ts b/app/apps/terminal/terminal-app.worker.ts index 17cf623d..49df3e51 100644 --- a/app/apps/terminal/terminal-app.worker.ts +++ b/app/apps/terminal/terminal-app.worker.ts @@ -88,6 +88,8 @@ const NEW_CONNECTION_DRAFT_KEY = "terminal.newConnectionDraft"; type BaseWindow = { windowId: string; surfaceId: string; + /** Shell-side window title, echoed back in the open-window message. */ + title: string; /** Content viewport from the shell's open-window message; grid = viewport / cell. */ viewportWidth: number; viewportHeight: number; @@ -304,7 +306,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { const message = event.data; switch (message.type) { case "open-window": - openWindow(message.windowId, message.surfaceId, message.viewport); + openWindow(message.windowId, message.surfaceId, message.title, message.viewport); break; case "close-window": closeWindow(message.windowId); @@ -430,11 +432,11 @@ function cancelPendingReconnects(): void { } } -function openWindow(windowId: string, surfaceId: string, viewport: { width: number; height: number }): void { +function openWindow(windowId: string, surfaceId: string, title: string, viewport: { width: number; height: number }): void { const pendingView = pendingViews.get(windowId); if (pendingView) { pendingViews.delete(windowId); - windows.set(windowId, createViewWindow(windowId, surfaceId, viewport, pendingView)); + windows.set(windowId, createViewWindow(windowId, surfaceId, title, viewport, pendingView)); renderHubWindows(); return; } @@ -443,6 +445,7 @@ function openWindow(windowId: string, surfaceId: string, viewport: { width: numb kind: "hub", windowId, surfaceId, + title, viewportWidth: viewport.width, viewportHeight: viewport.height, gridCols: Math.floor(viewport.width / hubCell.cellWidth), @@ -753,6 +756,7 @@ function noteSessionActivity(connectionId: string, socket: string): void { function createViewWindow( windowId: string, surfaceId: string, + title: string, viewport: { width: number; height: number }, view: PendingView, ): ViewWindow { @@ -768,6 +772,7 @@ function createViewWindow( kind: "view", windowId, surfaceId, + title, viewportWidth: viewport.width, viewportHeight: viewport.height, gridCols, @@ -900,6 +905,7 @@ function reconnectView(window: ViewWindow): void { function windowMenu(window: TerminalWindow): WindowMenu { if (!window.menu) { window.menu = new WindowMenu({ + title: () => window.title, size: { width: window.viewportWidth, height: window.viewportHeight }, paintBase: () => paintContent(window), isFocused: () => window.focused, diff --git a/app/apps/timer/timer-app.worker.ts b/app/apps/timer/timer-app.worker.ts index 1fdd1a92..fbe8f7da 100644 --- a/app/apps/timer/timer-app.worker.ts +++ b/app/apps/timer/timer-app.worker.ts @@ -42,6 +42,7 @@ type TimerView = "stopwatch" | "timers" | "editor"; type TimerWindow = { windowId: string; surfaceId: string; + title: string; viewportWidth: number; viewportHeight: number; foreground: boolean; @@ -132,6 +133,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { windows.set(message.windowId, { windowId: message.windowId, surfaceId: message.surfaceId, + title: message.title, viewportWidth: message.viewport.width, viewportHeight: message.viewport.height, foreground: false, @@ -296,6 +298,7 @@ function refreshWindowsAfterToolChange(): void { function windowMenu(window: TimerWindow): WindowMenu { if (!window.menu) { window.menu = new WindowMenu({ + title: () => window.title, size: { width: window.viewportWidth, height: window.viewportHeight }, paintBase: () => paintContent(window), isFocused: () => window.focused, diff --git a/app/ui/menu.ts b/app/ui/menu.ts index a4dfaff3..508961eb 100644 --- a/app/ui/menu.ts +++ b/app/ui/menu.ts @@ -17,7 +17,8 @@ const MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL = 15; const MENU_HIGHLIGHT_SELECTED_BORDER_STROKE = 45; export type MenuLayout = { - x: number; + /** Left edge, or "center" to center horizontally on the painted surface. */ + x: number | "center"; y: number; width: number; /** Whether to draw the rounded outline around the menu. Default: true. */ @@ -200,7 +201,8 @@ export class MenuLayer implements Layer { const rowHeight = listRowHeight(font); const base = ctx.stack.getBaseSize(); const image = this.layout.opaque ? new GrayImage(base.width, base.height, 0) : paintBelow(); - const { x, y, width } = this.layout; + const { y, width } = this.layout; + const x = this.layout.x === "center" ? ((image.width - width) / 2) | 0 : this.layout.x; const chromeTop = (this.title ? menuTitleHeight(font) : 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 diff --git a/app/ui/shell/in-process-window.ts b/app/ui/shell/in-process-window.ts index f6353f7e..a410a6d8 100644 --- a/app/ui/shell/in-process-window.ts +++ b/app/ui/shell/in-process-window.ts @@ -162,7 +162,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces }, }); } - stack.push(new WindowMenuLayer(items)); + stack.push(new WindowMenuLayer(options.title, items)); }; const window: ShellWindow = { diff --git a/app/ui/shell/shell.ts b/app/ui/shell/shell.ts index a030fc06..93a3b81f 100644 --- a/app/ui/shell/shell.ts +++ b/app/ui/shell/shell.ts @@ -171,13 +171,15 @@ const LONG_PRESS_ESCAPE_MENU_MS = 4000; 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; past the sidebar strip - // where one reserves width (none in the full-panel mode). - super(null, items, { - x: sidebarWidth() + 8, + // vertical position setting currently puts it; centered over the + // application area, i.e. the part of the screen past the sidebar strip + // (the whole screen in the full-panel mode, where the strip overlays). + const width = 272; + super("System", items, { + x: sidebarWidth() + (((G2_LENS_WIDTH - sidebarWidth() - width) / 2) | 0), y: minWindowTop() + TOP_BAR_HEIGHT + 8, - width: 272, - minHeight: 0, + width, + minHeight: 150, }); } diff --git a/app/ui/shell/worker-window.ts b/app/ui/shell/worker-window.ts index a44bfbca..6ea243f4 100644 --- a/app/ui/shell/worker-window.ts +++ b/app/ui/shell/worker-window.ts @@ -13,7 +13,7 @@ import { shell, type ShellWindow } from "./shell"; * worker→Java directly. */ export type WorkerAppMessage = - | { type: "open-window"; windowId: string; surfaceId: string; viewport: { width: number; height: number } } + | { type: "open-window"; windowId: string; surfaceId: string; title: 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 } @@ -303,6 +303,7 @@ export class WorkerAppHost { type: "open-window", windowId: spec.windowId, surfaceId, + title: spec.title, viewport: appViewportSize(heightMode), }); const window: ShellWindow = { diff --git a/app/ui/window-menu.ts b/app/ui/window-menu.ts index fb1df546..02362a92 100644 --- a/app/ui/window-menu.ts +++ b/app/ui/window-menu.ts @@ -13,16 +13,18 @@ import type { WorkerAppReply } from "./shell/worker-window"; * is held long enough, so an unresponsive app can always be closed. */ -/** Viewport-relative layout; visually matches the shell's escape menu position. */ -export const WINDOW_MENU_LAYOUT: MenuLayout = { x: 8, y: 8, width: 272, minHeight: 0 }; +/** Centered over the viewport; visually matches the shell's escape menu position. */ +export const WINDOW_MENU_LAYOUT: MenuLayout = { x: "center", y: 8, width: 272, minHeight: 150 }; export class WindowMenuLayer extends MenuLayer { - constructor(items: MenuItem[]) { - super(null, items, WINDOW_MENU_LAYOUT); + constructor(title: string | null, items: MenuItem[]) { + super(title, items, WINDOW_MENU_LAYOUT); } } export type WindowMenuOptions = { + /** Menu title: the window's title, read at open time. */ + title: () => string; /** Paint the window content the menu draws over (a fresh, mutable image). */ paintBase: () => GrayImage; size: { width: number; height: number }; @@ -53,7 +55,7 @@ export class WindowMenu { handleInput: () => {}, }; const stack = new LayerStack(base, { ...noopLayerActions }, this.options.size, this.options.isFocused); - stack.push(new WindowMenuLayer(items)); + stack.push(new WindowMenuLayer(this.options.title(), items)); this.stack = stack; }