forked from Blendman974/faceclaw
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:
1 parent
061f50e711
commit
987f442897
15 files changed
+343
-205
No files matched your search
@@ -1,5 +1,9 @@
|
||||
# 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
|
||||
* Context menus are centered and include window title
|
||||
* Long-press and short-then-long with a context menu open switches between context menus
|
||||
|
||||
@@ -10,14 +10,15 @@
|
||||
*/
|
||||
import "@nativescript/core/globals";
|
||||
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 { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import { getActiveDisplay } from "../../native/active-display";
|
||||
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 {
|
||||
directionalFallback,
|
||||
@@ -287,9 +288,9 @@ function playSfx(window: BlocksWindow, steps: Step[]): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** The window's long-press menu (sound toggle + default entries). */
|
||||
function openWindowMenu(window: BlocksWindow): void {
|
||||
windowMenu(window).open([
|
||||
/** The window's long-press menu (sound toggle); playing binds long-press to hard drop instead. */
|
||||
function windowMenuItems(window: BlocksWindow): MenuItem[] {
|
||||
return [
|
||||
{
|
||||
label: window.soundOn ? "Sound: on" : "Sound: off",
|
||||
onSelect: (ctx) => {
|
||||
@@ -298,14 +299,17 @@ function openWindowMenu(window: BlocksWindow): void {
|
||||
if (window.soundOn) playSfx(window, SFX_RESUME);
|
||||
},
|
||||
},
|
||||
...defaultWindowMenuItems(window.windowId, post),
|
||||
]);
|
||||
];
|
||||
}
|
||||
|
||||
function windowMenu(window: BlocksWindow): WindowMenu {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
windowId: window.windowId,
|
||||
post,
|
||||
title: () => window.title,
|
||||
items: () => windowMenuItems(window),
|
||||
longPressOpensMenu: () => window.phase !== "playing",
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
@@ -382,7 +386,7 @@ function handleIdleInput(window: BlocksWindow, event: InputEvent, frameId: numbe
|
||||
post({ type: "yield-focus", windowId: window.windowId });
|
||||
return;
|
||||
case "long-press":
|
||||
openWindowMenu(window);
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
default:
|
||||
frameTimings.finishFrame(frameId, "discarded: blocks ignored input");
|
||||
@@ -557,10 +561,7 @@ function updateTickTimer(window: BlocksWindow): void {
|
||||
}
|
||||
|
||||
function paint(window: BlocksWindow): Plane[] {
|
||||
if (window.menu?.isOpen()) {
|
||||
return window.menu.paint();
|
||||
}
|
||||
return singlePlane(paintContent(window));
|
||||
return windowMenu(window).paint();
|
||||
}
|
||||
|
||||
function paintContent(window: BlocksWindow): GrayImage {
|
||||
|
||||
@@ -22,7 +22,7 @@ import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import { getActiveDisplay } from "../../native/active-display";
|
||||
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 { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
|
||||
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). */
|
||||
function openWindowMenu(window: FreecellWindow): void {
|
||||
/** The window's long-press menu (game actions). */
|
||||
function windowMenuItems(window: FreecellWindow): MenuItem[] {
|
||||
const items: MenuItem[] = [];
|
||||
if (window.undoStack.length > 0 && window.phase === "playing") {
|
||||
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 {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
windowId: window.windowId,
|
||||
post,
|
||||
title: () => window.title,
|
||||
items: () => windowMenuItems(window),
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
@@ -330,7 +333,7 @@ function handlePlayingInput(window: FreecellWindow, event: InputEvent, frameId:
|
||||
}
|
||||
break;
|
||||
case "long-press":
|
||||
openWindowMenu(window);
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
default:
|
||||
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 });
|
||||
return;
|
||||
case "long-press":
|
||||
openWindowMenu(window);
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
default:
|
||||
frameTimings.finishFrame(frameId, "discarded: freecell ignored input");
|
||||
@@ -632,19 +635,18 @@ function layoutFor(window: FreecellWindow): Layout {
|
||||
}
|
||||
|
||||
function paint(window: FreecellWindow): Plane[] {
|
||||
if (window.menu?.isOpen()) {
|
||||
return window.menu.paint();
|
||||
}
|
||||
const planes = singlePlane(paintContent(window));
|
||||
if (window.phase === "won") {
|
||||
// The win box goes on its own plane: card labels are deferred glyphs that
|
||||
// render above their own image's raster, so an overlay drawn into the
|
||||
// board image could not cover them.
|
||||
const overlay = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
||||
paintWinOverlay(overlay, window);
|
||||
planes.push({ image: overlay, x: 0, y: 0 });
|
||||
}
|
||||
return planes;
|
||||
return windowMenu(window).paint(() => {
|
||||
const planes = singlePlane(paintContent(window));
|
||||
if (window.phase === "won") {
|
||||
// The win box goes on its own plane: card labels are deferred glyphs
|
||||
// that render above their own image's raster, so an overlay drawn into
|
||||
// the board image could not cover them.
|
||||
const overlay = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
||||
paintWinOverlay(overlay, window);
|
||||
planes.push({ image: overlay, x: 0, y: 0 });
|
||||
}
|
||||
return planes;
|
||||
});
|
||||
}
|
||||
|
||||
function paintContent(window: FreecellWindow): GrayImage {
|
||||
|
||||
@@ -15,14 +15,15 @@
|
||||
*/
|
||||
import "@nativescript/core/globals";
|
||||
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 { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import { getActiveDisplay } from "../../native/active-display";
|
||||
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 {
|
||||
directionalFallback,
|
||||
@@ -251,10 +252,10 @@ function playSfx(window: MinesweeperWindow, steps: Step[]): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** The window's long-press menu (game actions + default entries). */
|
||||
function openWindowMenu(window: MinesweeperWindow): void {
|
||||
/** The window's long-press menu (game actions); playing binds long-press to flagging instead. */
|
||||
function windowMenuItems(window: MinesweeperWindow): MenuItem[] {
|
||||
const nextDifficulty = DIFFICULTIES[(window.difficultyIndex + 1) % DIFFICULTIES.length]!;
|
||||
windowMenu(window).open([
|
||||
return [
|
||||
{
|
||||
label: "New game",
|
||||
onSelect: (ctx) => {
|
||||
@@ -280,14 +281,17 @@ function openWindowMenu(window: MinesweeperWindow): void {
|
||||
if (window.soundOn) playSfx(window, SFX_RESUME);
|
||||
},
|
||||
},
|
||||
...defaultWindowMenuItems(window.windowId, post),
|
||||
]);
|
||||
];
|
||||
}
|
||||
|
||||
function windowMenu(window: MinesweeperWindow): WindowMenu {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
windowId: window.windowId,
|
||||
post,
|
||||
title: () => window.title,
|
||||
items: () => windowMenuItems(window),
|
||||
longPressOpensMenu: () => window.phase !== "playing",
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
@@ -395,7 +399,7 @@ function handleIdleInput(window: MinesweeperWindow, event: InputEvent, frameId:
|
||||
post({ type: "yield-focus", windowId: window.windowId });
|
||||
return;
|
||||
case "long-press":
|
||||
openWindowMenu(window);
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
default:
|
||||
frameTimings.finishFrame(frameId, "discarded: minesweeper ignored input");
|
||||
@@ -591,10 +595,7 @@ function elapsedMs(window: MinesweeperWindow): number {
|
||||
}
|
||||
|
||||
function paint(window: MinesweeperWindow): Plane[] {
|
||||
if (window.menu?.isOpen()) {
|
||||
return window.menu.paint();
|
||||
}
|
||||
return singlePlane(paintContent(window));
|
||||
return windowMenu(window).paint();
|
||||
}
|
||||
|
||||
function paintContent(window: MinesweeperWindow): GrayImage {
|
||||
|
||||
@@ -8,13 +8,14 @@
|
||||
*/
|
||||
import "@nativescript/core/globals";
|
||||
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 { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
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 { ToolSpec, ToolResult } from "../../assistant/tool-registry";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, type InputEvent } from "../../ui/gestures";
|
||||
@@ -611,10 +612,28 @@ function describeRouteStatus(): string {
|
||||
// ---------------------------------------------------------------------------
|
||||
// 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 {
|
||||
if (!win.menu) {
|
||||
win.menu = new WindowMenu({
|
||||
windowId: win.windowId,
|
||||
post,
|
||||
title: () => win.title,
|
||||
items: () => windowMenuItems(win),
|
||||
size: { width: win.viewportWidth, height: win.viewportHeight },
|
||||
paintBase: () => paintContent(win),
|
||||
isFocused: () => win.focused,
|
||||
@@ -632,18 +651,7 @@ function handleInput(win: NavWindow, event: InputEvent, frameId: number): void {
|
||||
return;
|
||||
}
|
||||
if (event.type === "long-press") {
|
||||
const items = [...defaultWindowMenuItems(win.windowId, post)];
|
||||
if (phase === "navigating" || phase === "arrived") {
|
||||
items.unshift({
|
||||
label: "Stop navigation",
|
||||
onSelect: (ctx: any) => {
|
||||
ctx.stack.pop();
|
||||
stopNavigation("Navigation stopped.");
|
||||
render();
|
||||
},
|
||||
});
|
||||
}
|
||||
windowMenu(win).open(items);
|
||||
windowMenu(win).open();
|
||||
renderAndSubmit(win, frameId);
|
||||
return;
|
||||
}
|
||||
@@ -683,8 +691,7 @@ function handleInput(win: NavWindow, event: InputEvent, frameId: number): void {
|
||||
// Painting
|
||||
|
||||
function paint(win: NavWindow): Plane[] {
|
||||
if (win.menu?.isOpen()) return win.menu.paint();
|
||||
return singlePlane(paintContent(win));
|
||||
return windowMenu(win).paint();
|
||||
}
|
||||
|
||||
function paintContent(win: NavWindow): GrayImage {
|
||||
@@ -701,7 +708,7 @@ function paintIdle(image: GrayImage): void {
|
||||
image.drawText(mediumFont, 24, 16, "Navigate", 245);
|
||||
const busy = phase !== "idle";
|
||||
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.";
|
||||
image.drawTextWrapped({ font: smallFont, x: 24, y: 64, width: image.width - 48, text: hint, value: 170 });
|
||||
if (statusMessage) {
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
import "@nativescript/core/globals";
|
||||
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 { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
@@ -29,7 +29,8 @@ import * as frameTimings from "../../native/frame-timings";
|
||||
import { getActiveDisplay } from "../../native/active-display";
|
||||
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
||||
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 {
|
||||
directionalFallback,
|
||||
@@ -445,9 +446,9 @@ function playSfx(window: PinballWindow, steps: Step[], minor = false): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** The window's long-press menu (game actions + default entries). */
|
||||
function openWindowMenu(window: PinballWindow): void {
|
||||
windowMenu(window).open([
|
||||
/** The window's long-press menu (game actions); playing binds long-press to the nudge instead. */
|
||||
function windowMenuItems(window: PinballWindow): MenuItem[] {
|
||||
return [
|
||||
{
|
||||
label: "New game",
|
||||
onSelect: (ctx) => {
|
||||
@@ -464,14 +465,17 @@ function openWindowMenu(window: PinballWindow): void {
|
||||
if (window.soundOn) playSfx(window, SFX_RESUME);
|
||||
},
|
||||
},
|
||||
...defaultWindowMenuItems(window.windowId, post),
|
||||
]);
|
||||
];
|
||||
}
|
||||
|
||||
function windowMenu(window: PinballWindow): WindowMenu {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
windowId: window.windowId,
|
||||
post,
|
||||
title: () => window.title,
|
||||
items: () => windowMenuItems(window),
|
||||
longPressOpensMenu: () => window.phase !== "playing",
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
@@ -577,7 +581,7 @@ function handleIdleInput(window: PinballWindow, event: InputEvent, frameId: numb
|
||||
post({ type: "yield-focus", windowId: window.windowId });
|
||||
return;
|
||||
case "long-press":
|
||||
openWindowMenu(window);
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
default:
|
||||
frameTimings.finishFrame(frameId, "discarded: pinball ignored input");
|
||||
@@ -948,10 +952,7 @@ function drawFlipper(image: GrayImage, flipper: Flipper): void {
|
||||
}
|
||||
|
||||
function paint(window: PinballWindow): Plane[] {
|
||||
if (window.menu?.isOpen()) {
|
||||
return window.menu.paint();
|
||||
}
|
||||
return singlePlane(paintContent(window));
|
||||
return windowMenu(window).paint();
|
||||
}
|
||||
|
||||
function paintContent(window: PinballWindow): GrayImage {
|
||||
|
||||
@@ -17,7 +17,7 @@ import * as frameTimings from "../../native/frame-timings";
|
||||
import { getActiveDisplay } from "../../native/active-display";
|
||||
import { onSettingsStoreChanged } from "../../native/settings-store";
|
||||
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 { ToolResult, ToolSpec } from "../../assistant/tool-registry";
|
||||
import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures";
|
||||
@@ -329,7 +329,10 @@ function maybeRefreshStalePage(): void {
|
||||
function windowMenu(win: RoamWindow): WindowMenu {
|
||||
if (!win.menu) {
|
||||
win.menu = new WindowMenu({
|
||||
windowId: win.windowId,
|
||||
post,
|
||||
title: () => win.title,
|
||||
items: () => menuItems(win),
|
||||
size: { width: win.viewportWidth, height: win.viewportHeight },
|
||||
paintBase: () => paintContent(win),
|
||||
isFocused: () => win.focused,
|
||||
@@ -380,7 +383,7 @@ function menuItems(win: RoamWindow): MenuItem[] {
|
||||
beginSettingEdit(roamApiTokenSetting);
|
||||
},
|
||||
});
|
||||
return [...items, ...defaultWindowMenuItems(win.windowId, post)];
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -421,7 +424,7 @@ function handleInput(win: RoamWindow, event: InputEvent, frameId: number): void
|
||||
return;
|
||||
}
|
||||
if (event.type === "long-press") {
|
||||
windowMenu(win).open(menuItems(win));
|
||||
windowMenu(win).open();
|
||||
renderAndSubmit(win, frameId);
|
||||
return;
|
||||
}
|
||||
@@ -583,9 +586,9 @@ async function handleRoamTool(name: string, args: any): Promise<ToolResult> {
|
||||
// Painting
|
||||
|
||||
function paint(win: RoamWindow): Plane[] {
|
||||
if (win.menu?.isOpen()) return win.menu.paint();
|
||||
if (editingSetting) return singlePlane(paintSettingEdit(win, editingSetting));
|
||||
return singlePlane(paintContent(win));
|
||||
return windowMenu(win).paint(() =>
|
||||
singlePlane(editingSetting ? paintSettingEdit(win, editingSetting) : paintContent(win)),
|
||||
);
|
||||
}
|
||||
|
||||
/** The "type on the phone" screen shown while a Roam setting is being edited. */
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
import "@nativescript/core/globals";
|
||||
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 { getDefaultSmallFont, getTerminalFontConfig } from "../../graphics/ui-fonts";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
@@ -48,7 +48,7 @@ import { connectionDisplayName, loadConnections, parseConnectionString, saveConn
|
||||
import { TerminalEmulator } from "./terminal-emulator";
|
||||
import { drawListScrollbar, drawSelectionHighlight, scrollToKeepSelectionVisible, type MenuItem } from "../../ui/menu";
|
||||
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 type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
|
||||
import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
|
||||
@@ -905,7 +905,10 @@ function reconnectView(window: ViewWindow): void {
|
||||
function windowMenu(window: TerminalWindow): WindowMenu {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
windowId: window.windowId,
|
||||
post,
|
||||
title: () => window.title,
|
||||
items: () => windowMenuItems(window),
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
@@ -984,7 +987,6 @@ function windowMenuItems(window: TerminalWindow): MenuItem[] {
|
||||
},
|
||||
);
|
||||
}
|
||||
items.push(...defaultWindowMenuItems(window.windowId, post));
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -999,7 +1001,7 @@ function handleInput(window: TerminalWindow, event: InputEvent, frameId: number)
|
||||
return;
|
||||
}
|
||||
if (event.type === "long-press") {
|
||||
windowMenu(window).open(windowMenuItems(window));
|
||||
windowMenu(window).open();
|
||||
renderAndSubmit(window, frameId);
|
||||
return;
|
||||
}
|
||||
@@ -1457,10 +1459,7 @@ async function launchAndOpenView(control: ControlConnection, preset: string): Pr
|
||||
}
|
||||
|
||||
function paint(window: TerminalWindow): Plane[] {
|
||||
if (window.menu?.isOpen()) {
|
||||
return window.menu.paint();
|
||||
}
|
||||
return singlePlane(paintContent(window));
|
||||
return windowMenu(window).paint();
|
||||
}
|
||||
|
||||
function paintContent(window: TerminalWindow): GrayImage {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
import "@nativescript/core/globals";
|
||||
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 { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
fireTimerNotification,
|
||||
scheduleTimerNotification,
|
||||
} 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 { ToolResult, ToolSpec } from "../../assistant/tool-registry";
|
||||
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 {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
windowId: window.windowId,
|
||||
post,
|
||||
title: () => window.title,
|
||||
items: () => [],
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
@@ -317,7 +323,7 @@ function handleInput(window: TimerWindow, event: InputEvent, frameId: number): v
|
||||
return;
|
||||
}
|
||||
if (event.type === "long-press") {
|
||||
windowMenu(window).open(defaultWindowMenuItems(window.windowId, post));
|
||||
windowMenu(window).open();
|
||||
renderAndSubmit(window, frameId);
|
||||
return;
|
||||
}
|
||||
@@ -513,10 +519,7 @@ function updateRenderTimer(window: TimerWindow): void {
|
||||
}
|
||||
|
||||
function paint(window: TimerWindow): Plane[] {
|
||||
if (window.menu?.isOpen()) {
|
||||
return window.menu.paint();
|
||||
}
|
||||
return singlePlane(paintContent(window));
|
||||
return windowMenu(window).paint();
|
||||
}
|
||||
|
||||
function paintContent(window: TimerWindow): GrayImage {
|
||||
|
||||
+4
-1
@@ -115,13 +115,16 @@ export function directionalFallback(event: InputEvent): InputEvent {
|
||||
* double-click ●● (twice)
|
||||
* scroll ▲▼ (U+25B2 / U+25BC)
|
||||
* long-press - (hyphen-minus)
|
||||
* tap-then-hold ●- (click then long-press)
|
||||
*/
|
||||
export const GESTURE_CLICK = "\u25cf";
|
||||
export const GESTURE_DOUBLE_CLICK = GESTURE_CLICK+GESTURE_CLICK;
|
||||
export const GESTURE_SCROLL_UP = "▲";
|
||||
export const GESTURE_SCROLL_DOWN = "▼";
|
||||
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.
|
||||
|
||||
+16
-2
@@ -13,6 +13,8 @@ const DEFAULT_MENU_WIDTH = 272;
|
||||
// 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 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_BORDER_STROKE = 45;
|
||||
|
||||
@@ -27,6 +29,11 @@ export type MenuLayout = {
|
||||
minHeight?: number;
|
||||
/** Height cap before the menu starts scrolling. Default: the full screen. */
|
||||
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
|
||||
* 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,
|
||||
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 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,
|
||||
this.selectedIndex,
|
||||
@@ -230,6 +241,9 @@ export class MenuLayer implements Layer {
|
||||
if (this.title) {
|
||||
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 focused = ctx.stack.isFocused();
|
||||
|
||||
@@ -31,9 +31,11 @@ export type InProcessWindowOptions = {
|
||||
/** Window height: the standard 288px band ("min", default) or full screen ("max"). */
|
||||
heightMode?: WindowHeightMode;
|
||||
/**
|
||||
* App-specific entries for the window's long-press menu, listed ahead of
|
||||
* the default Voice input / Close window entries. Called at open time, so
|
||||
* the items can reflect current app state.
|
||||
* The window's long-press context menu: app-specific entries only (the
|
||||
* shared Focus app switcher / Voice input / Close window entries live in
|
||||
* 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[];
|
||||
/** 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
|
||||
// window shares. In-process apps run on the main thread, so the default
|
||||
// items act on the shell directly (workers post messages instead).
|
||||
const appMenuItems = () => options.menuItems?.() ?? [];
|
||||
|
||||
// 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 = () => {
|
||||
if (stack.topMatches((layer) => layer instanceof WindowMenuLayer)) return;
|
||||
// "Focus app switcher" first: long-press then tap defocuses the app
|
||||
// (hands focus to the sidebar) without closing it — the reliable way out
|
||||
// for apps that consume double-click.
|
||||
const items: MenuItem[] = [
|
||||
{
|
||||
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);
|
||||
},
|
||||
});
|
||||
const items = appMenuItems();
|
||||
if (!items.length) {
|
||||
shell.openSystemMenu(options.windowId);
|
||||
return;
|
||||
}
|
||||
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.
|
||||
acceptsDirectional: true,
|
||||
heightMode,
|
||||
hasAppMenu: () => appMenuItems().length > 0,
|
||||
close: () => {
|
||||
closed = true;
|
||||
// Fire onRemoved for any pushed layers so they release resources (e.g. a
|
||||
@@ -193,8 +173,9 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
||||
}
|
||||
return;
|
||||
}
|
||||
// The default long-press response: the window menu. Handled here (not
|
||||
// per-layer) so it works over submenus and app content alike.
|
||||
// The default long-press response: the window menu (or the system
|
||||
// menu in its place). Handled here (not per-layer) so it works over
|
||||
// submenus and app content alike.
|
||||
if (event.type === "long-press") {
|
||||
openWindowMenu();
|
||||
await render(frameId);
|
||||
|
||||
+87
-21
@@ -5,6 +5,8 @@ import { EvenAIStatus, EventSourceType, OsEventTypeList, WatchGestureType } from
|
||||
import type { RawInputEvent } from "../../native/faceclaw-communicator";
|
||||
import {
|
||||
directionalFallback,
|
||||
GESTURE_LONG_PRESS,
|
||||
gestureHints,
|
||||
InputEvent,
|
||||
type InputEventPayload,
|
||||
type InputSource,
|
||||
@@ -59,10 +61,11 @@ import {
|
||||
* 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
|
||||
* 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
|
||||
* past the escape threshold opens the shell's own escape menu, so the shell
|
||||
* keeps working when a window's handler hangs. The 2.2.9 tap-then-hold gesture
|
||||
* opens that shell menu immediately.
|
||||
* their own context menu, or ask for the system menu when they have none.
|
||||
* The system menu (Focus app switcher, Voice input, Close window, Debug) is
|
||||
* shell-owned: the 2.2.9 tap-then-hold gesture opens it directly, and holding
|
||||
* a long-press past the escape threshold opens it too, so the shell keeps
|
||||
* working when a window's handler hangs.
|
||||
*/
|
||||
|
||||
export type ShellWindow = {
|
||||
@@ -71,8 +74,15 @@ export type ShellWindow = {
|
||||
title: string;
|
||||
/** Compositor surface this window renders to; configured at connect / launch. */
|
||||
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;
|
||||
/**
|
||||
* 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
|
||||
* input) a meaning; otherwise the shell forwards directionalFallback(event).
|
||||
@@ -167,9 +177,16 @@ const noopActions: LayerActions = noopLayerActions;
|
||||
*/
|
||||
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 {
|
||||
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
|
||||
// vertical position setting currently puts it; centered over the
|
||||
// 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,
|
||||
width,
|
||||
minHeight: 150,
|
||||
footer,
|
||||
});
|
||||
}
|
||||
|
||||
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
|
||||
// the window first); apps conventionally answer it with their window
|
||||
// menu. The escape timer runs regardless of what the app does with it:
|
||||
// holding the press long enough opens the shell's own menu.
|
||||
// the window first); apps conventionally answer it with their context
|
||||
// menu, or ask for the system menu when they have none. The escape timer
|
||||
// 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") {
|
||||
this.startEscapeMenuTimer();
|
||||
const window = this.foregroundWindow();
|
||||
// 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
|
||||
// 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 (
|
||||
!this.activeVoiceLayer &&
|
||||
window?.hasAppMenu?.() &&
|
||||
this.stack.popIfTop((layer) => layer instanceof ShellOverlayMenuLayer)
|
||||
) {
|
||||
this.config.requestShellRender();
|
||||
@@ -662,7 +684,6 @@ class Shell {
|
||||
if (this.activeVoiceLayer || !this.stack.isAtBase()) {
|
||||
return { shell: true, window: false };
|
||||
}
|
||||
const window = this.foregroundWindow();
|
||||
if (!window) {
|
||||
return { shell: true, window: false };
|
||||
}
|
||||
@@ -931,9 +952,9 @@ class Shell {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* apps via a start-voice-input message). The menu click already ended the
|
||||
* press, so the dialog finishes on click instead of long-press-release.
|
||||
* user picks Voice input from the system menu (or an app asks via a
|
||||
* start-voice-input message). The menu click already ended the press, so
|
||||
* the dialog finishes on click instead of long-press-release.
|
||||
*/
|
||||
startVoiceInput(): void {
|
||||
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
|
||||
* an unresponsive app can always be closed. It opens after an extended hold
|
||||
* or immediately for tap-then-hold, over whatever the app did with an earlier
|
||||
* ordinary long-press, including opening its own menu.
|
||||
* A window's answer to a long-press when it has no context menu of its
|
||||
* own: open the system menu in its place, so both gestures land on the
|
||||
* same menu. Ignored unless the window is still the foreground one.
|
||||
*/
|
||||
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 {
|
||||
if (!this.screenOn || this.activeVoiceLayer || !this.stack.isAtBase()) return;
|
||||
const foreground = this.foregroundWindow();
|
||||
if (!foreground) return;
|
||||
let layer: ShellOverlayMenuLayer;
|
||||
const items: MenuItem[] = [];
|
||||
if (foreground.closeable) {
|
||||
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({
|
||||
label: "Debug",
|
||||
onSelect: (ctx) => {
|
||||
@@ -1191,7 +1249,15 @@ class Shell {
|
||||
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
|
||||
// context menu up closes it, so the two context menus never stack.
|
||||
void foreground.handleInput(makeInputEvent({ type: "system-menu-opened" }), 0);
|
||||
|
||||
@@ -62,15 +62,33 @@ export type WorkerAppReply =
|
||||
| { type: "set-title"; windowId: string; title: string }
|
||||
| { 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";
|
||||
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";
|
||||
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. */
|
||||
type: "open-settings";
|
||||
@@ -172,6 +190,8 @@ const TOOL_CALL_HOST_TIMEOUT_MS = 15_000;
|
||||
|
||||
export class WorkerAppHost {
|
||||
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 nextCallSerial = 1;
|
||||
/**
|
||||
@@ -241,6 +261,18 @@ export class WorkerAppHost {
|
||||
this.options.requestShellRender();
|
||||
}
|
||||
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":
|
||||
this.options.openSettings(message.section);
|
||||
break;
|
||||
@@ -314,8 +346,10 @@ export class WorkerAppHost {
|
||||
closeable: true,
|
||||
acceptsDirectional: spec.acceptsDirectional,
|
||||
heightMode,
|
||||
hasAppMenu: () => this.appMenuAvailable.has(spec.windowId),
|
||||
close: () => {
|
||||
this.openWindows.delete(spec.windowId);
|
||||
this.appMenuAvailable.delete(spec.windowId);
|
||||
// Withdraw this window's tools and fail any in-flight calls to it.
|
||||
toolRegistry.removeAppTools(spec.windowId);
|
||||
this.failPendingToolCallsFor(spec.windowId);
|
||||
|
||||
+68
-49
@@ -1,20 +1,29 @@
|
||||
import { GrayImage } from "../graphics/image";
|
||||
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 { MenuLayer, type MenuItem, type MenuLayout } from "./menu";
|
||||
import type { WorkerAppReply } from "./shell/worker-window";
|
||||
|
||||
/**
|
||||
* The window long-press menu. By convention every app answers a long-press by
|
||||
* opening one of these: its app-specific actions followed by the default
|
||||
* entries (Voice input, Close window). This is a convenience path, not the
|
||||
* safety net — the shell separately opens its own escape menu when the press
|
||||
* is held long enough, so an unresponsive app can always be closed.
|
||||
* The window long-press menu: an app's own context menu, holding its
|
||||
* app-specific actions. The shell's system menu (tap-then-hold, or a press
|
||||
* held past the escape threshold) carries the entries every window shares —
|
||||
* Focus app switcher, Voice input, Close window — so an app with nothing of
|
||||
* 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. */
|
||||
export const WINDOW_MENU_LAYOUT: MenuLayout = { x: "center", y: 8, width: 272, minHeight: 150 };
|
||||
/** 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,
|
||||
footer: gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "system menu"]]),
|
||||
};
|
||||
|
||||
export class WindowMenuLayer extends MenuLayer {
|
||||
constructor(title: string | null, items: MenuItem[]) {
|
||||
@@ -23,8 +32,22 @@ export class WindowMenuLayer extends MenuLayer {
|
||||
}
|
||||
|
||||
export type WindowMenuOptions = {
|
||||
windowId: string;
|
||||
post: (reply: WorkerAppReply) => void;
|
||||
/** Menu title: the window's title, read at open time. */
|
||||
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). */
|
||||
paintBase: () => GrayImage;
|
||||
size: { width: number; height: number };
|
||||
@@ -36,11 +59,14 @@ export type WindowMenuOptions = {
|
||||
* a persistent LayerStack. Wraps a short-lived stack so MenuLayer (and the
|
||||
* ctx.stack.pop() convention in item callbacks) works unchanged.
|
||||
*
|
||||
* Usage: route input to handleInput while isOpen(); paint() returns the
|
||||
* window content with the menu drawn over it.
|
||||
* Usage: answer a long-press with open(); route input to handleInput while
|
||||
* 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 {
|
||||
private stack: LayerStack | null = null;
|
||||
private reportedAvailable: boolean | null = null;
|
||||
|
||||
constructor(private readonly options: WindowMenuOptions) {}
|
||||
|
||||
@@ -48,8 +74,22 @@ export class WindowMenu {
|
||||
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 (!items.length) {
|
||||
this.options.post({ type: "open-system-menu", windowId: this.options.windowId });
|
||||
return;
|
||||
}
|
||||
const base: Layer = {
|
||||
paint: () => this.options.paintBase(),
|
||||
handleInput: () => {},
|
||||
@@ -59,9 +99,23 @@ export class WindowMenu {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
/** Paint the window content with the menu over it (content alone if closed). */
|
||||
paint(): Plane[] {
|
||||
return this.stack ? this.stack.paint() : singlePlane(this.options.paintBase());
|
||||
/**
|
||||
* Paint the window content with the menu over it. `content` paints the
|
||||
* 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. */
|
||||
@@ -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 });
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
Reference in new issue
Block a user