forked from Blendman974/faceclaw
Swap app and system context menu gestures
This commit is contained in:
1 parent
987f442897
commit
83c3732ba7
23 files changed
+213
-153
No files matched your search
@@ -6,7 +6,7 @@
|
||||
* Controls (in play): scroll moves the piece, click rotates, long-press hard
|
||||
* drops, double-click pauses. Watch swipes are spatial: left/right move,
|
||||
* up rotates, down hard-drops. Paused: click resumes, double-click yields
|
||||
* focus, long-press opens the window menu.
|
||||
* focus, tap-then-hold opens the window menu.
|
||||
*/
|
||||
import "@nativescript/core/globals";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
@@ -143,7 +143,7 @@ type BlocksWindow = {
|
||||
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. */
|
||||
/** Tap-then-hold window menu; created on first open. */
|
||||
menu: WindowMenu | null;
|
||||
phase: GamePhase;
|
||||
/** Locked cells; 0 = empty, otherwise the piece's shade byte. */
|
||||
@@ -288,7 +288,7 @@ function playSfx(window: BlocksWindow, steps: Step[]): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** The window's long-press menu (sound toggle); playing binds long-press to hard drop instead. */
|
||||
/** The window's context menu (sound toggle), offered while paused or over; playing keeps long-press for hard drop. */
|
||||
function windowMenuItems(window: BlocksWindow): MenuItem[] {
|
||||
return [
|
||||
{
|
||||
@@ -308,8 +308,8 @@ function windowMenu(window: BlocksWindow): WindowMenu {
|
||||
windowId: window.windowId,
|
||||
post,
|
||||
title: () => window.title,
|
||||
items: () => windowMenuItems(window),
|
||||
longPressOpensMenu: () => window.phase !== "playing",
|
||||
items: () => (window.phase === "playing" ? [] : windowMenuItems(window)),
|
||||
claimsLongPress: () => window.phase === "playing",
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
@@ -360,6 +360,10 @@ function handlePlayingInput(window: BlocksWindow, event: InputEvent, frameId: nu
|
||||
case "long-press":
|
||||
hardDrop(window);
|
||||
break;
|
||||
case "short-then-long-press":
|
||||
// No context menu mid-game, so this opens the system menu instead.
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
case "double-click":
|
||||
window.phase = "paused";
|
||||
updateTickTimer(window);
|
||||
@@ -385,7 +389,7 @@ function handleIdleInput(window: BlocksWindow, event: InputEvent, frameId: numbe
|
||||
frameTimings.finishFrame(frameId, "discarded: blocks yielded focus");
|
||||
post({ type: "yield-focus", windowId: window.windowId });
|
||||
return;
|
||||
case "long-press":
|
||||
case "short-then-long-press":
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Calculator window wiring: the in-process window, its long-press menu (mode
|
||||
* Calculator window wiring: the in-process window, its context menu (mode
|
||||
* follow-ups, clear, settings), the assistant tools, and the voice/text
|
||||
* plumbing into the layer.
|
||||
*
|
||||
|
||||
@@ -35,10 +35,11 @@ class EvenHubAppLayer implements Layer {
|
||||
}
|
||||
|
||||
handleInput(event: InputEvent): void {
|
||||
// Everything goes to the app; long-press never reaches here (the window
|
||||
// menu intercepts it), which is the guaranteed way out since EvenHub
|
||||
// apps own double-click. The press is still reported to the app as
|
||||
// LONG_PRESS_EVENT — see the handleInput wrapper below.
|
||||
// Everything goes to the app; the menu gestures never reach here (the
|
||||
// shell keeps long-press for its system menu and the window's context
|
||||
// menu intercepts tap-then-hold), which is the guaranteed way out since
|
||||
// EvenHub apps own double-click. Tap-then-hold is still reported to the
|
||||
// app as LONG_PRESS_EVENT — see the handleInput wrapper below.
|
||||
this.session.handleGesture(event);
|
||||
}
|
||||
}
|
||||
@@ -62,7 +63,7 @@ export function createEvenHubWindow(
|
||||
fallbackIcon,
|
||||
),
|
||||
heightMode: "medium",
|
||||
// The window's long-press menu doubles as the OS contextual menu EvenHub
|
||||
// The window's context menu doubles as the OS contextual menu EvenHub
|
||||
// apps register with `menuObject` (SDK 0.0.14): the app's own entries come
|
||||
// first, then the host entries. Evaluated at open time, so a rebuild that
|
||||
// changes or clears the menu is reflected on the next press.
|
||||
@@ -101,13 +102,15 @@ export function createEvenHubWindow(
|
||||
windowId,
|
||||
});
|
||||
|
||||
// LONG_PRESS_EVENT / LONG_PRESS_RELEASE_EVENT (SDK 0.0.14). Wrapped at the
|
||||
// window rather than handled in the base layer because the press opens the
|
||||
// window menu and so never reaches a layer, and because the release lands on
|
||||
// that menu once it is up.
|
||||
// LONG_PRESS_EVENT / LONG_PRESS_RELEASE_EVENT (SDK 0.0.14): the app hears
|
||||
// the context-menu gesture (tap-then-hold; a plain long-press is the
|
||||
// shell's and never arrives) as its long-press. Wrapped at the window
|
||||
// rather than handled in the base layer because the press opens the window
|
||||
// menu and so never reaches a layer, and because the release lands on that
|
||||
// menu once it is up.
|
||||
const baseHandleInput = created.window.handleInput;
|
||||
created.window.handleInput = async (event, frameId) => {
|
||||
if (event.type === "long-press" || event.type === "long-press-release") {
|
||||
if (event.type === "short-then-long-press" || event.type === "long-press-release") {
|
||||
session.handleGesture(event);
|
||||
}
|
||||
await baseHandleInput(event, frameId);
|
||||
|
||||
@@ -447,13 +447,16 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
|
||||
this.emitSysEvent(DOUBLE_CLICK_EVENT, gestureSource(event.source));
|
||||
break;
|
||||
case "long-press":
|
||||
case "short-then-long-press":
|
||||
case "long-press-release": {
|
||||
// SDK 0.0.14 exposes press and release as ordinary events. The window
|
||||
// still opens its menu on the same gesture (that menu is where the
|
||||
// app's contextual-menu items live, and it is the way out of an app
|
||||
// that owns double-click), so an app hears the press as well as
|
||||
// seeing the menu — it cannot be given exclusive use of the gesture.
|
||||
const eventType = event.type === "long-press" ? LONG_PRESS_EVENT : LONG_PRESS_RELEASE_EVENT;
|
||||
// SDK 0.0.14 exposes press and release as ordinary events. The app's
|
||||
// press is the context-menu gesture (tap-then-hold; the shell keeps
|
||||
// the plain long-press for its system menu): the window still opens
|
||||
// its menu on it (that menu is where the app's contextual-menu items
|
||||
// live, and it is the way out of an app that owns double-click), so
|
||||
// an app hears the press as well as seeing the menu — it cannot be
|
||||
// given exclusive use of the gesture.
|
||||
const eventType = event.type === "long-press-release" ? LONG_PRESS_RELEASE_EVENT : LONG_PRESS_EVENT;
|
||||
if (capture?.kind === "list") {
|
||||
this.emitListEvent(capture, eventType);
|
||||
} else {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* on a destination moves there; cascade-to-cascade moves take the longest
|
||||
* legal run that fits (supermoves via empty cells/columns). Double-click
|
||||
* sends the card at the cursor to its foundation, or cancels a pending
|
||||
* selection. Long-press opens the window menu (undo, new game, restart).
|
||||
* selection. Tap-then-hold opens the window menu (undo, new game, restart).
|
||||
* Watch swipes move the cursor spatially: left/right within the row, up/down
|
||||
* between the top row (cells + foundations) and the cascades.
|
||||
* Safe cards auto-play to the foundations after every move.
|
||||
@@ -106,7 +106,7 @@ type FreecellWindow = {
|
||||
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. */
|
||||
/** Tap-then-hold window menu; created on first open. */
|
||||
menu: WindowMenu | null;
|
||||
phase: "playing" | "won";
|
||||
cascades: number[][];
|
||||
@@ -214,7 +214,7 @@ function playSfx(window: FreecellWindow, steps: Step[]): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** The window's long-press menu (game actions). */
|
||||
/** The window's context menu (game actions). */
|
||||
function windowMenuItems(window: FreecellWindow): MenuItem[] {
|
||||
const items: MenuItem[] = [];
|
||||
if (window.undoStack.length > 0 && window.phase === "playing") {
|
||||
@@ -332,7 +332,7 @@ function handlePlayingInput(window: FreecellWindow, event: InputEvent, frameId:
|
||||
sendToFoundation(window, window.cursor);
|
||||
}
|
||||
break;
|
||||
case "long-press":
|
||||
case "short-then-long-press":
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
default:
|
||||
@@ -352,7 +352,7 @@ function handleWonInput(window: FreecellWindow, event: InputEvent, frameId: numb
|
||||
frameTimings.finishFrame(frameId, "discarded: freecell yielded focus");
|
||||
post({ type: "yield-focus", windowId: window.windowId });
|
||||
return;
|
||||
case "long-press":
|
||||
case "short-then-long-press":
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -169,7 +169,7 @@ class LauncherGridLayer implements Layer {
|
||||
}
|
||||
|
||||
/**
|
||||
* App-specific entries for the window's long-press menu. Only item mode
|
||||
* App-specific entries for the window's context menu. Only item mode
|
||||
* pins the selection to a single cell, and only apps can move to folders,
|
||||
* so anywhere else the menu falls back to just the defaults.
|
||||
*/
|
||||
|
||||
@@ -101,7 +101,7 @@ type MinesweeperWindow = {
|
||||
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. */
|
||||
/** Tap-then-hold window menu; created on first open. */
|
||||
menu: WindowMenu | null;
|
||||
phase: GamePhase;
|
||||
difficultyIndex: number;
|
||||
@@ -252,7 +252,7 @@ function playSfx(window: MinesweeperWindow, steps: Step[]): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** The window's long-press menu (game actions); playing binds long-press to flagging instead. */
|
||||
/** The window's context menu (game actions), offered while paused or over; playing keeps long-press for flagging. */
|
||||
function windowMenuItems(window: MinesweeperWindow): MenuItem[] {
|
||||
const nextDifficulty = DIFFICULTIES[(window.difficultyIndex + 1) % DIFFICULTIES.length]!;
|
||||
return [
|
||||
@@ -290,8 +290,8 @@ function windowMenu(window: MinesweeperWindow): WindowMenu {
|
||||
windowId: window.windowId,
|
||||
post,
|
||||
title: () => window.title,
|
||||
items: () => windowMenuItems(window),
|
||||
longPressOpensMenu: () => window.phase !== "playing",
|
||||
items: () => (window.phase === "playing" ? [] : windowMenuItems(window)),
|
||||
claimsLongPress: () => window.phase === "playing",
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
@@ -366,6 +366,10 @@ function handlePlayingInput(window: MinesweeperWindow, event: InputEvent, frameI
|
||||
}
|
||||
toggleFlag(window);
|
||||
break;
|
||||
case "short-then-long-press":
|
||||
// No context menu mid-game, so this opens the system menu instead.
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
case "double-click":
|
||||
if (rowMode || watch) {
|
||||
window.phase = "paused";
|
||||
@@ -398,7 +402,7 @@ function handleIdleInput(window: MinesweeperWindow, event: InputEvent, frameId:
|
||||
frameTimings.finishFrame(frameId, "discarded: minesweeper yielded focus");
|
||||
post({ type: "yield-focus", windowId: window.windowId });
|
||||
return;
|
||||
case "long-press":
|
||||
case "short-then-long-press":
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -612,7 +612,7 @@ function describeRouteStatus(): string {
|
||||
// ---------------------------------------------------------------------------
|
||||
// Input
|
||||
|
||||
/** The window's long-press menu: only Stop navigation, and only while a route is up. */
|
||||
/** The window's context menu: only Stop navigation, and only while a route is up. */
|
||||
function windowMenuItems(win: NavWindow): MenuItem[] {
|
||||
if (phase !== "navigating" && phase !== "arrived") return [];
|
||||
return [
|
||||
@@ -650,7 +650,7 @@ function handleInput(win: NavWindow, event: InputEvent, frameId: number): void {
|
||||
.then(() => renderAndSubmit(win, frameId));
|
||||
return;
|
||||
}
|
||||
if (event.type === "long-press") {
|
||||
if (event.type === "short-then-long-press") {
|
||||
windowMenu(win).open();
|
||||
renderAndSubmit(win, frameId);
|
||||
return;
|
||||
@@ -708,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 pick Voice input from the system menu (tap, then hold) to say a destination."
|
||||
? "Ask the voice assistant to navigate somewhere, or pick Voice input from the system menu (long-press) 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) {
|
||||
|
||||
@@ -249,7 +249,7 @@ type PinballWindow = {
|
||||
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. */
|
||||
/** Tap-then-hold window menu; created on first open. */
|
||||
menu: WindowMenu | null;
|
||||
phase: GamePhase;
|
||||
/** "ready" = parked on the plunger awaiting launch; "live" = in play. */
|
||||
@@ -446,7 +446,7 @@ function playSfx(window: PinballWindow, steps: Step[], minor = false): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** The window's long-press menu (game actions); playing binds long-press to the nudge instead. */
|
||||
/** The window's context menu (game actions), offered while paused or over; playing keeps long-press for the nudge. */
|
||||
function windowMenuItems(window: PinballWindow): MenuItem[] {
|
||||
return [
|
||||
{
|
||||
@@ -474,8 +474,8 @@ function windowMenu(window: PinballWindow): WindowMenu {
|
||||
windowId: window.windowId,
|
||||
post,
|
||||
title: () => window.title,
|
||||
items: () => windowMenuItems(window),
|
||||
longPressOpensMenu: () => window.phase !== "playing",
|
||||
items: () => (window.phase === "playing" ? [] : windowMenuItems(window)),
|
||||
claimsLongPress: () => window.phase === "playing",
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
@@ -554,6 +554,10 @@ function handlePlayingInput(window: PinballWindow, event: InputEvent, frameId: n
|
||||
}
|
||||
nudge(window);
|
||||
break;
|
||||
case "short-then-long-press":
|
||||
// No context menu mid-game, so this opens the system menu instead.
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
case "double-click":
|
||||
window.phase = "paused";
|
||||
syncTickTimer(window);
|
||||
@@ -580,7 +584,7 @@ function handleIdleInput(window: PinballWindow, event: InputEvent, frameId: numb
|
||||
frameTimings.finishFrame(frameId, "discarded: pinball yielded focus");
|
||||
post({ type: "yield-focus", windowId: window.windowId });
|
||||
return;
|
||||
case "long-press":
|
||||
case "short-then-long-press":
|
||||
windowMenu(window).open();
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -104,7 +104,7 @@ async function roamPost(endpoint: "q" | "pull" | "write", body: object): Promise
|
||||
const graph = roamGraphNameSetting.get();
|
||||
const token = roamApiTokenSetting.get();
|
||||
if (!graph || !token) {
|
||||
throw new Error("Set the Roam graph name and API token from the Roam app's long-press menu.");
|
||||
throw new Error("Set the Roam graph name and API token from the Roam app's context menu (tap, then hold).");
|
||||
}
|
||||
const path = `/api/graph/${encodeURIComponent(graph)}/${endpoint}`;
|
||||
const payload = JSON.stringify(body);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* todo or follows a [[page]] link, double-click walks back through visited
|
||||
* pages then yields focus. Edits (check/uncheck, add todo, edit block) go
|
||||
* through the Roam backend API and are also exposed as assistant tools.
|
||||
* The graph name and API token are configured here too, from the long-press
|
||||
* The graph name and API token are configured here too, from the context
|
||||
* menu, via the phone app's text editor.
|
||||
*/
|
||||
import "@nativescript/core/globals";
|
||||
@@ -423,7 +423,7 @@ function handleInput(win: RoamWindow, event: InputEvent, frameId: number): void
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.type === "long-press") {
|
||||
if (event.type === "short-then-long-press") {
|
||||
windowMenu(win).open();
|
||||
renderAndSubmit(win, frameId);
|
||||
return;
|
||||
@@ -525,7 +525,7 @@ async function addTodoFromText(text: string): Promise<void> {
|
||||
|
||||
async function handleRoamTool(name: string, args: any): Promise<ToolResult> {
|
||||
if (!isRoamConfigured()) {
|
||||
return { ok: false, error: "Roam is not configured; set the graph name and API token from the Roam app's long-press menu." };
|
||||
return { ok: false, error: "Roam is not configured; set the graph name and API token from the Roam app's context menu (tap, then hold)." };
|
||||
}
|
||||
switch (name) {
|
||||
case "read_page": {
|
||||
@@ -634,7 +634,7 @@ function paintContent(win: RoamWindow): GrayImage {
|
||||
image.drawLine(DOC_MARGIN, HEADER_HEIGHT - 4, win.viewportWidth - DOC_MARGIN, HEADER_HEIGHT - 4, 40);
|
||||
|
||||
if (!isRoamConfigured()) {
|
||||
drawBodyMessage(image, win, "Set the Roam graph name and API token: long-press for the menu, then pick Set graph name and Set API token.");
|
||||
drawBodyMessage(image, win, "Set the Roam graph name and API token: tap, then hold, for the menu; pick Set graph name and Set API token.");
|
||||
} else if (errorMessage) {
|
||||
drawBodyMessage(image, win, `${errorMessage}\n\n${GESTURE_CLICK} retry`);
|
||||
} else if (currentPage && currentPage.children.length === 0 && !loading) {
|
||||
|
||||
@@ -901,7 +901,7 @@ function reconnectView(window: ViewWindow): void {
|
||||
scheduleRender(window);
|
||||
}
|
||||
|
||||
/** The window's long-press menu, created lazily so window literals stay simple. */
|
||||
/** The window's context menu, created lazily so window literals stay simple. */
|
||||
function windowMenu(window: TerminalWindow): WindowMenu {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
@@ -1000,7 +1000,7 @@ function handleInput(window: TerminalWindow, event: InputEvent, frameId: number)
|
||||
.then(() => renderAndSubmit(window, frameId));
|
||||
return;
|
||||
}
|
||||
if (event.type === "long-press") {
|
||||
if (event.type === "short-then-long-press") {
|
||||
windowMenu(window).open();
|
||||
renderAndSubmit(window, frameId);
|
||||
return;
|
||||
|
||||
@@ -48,7 +48,7 @@ type TimerWindow = {
|
||||
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. */
|
||||
/** Tap-then-hold window menu; created on first open. */
|
||||
menu: WindowMenu | null;
|
||||
view: TimerView;
|
||||
stopwatchAction: number;
|
||||
@@ -295,8 +295,8 @@ function refreshWindowsAfterToolChange(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* The window's context menu, created lazily. The timer has no entries of
|
||||
* its own, so tap-then-hold opens the shell's system menu in its place.
|
||||
*/
|
||||
function windowMenu(window: TimerWindow): WindowMenu {
|
||||
if (!window.menu) {
|
||||
@@ -322,7 +322,7 @@ function handleInput(window: TimerWindow, event: InputEvent, frameId: number): v
|
||||
.then(() => renderAndSubmit(window, frameId));
|
||||
return;
|
||||
}
|
||||
if (event.type === "long-press") {
|
||||
if (event.type === "short-then-long-press") {
|
||||
windowMenu(window).open();
|
||||
renderAndSubmit(window, frameId);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user