Context menus: gesture switch between app and system context menus; gesture help text; move items from app to system menu

This commit is contained in:
James Babcock committed 2026-09-02 21:14:40 -07:00
1 parent 061f50e711
commit 987f442897
15 files changed
+343 -205

No files matched your search

+4
View File
@@ -1,5 +1,9 @@
# Changelog # Changelog
## 0.6.5 - Future
* System and app context menus show gesture help for switching to the other context menu
* Move some items from app context menus to the system context menu
## 0.6.4 - 2026-09-02 ## 0.6.4 - 2026-09-02
* Context menus are centered and include window title * Context menus are centered and include window title
* Long-press and short-then-long with a context menu open switches between context menus * Long-press and short-then-long with a context menu open switches between context menus
+13 -12
View File
@@ -10,14 +10,15 @@
*/ */
import "@nativescript/core/globals"; import "@nativescript/core/globals";
import { GrayImage } from "../../graphics/image"; import { GrayImage } from "../../graphics/image";
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane";
import { prepareFrameDraws } from "../../graphics/glyph-wire"; import { prepareFrameDraws } from "../../graphics/glyph-wire";
import { getFont } from "../../graphics/bdffont"; import { getFont } from "../../graphics/bdffont";
import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import * as frameTimings from "../../native/frame-timings"; import * as frameTimings from "../../native/frame-timings";
import { getActiveDisplay } from "../../native/active-display"; import { getActiveDisplay } from "../../native/active-display";
import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects"; import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects";
import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu"; import { type MenuItem } from "../../ui/menu";
import { WindowMenu } from "../../ui/window-menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import { import {
directionalFallback, directionalFallback,
@@ -287,9 +288,9 @@ function playSfx(window: BlocksWindow, steps: Step[]): void {
} }
} }
/** The window's long-press menu (sound toggle + default entries). */ /** The window's long-press menu (sound toggle); playing binds long-press to hard drop instead. */
function openWindowMenu(window: BlocksWindow): void { function windowMenuItems(window: BlocksWindow): MenuItem[] {
windowMenu(window).open([ return [
{ {
label: window.soundOn ? "Sound: on" : "Sound: off", label: window.soundOn ? "Sound: on" : "Sound: off",
onSelect: (ctx) => { onSelect: (ctx) => {
@@ -298,14 +299,17 @@ function openWindowMenu(window: BlocksWindow): void {
if (window.soundOn) playSfx(window, SFX_RESUME); if (window.soundOn) playSfx(window, SFX_RESUME);
}, },
}, },
...defaultWindowMenuItems(window.windowId, post), ];
]);
} }
function windowMenu(window: BlocksWindow): WindowMenu { function windowMenu(window: BlocksWindow): WindowMenu {
if (!window.menu) { if (!window.menu) {
window.menu = new WindowMenu({ window.menu = new WindowMenu({
windowId: window.windowId,
post,
title: () => window.title, title: () => window.title,
items: () => windowMenuItems(window),
longPressOpensMenu: () => window.phase !== "playing",
size: { width: window.viewportWidth, height: window.viewportHeight }, size: { width: window.viewportWidth, height: window.viewportHeight },
paintBase: () => paintContent(window), paintBase: () => paintContent(window),
isFocused: () => window.focused, isFocused: () => window.focused,
@@ -382,7 +386,7 @@ function handleIdleInput(window: BlocksWindow, event: InputEvent, frameId: numbe
post({ type: "yield-focus", windowId: window.windowId }); post({ type: "yield-focus", windowId: window.windowId });
return; return;
case "long-press": case "long-press":
openWindowMenu(window); windowMenu(window).open();
break; break;
default: default:
frameTimings.finishFrame(frameId, "discarded: blocks ignored input"); frameTimings.finishFrame(frameId, "discarded: blocks ignored input");
@@ -557,10 +561,7 @@ function updateTickTimer(window: BlocksWindow): void {
} }
function paint(window: BlocksWindow): Plane[] { function paint(window: BlocksWindow): Plane[] {
if (window.menu?.isOpen()) { return windowMenu(window).paint();
return window.menu.paint();
}
return singlePlane(paintContent(window));
} }
function paintContent(window: BlocksWindow): GrayImage { function paintContent(window: BlocksWindow): GrayImage {
+21 -19
View File
@@ -22,7 +22,7 @@ import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import * as frameTimings from "../../native/frame-timings"; import * as frameTimings from "../../native/frame-timings";
import { getActiveDisplay } from "../../native/active-display"; import { getActiveDisplay } from "../../native/active-display";
import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects"; import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects";
import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu"; import { WindowMenu } from "../../ui/window-menu";
import type { MenuItem } from "../../ui/menu"; import type { MenuItem } from "../../ui/menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import { directionalFallback, GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_LONG_PRESS, type InputEvent } from "../../ui/gestures"; import { directionalFallback, GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_LONG_PRESS, type InputEvent } from "../../ui/gestures";
@@ -214,8 +214,8 @@ function playSfx(window: FreecellWindow, steps: Step[]): void {
} }
} }
/** The window's long-press menu (game actions + default entries). */ /** The window's long-press menu (game actions). */
function openWindowMenu(window: FreecellWindow): void { function windowMenuItems(window: FreecellWindow): MenuItem[] {
const items: MenuItem[] = []; const items: MenuItem[] = [];
if (window.undoStack.length > 0 && window.phase === "playing") { if (window.undoStack.length > 0 && window.phase === "playing") {
items.push({ items.push({
@@ -252,13 +252,16 @@ function openWindowMenu(window: FreecellWindow): void {
}, },
}, },
); );
windowMenu(window).open([...items, ...defaultWindowMenuItems(window.windowId, post)]); return items;
} }
function windowMenu(window: FreecellWindow): WindowMenu { function windowMenu(window: FreecellWindow): WindowMenu {
if (!window.menu) { if (!window.menu) {
window.menu = new WindowMenu({ window.menu = new WindowMenu({
windowId: window.windowId,
post,
title: () => window.title, title: () => window.title,
items: () => windowMenuItems(window),
size: { width: window.viewportWidth, height: window.viewportHeight }, size: { width: window.viewportWidth, height: window.viewportHeight },
paintBase: () => paintContent(window), paintBase: () => paintContent(window),
isFocused: () => window.focused, isFocused: () => window.focused,
@@ -330,7 +333,7 @@ function handlePlayingInput(window: FreecellWindow, event: InputEvent, frameId:
} }
break; break;
case "long-press": case "long-press":
openWindowMenu(window); windowMenu(window).open();
break; break;
default: default:
frameTimings.finishFrame(frameId, "discarded: freecell ignored input"); frameTimings.finishFrame(frameId, "discarded: freecell ignored input");
@@ -350,7 +353,7 @@ function handleWonInput(window: FreecellWindow, event: InputEvent, frameId: numb
post({ type: "yield-focus", windowId: window.windowId }); post({ type: "yield-focus", windowId: window.windowId });
return; return;
case "long-press": case "long-press":
openWindowMenu(window); windowMenu(window).open();
break; break;
default: default:
frameTimings.finishFrame(frameId, "discarded: freecell ignored input"); frameTimings.finishFrame(frameId, "discarded: freecell ignored input");
@@ -632,19 +635,18 @@ function layoutFor(window: FreecellWindow): Layout {
} }
function paint(window: FreecellWindow): Plane[] { function paint(window: FreecellWindow): Plane[] {
if (window.menu?.isOpen()) { return windowMenu(window).paint(() => {
return window.menu.paint(); const planes = singlePlane(paintContent(window));
} if (window.phase === "won") {
const planes = singlePlane(paintContent(window)); // The win box goes on its own plane: card labels are deferred glyphs
if (window.phase === "won") { // that render above their own image's raster, so an overlay drawn into
// The win box goes on its own plane: card labels are deferred glyphs that // the board image could not cover them.
// render above their own image's raster, so an overlay drawn into the const overlay = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
// board image could not cover them. paintWinOverlay(overlay, window);
const overlay = new GrayImage(window.viewportWidth, window.viewportHeight, 0); planes.push({ image: overlay, x: 0, y: 0 });
paintWinOverlay(overlay, window); }
planes.push({ image: overlay, x: 0, y: 0 }); return planes;
} });
return planes;
} }
function paintContent(window: FreecellWindow): GrayImage { function paintContent(window: FreecellWindow): GrayImage {
+13 -12
View File
@@ -15,14 +15,15 @@
*/ */
import "@nativescript/core/globals"; import "@nativescript/core/globals";
import { GrayImage } from "../../graphics/image"; import { GrayImage } from "../../graphics/image";
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane";
import { prepareFrameDraws } from "../../graphics/glyph-wire"; import { prepareFrameDraws } from "../../graphics/glyph-wire";
import { getFont } from "../../graphics/bdffont"; import { getFont } from "../../graphics/bdffont";
import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import * as frameTimings from "../../native/frame-timings"; import * as frameTimings from "../../native/frame-timings";
import { getActiveDisplay } from "../../native/active-display"; import { getActiveDisplay } from "../../native/active-display";
import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects"; import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects";
import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu"; import { type MenuItem } from "../../ui/menu";
import { WindowMenu } from "../../ui/window-menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import { import {
directionalFallback, directionalFallback,
@@ -251,10 +252,10 @@ function playSfx(window: MinesweeperWindow, steps: Step[]): void {
} }
} }
/** The window's long-press menu (game actions + default entries). */ /** The window's long-press menu (game actions); playing binds long-press to flagging instead. */
function openWindowMenu(window: MinesweeperWindow): void { function windowMenuItems(window: MinesweeperWindow): MenuItem[] {
const nextDifficulty = DIFFICULTIES[(window.difficultyIndex + 1) % DIFFICULTIES.length]!; const nextDifficulty = DIFFICULTIES[(window.difficultyIndex + 1) % DIFFICULTIES.length]!;
windowMenu(window).open([ return [
{ {
label: "New game", label: "New game",
onSelect: (ctx) => { onSelect: (ctx) => {
@@ -280,14 +281,17 @@ function openWindowMenu(window: MinesweeperWindow): void {
if (window.soundOn) playSfx(window, SFX_RESUME); if (window.soundOn) playSfx(window, SFX_RESUME);
}, },
}, },
...defaultWindowMenuItems(window.windowId, post), ];
]);
} }
function windowMenu(window: MinesweeperWindow): WindowMenu { function windowMenu(window: MinesweeperWindow): WindowMenu {
if (!window.menu) { if (!window.menu) {
window.menu = new WindowMenu({ window.menu = new WindowMenu({
windowId: window.windowId,
post,
title: () => window.title, title: () => window.title,
items: () => windowMenuItems(window),
longPressOpensMenu: () => window.phase !== "playing",
size: { width: window.viewportWidth, height: window.viewportHeight }, size: { width: window.viewportWidth, height: window.viewportHeight },
paintBase: () => paintContent(window), paintBase: () => paintContent(window),
isFocused: () => window.focused, isFocused: () => window.focused,
@@ -395,7 +399,7 @@ function handleIdleInput(window: MinesweeperWindow, event: InputEvent, frameId:
post({ type: "yield-focus", windowId: window.windowId }); post({ type: "yield-focus", windowId: window.windowId });
return; return;
case "long-press": case "long-press":
openWindowMenu(window); windowMenu(window).open();
break; break;
default: default:
frameTimings.finishFrame(frameId, "discarded: minesweeper ignored input"); frameTimings.finishFrame(frameId, "discarded: minesweeper ignored input");
@@ -591,10 +595,7 @@ function elapsedMs(window: MinesweeperWindow): number {
} }
function paint(window: MinesweeperWindow): Plane[] { function paint(window: MinesweeperWindow): Plane[] {
if (window.menu?.isOpen()) { return windowMenu(window).paint();
return window.menu.paint();
}
return singlePlane(paintContent(window));
} }
function paintContent(window: MinesweeperWindow): GrayImage { function paintContent(window: MinesweeperWindow): GrayImage {
+24 -17
View File
@@ -8,13 +8,14 @@
*/ */
import "@nativescript/core/globals"; import "@nativescript/core/globals";
import { GrayImage } from "../../graphics/image"; import { GrayImage } from "../../graphics/image";
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane";
import { prepareFrameDraws } from "../../graphics/glyph-wire"; import { prepareFrameDraws } from "../../graphics/glyph-wire";
import { getFont } from "../../graphics/bdffont"; import { getFont } from "../../graphics/bdffont";
import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import * as frameTimings from "../../native/frame-timings"; import * as frameTimings from "../../native/frame-timings";
import { getActiveDisplay } from "../../native/active-display"; import { getActiveDisplay } from "../../native/active-display";
import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu"; import { type MenuItem } from "../../ui/menu";
import { WindowMenu } from "../../ui/window-menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { ToolSpec, ToolResult } from "../../assistant/tool-registry"; import type { ToolSpec, ToolResult } from "../../assistant/tool-registry";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, type InputEvent } from "../../ui/gestures"; import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, type InputEvent } from "../../ui/gestures";
@@ -611,10 +612,28 @@ function describeRouteStatus(): string {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Input // Input
/** The window's long-press menu: only Stop navigation, and only while a route is up. */
function windowMenuItems(win: NavWindow): MenuItem[] {
if (phase !== "navigating" && phase !== "arrived") return [];
return [
{
label: "Stop navigation",
onSelect: (ctx) => {
ctx.stack.pop();
stopNavigation("Navigation stopped.");
render();
},
},
];
}
function windowMenu(win: NavWindow): WindowMenu { function windowMenu(win: NavWindow): WindowMenu {
if (!win.menu) { if (!win.menu) {
win.menu = new WindowMenu({ win.menu = new WindowMenu({
windowId: win.windowId,
post,
title: () => win.title, title: () => win.title,
items: () => windowMenuItems(win),
size: { width: win.viewportWidth, height: win.viewportHeight }, size: { width: win.viewportWidth, height: win.viewportHeight },
paintBase: () => paintContent(win), paintBase: () => paintContent(win),
isFocused: () => win.focused, isFocused: () => win.focused,
@@ -632,18 +651,7 @@ function handleInput(win: NavWindow, event: InputEvent, frameId: number): void {
return; return;
} }
if (event.type === "long-press") { if (event.type === "long-press") {
const items = [...defaultWindowMenuItems(win.windowId, post)]; windowMenu(win).open();
if (phase === "navigating" || phase === "arrived") {
items.unshift({
label: "Stop navigation",
onSelect: (ctx: any) => {
ctx.stack.pop();
stopNavigation("Navigation stopped.");
render();
},
});
}
windowMenu(win).open(items);
renderAndSubmit(win, frameId); renderAndSubmit(win, frameId);
return; return;
} }
@@ -683,8 +691,7 @@ function handleInput(win: NavWindow, event: InputEvent, frameId: number): void {
// Painting // Painting
function paint(win: NavWindow): Plane[] { function paint(win: NavWindow): Plane[] {
if (win.menu?.isOpen()) return win.menu.paint(); return windowMenu(win).paint();
return singlePlane(paintContent(win));
} }
function paintContent(win: NavWindow): GrayImage { function paintContent(win: NavWindow): GrayImage {
@@ -701,7 +708,7 @@ function paintIdle(image: GrayImage): void {
image.drawText(mediumFont, 24, 16, "Navigate", 245); image.drawText(mediumFont, 24, 16, "Navigate", 245);
const busy = phase !== "idle"; const busy = phase !== "idle";
const hint = isMapboxConfigured() const hint = isMapboxConfigured()
? "Ask the voice assistant to navigate somewhere, or use Voice input from the long-press menu to say a destination." ? "Ask the voice assistant to navigate somewhere, or pick Voice input from the system menu (tap, then hold) to say a destination."
: "Set a Mapbox token in Settings > API Keys to enable navigation."; : "Set a Mapbox token in Settings > API Keys to enable navigation.";
image.drawTextWrapped({ font: smallFont, x: 24, y: 64, width: image.width - 48, text: hint, value: 170 }); image.drawTextWrapped({ font: smallFont, x: 24, y: 64, width: image.width - 48, text: hint, value: 170 });
if (statusMessage) { if (statusMessage) {
+13 -12
View File
@@ -21,7 +21,7 @@
*/ */
import "@nativescript/core/globals"; import "@nativescript/core/globals";
import { GrayImage } from "../../graphics/image"; import { GrayImage } from "../../graphics/image";
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane";
import { prepareFrameDraws } from "../../graphics/glyph-wire"; import { prepareFrameDraws } from "../../graphics/glyph-wire";
import { getFont } from "../../graphics/bdffont"; import { getFont } from "../../graphics/bdffont";
import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { getDefaultSmallFont } from "../../graphics/ui-fonts";
@@ -29,7 +29,8 @@ import * as frameTimings from "../../native/frame-timings";
import { getActiveDisplay } from "../../native/active-display"; import { getActiveDisplay } from "../../native/active-display";
import { getStringSetting, setStringSetting } from "../../native/settings-store"; import { getStringSetting, setStringSetting } from "../../native/settings-store";
import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects"; import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects";
import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu"; import { type MenuItem } from "../../ui/menu";
import { WindowMenu } from "../../ui/window-menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import { import {
directionalFallback, directionalFallback,
@@ -445,9 +446,9 @@ function playSfx(window: PinballWindow, steps: Step[], minor = false): void {
} }
} }
/** The window's long-press menu (game actions + default entries). */ /** The window's long-press menu (game actions); playing binds long-press to the nudge instead. */
function openWindowMenu(window: PinballWindow): void { function windowMenuItems(window: PinballWindow): MenuItem[] {
windowMenu(window).open([ return [
{ {
label: "New game", label: "New game",
onSelect: (ctx) => { onSelect: (ctx) => {
@@ -464,14 +465,17 @@ function openWindowMenu(window: PinballWindow): void {
if (window.soundOn) playSfx(window, SFX_RESUME); if (window.soundOn) playSfx(window, SFX_RESUME);
}, },
}, },
...defaultWindowMenuItems(window.windowId, post), ];
]);
} }
function windowMenu(window: PinballWindow): WindowMenu { function windowMenu(window: PinballWindow): WindowMenu {
if (!window.menu) { if (!window.menu) {
window.menu = new WindowMenu({ window.menu = new WindowMenu({
windowId: window.windowId,
post,
title: () => window.title, title: () => window.title,
items: () => windowMenuItems(window),
longPressOpensMenu: () => window.phase !== "playing",
size: { width: window.viewportWidth, height: window.viewportHeight }, size: { width: window.viewportWidth, height: window.viewportHeight },
paintBase: () => paintContent(window), paintBase: () => paintContent(window),
isFocused: () => window.focused, isFocused: () => window.focused,
@@ -577,7 +581,7 @@ function handleIdleInput(window: PinballWindow, event: InputEvent, frameId: numb
post({ type: "yield-focus", windowId: window.windowId }); post({ type: "yield-focus", windowId: window.windowId });
return; return;
case "long-press": case "long-press":
openWindowMenu(window); windowMenu(window).open();
break; break;
default: default:
frameTimings.finishFrame(frameId, "discarded: pinball ignored input"); frameTimings.finishFrame(frameId, "discarded: pinball ignored input");
@@ -948,10 +952,7 @@ function drawFlipper(image: GrayImage, flipper: Flipper): void {
} }
function paint(window: PinballWindow): Plane[] { function paint(window: PinballWindow): Plane[] {
if (window.menu?.isOpen()) { return windowMenu(window).paint();
return window.menu.paint();
}
return singlePlane(paintContent(window));
} }
function paintContent(window: PinballWindow): GrayImage { function paintContent(window: PinballWindow): GrayImage {
+9 -6
View File
@@ -17,7 +17,7 @@ import * as frameTimings from "../../native/frame-timings";
import { getActiveDisplay } from "../../native/active-display"; import { getActiveDisplay } from "../../native/active-display";
import { onSettingsStoreChanged } from "../../native/settings-store"; import { onSettingsStoreChanged } from "../../native/settings-store";
import type { MenuItem } from "../../ui/menu"; import type { MenuItem } from "../../ui/menu";
import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu"; import { WindowMenu } from "../../ui/window-menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { ToolResult, ToolSpec } from "../../assistant/tool-registry"; import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures"; import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures";
@@ -329,7 +329,10 @@ function maybeRefreshStalePage(): void {
function windowMenu(win: RoamWindow): WindowMenu { function windowMenu(win: RoamWindow): WindowMenu {
if (!win.menu) { if (!win.menu) {
win.menu = new WindowMenu({ win.menu = new WindowMenu({
windowId: win.windowId,
post,
title: () => win.title, title: () => win.title,
items: () => menuItems(win),
size: { width: win.viewportWidth, height: win.viewportHeight }, size: { width: win.viewportWidth, height: win.viewportHeight },
paintBase: () => paintContent(win), paintBase: () => paintContent(win),
isFocused: () => win.focused, isFocused: () => win.focused,
@@ -380,7 +383,7 @@ function menuItems(win: RoamWindow): MenuItem[] {
beginSettingEdit(roamApiTokenSetting); beginSettingEdit(roamApiTokenSetting);
}, },
}); });
return [...items, ...defaultWindowMenuItems(win.windowId, post)]; return items;
} }
/** /**
@@ -421,7 +424,7 @@ function handleInput(win: RoamWindow, event: InputEvent, frameId: number): void
return; return;
} }
if (event.type === "long-press") { if (event.type === "long-press") {
windowMenu(win).open(menuItems(win)); windowMenu(win).open();
renderAndSubmit(win, frameId); renderAndSubmit(win, frameId);
return; return;
} }
@@ -583,9 +586,9 @@ async function handleRoamTool(name: string, args: any): Promise<ToolResult> {
// Painting // Painting
function paint(win: RoamWindow): Plane[] { function paint(win: RoamWindow): Plane[] {
if (win.menu?.isOpen()) return win.menu.paint(); return windowMenu(win).paint(() =>
if (editingSetting) return singlePlane(paintSettingEdit(win, editingSetting)); singlePlane(editingSetting ? paintSettingEdit(win, editingSetting) : paintContent(win)),
return singlePlane(paintContent(win)); );
} }
/** The "type on the phone" screen shown while a Roam setting is being edited. */ /** The "type on the phone" screen shown while a Roam setting is being edited. */
+7 -8
View File
@@ -32,7 +32,7 @@
*/ */
import "@nativescript/core/globals"; import "@nativescript/core/globals";
import { GrayImage, type UiFont } from "../../graphics/image"; import { GrayImage, type UiFont } from "../../graphics/image";
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane";
import { prepareFrameDraws } from "../../graphics/glyph-wire"; import { prepareFrameDraws } from "../../graphics/glyph-wire";
import { getDefaultSmallFont, getTerminalFontConfig } from "../../graphics/ui-fonts"; import { getDefaultSmallFont, getTerminalFontConfig } from "../../graphics/ui-fonts";
import { truncateText } from "../../graphics/textwrap"; import { truncateText } from "../../graphics/textwrap";
@@ -48,7 +48,7 @@ import { connectionDisplayName, loadConnections, parseConnectionString, saveConn
import { TerminalEmulator } from "./terminal-emulator"; import { TerminalEmulator } from "./terminal-emulator";
import { drawListScrollbar, drawSelectionHighlight, scrollToKeepSelectionVisible, type MenuItem } from "../../ui/menu"; import { drawListScrollbar, drawSelectionHighlight, scrollToKeepSelectionVisible, type MenuItem } from "../../ui/menu";
import { lineStep, listRowHeight } from "../../ui/metrics"; import { lineStep, listRowHeight } from "../../ui/metrics";
import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu"; import { WindowMenu } from "../../ui/window-menu";
import { appViewportSize } from "../../ui/shell/geometry"; import { appViewportSize } from "../../ui/shell/geometry";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { ToolResult, ToolSpec } from "../../assistant/tool-registry"; import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
@@ -905,7 +905,10 @@ function reconnectView(window: ViewWindow): void {
function windowMenu(window: TerminalWindow): WindowMenu { function windowMenu(window: TerminalWindow): WindowMenu {
if (!window.menu) { if (!window.menu) {
window.menu = new WindowMenu({ window.menu = new WindowMenu({
windowId: window.windowId,
post,
title: () => window.title, title: () => window.title,
items: () => windowMenuItems(window),
size: { width: window.viewportWidth, height: window.viewportHeight }, size: { width: window.viewportWidth, height: window.viewportHeight },
paintBase: () => paintContent(window), paintBase: () => paintContent(window),
isFocused: () => window.focused, isFocused: () => window.focused,
@@ -984,7 +987,6 @@ function windowMenuItems(window: TerminalWindow): MenuItem[] {
}, },
); );
} }
items.push(...defaultWindowMenuItems(window.windowId, post));
return items; return items;
} }
@@ -999,7 +1001,7 @@ function handleInput(window: TerminalWindow, event: InputEvent, frameId: number)
return; return;
} }
if (event.type === "long-press") { if (event.type === "long-press") {
windowMenu(window).open(windowMenuItems(window)); windowMenu(window).open();
renderAndSubmit(window, frameId); renderAndSubmit(window, frameId);
return; return;
} }
@@ -1457,10 +1459,7 @@ async function launchAndOpenView(control: ControlConnection, preset: string): Pr
} }
function paint(window: TerminalWindow): Plane[] { function paint(window: TerminalWindow): Plane[] {
if (window.menu?.isOpen()) { return windowMenu(window).paint();
return window.menu.paint();
}
return singlePlane(paintContent(window));
} }
function paintContent(window: TerminalWindow): GrayImage { function paintContent(window: TerminalWindow): GrayImage {
+11 -8
View File
@@ -5,7 +5,7 @@
*/ */
import "@nativescript/core/globals"; import "@nativescript/core/globals";
import { type UiFont, GrayImage } from "../../graphics/image"; import { type UiFont, GrayImage } from "../../graphics/image";
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane";
import { prepareFrameDraws } from "../../graphics/glyph-wire"; import { prepareFrameDraws } from "../../graphics/glyph-wire";
import { getFont } from "../../graphics/bdffont"; import { getFont } from "../../graphics/bdffont";
import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { getDefaultSmallFont } from "../../graphics/ui-fonts";
@@ -16,7 +16,7 @@ import {
fireTimerNotification, fireTimerNotification,
scheduleTimerNotification, scheduleTimerNotification,
} from "../../native/timer-notifications"; } from "../../native/timer-notifications";
import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu"; import { WindowMenu } from "../../ui/window-menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { ToolResult, ToolSpec } from "../../assistant/tool-registry"; import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, type InputEvent } from "../../ui/gestures"; import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, type InputEvent } from "../../ui/gestures";
@@ -294,11 +294,17 @@ function refreshWindowsAfterToolChange(): void {
} }
} }
/** The window's long-press menu (default entries only), created lazily. */ /**
* The window's long-press menu, created lazily. The timer has no entries of
* its own, so a long-press opens the shell's system menu in its place.
*/
function windowMenu(window: TimerWindow): WindowMenu { function windowMenu(window: TimerWindow): WindowMenu {
if (!window.menu) { if (!window.menu) {
window.menu = new WindowMenu({ window.menu = new WindowMenu({
windowId: window.windowId,
post,
title: () => window.title, title: () => window.title,
items: () => [],
size: { width: window.viewportWidth, height: window.viewportHeight }, size: { width: window.viewportWidth, height: window.viewportHeight },
paintBase: () => paintContent(window), paintBase: () => paintContent(window),
isFocused: () => window.focused, isFocused: () => window.focused,
@@ -317,7 +323,7 @@ function handleInput(window: TimerWindow, event: InputEvent, frameId: number): v
return; return;
} }
if (event.type === "long-press") { if (event.type === "long-press") {
windowMenu(window).open(defaultWindowMenuItems(window.windowId, post)); windowMenu(window).open();
renderAndSubmit(window, frameId); renderAndSubmit(window, frameId);
return; return;
} }
@@ -513,10 +519,7 @@ function updateRenderTimer(window: TimerWindow): void {
} }
function paint(window: TimerWindow): Plane[] { function paint(window: TimerWindow): Plane[] {
if (window.menu?.isOpen()) { return windowMenu(window).paint();
return window.menu.paint();
}
return singlePlane(paintContent(window));
} }
function paintContent(window: TimerWindow): GrayImage { function paintContent(window: TimerWindow): GrayImage {
+4 -1
View File
@@ -115,13 +115,16 @@ export function directionalFallback(event: InputEvent): InputEvent {
* double-click ●● (twice) * double-click ●● (twice)
* scroll ▲▼ (U+25B2 / U+25BC) * scroll ▲▼ (U+25B2 / U+25BC)
* long-press - (hyphen-minus) * long-press - (hyphen-minus)
* tap-then-hold ●- (click then long-press)
*/ */
export const GESTURE_CLICK = "\u25cf"; export const GESTURE_CLICK = "\u25cf";
export const GESTURE_DOUBLE_CLICK = GESTURE_CLICK+GESTURE_CLICK; export const GESTURE_DOUBLE_CLICK = GESTURE_CLICK+GESTURE_CLICK;
export const GESTURE_SCROLL_UP = "▲"; export const GESTURE_SCROLL_UP = "▲";
export const GESTURE_SCROLL_DOWN = "▼"; export const GESTURE_SCROLL_DOWN = "▼";
export const GESTURE_SCROLL = "▲▼"; export const GESTURE_SCROLL = "▲▼";
export const GESTURE_LONG_PRESS = "-"; export const GESTURE_LONG_PRESS = "—";
/** The 2.2.9 tap-then-hold gesture (short-then-long-press): a click glyph then a hold. */
export const GESTURE_SHORT_THEN_LONG_PRESS = GESTURE_CLICK + GESTURE_LONG_PRESS;
/** /**
* Join "glyph action" hint pairs into a single line, e.g. * Join "glyph action" hint pairs into a single line, e.g.
+16 -2
View File
@@ -13,6 +13,8 @@ const DEFAULT_MENU_WIDTH = 272;
// fixed quarter-screen-era look) up to the full screen, then scroll. // fixed quarter-screen-era look) up to the full screen, then scroll.
const DEFAULT_MENU_MIN_HEIGHT = G2_LENS_HEIGHT / 2 - 2 * DEFAULT_MENU_Y; const DEFAULT_MENU_MIN_HEIGHT = G2_LENS_HEIGHT / 2 - 2 * DEFAULT_MENU_Y;
const MENU_BODY_PADDING = 8; const MENU_BODY_PADDING = 8;
/** Gap between the last item row and a footer hint line. */
const MENU_FOOTER_GAP = 8;
const MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL = 15; const MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL = 15;
const MENU_HIGHLIGHT_SELECTED_BORDER_STROKE = 45; const MENU_HIGHLIGHT_SELECTED_BORDER_STROKE = 45;
@@ -27,6 +29,11 @@ export type MenuLayout = {
minHeight?: number; minHeight?: number;
/** Height cap before the menu starts scrolling. Default: the full screen. */ /** Height cap before the menu starts scrolling. Default: the full screen. */
maxHeight?: number; maxHeight?: number;
/**
* Dim hint line pinned to the bottom edge inside the box, below the items
* (gesture help such as "●- system menu"). Takes a line off the item area.
*/
footer?: string;
/** /**
* Paint as a standalone page: the layers below stay in the stack for back * Paint as a standalone page: the layers below stay in the stack for back
* navigation but are not composited underneath. Default: false — the menu * navigation but are not composited underneath. Default: false — the menu
@@ -211,9 +218,13 @@ export class MenuLayer implements Layer {
this.layout.maxHeight ?? image.height - y - DEFAULT_MENU_Y, this.layout.maxHeight ?? image.height - y - DEFAULT_MENU_Y,
image.height - y, image.height - y,
); );
const contentHeight = chromeTop + this.items.length * rowHeight + MENU_BODY_PADDING; const footerHeight = this.layout.footer ? MENU_FOOTER_GAP + lineStep(font) : 0;
const contentHeight = chromeTop + this.items.length * rowHeight + footerHeight + MENU_BODY_PADDING;
const height = clamp(contentHeight, Math.min(minHeight, maxHeight), maxHeight); const height = clamp(contentHeight, Math.min(minHeight, maxHeight), maxHeight);
const visibleRowCount = Math.max(1, ((height - chromeTop - MENU_BODY_PADDING) / rowHeight) | 0); const visibleRowCount = Math.max(
1,
((height - chromeTop - footerHeight - MENU_BODY_PADDING) / rowHeight) | 0,
);
this.scrollRow = scrollToKeepSelectionVisible( this.scrollRow = scrollToKeepSelectionVisible(
this.scrollRow, this.scrollRow,
this.selectedIndex, this.selectedIndex,
@@ -230,6 +241,9 @@ export class MenuLayer implements Layer {
if (this.title) { if (this.title) {
image.drawText(font, x + 12, y + 8, this.title, 220); image.drawText(font, x + 12, y + 8, this.title, 220);
} }
if (this.layout.footer) {
image.drawText(font, x + 22, y + height - MENU_BODY_PADDING - font.lineHeight, this.layout.footer, 110);
}
const bodyY = y + chromeTop; const bodyY = y + chromeTop;
const focused = ctx.stack.isFocused(); const focused = ctx.stack.isFocused();
+17 -36
View File
@@ -31,9 +31,11 @@ export type InProcessWindowOptions = {
/** Window height: the standard 288px band ("min", default) or full screen ("max"). */ /** Window height: the standard 288px band ("min", default) or full screen ("max"). */
heightMode?: WindowHeightMode; heightMode?: WindowHeightMode;
/** /**
* App-specific entries for the window's long-press menu, listed ahead of * The window's long-press context menu: app-specific entries only (the
* the default Voice input / Close window entries. Called at open time, so * shared Focus app switcher / Voice input / Close window entries live in
* the items can reflect current app state. * the shell's system menu). Called at open time, so the items can reflect
* current app state. Omitted or empty means the window has no menu of its
* own, and a long-press opens the system menu instead.
*/ */
menuItems?: () => MenuItem[]; menuItems?: () => MenuItem[];
/** Shared actions; requestRender is rebound to this window's render. */ /** Shared actions; requestRender is rebound to this window's render. */
@@ -128,39 +130,16 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
} }
} }
// The window's long-press menu: app-specific items, then the defaults every const appMenuItems = () => options.menuItems?.() ?? [];
// window shares. In-process apps run on the main thread, so the default
// items act on the shell directly (workers post messages instead). // The window's long-press menu: the app's own entries, or the shell's
// system menu when it has none (so both gestures land on the same menu).
const openWindowMenu = () => { const openWindowMenu = () => {
if (stack.topMatches((layer) => layer instanceof WindowMenuLayer)) return; if (stack.topMatches((layer) => layer instanceof WindowMenuLayer)) return;
// "Focus app switcher" first: long-press then tap defocuses the app const items = appMenuItems();
// (hands focus to the sidebar) without closing it — the reliable way out if (!items.length) {
// for apps that consume double-click. shell.openSystemMenu(options.windowId);
const items: MenuItem[] = [ return;
{
label: "Focus app switcher",
onSelect: (ctx) => {
ctx.stack.pop();
shell.yieldFocusToSidebar();
},
},
...(options.menuItems?.() ?? []),
];
items.push({
label: "Voice input",
onSelect: (ctx) => {
ctx.stack.pop();
shell.startVoiceInput();
},
});
if (options.closeable) {
items.push({
label: "Close window",
onSelect: (ctx) => {
ctx.stack.pop();
shell.closeWindow(options.windowId);
},
});
} }
stack.push(new WindowMenuLayer(options.title, items)); stack.push(new WindowMenuLayer(options.title, items));
}; };
@@ -175,6 +154,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
// directional or falls back to click / double-click. // directional or falls back to click / double-click.
acceptsDirectional: true, acceptsDirectional: true,
heightMode, heightMode,
hasAppMenu: () => appMenuItems().length > 0,
close: () => { close: () => {
closed = true; closed = true;
// Fire onRemoved for any pushed layers so they release resources (e.g. a // Fire onRemoved for any pushed layers so they release resources (e.g. a
@@ -193,8 +173,9 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
} }
return; return;
} }
// The default long-press response: the window menu. Handled here (not // The default long-press response: the window menu (or the system
// per-layer) so it works over submenus and app content alike. // menu in its place). Handled here (not per-layer) so it works over
// submenus and app content alike.
if (event.type === "long-press") { if (event.type === "long-press") {
openWindowMenu(); openWindowMenu();
await render(frameId); await render(frameId);
+87 -21
View File
@@ -5,6 +5,8 @@ import { EvenAIStatus, EventSourceType, OsEventTypeList, WatchGestureType } from
import type { RawInputEvent } from "../../native/faceclaw-communicator"; import type { RawInputEvent } from "../../native/faceclaw-communicator";
import { import {
directionalFallback, directionalFallback,
GESTURE_LONG_PRESS,
gestureHints,
InputEvent, InputEvent,
type InputEventPayload, type InputEventPayload,
type InputSource, type InputSource,
@@ -59,10 +61,11 @@ import {
* everything while the sidebar or a shell overlay has focus and forwards the * everything while the sidebar or a shell overlay has focus and forwards the
* rest to the focused window. Long-press goes to the foreground window (from * rest to the focused window. Long-press goes to the foreground window (from
* the sidebar it focuses the window first); by convention apps answer it with * the sidebar it focuses the window first); by convention apps answer it with
* a window menu that ends in Voice input / Close window. Holding the press * their own context menu, or ask for the system menu when they have none.
* past the escape threshold opens the shell's own escape menu, so the shell * The system menu (Focus app switcher, Voice input, Close window, Debug) is
* keeps working when a window's handler hangs. The 2.2.9 tap-then-hold gesture * shell-owned: the 2.2.9 tap-then-hold gesture opens it directly, and holding
* opens that shell menu immediately. * a long-press past the escape threshold opens it too, so the shell keeps
* working when a window's handler hangs.
*/ */
export type ShellWindow = { export type ShellWindow = {
@@ -71,8 +74,15 @@ export type ShellWindow = {
title: string; title: string;
/** Compositor surface this window renders to; configured at connect / launch. */ /** Compositor surface this window renders to; configured at connect / launch. */
surfaceId: string; surfaceId: string;
/** Whether close menu entries (app menu default, shell escape menu) apply (the launcher is pinned). */ /** Whether the system menu offers Close window (the launcher is pinned). */
closeable: boolean; closeable: boolean;
/**
* True when a long-press currently opens the window's own context menu
* (with at least one entry). While false, the system menu shows no
* "long-press: app menu" hint and a long-press over the open system menu
* leaves it open instead of switching menus.
*/
hasAppMenu?: () => boolean;
/** /**
* True when the window gives swipe-left / swipe-right (watch directional * True when the window gives swipe-left / swipe-right (watch directional
* input) a meaning; otherwise the shell forwards directionalFallback(event). * input) a meaning; otherwise the shell forwards directionalFallback(event).
@@ -167,9 +177,16 @@ const noopActions: LayerActions = noopLayerActions;
*/ */
const LONG_PRESS_ESCAPE_MENU_MS = 4000; const LONG_PRESS_ESCAPE_MENU_MS = 4000;
/** Shell-surface overlay menu (the escape menu); closing it returns focus to the sidebar. */ /** Shell-surface overlay menu (the system menu); closing it returns focus to the sidebar. */
class ShellOverlayMenuLayer extends MenuLayer { class ShellOverlayMenuLayer extends MenuLayer {
constructor(items: MenuItem[], private readonly onClosed: () => void) { /**
* Set before popping to keep focus on the window: an entry that acts on
* the window (Voice input aims its transcript at it) must not first hand
* focus to the sidebar.
*/
keepWindowFocus = false;
constructor(items: MenuItem[], footer: string | undefined, private readonly onClosed: () => void) {
// Aligned to the min-height window band (like the sidebar), wherever the // Aligned to the min-height window band (like the sidebar), wherever the
// vertical position setting currently puts it; centered over the // vertical position setting currently puts it; centered over the
// application area, i.e. the part of the screen past the sidebar strip // application area, i.e. the part of the screen past the sidebar strip
@@ -180,11 +197,12 @@ class ShellOverlayMenuLayer extends MenuLayer {
y: minWindowTop() + TOP_BAR_HEIGHT + 8, y: minWindowTop() + TOP_BAR_HEIGHT + 8,
width, width,
minHeight: 150, minHeight: 150,
footer,
}); });
} }
onRemoved(): void { onRemoved(): void {
this.onClosed(); if (!this.keepWindowFocus) this.onClosed();
} }
} }
@@ -645,16 +663,20 @@ class Shell {
} }
// Long-press goes to the foreground window (from the sidebar it focuses // Long-press goes to the foreground window (from the sidebar it focuses
// the window first); apps conventionally answer it with their window // the window first); apps conventionally answer it with their context
// menu. The escape timer runs regardless of what the app does with it: // menu, or ask for the system menu when they have none. The escape timer
// holding the press long enough opens the shell's own menu. // runs regardless of what the app does with it: holding the press long
// enough opens the shell's own menu.
if (event.type === "long-press") { if (event.type === "long-press") {
this.startEscapeMenuTimer(); this.startEscapeMenuTimer();
const window = this.foregroundWindow();
// A long-press while the system menu is open switches to the app's // A long-press while the system menu is open switches to the app's
// context menu: close the system menu and deliver the press to the // context menu: close the system menu and deliver the press to the
// window as usual (apps conventionally answer it with their menu). // window as usual. A window without a menu of its own would only ask
// for the system menu back, so for it the open menu stays.
if ( if (
!this.activeVoiceLayer && !this.activeVoiceLayer &&
window?.hasAppMenu?.() &&
this.stack.popIfTop((layer) => layer instanceof ShellOverlayMenuLayer) this.stack.popIfTop((layer) => layer instanceof ShellOverlayMenuLayer)
) { ) {
this.config.requestShellRender(); this.config.requestShellRender();
@@ -662,7 +684,6 @@ class Shell {
if (this.activeVoiceLayer || !this.stack.isAtBase()) { if (this.activeVoiceLayer || !this.stack.isAtBase()) {
return { shell: true, window: false }; return { shell: true, window: false };
} }
const window = this.foregroundWindow();
if (!window) { if (!window) {
return { shell: true, window: false }; return { shell: true, window: false };
} }
@@ -931,9 +952,9 @@ class Shell {
/** /**
* Open the voice dialog aimed at the foreground window. Called when the * Open the voice dialog aimed at the foreground window. Called when the
* user picks Voice input from a window's menu (in-process directly, worker * user picks Voice input from the system menu (or an app asks via a
* apps via a start-voice-input message). The menu click already ended the * start-voice-input message). The menu click already ended the press, so
* press, so the dialog finishes on click instead of long-press-release. * the dialog finishes on click instead of long-press-release.
*/ */
startVoiceInput(): void { startVoiceInput(): void {
if (!this.screenOn || this.activeVoiceLayer || !this.stack.isAtBase()) return; if (!this.screenOn || this.activeVoiceLayer || !this.stack.isAtBase()) return;
@@ -1163,15 +1184,28 @@ class Shell {
} }
/** /**
* The system/escape menu. Shell-owned and shell-drawn (never the app's), so * A window's answer to a long-press when it has no context menu of its
* an unresponsive app can always be closed. It opens after an extended hold * own: open the system menu in its place, so both gestures land on the
* or immediately for tap-then-hold, over whatever the app did with an earlier * same menu. Ignored unless the window is still the foreground one.
* ordinary long-press, including opening its own menu. */
openSystemMenu(windowId: string): void {
if (this.foregroundWindow()?.windowId !== windowId) return;
this.openEscapeMenu();
}
/**
* The system/escape menu: the entries every window shares (Focus app
* switcher, Voice input, Close window) plus Debug. Shell-owned and
* shell-drawn (never the app's), so an unresponsive app can always be
* closed. It opens for tap-then-hold, after an extended hold (over whatever
* the app did with the ordinary long-press, including opening its own
* menu), and on a window's request when it has no menu of its own.
*/ */
private openEscapeMenu(): void { private openEscapeMenu(): void {
if (!this.screenOn || this.activeVoiceLayer || !this.stack.isAtBase()) return; if (!this.screenOn || this.activeVoiceLayer || !this.stack.isAtBase()) return;
const foreground = this.foregroundWindow(); const foreground = this.foregroundWindow();
if (!foreground) return; if (!foreground) return;
let layer: ShellOverlayMenuLayer;
const items: MenuItem[] = []; const items: MenuItem[] = [];
if (foreground.closeable) { if (foreground.closeable) {
items.push({ items.push({
@@ -1184,6 +1218,30 @@ class Shell {
}, },
}); });
} }
// Close window sits first but the menu opens on Focus app switcher, so a
// reflexive tap never closes the window.
const initialSelection = items.length;
items.push(
{
// Defocus the app (hand focus to the sidebar) without closing it: the
// reliable way out of an app that consumes double-click. Closing the
// menu is what yields focus, so popping is the whole action.
label: "Focus app switcher",
onSelect: (ctx) => {
ctx.stack.pop();
},
},
{
label: "Voice input",
onSelect: (ctx) => {
// The transcript is aimed at the foreground window, so keep focus
// there through the pop instead of yielding to the sidebar.
layer.keepWindowFocus = true;
ctx.stack.pop();
this.startVoiceInput();
},
},
);
items.push({ items.push({
label: "Debug", label: "Debug",
onSelect: (ctx) => { onSelect: (ctx) => {
@@ -1191,7 +1249,15 @@ class Shell {
this.openToolDebugDialog(); this.openToolDebugDialog();
}, },
}); });
this.stack.push(new ShellOverlayMenuLayer(items, () => this.yieldFocusToSidebar())); // Gesture help: a long-press switches to the app's own context menu, when
// the app has one (otherwise it either does something app-specific or
// opens this very menu, neither worth a hint).
const footer = foreground.hasAppMenu?.()
? gestureHints([[GESTURE_LONG_PRESS, "app menu"]])
: undefined;
layer = new ShellOverlayMenuLayer(items, footer, () => this.yieldFocusToSidebar());
layer.selectItem(initialSelection);
this.stack.push(layer);
// Tell the window the system menu opened over it: an app with its own // Tell the window the system menu opened over it: an app with its own
// context menu up closes it, so the two context menus never stack. // context menu up closes it, so the two context menus never stack.
void foreground.handleInput(makeInputEvent({ type: "system-menu-opened" }), 0); void foreground.handleInput(makeInputEvent({ type: "system-menu-opened" }), 0);
+36 -2
View File
@@ -62,15 +62,33 @@ export type WorkerAppReply =
| { type: "set-title"; windowId: string; title: string } | { type: "set-title"; windowId: string; title: string }
| { type: "set-attention"; windowId: string; attention: boolean } | { type: "set-attention"; windowId: string; attention: boolean }
| { | {
/** Window-menu pick: open the shell's voice dialog aimed at this window. */ /** Open the shell's voice dialog aimed at this window (a menu pick). */
type: "start-voice-input"; type: "start-voice-input";
windowId: string; windowId: string;
} }
| { | {
/** Window-menu pick: close this window (the shell owns the close path). */ /** Close this window (the shell owns the close path). */
type: "close-window-request"; type: "close-window-request";
windowId: string; windowId: string;
} }
| {
/**
* The window's answer to a long-press when it has no context menu of
* its own: open the shell's system menu in its place.
*/
type: "open-system-menu";
windowId: string;
}
| {
/**
* Whether a long-press currently opens the window's own context menu
* (with something in it). Posted on change; the shell's system menu
* shows its "long-press: app menu" hint only while this is true.
*/
type: "set-app-menu-available";
windowId: string;
available: boolean;
}
| { | {
/** Open or focus the Settings app, optionally jumping to a section. */ /** Open or focus the Settings app, optionally jumping to a section. */
type: "open-settings"; type: "open-settings";
@@ -172,6 +190,8 @@ const TOOL_CALL_HOST_TIMEOUT_MS = 15_000;
export class WorkerAppHost { export class WorkerAppHost {
private readonly openWindows = new Set<string>(); private readonly openWindows = new Set<string>();
/** Windows that reported a context menu of their own (see set-app-menu-available). */
private readonly appMenuAvailable = new Set<string>();
private readonly pendingToolCalls = new Map<string, PendingToolCall>(); private readonly pendingToolCalls = new Map<string, PendingToolCall>();
private nextCallSerial = 1; private nextCallSerial = 1;
/** /**
@@ -241,6 +261,18 @@ export class WorkerAppHost {
this.options.requestShellRender(); this.options.requestShellRender();
} }
break; break;
case "open-system-menu":
if (this.openWindows.has(message.windowId)) {
shell.openSystemMenu(message.windowId);
}
break;
case "set-app-menu-available":
if (message.available) {
this.appMenuAvailable.add(message.windowId);
} else {
this.appMenuAvailable.delete(message.windowId);
}
break;
case "open-settings": case "open-settings":
this.options.openSettings(message.section); this.options.openSettings(message.section);
break; break;
@@ -314,8 +346,10 @@ export class WorkerAppHost {
closeable: true, closeable: true,
acceptsDirectional: spec.acceptsDirectional, acceptsDirectional: spec.acceptsDirectional,
heightMode, heightMode,
hasAppMenu: () => this.appMenuAvailable.has(spec.windowId),
close: () => { close: () => {
this.openWindows.delete(spec.windowId); this.openWindows.delete(spec.windowId);
this.appMenuAvailable.delete(spec.windowId);
// Withdraw this window's tools and fail any in-flight calls to it. // Withdraw this window's tools and fail any in-flight calls to it.
toolRegistry.removeAppTools(spec.windowId); toolRegistry.removeAppTools(spec.windowId);
this.failPendingToolCallsFor(spec.windowId); this.failPendingToolCallsFor(spec.windowId);
+68 -49
View File
@@ -1,20 +1,29 @@
import { GrayImage } from "../graphics/image"; import { GrayImage } from "../graphics/image";
import { singlePlane, type Plane } from "../graphics/plane"; import { singlePlane, type Plane } from "../graphics/plane";
import { type InputEvent } from "./gestures"; import { GESTURE_SHORT_THEN_LONG_PRESS, gestureHints, type InputEvent } from "./gestures";
import { type Layer, LayerStack, noopLayerActions } from "./layers"; import { type Layer, LayerStack, noopLayerActions } from "./layers";
import { MenuLayer, type MenuItem, type MenuLayout } from "./menu"; import { MenuLayer, type MenuItem, type MenuLayout } from "./menu";
import type { WorkerAppReply } from "./shell/worker-window"; import type { WorkerAppReply } from "./shell/worker-window";
/** /**
* The window long-press menu. By convention every app answers a long-press by * The window long-press menu: an app's own context menu, holding its
* opening one of these: its app-specific actions followed by the default * app-specific actions. The shell's system menu (tap-then-hold, or a press
* entries (Voice input, Close window). This is a convenience path, not the * held past the escape threshold) carries the entries every window shares —
* safety net — the shell separately opens its own escape menu when the press * Focus app switcher, Voice input, Close window — so an app with nothing of
* is held long enough, so an unresponsive app can always be closed. * its own to offer has no menu of its own: a long-press then opens the system
* menu in its place, so both gestures land on the same menu. The system menu
* is also the safety net: shell-owned, so an unresponsive app can always be
* closed.
*/ */
/** Centered over the viewport; visually matches the shell's escape menu position. */ /** Centered over the viewport; visually matches the shell's system menu position. */
export const WINDOW_MENU_LAYOUT: MenuLayout = { x: "center", y: 8, width: 272, minHeight: 150 }; export const WINDOW_MENU_LAYOUT: MenuLayout = {
x: "center",
y: 8,
width: 272,
minHeight: 150,
footer: gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "system menu"]]),
};
export class WindowMenuLayer extends MenuLayer { export class WindowMenuLayer extends MenuLayer {
constructor(title: string | null, items: MenuItem[]) { constructor(title: string | null, items: MenuItem[]) {
@@ -23,8 +32,22 @@ export class WindowMenuLayer extends MenuLayer {
} }
export type WindowMenuOptions = { export type WindowMenuOptions = {
windowId: string;
post: (reply: WorkerAppReply) => void;
/** Menu title: the window's title, read at open time. */ /** Menu title: the window's title, read at open time. */
title: () => string; title: () => string;
/**
* The app's menu entries, built at open time so they reflect current
* state. Empty means the window has no context menu: open() asks the shell
* for the system menu instead.
*/
items: () => MenuItem[];
/**
* False while the app gives long-press a meaning of its own (a game move)
* instead of opening this menu. Default: always true. Only informs the
* shell's system-menu hint; what a long-press does stays the app's call.
*/
longPressOpensMenu?: () => boolean;
/** Paint the window content the menu draws over (a fresh, mutable image). */ /** Paint the window content the menu draws over (a fresh, mutable image). */
paintBase: () => GrayImage; paintBase: () => GrayImage;
size: { width: number; height: number }; size: { width: number; height: number };
@@ -36,11 +59,14 @@ export type WindowMenuOptions = {
* a persistent LayerStack. Wraps a short-lived stack so MenuLayer (and the * a persistent LayerStack. Wraps a short-lived stack so MenuLayer (and the
* ctx.stack.pop() convention in item callbacks) works unchanged. * ctx.stack.pop() convention in item callbacks) works unchanged.
* *
* Usage: route input to handleInput while isOpen(); paint() returns the * Usage: answer a long-press with open(); route input to handleInput while
* window content with the menu drawn over it. * isOpen(); paint every frame through paint(), which returns the window
* content with the menu drawn over it and keeps the shell told whether the
* window currently has a menu (the system menu's gesture hint depends on it).
*/ */
export class WindowMenu { export class WindowMenu {
private stack: LayerStack | null = null; private stack: LayerStack | null = null;
private reportedAvailable: boolean | null = null;
constructor(private readonly options: WindowMenuOptions) {} constructor(private readonly options: WindowMenuOptions) {}
@@ -48,8 +74,22 @@ export class WindowMenu {
return this.stack !== null; return this.stack !== null;
} }
open(items: MenuItem[]): void { /** True when a long-press currently opens this menu with something in it. */
isAvailable(): boolean {
return (this.options.longPressOpensMenu?.() ?? true) && this.options.items().length > 0;
}
/**
* Open the menu, or the shell's system menu when this window has no
* entries. `items` overrides the window's own entries for an app that
* reuses this host for another list (a per-row action menu).
*/
open(items: MenuItem[] = this.options.items()): void {
if (this.stack) return; if (this.stack) return;
if (!items.length) {
this.options.post({ type: "open-system-menu", windowId: this.options.windowId });
return;
}
const base: Layer = { const base: Layer = {
paint: () => this.options.paintBase(), paint: () => this.options.paintBase(),
handleInput: () => {}, handleInput: () => {},
@@ -59,9 +99,23 @@ export class WindowMenu {
this.stack = stack; this.stack = stack;
} }
/** Paint the window content with the menu over it (content alone if closed). */ /**
paint(): Plane[] { * Paint the window content with the menu over it. `content` paints the
return this.stack ? this.stack.paint() : singlePlane(this.options.paintBase()); * closed-state content (default: paintBase alone), for windows whose
* ordinary frame has more planes than the menu needs beneath it.
*/
paint(content?: () => Plane[]): Plane[] {
this.syncAvailability();
if (this.stack) return this.stack.paint();
return content ? content() : singlePlane(this.options.paintBase());
}
/** Tell the shell when this window gains or loses its context menu. */
private syncAvailability(): void {
const available = this.isAvailable();
if (available === this.reportedAvailable) return;
this.reportedAvailable = available;
this.options.post({ type: "set-app-menu-available", windowId: this.options.windowId, available });
} }
/** Route an input event to the menu; the menu closes by popping itself. */ /** Route an input event to the menu; the menu closes by popping itself. */
@@ -81,38 +135,3 @@ export class WindowMenu {
} }
} }
} }
/**
* The default entries every window menu ends with, in worker form: the
* actions cross to the shell as WorkerAppReply messages. In-process windows
* build the equivalent items against the shell directly (in-process-window.ts).
*/
export function defaultWindowMenuItems(
windowId: string,
post: (reply: WorkerAppReply) => void,
): MenuItem[] {
return [
{
// Defocus the app (hand focus to the sidebar) without closing it.
label: "Focus app switcher",
onSelect: (ctx) => {
ctx.stack.pop();
post({ type: "yield-focus", windowId });
},
},
{
label: "Voice input",
onSelect: (ctx) => {
ctx.stack.pop();
post({ type: "start-voice-input", windowId });
},
},
{
label: "Close window",
onSelect: (ctx) => {
ctx.stack.pop();
post({ type: "close-window-request", windowId });
},
},
];
}