forked from Blendman974/faceclaw
Redesign handling of long-press gesture and context menus
This commit is contained in:
1 parent
3452945322
commit
afc05d6a19
10 files changed
+455
-56
No files matched your search
@@ -836,9 +836,10 @@ class DashboardController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Launch or focus the (in-process, singleton) Settings app. */
|
/** Launch or focus the (in-process, singleton) Settings app, optionally on a section. */
|
||||||
private async launchSettingsApp(): Promise<void> {
|
private async launchSettingsApp(section?: string): Promise<void> {
|
||||||
if (this.settingsApp) {
|
if (this.settingsApp) {
|
||||||
|
if (section) this.settingsApp.focusSection(section);
|
||||||
shell.focusWindow(SETTINGS_WINDOW_ID);
|
shell.focusWindow(SETTINGS_WINDOW_ID);
|
||||||
this.requestShellRender();
|
this.requestShellRender();
|
||||||
return;
|
return;
|
||||||
@@ -859,6 +860,7 @@ class DashboardController {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.settingsApp = settingsApp;
|
this.settingsApp = settingsApp;
|
||||||
|
if (section) settingsApp.focusSection(section);
|
||||||
shell.registerWindow(settingsApp.window);
|
shell.registerWindow(settingsApp.window);
|
||||||
// Configure the surface before foregrounding so the first frame has
|
// Configure the surface before foregrounding so the first frame has
|
||||||
// somewhere to land.
|
// somewhere to land.
|
||||||
@@ -921,6 +923,11 @@ class DashboardController {
|
|||||||
setSurfaceVisible: (surfaceId, visible) => this.setWindowSurfaceVisible(surfaceId, visible),
|
setSurfaceVisible: (surfaceId, visible) => this.setWindowSurfaceVisible(surfaceId, visible),
|
||||||
removeSurface: (surfaceId) => this.removeWindowSurface(surfaceId),
|
removeSurface: (surfaceId) => this.removeWindowSurface(surfaceId),
|
||||||
requestShellRender: () => this.requestShellRender(),
|
requestShellRender: () => this.requestShellRender(),
|
||||||
|
openSettings: (section) => {
|
||||||
|
void this.launchSettingsApp(section).catch((error) => {
|
||||||
|
this.appendLog(`settings launch failed: ${this.formatError(error)}`);
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
this.appHosts.set(appId, host);
|
this.appHosts.set(appId, host);
|
||||||
return host;
|
return host;
|
||||||
|
|||||||
@@ -50,6 +50,15 @@ export class SettingsPanelLayer implements Layer {
|
|||||||
return this.sections[clamp(this.leftIndex, 0, this.sections.length - 1)]!;
|
return this.sections[clamp(this.leftIndex, 0, this.sections.length - 1)]!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Select a left-column section by label (deep link, e.g. from an app's menu). */
|
||||||
|
focusSection(label: string): void {
|
||||||
|
const index = this.sections.findIndex((section) => section.label === label);
|
||||||
|
if (index < 0) return;
|
||||||
|
this.leftIndex = index;
|
||||||
|
this.focus = "left";
|
||||||
|
this.resetRight();
|
||||||
|
}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
const font = getDefaultSmallFont();
|
const font = getDefaultSmallFont();
|
||||||
const { width, height } = ctx.stack.getBaseSize();
|
const { width, height } = ctx.stack.getBaseSize();
|
||||||
|
|||||||
@@ -40,6 +40,19 @@ export type LayerActions = {
|
|||||||
playBuzzerSequence: (payload: Uint8Array) => Promise<void> | void;
|
playBuzzerSequence: (payload: Uint8Array) => Promise<void> | void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Do-nothing actions, for stacks whose layers never use them (or as a base to spread over). */
|
||||||
|
export const noopLayerActions: LayerActions = {
|
||||||
|
requestRender: () => {},
|
||||||
|
disconnect: () => {},
|
||||||
|
startTextSettingEdit: () => {},
|
||||||
|
endTextSettingEdit: () => {},
|
||||||
|
startVoiceCapture: () => {},
|
||||||
|
stopVoiceCapture: () => {},
|
||||||
|
startContinuousVoiceCapture: () => {},
|
||||||
|
stopContinuousVoiceCapture: () => {},
|
||||||
|
playBuzzerSequence: () => {},
|
||||||
|
};
|
||||||
|
|
||||||
export type PaintBelow = () => GrayImage;
|
export type PaintBelow = () => GrayImage;
|
||||||
|
|
||||||
function notifyRemoved(layer: Layer | undefined): void {
|
function notifyRemoved(layer: Layer | undefined): void {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { GrayImage } from "../../graphics/image";
|
import { GrayImage } from "../../graphics/image";
|
||||||
|
import * as frameTimings from "../../native/frame-timings";
|
||||||
import { beginRenderPass, endRenderPass } from "../../util/render-freshness";
|
import { beginRenderPass, endRenderPass } from "../../util/render-freshness";
|
||||||
import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, PaintBelow } from "../layers";
|
import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, PaintBelow } from "../layers";
|
||||||
|
import { type MenuItem } from "../menu";
|
||||||
|
import { WindowMenuLayer } from "../window-menu";
|
||||||
import { windowIcon } from "./chrome-layer";
|
import { windowIcon } from "./chrome-layer";
|
||||||
import { type IconName } from "../../graphics/icons";
|
import { type IconName } from "../../graphics/icons";
|
||||||
import { APP_VIEWPORT } from "./geometry";
|
import { APP_VIEWPORT } from "./geometry";
|
||||||
@@ -21,6 +24,12 @@ export type InProcessWindowOptions = {
|
|||||||
/** Lucide icon name for the sidebar indicator; falls back to iconLetter. */
|
/** Lucide icon name for the sidebar indicator; falls back to iconLetter. */
|
||||||
icon?: IconName;
|
icon?: IconName;
|
||||||
closeable: boolean;
|
closeable: boolean;
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
menuItems?: () => MenuItem[];
|
||||||
/** Shared actions; requestRender is rebound to this window's render. */
|
/** Shared actions; requestRender is rebound to this window's render. */
|
||||||
actions: LayerActions;
|
actions: LayerActions;
|
||||||
baseLayer: Layer;
|
baseLayer: Layer;
|
||||||
@@ -62,8 +71,15 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
|||||||
// to keep the paint fast; when they do, schedule one follow-up render that
|
// to keep the paint fast; when they do, schedule one follow-up render that
|
||||||
// requires fresh data (same contract as the dashboard render loop).
|
// requires fresh data (same contract as the dashboard render loop).
|
||||||
let nextRenderWantsFreshData = false;
|
let nextRenderWantsFreshData = false;
|
||||||
|
let closed = false;
|
||||||
|
|
||||||
async function render(frameId: number): Promise<void> {
|
async function render(frameId: number): Promise<void> {
|
||||||
|
if (closed) {
|
||||||
|
// The surface is gone (e.g. Close window picked from this window's own
|
||||||
|
// menu); dropping the frame beats submitting to a removed surface.
|
||||||
|
frameTimings.finishFrame(frameId, "discarded: window closed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const wantFreshData = nextRenderWantsFreshData;
|
const wantFreshData = nextRenderWantsFreshData;
|
||||||
nextRenderWantsFreshData = false;
|
nextRenderWantsFreshData = false;
|
||||||
beginRenderPass(!wantFreshData);
|
beginRenderPass(!wantFreshData);
|
||||||
@@ -77,6 +93,31 @@ 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 openWindowMenu = () => {
|
||||||
|
if (stack.topMatches((layer) => layer instanceof WindowMenuLayer)) return;
|
||||||
|
const items: MenuItem[] = [...(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(items));
|
||||||
|
};
|
||||||
|
|
||||||
const window: ShellWindow = {
|
const window: ShellWindow = {
|
||||||
appId: options.appId,
|
appId: options.appId,
|
||||||
windowId: options.windowId,
|
windowId: options.windowId,
|
||||||
@@ -84,6 +125,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
|||||||
surfaceId: `window:${options.windowId}`,
|
surfaceId: `window:${options.windowId}`,
|
||||||
closeable: options.closeable,
|
closeable: options.closeable,
|
||||||
close: () => {
|
close: () => {
|
||||||
|
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
|
||||||
// demo that enabled a hardware stream) even when closed from within.
|
// demo that enabled a hardware stream) even when closed from within.
|
||||||
stack.clearToBase();
|
stack.clearToBase();
|
||||||
@@ -92,6 +134,13 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
|||||||
},
|
},
|
||||||
drawIcon: windowIcon(options.icon, options.iconLetter),
|
drawIcon: windowIcon(options.icon, options.iconLetter),
|
||||||
handleInput: async (event, frameId) => {
|
handleInput: async (event, frameId) => {
|
||||||
|
// The default long-press response: the window menu. Handled here (not
|
||||||
|
// per-layer) so it works over submenus and app content alike.
|
||||||
|
if (event.type === "long-press") {
|
||||||
|
openWindowMenu();
|
||||||
|
await render(frameId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
await stack.handleInput(event);
|
await stack.handleInput(event);
|
||||||
await render(frameId);
|
await render(frameId);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ export type SettingsAppOptions = {
|
|||||||
export type SettingsAppWindow = {
|
export type SettingsAppWindow = {
|
||||||
window: ShellWindow;
|
window: ShellWindow;
|
||||||
requestRender: () => void;
|
requestRender: () => void;
|
||||||
|
/** Select a section in the left column by label (e.g. "Terminal"). */
|
||||||
|
focusSection: (label: string) => void;
|
||||||
/** Whether the glasses-side text-setting editor is the top layer. */
|
/** Whether the glasses-side text-setting editor is the top layer. */
|
||||||
isTextEditorOnTop: () => boolean;
|
isTextEditorOnTop: () => boolean;
|
||||||
/** Pop the text-setting editor if it is on top; returns whether it was. */
|
/** Pop the text-setting editor if it is on top; returns whether it was. */
|
||||||
@@ -32,6 +34,7 @@ export type SettingsAppWindow = {
|
|||||||
* controller, which lives on the main thread.
|
* controller, which lives on the main thread.
|
||||||
*/
|
*/
|
||||||
export function createSettingsAppWindow(options: SettingsAppOptions): SettingsAppWindow {
|
export function createSettingsAppWindow(options: SettingsAppOptions): SettingsAppWindow {
|
||||||
|
const panel = createSettingsPanelLayer();
|
||||||
const { window, stack, requestRender } = createInProcessWindow({
|
const { window, stack, requestRender } = createInProcessWindow({
|
||||||
appId: "settings",
|
appId: "settings",
|
||||||
windowId: SETTINGS_WINDOW_ID,
|
windowId: SETTINGS_WINDOW_ID,
|
||||||
@@ -42,7 +45,7 @@ export function createSettingsAppWindow(options: SettingsAppOptions): SettingsAp
|
|||||||
actions: options.actions,
|
actions: options.actions,
|
||||||
// Not wrapped in YieldAtRootLayer: the panel routes double-click itself
|
// Not wrapped in YieldAtRootLayer: the panel routes double-click itself
|
||||||
// (right column -> left column, then left column -> sidebar).
|
// (right column -> left column, then left column -> sidebar).
|
||||||
baseLayer: createSettingsPanelLayer(),
|
baseLayer: panel,
|
||||||
submitFrame: options.submitFrame,
|
submitFrame: options.submitFrame,
|
||||||
setSurfaceVisible: options.setSurfaceVisible,
|
setSurfaceVisible: options.setSurfaceVisible,
|
||||||
removeSurface: options.removeSurface,
|
removeSurface: options.removeSurface,
|
||||||
@@ -51,6 +54,10 @@ export function createSettingsAppWindow(options: SettingsAppOptions): SettingsAp
|
|||||||
return {
|
return {
|
||||||
window,
|
window,
|
||||||
requestRender,
|
requestRender,
|
||||||
|
focusSection: (label) => {
|
||||||
|
panel.focusSection(label);
|
||||||
|
requestRender();
|
||||||
|
},
|
||||||
isTextEditorOnTop: () => stack.topMatches((layer) => layer instanceof EditTextSettingLayer),
|
isTextEditorOnTop: () => stack.topMatches((layer) => layer instanceof EditTextSettingLayer),
|
||||||
closeTextEditor: () => stack.popIfTop((layer) => layer instanceof EditTextSettingLayer),
|
closeTextEditor: () => stack.popIfTop((layer) => layer instanceof EditTextSettingLayer),
|
||||||
};
|
};
|
||||||
|
|||||||
+104
-52
@@ -1,7 +1,7 @@
|
|||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
||||||
import { EvenAIStatus, EventSourceType, OsEventTypeList } from "../../g2/events";
|
import { EvenAIStatus, EventSourceType, OsEventTypeList } from "../../g2/events";
|
||||||
import type { RawInputEvent } from "../../native/faceclaw-communicator";
|
import type { RawInputEvent } from "../../native/faceclaw-communicator";
|
||||||
import { DashboardInputEvent, LayerActions, LayerStack } from "../layers";
|
import { DashboardInputEvent, LayerActions, LayerStack, noopLayerActions } from "../layers";
|
||||||
import { MenuLayer, type MenuItem } from "../menu";
|
import { MenuLayer, type MenuItem } from "../menu";
|
||||||
import { VoiceInputLayer } from "../apps/voice-input";
|
import { VoiceInputLayer } from "../apps/voice-input";
|
||||||
import { SingleNotificationLayer } from "../notifications";
|
import { SingleNotificationLayer } from "../notifications";
|
||||||
@@ -17,15 +17,17 @@ import { SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The shell: owns the window registry, focus, screen on/off, and the shell
|
* The shell: owns the window registry, focus, screen on/off, and the shell
|
||||||
* surface (sidebar + top bar + shell overlays such as the long-press menu and
|
* surface (sidebar + top bar + shell overlays such as the escape menu and
|
||||||
* the push-to-talk dialog). Runs on the main thread; windows will later live
|
* the voice dialog). Runs on the main thread; windows are hosted in-process
|
||||||
* in worker threads, today the only window is the in-process dashboard.
|
* or in per-app worker threads.
|
||||||
*
|
*
|
||||||
* Input flow: every event enters via receiveInput. The shell consumes its
|
* Input flow: every event enters via receiveInput. The shell consumes
|
||||||
* reserved gestures (long-press, and everything while the sidebar or a shell
|
* everything while the sidebar or a shell overlay has focus and forwards the
|
||||||
* overlay has focus) and forwards the rest to the focused window. Windows
|
* rest to the focused window. Long-press goes to the foreground window (from
|
||||||
* never see events the shell consumed, and the shell keeps working when a
|
* the sidebar it focuses the window first); by convention apps answer it with
|
||||||
* window's handler hangs (the long-press menu is the escape hatch).
|
* 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type ShellWindow = {
|
export type ShellWindow = {
|
||||||
@@ -34,7 +36,7 @@ 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 the shell's long-press menu offers Close Window (launcher and dashboard are pinned). */
|
/** Whether close menu entries (app menu default, shell escape menu) apply (the launcher is pinned). */
|
||||||
closeable: boolean;
|
closeable: boolean;
|
||||||
/** App-side cleanup when the shell closes the window (worker notification, surface removal). */
|
/** App-side cleanup when the shell closes the window (worker notification, surface removal). */
|
||||||
close?: () => void;
|
close?: () => void;
|
||||||
@@ -72,19 +74,16 @@ export type ShellInputOutcome = { shell: boolean; window: boolean };
|
|||||||
|
|
||||||
type FocusKind = "sidebar" | "window";
|
type FocusKind = "sidebar" | "window";
|
||||||
|
|
||||||
const noopActions: LayerActions = {
|
const noopActions: LayerActions = noopLayerActions;
|
||||||
requestRender: () => {},
|
|
||||||
disconnect: () => {},
|
|
||||||
startTextSettingEdit: () => {},
|
|
||||||
endTextSettingEdit: () => {},
|
|
||||||
startVoiceCapture: () => {},
|
|
||||||
stopVoiceCapture: () => {},
|
|
||||||
startContinuousVoiceCapture: () => {},
|
|
||||||
stopContinuousVoiceCapture: () => {},
|
|
||||||
playBuzzerSequence: () => {},
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Long-press overlay menu; closing it returns focus to the sidebar. */
|
/**
|
||||||
|
* Hold a long-press this much past the long-press event (which the firmware
|
||||||
|
* itself only fires after a shorter hold) and the shell opens its own escape
|
||||||
|
* menu — the recovery path when an app ignores or mishandles the gesture.
|
||||||
|
*/
|
||||||
|
const LONG_PRESS_ESCAPE_MENU_MS = 4000;
|
||||||
|
|
||||||
|
/** Shell-surface overlay menu (the escape menu); closing it returns focus to the sidebar. */
|
||||||
class ShellOverlayMenuLayer extends MenuLayer {
|
class ShellOverlayMenuLayer extends MenuLayer {
|
||||||
constructor(items: MenuItem[], private readonly onClosed: () => void) {
|
constructor(items: MenuItem[], private readonly onClosed: () => void) {
|
||||||
super(null, items, {
|
super(null, items, {
|
||||||
@@ -112,6 +111,7 @@ class Shell {
|
|||||||
// notification icons and the battery indicators.
|
// notification icons and the battery indicators.
|
||||||
private readonly trayIcons = new Map<string, GrayImage>();
|
private readonly trayIcons = new Map<string, GrayImage>();
|
||||||
private activeVoiceLayer: VoiceInputLayer | null = null;
|
private activeVoiceLayer: VoiceInputLayer | null = null;
|
||||||
|
private escapeMenuTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
private readonly actions: LayerActions = { ...noopActions };
|
private readonly actions: LayerActions = { ...noopActions };
|
||||||
private config: ShellConfig = {
|
private config: ShellConfig = {
|
||||||
actions: noopActions,
|
actions: noopActions,
|
||||||
@@ -186,9 +186,9 @@ class Shell {
|
|||||||
this.config.requestShellRender();
|
this.config.requestShellRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Close the foreground window via the shell (long-press menu action). */
|
/** Close a window by id, if it is closeable (menu actions route here). */
|
||||||
closeForegroundWindow(): void {
|
closeWindow(windowId: string): void {
|
||||||
const window = this.foregroundWindow();
|
const window = this.windows.find((w) => w.windowId === windowId);
|
||||||
if (!window || !window.closeable) return;
|
if (!window || !window.closeable) return;
|
||||||
try {
|
try {
|
||||||
window.close?.();
|
window.close?.();
|
||||||
@@ -198,6 +198,12 @@ class Shell {
|
|||||||
this.removeWindow(window.windowId);
|
this.removeWindow(window.windowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Close the foreground window via the shell (escape menu action). */
|
||||||
|
closeForegroundWindow(): void {
|
||||||
|
const window = this.foregroundWindow();
|
||||||
|
if (window) this.closeWindow(window.windowId);
|
||||||
|
}
|
||||||
|
|
||||||
getWindows(): readonly ShellWindow[] {
|
getWindows(): readonly ShellWindow[] {
|
||||||
return this.windows;
|
return this.windows;
|
||||||
}
|
}
|
||||||
@@ -253,6 +259,7 @@ class Shell {
|
|||||||
/** Turn the screen off, closing any shell overlays. Sidebar selection is kept. */
|
/** Turn the screen off, closing any shell overlays. Sidebar selection is kept. */
|
||||||
sleep(): void {
|
sleep(): void {
|
||||||
if (!this.screenOn) return;
|
if (!this.screenOn) return;
|
||||||
|
this.cancelEscapeMenuTimer();
|
||||||
this.screenOn = false;
|
this.screenOn = false;
|
||||||
this.stack.clearToBase();
|
this.stack.clearToBase();
|
||||||
for (const window of this.windows) {
|
for (const window of this.windows) {
|
||||||
@@ -350,6 +357,12 @@ class Shell {
|
|||||||
|
|
||||||
this.lastInputAtMs = Date.now();
|
this.lastInputAtMs = Date.now();
|
||||||
|
|
||||||
|
// Anything but the long-press itself means the press ended (or the event
|
||||||
|
// stream moved on), so the escape countdown stops.
|
||||||
|
if (event.type !== "long-press") {
|
||||||
|
this.cancelEscapeMenuTimer();
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.screenOn) {
|
if (!this.screenOn) {
|
||||||
if (event.type === "double-click") {
|
if (event.type === "double-click") {
|
||||||
this.wake("sidebar");
|
this.wake("sidebar");
|
||||||
@@ -358,21 +371,37 @@ class Shell {
|
|||||||
return { shell: false, window: false };
|
return { shell: false, window: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Long-press is reserved by the shell: PTT from the sidebar, the overlay
|
// Long-press goes to the foreground window (from the sidebar it focuses
|
||||||
// menu from inside a window. Windows never see it.
|
// 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.
|
||||||
if (event.type === "long-press") {
|
if (event.type === "long-press") {
|
||||||
if (!this.activeVoiceLayer && this.stack.isAtBase()) {
|
this.startEscapeMenuTimer();
|
||||||
if (this.focus === "sidebar") {
|
if (this.activeVoiceLayer || !this.stack.isAtBase()) {
|
||||||
this.openVoiceDialog();
|
return { shell: true, window: false };
|
||||||
} else {
|
|
||||||
this.openOverlayMenu();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return { shell: true, window: false };
|
const window = this.foregroundWindow();
|
||||||
|
if (!window) {
|
||||||
|
return { shell: true, window: false };
|
||||||
|
}
|
||||||
|
if (this.focus === "sidebar") {
|
||||||
|
this.focus = "window";
|
||||||
|
}
|
||||||
|
// The window owns frameId from here (render or explicit finish).
|
||||||
|
await window.handleInput(event, frameId);
|
||||||
|
return { shell: true, window: true };
|
||||||
}
|
}
|
||||||
if (event.type === "long-press-release") {
|
if (event.type === "long-press-release") {
|
||||||
this.activeVoiceLayer?.endCapture();
|
this.activeVoiceLayer?.endCapture();
|
||||||
return { shell: true, window: false };
|
if (this.activeVoiceLayer || !this.stack.isAtBase() || this.focus !== "window") {
|
||||||
|
return { shell: true, window: false };
|
||||||
|
}
|
||||||
|
const window = this.foregroundWindow();
|
||||||
|
if (!window) {
|
||||||
|
return { shell: true, window: false };
|
||||||
|
}
|
||||||
|
await window.handleInput(event, frameId);
|
||||||
|
return { shell: false, window: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.stack.isAtBase()) {
|
if (!this.stack.isAtBase()) {
|
||||||
@@ -476,24 +505,46 @@ class Shell {
|
|||||||
this.foregroundWindow()?.receiveTextInput?.(text);
|
this.foregroundWindow()?.receiveTextInput?.(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private openOverlayMenu(): void {
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
startVoiceInput(): void {
|
||||||
|
if (!this.screenOn || this.activeVoiceLayer || !this.stack.isAtBase()) return;
|
||||||
|
// The transcript is aimed at the window whose menu requested it.
|
||||||
|
this.focus = "window";
|
||||||
|
this.openVoiceDialog(true);
|
||||||
|
this.config.requestShellRender();
|
||||||
|
}
|
||||||
|
|
||||||
|
private startEscapeMenuTimer(): void {
|
||||||
|
this.cancelEscapeMenuTimer();
|
||||||
|
this.escapeMenuTimer = setTimeout(() => {
|
||||||
|
this.escapeMenuTimer = null;
|
||||||
|
this.openEscapeMenu();
|
||||||
|
}, LONG_PRESS_ESCAPE_MENU_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private cancelEscapeMenuTimer(): void {
|
||||||
|
if (this.escapeMenuTimer !== null) {
|
||||||
|
clearTimeout(this.escapeMenuTimer);
|
||||||
|
this.escapeMenuTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The held-long-press safeguard menu. Shell-owned and shell-drawn (never
|
||||||
|
* the app's), so an unresponsive app can always be closed. It opens over
|
||||||
|
* whatever the app did with the long-press, including its own menu.
|
||||||
|
*/
|
||||||
|
private openEscapeMenu(): void {
|
||||||
|
if (!this.screenOn || this.activeVoiceLayer || !this.stack.isAtBase()) return;
|
||||||
const foreground = this.foregroundWindow();
|
const foreground = this.foregroundWindow();
|
||||||
|
if (!foreground?.closeable) return;
|
||||||
const items: MenuItem[] = [
|
const items: MenuItem[] = [
|
||||||
{
|
{
|
||||||
label: "Voice input",
|
|
||||||
onSelect: (ctx) => {
|
|
||||||
// Pop the menu first (its onRemoved yields focus to the sidebar),
|
|
||||||
// then take focus back: the transcript is aimed at the window the
|
|
||||||
// menu was opened over. The button is no longer held here, so the
|
|
||||||
// dialog finishes on click instead of long-press-release.
|
|
||||||
ctx.stack.pop();
|
|
||||||
this.focus = "window";
|
|
||||||
this.openVoiceDialog(true);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
if (foreground?.closeable) {
|
|
||||||
items.push({
|
|
||||||
label: "Close window",
|
label: "Close window",
|
||||||
onSelect: (ctx) => {
|
onSelect: (ctx) => {
|
||||||
// Pop the menu first (its onRemoved returns focus to the sidebar),
|
// Pop the menu first (its onRemoved returns focus to the sidebar),
|
||||||
@@ -501,9 +552,10 @@ class Shell {
|
|||||||
ctx.stack.pop();
|
ctx.stack.pop();
|
||||||
this.closeForegroundWindow();
|
this.closeForegroundWindow();
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
}
|
];
|
||||||
this.stack.push(new ShellOverlayMenuLayer(items, () => this.yieldFocusToSidebar()));
|
this.stack.push(new ShellOverlayMenuLayer(items, () => this.yieldFocusToSidebar()));
|
||||||
|
this.config.requestShellRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
private chromeState(): ShellChromeState {
|
private chromeState(): ShellChromeState {
|
||||||
|
|||||||
@@ -36,6 +36,21 @@ 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. */
|
||||||
|
type: "start-voice-input";
|
||||||
|
windowId: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
/** Window-menu pick: close this window (the shell owns the close path). */
|
||||||
|
type: "close-window-request";
|
||||||
|
windowId: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
/** Open or focus the Settings app, optionally jumping to a section. */
|
||||||
|
type: "open-settings";
|
||||||
|
section?: string;
|
||||||
|
}
|
||||||
| {
|
| {
|
||||||
/**
|
/**
|
||||||
* Set or clear the app's top-bar tray icon. Pixels ride the JSON
|
* Set or clear the app's top-bar tray icon. Pixels ride the JSON
|
||||||
@@ -66,6 +81,8 @@ export type WorkerAppHostOptions = {
|
|||||||
setSurfaceVisible: (surfaceId: string, visible: boolean) => void;
|
setSurfaceVisible: (surfaceId: string, visible: boolean) => void;
|
||||||
removeSurface: (surfaceId: string) => void;
|
removeSurface: (surfaceId: string) => void;
|
||||||
requestShellRender: () => void;
|
requestShellRender: () => void;
|
||||||
|
/** Open or focus the Settings app, optionally selecting a section. */
|
||||||
|
openSettings: (section?: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,6 +124,22 @@ export class WorkerAppHost {
|
|||||||
case "set-attention":
|
case "set-attention":
|
||||||
shell.setWindowAttention(message.windowId, message.attention);
|
shell.setWindowAttention(message.windowId, message.attention);
|
||||||
break;
|
break;
|
||||||
|
case "start-voice-input":
|
||||||
|
// Menus only open on the focused window, but re-check foreground:
|
||||||
|
// the reply crosses a thread boundary and focus may have moved.
|
||||||
|
if (shell.foregroundWindow()?.windowId === message.windowId) {
|
||||||
|
shell.startVoiceInput();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "close-window-request":
|
||||||
|
if (this.openWindows.has(message.windowId)) {
|
||||||
|
shell.closeWindow(message.windowId);
|
||||||
|
this.options.requestShellRender();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "open-settings":
|
||||||
|
this.options.openSettings(message.section);
|
||||||
|
break;
|
||||||
case "set-tray-icon": {
|
case "set-tray-icon": {
|
||||||
let icon: GrayImage | null = null;
|
let icon: GrayImage | null = null;
|
||||||
if (message.icon) {
|
if (message.icon) {
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
import { GrayImage } from "../graphics/image";
|
||||||
|
import {
|
||||||
|
noopLayerActions,
|
||||||
|
LayerStack,
|
||||||
|
type DashboardInputEvent,
|
||||||
|
type Layer,
|
||||||
|
} 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Viewport-relative layout; visually matches the shell's escape menu position. */
|
||||||
|
export const WINDOW_MENU_LAYOUT: MenuLayout = { x: 8, y: 8, width: 272, minHeight: 0 };
|
||||||
|
|
||||||
|
export class WindowMenuLayer extends MenuLayer {
|
||||||
|
constructor(items: MenuItem[]) {
|
||||||
|
super(null, items, WINDOW_MENU_LAYOUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type WindowMenuOptions = {
|
||||||
|
/** Paint the window content the menu draws over (a fresh, mutable image). */
|
||||||
|
paintBase: () => GrayImage;
|
||||||
|
size: { width: number; height: number };
|
||||||
|
isFocused: () => boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Menu host for worker apps, which paint pixels directly rather than through
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
export class WindowMenu {
|
||||||
|
private stack: LayerStack | null = null;
|
||||||
|
|
||||||
|
constructor(private readonly options: WindowMenuOptions) {}
|
||||||
|
|
||||||
|
isOpen(): boolean {
|
||||||
|
return this.stack !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
open(items: MenuItem[]): void {
|
||||||
|
if (this.stack) return;
|
||||||
|
const base: Layer = {
|
||||||
|
paint: () => this.options.paintBase(),
|
||||||
|
handleInput: () => {},
|
||||||
|
};
|
||||||
|
const stack = new LayerStack(base, { ...noopLayerActions }, this.options.size, this.options.isFocused);
|
||||||
|
stack.push(new WindowMenuLayer(items));
|
||||||
|
this.stack = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Paint the window content with the menu over it (content alone if closed). */
|
||||||
|
paint(): GrayImage {
|
||||||
|
return this.stack ? this.stack.paint() : this.options.paintBase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Route an input event to the menu; the menu closes by popping itself. */
|
||||||
|
async handleInput(event: DashboardInputEvent): Promise<void> {
|
||||||
|
const stack = this.stack;
|
||||||
|
if (!stack) return;
|
||||||
|
await stack.handleInput(event);
|
||||||
|
if (stack.isAtBase()) {
|
||||||
|
this.stack = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 [
|
||||||
|
{
|
||||||
|
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 });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -31,6 +31,8 @@ import {
|
|||||||
} from "../ui/dashboard-settings";
|
} from "../ui/dashboard-settings";
|
||||||
import { TerminalEmulator } from "../ui/apps/terminal-emulator";
|
import { TerminalEmulator } from "../ui/apps/terminal-emulator";
|
||||||
import type { DashboardInputEvent } from "../ui/layers";
|
import type { DashboardInputEvent } from "../ui/layers";
|
||||||
|
import type { MenuItem } from "../ui/menu";
|
||||||
|
import { defaultWindowMenuItems, WindowMenu } from "../ui/window-menu";
|
||||||
import type { WorkerAppMessage, WorkerAppReply } from "../ui/shell/worker-window";
|
import type { WorkerAppMessage, WorkerAppReply } from "../ui/shell/worker-window";
|
||||||
|
|
||||||
declare const global: any;
|
declare const global: any;
|
||||||
@@ -58,6 +60,8 @@ type BaseWindow = {
|
|||||||
focused: boolean;
|
focused: boolean;
|
||||||
renderScheduled: boolean;
|
renderScheduled: boolean;
|
||||||
lastSubmittedFingerprint: string;
|
lastSubmittedFingerprint: string;
|
||||||
|
/** Long-press window menu; created on first open. */
|
||||||
|
menu: WindowMenu | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
type HubWindow = BaseWindow & {
|
type HubWindow = BaseWindow & {
|
||||||
@@ -195,6 +199,7 @@ function openWindow(windowId: string, surfaceId: string, viewport: { width: numb
|
|||||||
focused: false,
|
focused: false,
|
||||||
renderScheduled: false,
|
renderScheduled: false,
|
||||||
lastSubmittedFingerprint: "",
|
lastSubmittedFingerprint: "",
|
||||||
|
menu: null,
|
||||||
selectedIndex: 0,
|
selectedIndex: 0,
|
||||||
});
|
});
|
||||||
if (!controlClient) {
|
if (!controlClient) {
|
||||||
@@ -284,6 +289,7 @@ function createViewWindow(windowId: string, surfaceId: string, socket: string, l
|
|||||||
focused: false,
|
focused: false,
|
||||||
renderScheduled: false,
|
renderScheduled: false,
|
||||||
lastSubmittedFingerprint: "",
|
lastSubmittedFingerprint: "",
|
||||||
|
menu: null,
|
||||||
socket,
|
socket,
|
||||||
label,
|
label,
|
||||||
client,
|
client,
|
||||||
@@ -344,7 +350,76 @@ function createViewWindow(windowId: string, surfaceId: string, socket: string, l
|
|||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The window's long-press menu, created lazily so window literals stay simple. */
|
||||||
|
function windowMenu(window: TerminalWindow): WindowMenu {
|
||||||
|
if (!window.menu) {
|
||||||
|
window.menu = new WindowMenu({
|
||||||
|
size: { width: viewportWidth, height: viewportHeight },
|
||||||
|
paintBase: () => paintContent(window),
|
||||||
|
isFocused: () => window.focused,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return window.menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
function windowMenuItems(window: TerminalWindow): MenuItem[] {
|
||||||
|
const items: MenuItem[] = [
|
||||||
|
{
|
||||||
|
label: "Settings",
|
||||||
|
onSelect: (ctx) => {
|
||||||
|
ctx.stack.pop();
|
||||||
|
post({ type: "open-settings", section: "Terminal" });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
if (window.kind === "hub") {
|
||||||
|
const phase = controlState?.phase;
|
||||||
|
if (phase === "connected" || phase === "attached") {
|
||||||
|
items.push({
|
||||||
|
label: "Disconnect",
|
||||||
|
onSelect: (ctx) => {
|
||||||
|
ctx.stack.pop();
|
||||||
|
stopControlClient();
|
||||||
|
renderHubWindows();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
items.push(
|
||||||
|
{
|
||||||
|
label: "Send <Enter>",
|
||||||
|
onSelect: (ctx) => {
|
||||||
|
ctx.stack.pop();
|
||||||
|
window.client.sendInput("\r");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Send <Esc>",
|
||||||
|
onSelect: (ctx) => {
|
||||||
|
ctx.stack.pop();
|
||||||
|
window.client.sendInput("\u001b");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
items.push(...defaultWindowMenuItems(window.windowId, post));
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
function handleInput(window: TerminalWindow, event: DashboardInputEvent, frameId: number): void {
|
function handleInput(window: TerminalWindow, event: DashboardInputEvent, frameId: number): void {
|
||||||
|
// An open window menu owns all input (it closes itself via pop).
|
||||||
|
if (window.menu?.isOpen()) {
|
||||||
|
window.menu
|
||||||
|
.handleInput(event)
|
||||||
|
.catch((error) => console.error(`terminal menu input failed: ${error}`))
|
||||||
|
.then(() => renderAndSubmit(window, frameId));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.type === "long-press") {
|
||||||
|
windowMenu(window).open(windowMenuItems(window));
|
||||||
|
renderAndSubmit(window, frameId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (event.type === "double-click") {
|
if (event.type === "double-click") {
|
||||||
frameTimings.finishFrame(frameId, "discarded: terminal yielded focus");
|
frameTimings.finishFrame(frameId, "discarded: terminal yielded focus");
|
||||||
post({ type: "yield-focus", windowId: window.windowId });
|
post({ type: "yield-focus", windowId: window.windowId });
|
||||||
@@ -493,6 +568,13 @@ function openViewWindowFor(session: G2MirrorSession): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function paint(window: TerminalWindow): GrayImage {
|
function paint(window: TerminalWindow): GrayImage {
|
||||||
|
if (window.menu?.isOpen()) {
|
||||||
|
return window.menu.paint();
|
||||||
|
}
|
||||||
|
return paintContent(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
function paintContent(window: TerminalWindow): GrayImage {
|
||||||
return window.kind === "hub" ? paintHub(window) : paintView(window);
|
return window.kind === "hub" ? paintHub(window) : paintView(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
scheduleTimerNotification,
|
scheduleTimerNotification,
|
||||||
} from "../native/timer-notifications";
|
} from "../native/timer-notifications";
|
||||||
import type { DashboardInputEvent } from "../ui/layers";
|
import type { DashboardInputEvent } from "../ui/layers";
|
||||||
|
import { defaultWindowMenuItems, 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 {
|
||||||
GESTURE_CLICK,
|
GESTURE_CLICK,
|
||||||
@@ -40,6 +41,10 @@ type TimerWindow = {
|
|||||||
viewportWidth: number;
|
viewportWidth: number;
|
||||||
viewportHeight: number;
|
viewportHeight: number;
|
||||||
foreground: boolean;
|
foreground: boolean;
|
||||||
|
/** Whether this window is the shell's input target (pushed with each message). */
|
||||||
|
focused: boolean;
|
||||||
|
/** Long-press window menu; created on first open. */
|
||||||
|
menu: WindowMenu | null;
|
||||||
view: TimerView;
|
view: TimerView;
|
||||||
stopwatchAction: number;
|
stopwatchAction: number;
|
||||||
timerSelection: number;
|
timerSelection: number;
|
||||||
@@ -81,6 +86,8 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
|||||||
viewportWidth: message.viewport.width,
|
viewportWidth: message.viewport.width,
|
||||||
viewportHeight: message.viewport.height,
|
viewportHeight: message.viewport.height,
|
||||||
foreground: false,
|
foreground: false,
|
||||||
|
focused: false,
|
||||||
|
menu: null,
|
||||||
view: "stopwatch",
|
view: "stopwatch",
|
||||||
stopwatchAction: 0,
|
stopwatchAction: 0,
|
||||||
timerSelection: 0,
|
timerSelection: 0,
|
||||||
@@ -106,18 +113,22 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
|||||||
frameTimings.finishFrame(message.frameId, "discarded: unknown timer window");
|
frameTimings.finishFrame(message.frameId, "discarded: unknown timer window");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
window.focused = message.focused;
|
||||||
handleInput(window, message.event as DashboardInputEvent, message.frameId);
|
handleInput(window, message.event as DashboardInputEvent, message.frameId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "render": {
|
case "render": {
|
||||||
const window = windows.get(message.windowId);
|
const window = windows.get(message.windowId);
|
||||||
if (window) renderAndSubmit(window, 0);
|
if (!window) break;
|
||||||
|
window.focused = message.focused;
|
||||||
|
renderAndSubmit(window, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "foreground": {
|
case "foreground": {
|
||||||
const window = windows.get(message.windowId);
|
const window = windows.get(message.windowId);
|
||||||
if (!window) break;
|
if (!window) break;
|
||||||
window.foreground = message.foreground;
|
window.foreground = message.foreground;
|
||||||
|
window.focused = message.focused;
|
||||||
updateRenderTimer(window);
|
updateRenderTimer(window);
|
||||||
if (window.foreground) renderAndSubmit(window, 0);
|
if (window.foreground) renderAndSubmit(window, 0);
|
||||||
break;
|
break;
|
||||||
@@ -129,7 +140,32 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** The window's long-press menu (default entries only), created lazily. */
|
||||||
|
function windowMenu(window: TimerWindow): WindowMenu {
|
||||||
|
if (!window.menu) {
|
||||||
|
window.menu = new WindowMenu({
|
||||||
|
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||||
|
paintBase: () => paintContent(window),
|
||||||
|
isFocused: () => window.focused,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return window.menu;
|
||||||
|
}
|
||||||
|
|
||||||
function handleInput(window: TimerWindow, event: DashboardInputEvent, frameId: number): void {
|
function handleInput(window: TimerWindow, event: DashboardInputEvent, frameId: number): void {
|
||||||
|
// An open window menu owns all input (it closes itself via pop).
|
||||||
|
if (window.menu?.isOpen()) {
|
||||||
|
window.menu
|
||||||
|
.handleInput(event)
|
||||||
|
.catch((error) => console.error(`timer menu input failed: ${error}`))
|
||||||
|
.then(() => renderAndSubmit(window, frameId));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.type === "long-press") {
|
||||||
|
windowMenu(window).open(defaultWindowMenuItems(window.windowId, post));
|
||||||
|
renderAndSubmit(window, frameId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (event.type === "double-click") {
|
if (event.type === "double-click") {
|
||||||
if (window.view === "editor") {
|
if (window.view === "editor") {
|
||||||
window.view = "timers";
|
window.view = "timers";
|
||||||
@@ -322,6 +358,13 @@ function updateRenderTimer(window: TimerWindow): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function paint(window: TimerWindow): GrayImage {
|
function paint(window: TimerWindow): GrayImage {
|
||||||
|
if (window.menu?.isOpen()) {
|
||||||
|
return window.menu.paint();
|
||||||
|
}
|
||||||
|
return paintContent(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
function paintContent(window: TimerWindow): GrayImage {
|
||||||
syncExpiredTimers();
|
syncExpiredTimers();
|
||||||
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
||||||
if (window.view === "stopwatch") {
|
if (window.view === "stopwatch") {
|
||||||
|
|||||||
Reference in new issue
Block a user