Migrate things into new UI design

This commit is contained in:
James Babcock committed 2026-07-07 00:52:47 -07:00
1 parent 1133f952e9
commit 68ab599856
21 files changed
+1262 -602

No files matched your search

+4 -1
View File
@@ -11,6 +11,8 @@ const ICON_MARGIN_X = ((SIDEBAR_WIDTH - ICON_SIZE) / 2) | 0;
const ICON_SPACING = 8;
const NOTIFICATION_ICON_SIZE = 24;
const BORDER_VALUE = 40;
const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
export type ShellChromeWindow = {
windowId: string;
@@ -82,7 +84,8 @@ export class ShellChromeLayer implements Layer {
image.drawLine(SIDEBAR_WIDTH, TOP_BAR_HEIGHT - 1, G2_LENS_WIDTH - 1, TOP_BAR_HEIGHT - 1, BORDER_VALUE);
const now = new Date();
const clock = `${now.getHours()}:${String(now.getMinutes()).padStart(2, "0")}`;
const clock = `${WEEKDAYS[now.getDay()]} ${now.getDate()} ${MONTHS[now.getMonth()]} ` +
`${now.getHours()}:${String(now.getMinutes()).padStart(2, "0")}`;
const clockX = SIDEBAR_WIDTH + 10;
const textY = Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0);
image.drawText(font, clockX, textY, clock, 210);
+117
View File
@@ -0,0 +1,117 @@
import { GrayImage } from "../../graphics/image";
import { beginRenderPass, endRenderPass } from "../../util/render-freshness";
import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, PaintBelow } from "../layers";
import { makeLetterWindowIcon } from "./chrome-layer";
import { APP_VIEWPORT } from "./geometry";
import { shell, type ShellWindow } from "./shell";
/**
* A window whose app logic runs on the main thread (launcher, settings):
* hosts a viewport-sized LayerStack, renders it on input or request, and
* submits frames through a controller-provided submitter. Java-side dedup
* finishes no-change frames, so unconditional resubmits keep frame ownership
* simple.
*/
export type InProcessWindowOptions = {
appId: string;
windowId: string;
title: string;
iconLetter: string;
closeable: boolean;
/** Shared actions; requestRender is rebound to this window's render. */
actions: LayerActions;
baseLayer: Layer;
submitFrame: (image: GrayImage, paintMs: number, frameId: number) => Promise<void>;
setSurfaceVisible: (visible: boolean) => void;
removeSurface?: () => void;
onClosed?: () => void;
};
export type InProcessWindow = {
window: ShellWindow;
stack: LayerStack;
requestRender: () => void;
};
export function createInProcessWindow(options: InProcessWindowOptions): InProcessWindow {
const requestRender = () => {
void render(0).catch((error) => {
console.error(`${options.windowId} render failed: ${error}`);
});
};
const stack = new LayerStack(
options.baseLayer,
{ ...options.actions, requestRender },
{ width: APP_VIEWPORT.width, height: APP_VIEWPORT.height },
);
// Data sources with caches (e.g. notification icons) may serve stale data
// to keep the paint fast; when they do, schedule one follow-up render that
// requires fresh data (same contract as the dashboard render loop).
let nextRenderWantsFreshData = false;
async function render(frameId: number): Promise<void> {
const wantFreshData = nextRenderWantsFreshData;
nextRenderWantsFreshData = false;
beginRenderPass(!wantFreshData);
const paintStartedAtMs = Date.now();
const image = stack.paint();
const paintUsedStaleData = endRenderPass();
await options.submitFrame(image, Date.now() - paintStartedAtMs, frameId);
if (paintUsedStaleData) {
nextRenderWantsFreshData = true;
requestRender();
}
}
const window: ShellWindow = {
appId: options.appId,
windowId: options.windowId,
title: options.title,
surfaceId: `window:${options.windowId}`,
closeable: options.closeable,
close: () => {
options.onClosed?.();
options.removeSurface?.();
},
drawIcon: makeLetterWindowIcon(options.iconLetter),
handleInput: async (event, frameId) => {
await stack.handleInput(event);
await render(frameId);
},
requestRender,
setForeground: (foreground) => {
options.setSurfaceVisible(foreground);
},
};
return { window, stack, requestRender };
}
/**
* Wrap an app's root layer so double-click at the root yields focus to the
* shell sidebar (the standard leave-the-app gesture) instead of being
* swallowed by the layer's own back handling.
*/
export class YieldAtRootLayer implements Layer {
constructor(private readonly inner: Layer) {}
get paintOverBase(): boolean | undefined {
return this.inner.paintOverBase;
}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
return this.inner.paint(ctx, paintBelow);
}
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
if (event.type === "double-click") {
shell.yieldFocusToSidebar();
return;
}
await this.inner.handleInput(event, ctx);
}
onRemoved(): void {
this.inner.onRemoved?.();
}
}
+11 -44
View File
@@ -1,9 +1,9 @@
import { GrayImage } from "../../graphics/image";
import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack } from "../layers";
import { LayerActions } from "../layers";
import { MenuLayer } from "../menu";
import { makeLetterWindowIcon } from "./chrome-layer";
import { APP_VIEWPORT } from "./geometry";
import { shell, type ShellWindow } from "./shell";
import { createInProcessWindow, YieldAtRootLayer } from "./in-process-window";
import { type ShellWindow } from "./shell";
export type LauncherAppEntry = {
appId: string;
@@ -23,24 +23,13 @@ export type LauncherOptions = {
export const LAUNCHER_WINDOW_ID = "launcher";
export const LAUNCHER_SURFACE_ID = "window:launcher";
/** The launcher's root menu; backing out of it yields to the sidebar. */
class LauncherMenuLayer extends MenuLayer {
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
if (event.type === "double-click") {
shell.yieldFocusToSidebar();
return;
}
await super.handleInput(event, ctx);
}
}
/**
* The launcher: a pinned, uncloseable in-process window listing launchable
* apps. Selecting an app asks the controller to launch it (new window,
* possibly in an existing app worker) and foregrounds the new window.
*/
export function createLauncherWindow(options: LauncherOptions): ShellWindow {
const baseLayer: Layer = new LauncherMenuLayer(
const menu = new MenuLayer(
"Apps",
options.apps.map((app) => ({
label: app.label,
@@ -56,37 +45,15 @@ export function createLauncherWindow(options: LauncherOptions): ShellWindow {
maxHeight: APP_VIEWPORT.height - 16,
},
);
const stack = new LayerStack(baseLayer, options.actions, {
width: APP_VIEWPORT.width,
height: APP_VIEWPORT.height,
});
async function render(frameId: number): Promise<void> {
const paintStartedAtMs = Date.now();
const image = stack.paint();
await options.submitFrame(image, Date.now() - paintStartedAtMs, frameId);
}
return {
return createInProcessWindow({
appId: "launcher",
windowId: LAUNCHER_WINDOW_ID,
title: "Apps",
surfaceId: LAUNCHER_SURFACE_ID,
iconLetter: "A",
closeable: false,
drawIcon: makeLetterWindowIcon("A"),
handleInput: async (event, frameId) => {
await stack.handleInput(event);
// Java-side dedup finishes no-change frames, so an unconditional
// resubmit keeps frame ownership simple.
await render(frameId);
},
requestRender: () => {
void render(0).catch((error) => {
console.error(`launcher render failed: ${error}`);
});
},
setForeground: (foreground) => {
options.setSurfaceVisible(foreground);
},
};
actions: options.actions,
baseLayer: new YieldAtRootLayer(menu),
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
}).window;
}
+49
View File
@@ -0,0 +1,49 @@
import { GrayImage } from "../../graphics/image";
import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, PaintBelow } from "../layers";
import { APP_VIEWPORT, SHELL_OPAQUE_BLACK } from "./geometry";
// The modal covers most of the app viewport, leaving a little of the
// foreground app visible around the edges.
const MODAL_MARGIN = 14;
const MODAL_PADDING = 4;
export const MODAL_RECT = {
x: APP_VIEWPORT.x + MODAL_MARGIN,
y: APP_VIEWPORT.y + MODAL_MARGIN,
width: APP_VIEWPORT.width - 2 * MODAL_MARGIN,
height: APP_VIEWPORT.height - 2 * MODAL_MARGIN,
} as const;
export const MODAL_INTERIOR = {
width: MODAL_RECT.width - 2 * MODAL_PADDING,
height: MODAL_RECT.height - 2 * MODAL_PADDING,
} as const;
/**
* A shell overlay hosting an inner layer stack in a bordered box over the
* app viewport (used for new-notification popups). The inner stack paints at
* the modal's interior size; its pixels blit onto an opaque black backdrop,
* so inner value-0 pixels read as black, not transparent.
*/
export class ShellModalLayer implements Layer {
private readonly stack: LayerStack;
constructor(baseLayer: Layer, actions: LayerActions) {
this.stack = new LayerStack(baseLayer, actions, {
width: MODAL_INTERIOR.width,
height: MODAL_INTERIOR.height,
});
}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
const image = paintBelow();
const inner = this.stack.paint();
image.fillRoundedRect(MODAL_RECT.x, MODAL_RECT.y, MODAL_RECT.width, MODAL_RECT.height, SHELL_OPAQUE_BLACK, 8);
image.drawRoundedRect(MODAL_RECT.x, MODAL_RECT.y, MODAL_RECT.width, MODAL_RECT.height, 110, 8);
image.bitBlt(inner, MODAL_RECT.x + MODAL_PADDING, MODAL_RECT.y + MODAL_PADDING, { transparentZero: true });
return image;
}
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
await this.stack.handleInput(event);
}
}
+36
View File
@@ -0,0 +1,36 @@
import { GrayImage } from "../../graphics/image";
import { LayerActions } from "../layers";
import { NotificationsListLayer } from "../notifications";
import { createInProcessWindow, YieldAtRootLayer, type InProcessWindow } from "./in-process-window";
export const NOTIFICATIONS_WINDOW_ID = "notifications";
export const NOTIFICATIONS_SURFACE_ID = "window:notifications";
export type NotificationsAppOptions = {
actions: LayerActions;
submitFrame: (image: GrayImage, paintMs: number, frameId: number) => Promise<void>;
setSurfaceVisible: (visible: boolean) => void;
removeSurface: () => void;
onClosed: () => void;
};
/**
* The Notifications app: the Android-notification list (previously a
* dashboard page) in its own in-process window; selecting a notification
* opens the detail view with its quick actions.
*/
export function createNotificationsAppWindow(options: NotificationsAppOptions): InProcessWindow {
return createInProcessWindow({
appId: "notifications",
windowId: NOTIFICATIONS_WINDOW_ID,
title: "Notifications",
iconLetter: "N",
closeable: true,
actions: options.actions,
baseLayer: new YieldAtRootLayer(new NotificationsListLayer()),
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface,
onClosed: options.onClosed,
});
}
+54
View File
@@ -0,0 +1,54 @@
import { GrayImage } from "../../graphics/image";
import { LayerActions } from "../layers";
import { EditTextSettingLayer } from "../dashboard-settings";
import { createSettingsMenuLayer } from "../dashboard/settings-menus";
import { createInProcessWindow, YieldAtRootLayer } from "./in-process-window";
import { type ShellWindow } from "./shell";
export const SETTINGS_WINDOW_ID = "settings";
export const SETTINGS_SURFACE_ID = "window:settings";
export type SettingsAppOptions = {
actions: LayerActions;
submitFrame: (image: GrayImage, paintMs: number, frameId: number) => Promise<void>;
setSurfaceVisible: (visible: boolean) => void;
removeSurface: () => void;
onClosed: () => void;
};
export type SettingsAppWindow = {
window: ShellWindow;
requestRender: () => void;
/** Whether the glasses-side text-setting editor is the top layer. */
isTextEditorOnTop: () => boolean;
/** Pop the text-setting editor if it is on top; returns whether it was. */
closeTextEditor: () => boolean;
};
/**
* The Settings app: the settings menu tree (previously a dashboard submenu)
* hosted in its own in-process window. In-process because the text-setting
* editor is synchronized with the phone-side TextField through the
* controller, which lives on the main thread.
*/
export function createSettingsAppWindow(options: SettingsAppOptions): SettingsAppWindow {
const { window, stack, requestRender } = createInProcessWindow({
appId: "settings",
windowId: SETTINGS_WINDOW_ID,
title: "Settings",
iconLetter: "Se",
closeable: true,
actions: options.actions,
baseLayer: new YieldAtRootLayer(createSettingsMenuLayer()),
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface,
onClosed: options.onClosed,
});
return {
window,
requestRender,
isTextEditorOnTop: () => stack.topMatches((layer) => layer instanceof EditTextSettingLayer),
closeTextEditor: () => stack.popIfTop((layer) => layer instanceof EditTextSettingLayer),
};
}
+28
View File
@@ -4,7 +4,9 @@ import type { RawInputEvent } from "../../native/faceclaw-communicator";
import { DashboardInputEvent, LayerActions, LayerStack } from "../layers";
import { MenuLayer, type MenuItem } from "../menu";
import { VoiceInputLayer } from "../apps/voice-input";
import { SingleNotificationLayer } from "../notifications";
import { ShellChromeLayer, type ShellChromeState, type ShellChromeWindow } from "./chrome-layer";
import { ShellModalLayer } from "./modal-layer";
import { SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry";
/**
@@ -223,6 +225,32 @@ class Shell {
return true;
}
/**
* Show a new notification in a shell modal over the app viewport. If the
* notification woke the screen, closing the modal goes back to sleep
* (matching the old sleep-popup behavior).
*/
openNotificationModal(notificationKey: string, wokeScreen: boolean): void {
if (!this.screenOn) return;
const modal: ShellModalLayer = new ShellModalLayer(
new SingleNotificationLayer(notificationKey, {
origin: "new-notification-modal",
closeModal: () => this.closeNotificationModal(modal, wokeScreen),
}),
this.config.actions,
);
this.stack.push(modal);
this.config.requestShellRender();
}
private closeNotificationModal(modal: ShellModalLayer, wokeScreen: boolean): void {
this.stack.popIfTop((layer) => layer === modal);
if (wokeScreen) {
this.sleep();
}
this.config.requestShellRender();
}
/** Called by a window when the user backs out of its root (double-tap). */
yieldFocusToSidebar(): void {
if (this.focus === "sidebar") return;
+95 -42
View File
@@ -15,45 +15,78 @@ export type WorkerAppMessage =
| { type: "foreground"; windowId: string; foreground: boolean }
| { type: "screen"; on: boolean };
export type WorkerAppReply = { type: "yield-focus"; windowId: string };
export type WorkerAppReply =
| { type: "yield-focus"; windowId: string }
| {
/** App-initiated window (e.g. a terminal view opened from the hub list). */
type: "open-window-request";
windowId: string;
title: string;
iconLetter: string;
focus?: boolean;
}
| { type: "set-title"; windowId: string; title: string }
| { type: "set-attention"; windowId: string; attention: boolean };
export type WorkerWindowOptions = {
export type WorkerWindowSpec = {
/** Unique across the shell; namespace with the appId (e.g. "terminal:view:3"). */
windowId: string;
title: string;
iconLetter: string;
surfaceId: string;
/** Foreground and focus the window once its surface exists. */
focus?: boolean;
};
export type WorkerAppHostOptions = {
appId: string;
worker: Worker;
viewport: { width: number; height: number };
/** Flip the window's compositor surface visibility. */
setSurfaceVisible: (visible: boolean) => void;
/** Remove the window's compositor surface (on close). */
removeSurface: () => void;
/** Create/refresh a window surface on the compositor (no-op when disconnected). */
configureSurface: (surfaceId: string, visible: boolean) => Promise<void>;
setSurfaceVisible: (surfaceId: string, visible: boolean) => void;
removeSurface: (surfaceId: string) => void;
requestShellRender: () => void;
};
/**
* Owns the Worker for one app and adapts its windows to the shell's window
* interface: forwards input and lifecycle over postMessage, relays
* yield-focus back to the shell, and tells the worker when windows open and
* close. The worker submits frames straight to the Java compositor, so no
* pixels cross this boundary.
* interface: forwards input and lifecycle over postMessage, relays worker
* requests (yield-focus, new windows, attention flags) back to the shell,
* and manages compositor surfaces for the app's windows. The worker submits
* frames straight to the Java compositor, so no pixels cross this boundary.
*/
export class WorkerAppHost {
private readonly openWindows = new Set<string>();
constructor(
private readonly appId: string,
private readonly worker: Worker,
) {
worker.onmessage = (event: MessageEvent) => {
constructor(private readonly options: WorkerAppHostOptions) {
options.worker.onmessage = (event: MessageEvent) => {
const message = event.data as WorkerAppReply | undefined;
if (message?.type === "yield-focus") {
// Only the focused window's yield is meaningful.
if (shell.foregroundWindow()?.windowId === message.windowId) {
shell.yieldFocusToSidebar();
}
if (!message) return;
switch (message.type) {
case "yield-focus":
// Only the focused window's yield is meaningful.
if (shell.foregroundWindow()?.windowId === message.windowId) {
shell.yieldFocusToSidebar();
}
break;
case "open-window-request":
this.openWindow({
windowId: message.windowId,
title: message.title,
iconLetter: message.iconLetter,
focus: message.focus,
});
break;
case "set-attention":
shell.setWindowAttention(message.windowId, message.attention);
break;
case "set-title":
// Titles are informational for now (sidebar shows icons only).
break;
}
};
worker.onerror = (error) => {
console.error(`worker app ${appId} error: ${JSON.stringify(error)}`);
options.worker.onerror = (error) => {
console.error(`worker app ${options.appId} error: ${JSON.stringify(error)}`);
};
}
@@ -61,35 +94,40 @@ export class WorkerAppHost {
return this.openWindows.size;
}
openWindow(options: WorkerWindowOptions): ShellWindow {
this.openWindows.add(options.windowId);
/** Open a window of this app and register it with the shell. */
openWindow(spec: WorkerWindowSpec): ShellWindow {
const surfaceId = `window:${spec.windowId}`;
this.openWindows.add(spec.windowId);
this.post({
type: "open-window",
windowId: options.windowId,
surfaceId: options.surfaceId,
viewport: options.viewport,
windowId: spec.windowId,
surfaceId,
viewport: this.options.viewport,
});
return {
appId: this.appId,
windowId: options.windowId,
title: options.title,
surfaceId: options.surfaceId,
const window: ShellWindow = {
appId: this.options.appId,
windowId: spec.windowId,
title: spec.title,
surfaceId,
closeable: true,
close: () => {
this.openWindows.delete(options.windowId);
this.post({ type: "close-window", windowId: options.windowId });
options.removeSurface();
this.openWindows.delete(spec.windowId);
this.post({ type: "close-window", windowId: spec.windowId });
this.options.removeSurface(surfaceId);
},
drawIcon: makeLetterWindowIcon(options.iconLetter),
drawIcon: makeLetterWindowIcon(spec.iconLetter),
handleInput: (event, frameId) => {
this.post({ type: "input", windowId: options.windowId, event, frameId });
this.post({ type: "input", windowId: spec.windowId, event, frameId });
},
requestRender: () => {
this.post({ type: "render", windowId: options.windowId });
this.post({ type: "render", windowId: spec.windowId });
},
setForeground: (foreground) => {
options.setSurfaceVisible(foreground);
this.post({ type: "foreground", windowId: options.windowId, foreground });
this.options.setSurfaceVisible(surfaceId, foreground);
if (foreground) {
shell.setWindowAttention(spec.windowId, false);
}
this.post({ type: "foreground", windowId: spec.windowId, foreground });
},
setScreenOn: (on) => {
// Screen state is per-app, but sending per-window keeps the protocol
@@ -97,9 +135,24 @@ export class WorkerAppHost {
this.post({ type: "screen", on });
},
};
shell.registerWindow(window);
// Configure the surface before any foregrounding so the worker's first
// frame has somewhere to land.
void this.options
.configureSurface(surfaceId, false)
.then(() => {
if (spec.focus) {
shell.focusWindow(spec.windowId);
}
this.options.requestShellRender();
})
.catch((error) => {
console.error(`surface setup for ${spec.windowId} failed: ${error}`);
});
return window;
}
private post(message: WorkerAppMessage): void {
this.worker.postMessage(message);
this.options.worker.postMessage(message);
}
}