This commit is contained in:
James Babcock committed 2026-10-26 00:45:27 -07:00
commit bc57557f04
32 files changed
+652 -151

No files matched your search

+12 -1
View File
@@ -102,6 +102,15 @@ export interface Layer {
readonly depth?: number;
paintParts?(): Plane[];
readonly paintOverBase?: boolean;
/**
* True when this layer stands in for `below`, a stacked layer directly
* beneath it (or beneath another layer it stands in for): when this layer
* calls paintBelow, the stack skips `below` and paints what is under it
* instead. A submenu replacing the menu it opened from uses this, so the
* hidden menu costs no plane and its dimUnderneath doesn't dim the content
* a second time; popping the submenu still returns to it.
*/
replacesLayerBelow?(below: Layer): boolean;
/**
* Dim everything painted beneath this layer: a 0..1 brightness factor
* applied to the pixels and glyphs of every plane below it in the stack
@@ -326,7 +335,9 @@ export class LayerStack {
return [ownPlane];
}
const dim = layer.dimUnderneath || 1;
const below = this.paintLayer(layer.paintOverBase ? 0 : index - 1, dimSoFar * dim, raw);
let belowIndex = layer.paintOverBase ? 0 : index - 1;
while (belowIndex > 0 && layer.replacesLayerBelow?.(this.layers[belowIndex]!)) belowIndex--;
const below = this.paintLayer(belowIndex, dimSoFar * dim, raw);
return [...(!raw && dim < 1 ? dimPlanes(below, dim) : below), ownPlane];
}
}
+5 -4
View File
@@ -192,12 +192,13 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
drawIcon: options.drawIcon ?? windowIcon(options.icon, options.iconLetter),
handleInput: async (event, frameId) => {
// The shell opened its system menu over this window; close our own
// context menu so the two never stack. Never forwarded to app layers.
// context menu (and any window submenus open from it) so the two never
// stack. Never forwarded to app layers.
if (event.type === "system-menu-opened") {
options.onSystemMenuOpened?.();
if (stack.popIfTop((layer) => layer instanceof WindowMenuLayer)) {
requestRender();
}
let closedMenu = false;
while (stack.popIfTop((layer) => layer instanceof WindowMenuLayer)) closedMenu = true;
if (closedMenu) requestRender();
return;
}
// The default tap-then-hold response: the window menu (or the system
+88 -6
View File
@@ -8,6 +8,16 @@ import { type VoiceSendTarget } from "./voice-input";
/** A menu row: a send target, or Discard (no target). */
type KeyboardMenuRow = InputDialogRow & { target?: VoiceSendTarget };
/**
* Where the keyboard dialog shows: on both ends, only the phone's typing panel
* (the glasses carry on as if no dialog were open), or only the glasses (the
* phone hides its copy of the text but keeps the IME typing into it).
*/
export type KeyboardInputVisibility = "both" | "phone" | "glasses";
/** Sent messages kept for the phone's history button. */
const MAX_HISTORY = 20;
/**
* The phone side's handle on an open keyboard-input dialog: the phone types
* into it and picks where the text goes. The layer itself implements this;
@@ -25,6 +35,10 @@ export type KeyboardInputSession = {
send(): void;
sendTo(targetId: string): void;
discard(): void;
readonly visibility: KeyboardInputVisibility;
setVisibility(visibility: KeyboardInputVisibility): void;
/** Messages sent from keyboard dialogs since the app started, newest first. */
readonly history: ReadonlyArray<string>;
};
export type KeyboardInputLayerOptions = {
@@ -33,6 +47,16 @@ export type KeyboardInputLayerOptions = {
onClosed: () => void;
/** Pop this layer off the shell stack. */
dismiss: () => void;
/**
* Put the layer back on the shell stack, or take it off without ending the
* session (phone-only visibility; onRemoved is ignored while hiding).
*/
setShownOnGlasses: (shown: boolean) => void;
/** Starting visibility; the shell pushes the layer only if it isn't "phone". */
visibility: KeyboardInputVisibility;
onVisibilityChanged: (visibility: KeyboardInputVisibility) => void;
/** Shared, newest-first list this layer adds its sent message to. */
history: string[];
/** Ordered send destinations shown as the first menu rows. */
sendTargets: VoiceSendTarget[];
/** Which send target is highlighted by default (entry-point dependent). */
@@ -52,10 +76,16 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
private text = "";
private readonly menu: Menu<KeyboardMenuRow>;
private closed = false;
private currentVisibility: KeyboardInputVisibility;
// Set while the shell takes the layer off the stack for phone-only typing.
private hiding = false;
private readonly actions: LayerActions;
private readonly onClosed: () => void;
private readonly dismiss: () => void;
private readonly setShownOnGlasses: (shown: boolean) => void;
private readonly onVisibilityChanged: (visibility: KeyboardInputVisibility) => void;
private readonly sentHistory: string[];
private readonly sendTargets: VoiceSendTarget[];
private readonly defaultTargetIndex: number;
@@ -63,6 +93,10 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
this.actions = options.actions;
this.onClosed = options.onClosed;
this.dismiss = options.dismiss;
this.setShownOnGlasses = options.setShownOnGlasses;
this.currentVisibility = options.visibility;
this.onVisibilityChanged = options.onVisibilityChanged;
this.sentHistory = options.history;
this.sendTargets = options.sendTargets;
const defaultIndex = options.defaultTargetIndex ?? 0;
this.defaultTargetIndex = Math.min(Math.max(0, defaultIndex), Math.max(0, this.sendTargets.length - 1));
@@ -73,6 +107,33 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
return this.sendTargets.map((target) => ({ id: target.id, label: target.label }));
}
get visibility(): KeyboardInputVisibility {
return this.currentVisibility;
}
get history(): ReadonlyArray<string> {
return this.sentHistory;
}
/** Whether the dialog is on the glasses (the shell stack) rather than phone-only. */
get shownOnGlasses(): boolean {
return this.currentVisibility !== "phone";
}
setVisibility(visibility: KeyboardInputVisibility): void {
if (this.closed || visibility === this.currentVisibility) return;
const wasShown = this.shownOnGlasses;
this.currentVisibility = visibility;
this.onVisibilityChanged(visibility);
if (this.shownOnGlasses === wasShown) return;
this.hiding = !this.shownOnGlasses;
try {
this.setShownOnGlasses(this.shownOnGlasses);
} finally {
this.hiding = false;
}
}
setText(text: string): void {
if (this.closed || this.text === text) return;
this.text = text;
@@ -90,7 +151,23 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
}
discard(): void {
if (!this.closed) this.dismiss();
this.close();
}
private close(): void {
if (this.closed) return;
// Phone-only, there is no stack entry to pop; end the session directly.
if (this.shownOnGlasses) {
this.dismiss();
} else {
this.finish();
}
}
private finish(): void {
if (this.closed) return;
this.closed = true;
this.onClosed();
}
private sendToTarget(target: VoiceSendTarget): void {
@@ -99,7 +176,11 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
// An empty message has nothing to deliver; the dialog stays up for the
// phone to keep typing (the glasses row is drawn dim for the same reason).
if (!text) return;
this.dismiss();
const previous = this.sentHistory.indexOf(text);
if (previous >= 0) this.sentHistory.splice(previous, 1);
this.sentHistory.unshift(text);
this.sentHistory.length = Math.min(this.sentHistory.length, MAX_HISTORY);
this.close();
target.onSend(text);
}
@@ -140,12 +221,12 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
if (row.target) {
this.sendToTarget(row.target);
} else {
this.dismiss();
this.close();
}
return;
}
case "double-click":
this.dismiss();
this.close();
return;
default:
return;
@@ -153,7 +234,8 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
}
onRemoved(): void {
this.closed = true;
this.onClosed();
// Taken off the glasses for phone-only typing: the session carries on.
if (this.hiding) return;
this.finish();
}
}
+37 -7
View File
@@ -20,7 +20,7 @@ import {
import { Layer, LayerActions, LayerContext, LayerStack, noopLayerActions } from "../layers";
import { CONTEXT_MENU_DIM, MenuLayer, type MenuItem } from "../menu";
import { VoiceInputLayer, type VoiceSendTarget } from "./voice-input";
import { KeyboardInputLayer, type KeyboardInputSession } from "./keyboard-input";
import { KeyboardInputLayer, type KeyboardInputSession, type KeyboardInputVisibility } from "./keyboard-input";
import { voiceActivity } from "./voice-activity";
import { AssistantLayer } from "./assistant";
import { AssistantSession, type AssistantBackendConfig } from "../../assistant/session";
@@ -310,6 +310,9 @@ const noopActions: LayerActions = noopLayerActions;
*/
const LONG_PRESS_ESCAPE_MENU_MS = 4000;
/** Settings-store key for the keyboard dialog's last-chosen KeyboardInputVisibility. */
const KEYBOARD_INPUT_VISIBILITY_KEY = "keyboardInput.visibility";
/** Shell-surface overlay menu (the system menu); closing it returns focus to the sidebar. */
class ShellOverlayMenuLayer extends MenuLayer {
/**
@@ -455,6 +458,8 @@ class Shell {
private readonly trayIcons = new Map<string, { icon: GrayImage; widget?: TrayWidget }>();
private activeVoiceLayer: VoiceInputLayer | null = null;
private activeKeyboardLayer: KeyboardInputLayer | null = null;
// Messages sent from keyboard dialogs, newest first; in memory only.
private readonly keyboardInputHistory: string[] = [];
// App-posted notifications that are open or queued, by key.
private readonly appNotifications = new Map<string, AppNotification>();
private readonly notificationModals = new NotificationModalQueue<NotificationPopup>({
@@ -1194,7 +1199,7 @@ class Shell {
const foreground = this.foregroundWindow()?.windowId ?? "none";
if (!this.screenOn) return `fg=${foreground} target=screen-off`;
if (this.activeVoiceLayer) return `fg=${foreground} target=voice`;
if (this.activeKeyboardLayer) return `fg=${foreground} target=keyboard`;
if (this.activeKeyboardLayer?.shownOnGlasses) return `fg=${foreground} target=keyboard`;
if (!this.stack.isAtBase()) return `fg=${foreground} target=shell-overlay`;
return `fg=${foreground} target=${this.focus}`;
}
@@ -1583,12 +1588,16 @@ class Shell {
* continues that conversation; otherwise it goes to the usual destinations
* with Send to Assistant highlighted. Returns the session the phone types
* into (the already-open one if there is one), or null while a voice
* dialog is up.
* dialog is up. The phone can keep the dialog off the glasses (see
* KeyboardInputVisibility); that choice persists across dialogs.
*/
startKeyboardInput(): KeyboardInputSession | null {
if (this.activeKeyboardLayer) return this.activeKeyboardLayer;
if (this.activeVoiceLayer || this.foregroundWindow()?.isVoiceCapturing?.()) return null;
if (!this.screenOn) this.wake("sidebar");
const storedVisibility = getStringSetting(KEYBOARD_INPUT_VISIBILITY_KEY, "both");
const visibility: KeyboardInputVisibility =
storedVisibility === "phone" || storedVisibility === "glasses" ? storedVisibility : "both";
if (visibility !== "phone" && !this.screenOn) this.wake("sidebar");
const assistantLayer = this.assistantLayer;
const assistantSession = this.assistantSession;
let targets: VoiceSendTarget[];
@@ -1598,7 +1607,15 @@ class Shell {
{
id: "assistant",
label: "Send",
onSend: (text) => this.runAssistantTurn(assistantSession, assistantLayer, text),
// Phone-only, the overlay can close while the dialog is open; the
// text then starts a fresh overlay on the same conversation.
onSend: (text) => {
if (this.assistantLayer === assistantLayer) {
this.runAssistantTurn(assistantSession, assistantLayer, text);
} else {
this.sendToAssistant(text);
}
},
},
];
} else {
@@ -1616,16 +1633,29 @@ class Shell {
}
},
dismiss: () => {
this.stack.popIfTop((top) => top === layer);
// Wherever it sits: a menu opened over the dialog stays open.
this.stack.remove(layer);
// A send or discard from the phone side arrives outside the input
// path, so nothing else asks for the repaint.
this.config.requestShellRender();
},
setShownOnGlasses: (shown) => {
if (shown) {
if (!this.screenOn) this.wake("sidebar");
this.stack.push(layer);
} else {
this.stack.remove(layer);
}
this.config.requestShellRender();
},
visibility,
onVisibilityChanged: (value) => setStringSetting(KEYBOARD_INPUT_VISIBILITY_KEY, value),
history: this.keyboardInputHistory,
sendTargets: targets,
defaultTargetIndex: defaultIndex,
});
this.activeKeyboardLayer = layer;
this.stack.push(layer);
if (layer.shownOnGlasses) this.stack.push(layer);
this.config.onKeyboardInputChanged?.(layer);
this.config.requestShellRender();
return layer;
+10
View File
@@ -33,6 +33,16 @@ export class WindowMenuLayer extends MenuLayer {
? { ...WINDOW_MENU_LAYOUT, footer: gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "system menu"]]) }
: WINDOW_MENU_LAYOUT);
}
/**
* A window submenu (Settings, Spotify, ...) opens in place of the window
* menu it came from, which it would mostly cover anyway: the window content
* shows beneath it, dimmed once, rather than the parent menu dimming it a
* second time and costing a plane of its own.
*/
replacesLayerBelow(below: Layer): boolean {
return below instanceof WindowMenuLayer;
}
}
export type WindowMenuOptions = {