Merge upstream main preserving custom feature integrations

This commit is contained in:
MasterControl committed 2026-11-10 17:08:15 +00:00
commit 6150a1ac57
228 files changed
+16844 -1388

No files matched your search

+126 -12
View File
@@ -2,7 +2,7 @@ import { readHealthExportSecret, writeHealthExportSecret } from "../native/healt
import type { OpenAiSttModel } from "../native/openai-stt";
import { normalizeNightscoutThreshold, type NightscoutThresholds } from "../apps/nightscout/nightscout-alerts";
import { GESTURE_DOUBLE_CLICK, InputEvent } from "./gestures";
import { DEFAULT_BRIGHTNESS_CURVE, normalizeBrightnessCurve, brightnessCurveError } from "../g2/brightness-curve";
import { DEFAULT_BRIGHTNESS_CURVE, G1_BRIGHTNESS_CURVE, RAYNEO_IO_BRIGHTNESS_CURVE, normalizeBrightnessCurve, brightnessCurveError } from "../g2/brightness-curve";
import {
getBooleanSetting,
getStringSetting,
@@ -19,6 +19,7 @@ import {
type AssistantModel,
} from "~/assistant/models";
import { isLocalModelReady } from "../native/local-llm";
import { shouldShowNotificationOnGlasses } from "../native/notification-sources";
import { normalizeWhisperServerUrl } from "../native/whisper-server-stt";
import { TRANSCRIPTION_LANGUAGES, resolveTranscriptionLanguage, type TranscriptionLanguage } from "../native/transcription-language";
import { normalizeOpenAiCompatibleUrl } from "../native/openai-chat";
@@ -43,6 +44,8 @@ export type TimeFormat = "24h" | "12h";
export type TemperatureUnit = "fahrenheit" | "celsius";
export type DistanceUnit = "miles" | "kilometers";
export type ScreenTimeoutSetting = "15s" | "30s" | "1m" | "3m" | "never";
/** Whether new phone notifications pop up on the glasses, and for how long without interaction. */
export type NewNotificationDisplay = "off" | "until-dismissed" | "5s" | "15s" | "1m";
// Auto runs Faceclaw's light curve. Numeric values use the calibrated firmware
// scale, clamped to 2–100; 2 is also the endpoint for screen fades.
export const BRIGHTNESS_VALUES = ["auto", "2", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"] as const;
@@ -189,31 +192,40 @@ type ConfigSettingEnumOptions<TValue extends string, TId extends string> = Confi
normalize?: (value: string | null | undefined) => TValue;
/** Dynamic availability check used by enum picker rows. */
isDisabled?: (value: TValue) => boolean;
/** The default while nothing is stored, when it depends on context (else `defaultValue`). */
dynamicDefault?: () => TValue | undefined;
};
export class ConfigSettingEnum<TValue extends string, TId extends string = string> extends ConfigSetting<TValue, TId> {
readonly values: readonly TValue[];
private readonly normalizer: (value: string | null | undefined) => TValue;
private readonly disabledPredicate: (value: TValue) => boolean;
private readonly dynamicDefault: (() => TValue | undefined) | undefined;
constructor(options: ConfigSettingEnumOptions<TValue, TId>) {
super(options);
this.dynamicDefault = options.dynamicDefault;
if (options.reportInAnalytics !== false) fixedChoiceSettings.set(options.storageKey, this);
this.values = options.values;
this.disabledPredicate = options.isDisabled ?? (() => false);
if (options.normalize) {
this.normalizer = (value: string | null | undefined) => {
const normalized = options.normalize(value) as TValue|undefined;
if (normalized === undefined) return this.defaultValue;
if (normalized === undefined) return this.currentDefault();
return normalized;
}
} else {
this.normalizer = (value) => this.values.includes(value as TValue) ? value as TValue : this.defaultValue;
this.normalizer = (value) => this.values.includes(value as TValue) ? value as TValue : this.currentDefault();
}
}
/** What an unset (or invalid) value reads as now. */
protected currentDefault(): TValue {
return this.dynamicDefault?.() ?? this.defaultValue;
}
get(): TValue {
return this.normalizer(getStringSetting(this.storageKey, this.defaultValue));
return this.normalizer(getStringSetting(this.storageKey, this.currentDefault()));
}
set(value: TValue): TValue {
@@ -249,6 +261,8 @@ type ConfigSettingStringOptions<TId extends string> = ConfigSettingOptions<strin
inputKind?: "text" | "email" | "password";
normalize?: (value: string | null | undefined) => string;
validate?: (value: string) => string | null;
/** The default while nothing is stored, when it depends on context (else `defaultValue`). */
dynamicDefault?: () => string | undefined;
};
// Every string setting by id, so isolates that can only pass an id over a
@@ -266,6 +280,7 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
readonly inputKind: "text" | "email" | "password";
private readonly normalizer: (value: string | null | undefined) => string;
private readonly validator?: (value: string) => string | null;
private readonly dynamicDefault: (() => string | undefined) | undefined;
constructor(options: ConfigSettingStringOptions<TId>) {
super(options);
@@ -274,11 +289,16 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
this.inputKind = options.inputKind ?? "text";
this.normalizer = options.normalize ?? ((value) => value ?? "");
this.validator = options.validate;
this.dynamicDefault = options.dynamicDefault;
stringSettingsById.set(this.id, this);
}
private currentDefault(): string {
return this.dynamicDefault?.() ?? this.defaultValue;
}
get(): string {
return this.normalizer(getStringSetting(this.storageKey, this.defaultValue));
return this.normalizer(getStringSetting(this.storageKey, this.currentDefault()));
}
set(value: string): string {
@@ -297,8 +317,8 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
getValidValue(): string {
const value = this.get();
if (!this.validationError(value)) return value;
const saved = this.normalizer(getStringSetting(this.storageKey + ".valid", this.defaultValue));
return this.validationError(saved) ? this.defaultValue : saved;
const saved = this.normalizer(getStringSetting(this.storageKey + ".valid", this.currentDefault()));
return this.validationError(saved) ? this.currentDefault() : saved;
}
}
@@ -369,7 +389,7 @@ export const phoneBatteryVisibilitySetting = batteryVisibilitySetting(
"phoneBatteryVisibility", "Phone", "display.battery.phoneVisibility",
);
export const glassesBatteryVisibilitySetting = batteryVisibilitySetting(
"glassesBatteryVisibility", "G2", "display.battery.glassesVisibility",
"glassesBatteryVisibility", "Glasses", "display.battery.glassesVisibility",
);
export const ringBatteryVisibilitySetting = batteryVisibilitySetting(
"ringBatteryVisibility", "R1", "display.battery.ringVisibility",
@@ -443,6 +463,34 @@ export const distanceUnitSetting = new ConfigSettingEnum<DistanceUnit>({
*/
export type AppSwitcherPosition = "left" | "right" | "bottom" | "popup";
/** Which glasses the saved addresses belong to (set by pairing; see g2/device-addresses.ts). */
export type GlassesType = "g2" | "rayneo-io" | "g1";
export const glassesTypeSetting = new ConfigSettingEnum<GlassesType>({
id: "glasses-type",
label: "Glasses",
storageKey: "deviceType", // graphics/screen-size.ts GLASSES_TYPE_KEY reads it directly
defaultValue: "g2",
values: ["g2", "rayneo-io", "g1"],
reportInAnalytics: false,
});
/**
* Whether the paired glasses can report a heading. A G1 has an accelerometer
* and a gyroscope but no magnetometer; the RayNeo iO's firmware has no compass
* messages.
*/
export function glassesHaveCompass(): boolean {
return glassesTypeSetting.get() === "g2";
}
const GLASSES_MODEL_NAMES: Record<GlassesType, string> = { g2: "G2", g1: "G1", "rayneo-io": "iO" };
/** The paired glasses' model without the brand, short enough for battery labels and a watch's one-line charging status. */
export function glassesModelName(): string {
return GLASSES_MODEL_NAMES[glassesTypeSetting.get()];
}
const APP_SWITCHER_POSITION_LABELS: Record<AppSwitcherPosition, string> = {
left: "Left",
right: "Right",
@@ -456,6 +504,8 @@ export const appSwitcherPositionSetting = new ConfigSettingEnum<AppSwitcherPosit
storageKey: "display.appSwitcherPosition",
defaultValue: "bottom",
values: ["left", "right", "bottom", "popup"],
// The RayNeo iO's 220 rows can't spare a bottom row: a side strip by default there.
dynamicDefault: () => (glassesTypeSetting.get() === "rayneo-io" ? "left" : undefined),
formatValue: (value) => APP_SWITCHER_POSITION_LABELS[value] ?? value,
description:
"Where the open-app icons go. Left and right take a column beside windows; bottom puts a row beneath the window, which makes full-height windows a little shorter; popup shows them only while you're in the app switcher, in a box over the dimmed window. Bottom and popup leave room at the sides to set the display's depth. Open apps reopen at their new size when a change resizes windows.",
@@ -677,6 +727,10 @@ export const autoBrightnessMaxSetting = new ConfigSettingEnum({
export const autoBrightnessCurveSetting = new ConfigSettingString({
id: "autoBrightnessCurve", label: "Auto light curve", storageKey: "display.autoBrightnessCurve",
defaultValue: DEFAULT_BRIGHTNESS_CURVE, normalize: normalizeBrightnessCurve, validate: brightnessCurveError,
dynamicDefault: () => {
const glasses = glassesTypeSetting.get();
return glasses === "rayneo-io" ? RAYNEO_IO_BRIGHTNESS_CURVE : glasses === "g1" ? G1_BRIGHTNESS_CURVE : undefined;
},
description: "2–16 lux:percent pairs, separated by commas. Percent is within your minimum–maximum range. Start at 0:0, end at 100%, and increase lux without decreasing percent. Incomplete edits stay in the preview; brightness keeps using the last valid curve.",
});
/** The screen on/off fade at Normal speed. */
@@ -735,6 +789,23 @@ export const screenTimeoutSetting = new ConfigSettingEnum<ScreenTimeoutSetting>(
description: "How long the display stays on after the last input before turning itself off. \"Never\" keeps it on until turned off manually.",
});
export const newNotificationDisplaySetting = new ConfigSettingEnum<NewNotificationDisplay>({
id: "new-notification-display",
label: "Display new notifications",
storageKey: "notifications.newNotificationDisplay",
defaultValue: "15s",
values: ["off", "until-dismissed", "5s", "15s", "1m"],
formatValue: newNotificationDisplayLabel,
description:
"Pop up new phone notifications on the glasses. A timed popup closes once left untouched that long; " +
"the notification stays on the phone and in the status bar.",
});
/** Whether a newly posted phone notification from this app pops up on the glasses (the global setting, then the app's filter toggle). */
export function shouldPopUpNewNotification(packageName: string): boolean {
return newNotificationDisplaySetting.get() !== "off" && shouldShowNotificationOnGlasses(packageName);
}
export const lockScreenEnabledSetting = new ConfigSettingBoolean({
id: "lock-screen-enabled",
label: "Enable lock screen",
@@ -988,9 +1059,18 @@ export const ringConnectionModeSetting = new ConfigSettingEnum<RingConnectionMod
formatValue: (value) =>
value === "direct" ? "Direct to phone" : value === "health" ? "Via glasses + health sync" : "Only via glasses",
description:
"How the R1 ring reaches the phone. Only via glasses: the glasses relay the ring's gestures and the phone never connects to it. Via glasses + health sync: the same, plus the phone connects to the ring to sync health data. Direct to phone (experimental): the phone takes the ring over from the glasses and gets its gestures and battery itself; the glasses lose ring input. Health still syncs, but each sync (on opening Health, and at :01 and :31) pauses ring gestures for up to a minute while the phone briefly reconnects to the ring in its health role. Leaving Direct hands the ring back to the glasses. Takes effect on the next connection to the glasses.",
"How the R1 ring reaches the phone. Only via glasses: the glasses relay the ring's gestures and the phone never connects to it. Via glasses + health sync: the same, plus the phone connects to the ring to sync health data. Direct to phone (experimental): the phone takes the ring over from the glasses and gets its gestures and battery itself; the glasses lose ring input. Health still syncs, but each sync (on opening Health, and at :01 and :31) pauses ring gestures for up to a minute while the phone briefly reconnects to the ring in its health role. Leaving Direct hands the ring back to the glasses. A RayNeo iO has no ring link of its own, so with one the phone always connects to the ring directly. Takes effect on the next connection to the glasses.",
});
/**
* The ring connection in effect: the setting with G2 glasses; Direct with a
* RayNeo iO or Even G1, which cannot relay a ring, so the phone holds the ring's
* glasses role itself (gestures, battery; health in brief phone-role windows).
*/
export function effectiveRingConnectionMode(): RingConnectionMode {
return glassesTypeSetting.get() !== "g2" ? "direct" : ringConnectionModeSetting.get();
}
// "whisper" (no "onboard-" prefix) is OpenAI's CLOUD realtime model
// (gpt-realtime-whisper); "onboard-whisper" is the on-device sherpa-onnx
// Whisper backend. Same underlying model family, two different places it
@@ -1660,6 +1740,34 @@ export function screenTimeoutSettingToMs(value: ScreenTimeoutSetting): number |
}
}
/** How long an untouched new-notification popup stays up; null keeps it until dismissed (and for "off", which never opens one). */
export function newNotificationDisplayTimeoutMs(value: NewNotificationDisplay): number | null {
switch (value) {
case "5s":
return 5_000;
case "15s":
return 15_000;
case "1m":
return 60_000;
case "off":
case "until-dismissed":
return null;
}
}
export function newNotificationDisplayLabel(value: NewNotificationDisplay): string {
switch (value) {
case "off":
return "Off";
case "until-dismissed":
return "Until dismissed";
case "1m":
return "1min";
default:
return value;
}
}
export function brightnessLabel(value: BrightnessSetting): string {
return value === "auto" ? "Auto" : value;
}
@@ -1822,11 +1930,17 @@ export class EditTextSettingLayer implements Layer {
for (let index = 0; index < message.length; index++) {
image.drawText(font, 22, messageTop + index * step, message[index]!, 200);
}
image.drawText(font, 22, messageTop + (message.length + 2) * step, truncateSetting(this.setting.inputKind === "password" ? this.setting.displayValue() : this.setting.get(), 52), 220);
const valueY = messageTop + (message.length + 2) * step;
image.drawText(font, 22, valueY, truncateSetting(this.setting.inputKind === "password" ? this.setting.displayValue() : this.setting.get(), 52), 220);
const error = this.setting.validationError();
if (error) wrapText(font, error, width - 48).forEach((line, index) =>
const errorLines = error ? wrapText(font, error, width - 48) : [];
errorLines.forEach((line, index) =>
image.drawText(font, 22, messageTop + (message.length + 4 + index) * step, line, 180));
image.drawText(font, 22, height - 24 - font.lineHeight, `${GESTURE_DOUBLE_CLICK} back`, 110);
// The back hint at the bottom, unless a short window (the RayNeo iO's)
// leaves it no room under the value and error.
const contentBottom = errorLines.length ? messageTop + (message.length + 4 + errorLines.length) * step : valueY + step;
const hintY = height - 24 - font.lineHeight;
if (hintY >= contentBottom) image.drawText(font, 22, hintY, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image;
}
+49 -10
View File
@@ -24,7 +24,6 @@ import {
type AsrModelId,
} from "../../native/asr-model";
import { TextViewerLayer } from "../../apps/files/text-viewer";
import { IOS_PRIVACY_NOTICE } from "../../analytics/privacy-disclosure";
import type { LayerContext } from "../layers";
import { drawRightValueMenuItem, openModalMenu, submenuItem, type MenuItem } from "../menu";
import { shell } from "../shell/shell";
@@ -61,6 +60,7 @@ import {
dataCollectionSetting,
distanceUnitSetting,
glassesBatteryVisibilitySetting,
glassesModelName,
phoneBatteryVisibilitySetting,
ringBatteryVisibilitySetting,
watchBatteryVisibilitySetting,
@@ -74,6 +74,7 @@ import {
previewScalingSetting,
phoneRotationSetting,
ringConnectionModeSetting,
glassesTypeSetting,
sonioxApiKeySetting,
saveTranscribeAudioSetting,
whisperServerApiKeySetting,
@@ -85,6 +86,7 @@ import {
firmwareDebugFlagsSetting,
lockScreenEnabledSetting,
menuAnimationSetting,
newNotificationDisplaySetting,
saveVoiceRecordingsSetting,
showBleBandwidthSetting,
suspendEvenHubWhenScreenOffSetting,
@@ -109,9 +111,13 @@ import {
import { wearBridge } from "../../native/wear-bridge";
import { openSettingsSubMenu, SettingsPanelLayer, type SettingsSection } from "./settings-panel";
import { uiFontPickerMenuItem } from "../font-picker";
import { NotificationFilterLayer } from "../notification-filter";
import { compatibleModelDiscoveryMenuItem } from "../openai-compatible-model-picker";
import { isVeniceApiBaseUrl } from "../../native/openai-chat";
/** The Settings section the Notifications app's "Settings" menu item opens. */
export const NOTIFICATIONS_SETTINGS_SECTION = "Notifications";
/** The Settings app's master-detail panel (sections on the left, contents on the right). */
export function createSettingsPanelLayer(): SettingsPanelLayer {
return new SettingsPanelLayer(settingsSections());
@@ -127,7 +133,7 @@ function settingsSections(): SettingsSection[] {
// the dashboard controller when changed and on each connect.
enumSettingMenuItem(brightnessSetting),
autoBrightnessMenuItem(),
...(!global.isIOS ? [toggleSettingMenuItem(headUpWakeSetting), enumSettingMenuItem(headUpAngleSetting)] : []),
...(!global.isIOS && glassesTypeSetting.get() === "g2" ? [toggleSettingMenuItem(headUpWakeSetting), enumSettingMenuItem(headUpAngleSetting)] : []),
enumSettingMenuItem(screenTimeoutSetting, {
onChange: () => {
shell.noteUserActivity();
@@ -149,6 +155,14 @@ function settingsSections(): SettingsSection[] {
return customizationItems();
},
},
{
// Also opened from the Notifications app's menu (deep link by label).
label: NOTIFICATIONS_SETTINGS_SECTION,
items: [
enumSettingMenuItem(newNotificationDisplaySetting),
notificationFilterMenuItem(),
],
},
{
label: "Voice",
items: [
@@ -254,7 +268,7 @@ function settingsSections(): SettingsSection[] {
items: [
// Whether and how the phone opens its own BLE link to the R1 ring.
// Applied at connect time.
enumSettingMenuItem(ringConnectionModeSetting),
ringConnectionMenuItem(),
toggleSettingMenuItem(saveVoiceRecordingsSetting),
toggleSettingMenuItem(firmwareDebugFlagsSetting),
toggleSettingMenuItem(suspendEvenHubWhenScreenOffSetting),
@@ -267,11 +281,6 @@ function settingsSections(): SettingsSection[] {
items: [
// First chosen in the on-glasses onboarding (app/apps/onboarding/).
enumSettingMenuItem(dataCollectionSetting),
...(global.isIOS ? [{
label: "iOS / TestFlight privacy",
description: "Apple's beta reports are separate from Faceclaw statistics. Tap to read.",
onSelect: (ctx: LayerContext) => ctx.stack.push(new TextViewerLayer(IOS_PRIVACY_NOTICE, "iOS / TestFlight privacy")),
}] : []),
bundledDocMenuItem("PRIVACY", "Privacy policy"),
],
},
@@ -303,7 +312,7 @@ function settingsSections(): SettingsSection[] {
];
if (!global.isIOS) return sections;
return sections.map(section => {
if (section.label === "Developer") return { ...section, items: [enumSettingMenuItem(ringConnectionModeSetting),
if (section.label === "Developer") return { ...section, items: [ringConnectionMenuItem(),
toggleSettingMenuItem(showBleBandwidthSetting)] };
// No downloadable on-device models: iOS's on-device option is Apple's recognizer.
if (section.label === "Voice") return { label: "Voice", items: [enumSettingMenuItem(wakeWordActionSetting),
@@ -362,6 +371,17 @@ function customizationRows(): () => MenuItem[] {
};
}
/** Notifications > Notification filter: per-app toggles for notifications shown on the glasses. */
function notificationFilterMenuItem(): MenuItem {
return submenuItem(
"Notification filter",
(ctx) => {
ctx.stack.push(new NotificationFilterLayer());
},
{ description: "Disabled apps are hidden from glasses popups, the notification list, and the tray. Their notifications remain on your phone." },
);
}
function autoBrightnessMenuItem(): MenuItem {
return submenuItem(
"Auto-brightness",
@@ -391,7 +411,8 @@ function batteryIndicatorsMenuItem(): MenuItem {
enumSettingMenuItem(batteryDisplayModeSetting),
enumSettingMenuItem(phoneBatteryVisibilitySetting),
enumSettingMenuItem(watchBatteryVisibilitySetting),
enumSettingMenuItem(glassesBatteryVisibilitySetting),
// Named as the top bar names this indicator.
enumSettingMenuItem(glassesBatteryVisibilitySetting, { label: glassesModelName() }),
enumSettingMenuItem(ringBatteryVisibilitySetting),
]);
},
@@ -624,6 +645,24 @@ function readBundledDoc(fileName: string): string {
}
}
/**
* Developer > Ring connection: the setting, except with a RayNeo iO, which
* always takes the ring directly (effectiveRingConnectionMode): then a fixed,
* disabled "Direct" row, the stored choice kept for G2 glasses.
*/
function ringConnectionMenuItem(): MenuItem {
const item = enumSettingMenuItem(ringConnectionModeSetting);
const io = () => glassesTypeSetting.get() !== "g2";
return {
...item,
disabled: io,
render: (args) => {
if (!io()) return item.render?.(args);
drawRightValueMenuItem(args.image, getDefaultSmallFont(), args.x, args.y, args.width, item.label, glassesTypeSetting.get() === "g1" ? "Direct (Even G1)" : "Direct (RayNeo iO)");
},
};
}
function renderWatchStatus(args: { image: GrayImage; x: number; y: number; width: number }): number {
const { image, x, y, width } = args;
const font = getDefaultSmallFont();
+25 -1
View File
@@ -36,6 +36,8 @@ const ROW_GAP = 2;
/** Horizontal inset of row text (and custom row content) from its selection box. */
const ROW_TEXT_X = 10;
const MAX_DESCRIPTION_LINES = 3;
/** Rows a section's list keeps beside its detail while focus is in it (see detailCrowdsList). */
const MIN_LIST_ROWS = 3;
// A throwaway menu to satisfy MenuItem.onSelect's second parameter; the
// settings items never use it (they act via ctx only).
const NO_MENU = new MenuLayer(null, []);
@@ -134,7 +136,7 @@ export class SettingsPanelLayer implements Layer {
const rightX = divX + 14;
const rightW = width - rightX - PAD;
let rightTop = top;
if (section.renderDetail) {
if (section.renderDetail && !this.detailCrowdsList(section, ctx, font, { x: rightX, y: top, width: rightW, height: listBottom - top })) {
const used = section.renderDetail({ image, x: rightX, y: top, width: rightW, height: listBottom - top, ctx });
rightTop = typeof used === "number" ? Math.min(top + used, listBottom) : listBottom;
}
@@ -157,6 +159,28 @@ export class SettingsPanelLayer implements Layer {
return image;
}
/**
* Whether the section's detail (About's blurb, the watch status) would
* leave its rows less than MIN_LIST_ROWS while focus is in them, as on a
* short screen (the RayNeo iO's): the list then takes the whole pane, the
* detail staying in the preview. Measured by drawing the detail on a
* scratch image.
*/
private detailCrowdsList(
section: SettingsSection,
ctx: LayerContext,
font: UiFont,
pane: { x: number; y: number; width: number; height: number },
): boolean {
if (this.focus !== "right" || !section.items.length || !section.renderDetail) return false;
const scratch = new GrayImage(pane.x + pane.width, pane.y + pane.height, 0);
const used = section.renderDetail({ image: scratch, ...pane, ctx });
if (typeof used !== "number") return false;
const rows = Math.min(MIN_LIST_ROWS, section.items.length);
const room = pane.height - used - this.descriptionHeight(font, pane.width);
return room < rows * (listRowHeight(font) + ROW_GAP);
}
/** The selected item's wrapped help text, or [] when none applies. */
private descriptionLines(font: UiFont, rightW: number): string[] {
if (this.focus !== "right") return [];
+32 -9
View File
@@ -13,6 +13,7 @@ import { getFont } from "../graphics/bdffont";
import { GrayImage, type UiFont } from "../graphics/image";
import { TtfFont } from "../graphics/ttf-font";
import { listInstalledFonts, type InstalledFont } from "../graphics/installed-fonts";
import { wrapText } from "../graphics/textwrap";
import {
fontSelectionLabel,
getDefaultSmallFont,
@@ -140,18 +141,40 @@ export class FontPickerLayer implements Layer {
const rowWidth = width - 2 * rowX;
const rowHeight = listRowHeight(font);
const rowsTop = 24 + font.lineHeight;
this.menu.paint(image, { x: rowX - 10, y: rowsTop, width: rowWidth + 20, height: ROWS.length * rowHeight }, focused);
// Preview: a separator, then the sample line in the draft font.
const previewTop = rowsTop + ROWS.length * rowHeight + 10;
image.drawLine(rowX - 10, previewTop, rowX + rowWidth + 10, previewTop, 60);
const rowsHeight = ROWS.length * rowHeight;
const preview = this.previewFont();
const sample =
preview.measureText(PREVIEW_TEXT) <= rowWidth + 20 ? PREVIEW_TEXT : "The quick brown fox 0123";
preview.drawText(image, rowX - 4, previewTop + 8, sample, 230);
const info = `Line height: ${preview.lineHeight}px`;
image.drawText(font, rowX - 4, previewTop + 8 + preview.lineHeight + 6, info, 110);
// Preview under the rows, where its sample line and the info line fit
// (the G2's window): a separator, then the sample line in the draft font.
const previewTop = rowsTop + rowsHeight + 10;
if (previewTop + 8 + preview.lineHeight + 6 + font.lineHeight <= height) {
this.menu.paint(image, { x: rowX - 10, y: rowsTop, width: rowWidth + 20, height: rowsHeight }, focused);
image.drawLine(rowX - 10, previewTop, rowX + rowWidth + 10, previewTop, 60);
const sample =
preview.measureText(PREVIEW_TEXT) <= rowWidth + 20 ? PREVIEW_TEXT : "The quick brown fox 0123";
preview.drawText(image, rowX - 4, previewTop + 8, sample, 230);
image.drawText(font, rowX - 4, previewTop + 8 + preview.lineHeight + 6, info, 110);
return image;
}
// Else beside them (a short window, as on the RayNeo iO), the sample
// wrapped to the column, as many lines as fit above the info line.
const columnWidth = Math.round(rowWidth / 2);
const bottom = height - 8;
this.menu.paint(image, { x: rowX - 10, y: rowsTop, width: columnWidth + 20, height: Math.min(rowsHeight, bottom - rowsTop) }, focused);
const dividerX = rowX + columnWidth + 20;
image.drawLine(dividerX, rowsTop, dividerX, Math.min(rowsTop + rowsHeight, bottom), 60);
const previewX = dividerX + 12;
const lines = wrapText(preview, PREVIEW_TEXT, width - previewX - 12);
const infoY = bottom - font.lineHeight;
let y = rowsTop + 4;
for (const line of lines) {
if (y + preview.lineHeight > infoY - 6) break;
preview.drawText(image, previewX, y, line, 230);
y += preview.lineHeight;
}
image.drawText(font, previewX, Math.min(infoY, y + 6), info, 110);
return image;
}
+13 -9
View File
@@ -1,4 +1,5 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
import { GrayImage } from "../graphics/image";
import { screenHeight, screenWidth } from "../graphics/screen-size";
import { dimPlanes, type Plane } from "../graphics/plane";
import { spanCurrent } from "../native/frame-timings";
import { type ConfigSettingBoolean, type ConfigSettingString, type VoiceProvider } from "./dashboard-settings";
@@ -153,8 +154,12 @@ export class LayerStack {
}
private readonly shellKeys = new WeakMap<Layer, number>();
private readonly ctx: LayerContext;
private baseWidth: number;
private baseHeight: number;
/**
* The base viewport's size, or null to follow the paired glasses' screen
* as it is now: the shell's own stack lives for the whole process, and
* re-pairing with the other glasses type changes the screen under it.
*/
private baseSize: { width: number; height: number } | null;
private readonly focusedFn: () => boolean;
private lastBaseDim: number | false = 1;
@@ -172,8 +177,7 @@ export class LayerStack {
stack: this,
actions,
};
this.baseWidth = baseSize?.width ?? G2_LENS_WIDTH;
this.baseHeight = baseSize?.height ?? G2_LENS_HEIGHT;
this.baseSize = baseSize ? { width: baseSize.width, height: baseSize.height } : null;
this.focusedFn = isFocused;
}
@@ -244,13 +248,12 @@ export class LayerStack {
}
getBaseSize(): { width: number; height: number } {
return { width: this.baseWidth, height: this.baseHeight };
return this.baseSize ? { ...this.baseSize } : { width: screenWidth(), height: screenHeight() };
}
/** Resize the base viewport (e.g. an EvenHub window switching to the tall canvas). */
setBaseSize(size: { width: number; height: number }): void {
this.baseWidth = size.width;
this.baseHeight = size.height;
this.baseSize = { width: size.width, height: size.height };
}
setActions(actions: Partial<LayerActions>): void {
@@ -321,7 +324,8 @@ export class LayerStack {
layer.paint(this.ctx, () => {
belowRequested = true;
if (!canvas) {
canvas = new GrayImage(this.baseWidth, this.baseHeight, 0);
const { width, height } = this.getBaseSize();
canvas = new GrayImage(width, height, 0);
}
return canvas;
}),
+13 -4
View File
@@ -1,4 +1,5 @@
import { G2_LENS_HEIGHT, GrayImage, type UiFont } from "../graphics/image";
import { GrayImage, type UiFont } from "../graphics/image";
import { screenHeight } from "../graphics/screen-size";
import { wrapText } from "../graphics/textwrap";
import { getDefaultSmallFont } from "../graphics/ui-fonts";
import { getStringSetting } from "../native/settings-store";
@@ -18,9 +19,14 @@ setMenuAnimationReader(() => normalizeAnimationSpeed(getStringSetting(MENU_ANIMA
const DEFAULT_MENU_X = 8;
const DEFAULT_MENU_Y = 8;
const DEFAULT_MENU_WIDTH = 272;
/** Windows shorter than this (the RayNeo iO's, not the G2's) get tighter modal margins. */
const SHORT_WINDOW_HEIGHT = 200;
// Menus grow with their item count, from half the screen (matching the old
// fixed quarter-screen-era look) up to the full screen, then scroll.
const DEFAULT_MENU_MIN_HEIGHT = G2_LENS_HEIGHT / 2 - 2 * DEFAULT_MENU_Y;
/** Half the screen, less the menu's top and bottom offsets. */
function defaultMenuMinHeight(): number {
return screenHeight() / 2 - 2 * DEFAULT_MENU_Y;
}
const MENU_BODY_PADDING = 8;
/** Gap between the last item row and a footer hint line. */
const MENU_FOOTER_GAP = 8;
@@ -302,7 +308,7 @@ export class MenuLayer implements Layer {
const { y, width } = this.layout;
const x = this.layout.x === "center" ? ((image.width - width) / 2) | 0 : this.layout.x;
const chromeTop = (this.title ? menuTitleHeight(font) : 0) + MENU_BODY_PADDING;
const minHeight = this.layout.minHeight ?? DEFAULT_MENU_MIN_HEIGHT;
const minHeight = this.layout.minHeight ?? defaultMenuMinHeight();
// Cap to the surface being painted on: a window's stack image may be much
// shorter than the full screen (min-height windows).
const maxHeight = Math.min(
@@ -376,7 +382,10 @@ export function openModalMenu(
const font = getDefaultSmallFont();
const menuWidth = Math.min(320, width - 40);
const naturalHeight = menuTitleHeight(font) + 2 * MENU_BODY_PADDING + items.length * listRowHeight(font);
const menuHeight = Math.min(naturalHeight, height - 40);
// 20px clear above and below, or 8 in a short window (the RayNeo iO's),
// where those rows are worth more than the margin.
const marginY = height < SHORT_WINDOW_HEIGHT ? 8 : 20;
const menuHeight = Math.min(naturalHeight, height - 2 * marginY);
const layout: MenuLayout = {
x: ((width - menuWidth) / 2) | 0,
y: ((height - menuHeight) / 2) | 0,
+13 -7
View File
@@ -8,7 +8,11 @@ import { appViewportRect, SHELL_OPAQUE_BLACK } from "./geometry";
const DIALOG_WIDTH = 272;
const BAR_WIDTH = 12;
/** The bar's height where the window has room (the G2's); it shrinks to fit a shorter one, down to MIN_BAR_HEIGHT. */
const BAR_HEIGHT = 100;
const MIN_BAR_HEIGHT = 24;
/** Clear space kept above and below the dialog in the window. */
const MARGIN_Y = 4;
/** Manual brightness changes apply immediately so the wearer can judge the level. */
export class BrightnessPickerLayer implements Layer {
@@ -22,7 +26,9 @@ export class BrightnessPickerLayer implements Layer {
const image = paintBelow();
const font = getDefaultSmallFont();
const viewport = appViewportRect("min");
const height = BAR_HEIGHT + 3 * font.lineHeight + 56;
const chrome = 3 * font.lineHeight + 56;
const barHeight = clamp(viewport.height - 2 * MARGIN_Y - chrome, MIN_BAR_HEIGHT, BAR_HEIGHT);
const height = barHeight + chrome;
const left = viewport.x + Math.round((viewport.width - DIALOG_WIDTH) / 2);
const top = viewport.y + Math.round((viewport.height - height) / 2);
image.fillRect(left, top, DIALOG_WIDTH, height, SHELL_OPAQUE_BLACK);
@@ -35,14 +41,14 @@ export class BrightnessPickerLayer implements Layer {
const barX = left + Math.round((DIALOG_WIDTH - BAR_WIDTH) / 2);
const barY = top + font.lineHeight + 24;
const level = brightnessSettingToLevel(brightnessSetting.get());
image.drawRect(barX - 2, barY - 2, BAR_WIDTH + 4, BAR_HEIGHT + 4, 150);
const filledHeight = Math.round(BAR_HEIGHT * (level ?? 0) / 100);
image.fillRect(barX, barY + BAR_HEIGHT - filledHeight, BAR_WIDTH, filledHeight, 255);
image.drawText(font, barX + BAR_WIDTH + 12, barY + Math.round((BAR_HEIGHT - font.lineHeight) / 2),
image.drawRect(barX - 2, barY - 2, BAR_WIDTH + 4, barHeight + 4, 150);
const filledHeight = Math.round(barHeight * (level ?? 0) / 100);
image.fillRect(barX, barY + barHeight - filledHeight, BAR_WIDTH, filledHeight, 255);
image.drawText(font, barX + BAR_WIDTH + 12, barY + Math.round((barHeight - font.lineHeight) / 2),
level === null ? "Auto" : `${level}%`, 235);
centeredText(gestureHints([[GESTURE_SCROLL, "adjust"]]), barY + BAR_HEIGHT + 12, 150);
centeredText(gestureHints([[GESTURE_SCROLL, "adjust"]]), barY + barHeight + 12, 150);
centeredText(gestureHints([[`${GESTURE_CLICK} / ${GESTURE_DOUBLE_CLICK}`, "confirm"]]),
barY + BAR_HEIGHT + font.lineHeight + 16, 150);
barY + barHeight + font.lineHeight + 16, 150);
return image;
}
+22 -16
View File
@@ -1,7 +1,7 @@
import { shellCrop } from "../../graphics/shell-scene";
import type { Plane } from "../../graphics/plane";
import { DrawOp, type ListCall, type ListClip } from "../../graphics/display-list";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage, grayToNibble } from "../../graphics/image";
import { GrayImage, grayToNibble } from "../../graphics/image";
import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
import { truncateText } from "../../graphics/textwrap";
import { activeAmbientCards } from "./ambient-cards";
@@ -15,6 +15,7 @@ import {
batteryDisplayModeSetting,
batteryIndicatorVisible,
glassesBatteryVisibilitySetting,
glassesModelName,
phoneBatteryVisibilitySetting,
ringBatteryVisibilitySetting,
watchBatteryVisibilitySetting,
@@ -29,7 +30,9 @@ import { lineStep } from "../metrics";
import {
appViewportRect,
isImmersive,
MIN_WINDOW_HEIGHT,
minWindowHeight,
screenHeight,
screenWidth,
minWindowTop,
setSwitcherBarHeight,
SHELL_OPAQUE_BLACK,
@@ -68,7 +71,10 @@ const TWO_COLUMN: SidebarVariant = { columns: 2, columnWidth: 32, iconSize: 28 }
const ICON_SPACING = 8;
/** Icon list top/bottom margins within the sidebar band, below the top bar (and a bottom row's end margins). */
const LIST_MARGIN = 10;
const LIST_HEIGHT = MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 2 * LIST_MARGIN;
/** Height of the sidebar's icon list: the min-height band less its top bar and margins. */
function listHeight(appId?: string): number {
return minWindowHeight(appId) - TOP_BAR_HEIGHT - 2 * LIST_MARGIN;
}
/** Bottom-row icons: one tall tab's worth of row, the icon inset 2px all round. */
const ROW_ICON_SIZE = SWITCHER_ROW_HEIGHT - 4;
@@ -123,7 +129,7 @@ const POPUP_DIM = 0.5;
/** Icon rows that fit in one sidebar column. */
function rowsPerColumn(variant: SidebarVariant): number {
return Math.max(1, ((LIST_HEIGHT + ICON_SPACING) / (variant.iconSize + ICON_SPACING)) | 0);
return Math.max(1, ((listHeight() + ICON_SPACING) / (variant.iconSize + ICON_SPACING)) | 0);
}
function sidebarVariant(windowCount: number): SidebarVariant {
@@ -136,7 +142,7 @@ function sidebarVariant(windowCount: number): SidebarVariant {
*/
function columnLeft(variant: SidebarVariant, column: number, position: AppSwitcherPosition): number {
return position === "right"
? G2_LENS_WIDTH - SIDEBAR_WIDTH + column * variant.columnWidth
? screenWidth() - SIDEBAR_WIDTH + column * variant.columnWidth
: SIDEBAR_WIDTH - (column + 1) * variant.columnWidth;
}
@@ -382,7 +388,7 @@ export function sidebarContentSpan(windowCount: number): { left: number; right:
const variant = sidebarVariant(windowCount);
const width = variant.columns * variant.columnWidth;
return switcherPosition() === "right"
? { left: G2_LENS_WIDTH - SIDEBAR_WIDTH, right: G2_LENS_WIDTH - SIDEBAR_WIDTH + width }
? { left: screenWidth() - SIDEBAR_WIDTH, right: screenWidth() - SIDEBAR_WIDTH + width }
: { left: SIDEBAR_WIDTH - width, right: SIDEBAR_WIDTH };
}
@@ -396,7 +402,7 @@ function topBarSpan(state: ShellChromeState): { left: number; right: number } {
if (sidebarStripVisible(state.focus, state.foregroundAppId)) {
const position = switcherPosition();
if (position === "left") left = Math.max(left, SIDEBAR_WIDTH);
if (position === "right") right = Math.min(right, G2_LENS_WIDTH - SIDEBAR_WIDTH);
if (position === "right") right = Math.min(right, screenWidth() - SIDEBAR_WIDTH);
}
return { left, right };
}
@@ -632,7 +638,7 @@ export class ShellChromeLayer implements Layer {
) {}
paint(): GrayImage {
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const image = new GrayImage(screenWidth(), screenHeight(), 0);
const state = this.getState();
this.statusEntries = [];
this.bottomBar = this.layoutBottomBar(state);
@@ -659,7 +665,7 @@ export class ShellChromeLayer implements Layer {
this.statusEntries = [];
this.bottomBar = this.layoutBottomBar(state);
const statusInRow = statusInSwitcherRow(state.foregroundAppId);
const canvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const canvas = new GrayImage(screenWidth(), screenHeight(), 0);
const span = topBarSpan(state);
const bar = statusBarPlacement(state);
if (bar) {
@@ -672,7 +678,7 @@ export class ShellChromeLayer implements Layer {
return parts;
}
if (switcherShown) {
const stripCanvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const stripCanvas = new GrayImage(screenWidth(), screenHeight(), 0);
const statusLeft = this.drawSidebar(stripCanvas, state, statusInRow ? canvas : undefined);
// The window frame rides on the switcher row, whose top edge is its
// bottom side, and so replays after any top bar, whose bottom row is
@@ -712,14 +718,14 @@ export class ShellChromeLayer implements Layer {
// to be sent at all, so the frame rides on one at its top-left corner,
// outside its curve, which it paints black anyway. As in the bottom
// row's case, it plays at the screen's own depth.
const frameCanvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const frameCanvas = new GrayImage(screenWidth(), screenHeight(), 0);
frameCanvas.fillRect(frame.x, frame.y, 1, 1, SHELL_OPAQUE_BLACK);
drawWindowFrame(frameCanvas, frame, false, true);
parts.push(shellCrop(frameCanvas, frame.x, frame.y, 1, 1, 1));
}
drawAmbientCards(canvas, topBarSpan(state).right, parts);
if (!switcherShown) return;
const popupCanvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const popupCanvas = new GrayImage(screenWidth(), screenHeight(), 0);
const box = this.drawPopup(popupCanvas, state);
this.popupKey ??= LayerStack.allocateShellKey();
parts.push({ ...shellCrop(popupCanvas, box.x, box.y, box.width, box.height, this.popupKey), depth: POPUP_DEPTH });
@@ -900,8 +906,8 @@ export class ShellChromeLayer implements Layer {
const batteries = batteryItems(state);
if (batteries.length) {
// Measured by drawing it: each battery style lays itself out as it draws.
const scratch = new GrayImage(G2_LENS_WIDTH, TOP_BAR_HEIGHT, 0);
const width = G2_LENS_WIDTH - BATTERY_BLOCK_RIGHT_MARGIN - drawBatteryBlock(scratch, batteries, 0, G2_LENS_WIDTH);
const scratch = new GrayImage(screenWidth(), TOP_BAR_HEIGHT, 0);
const width = screenWidth() - BATTERY_BLOCK_RIGHT_MARGIN - drawBatteryBlock(scratch, batteries, 0, screenWidth());
// The block keeps its usual right margin inside the edge it's given.
items.push({ kind: "batteries", width,
draw: (image, x, top) => drawBatteryBlock(image, batteries, top, x + width + BATTERY_BLOCK_RIGHT_MARGIN) });
@@ -1084,7 +1090,7 @@ function batteryItems(state: ShellChromeState): BatteryItem[] {
Boolean(state.battery.watchCharging));
}
if (state.battery.headset !== null && Number.isFinite(state.battery.headset)) {
pushBatteryItem(items, glassesBatteryVisibilitySetting.get(), "G2", "glasses", state.battery.headset,
pushBatteryItem(items, glassesBatteryVisibilitySetting.get(), glassesModelName(), "glasses", state.battery.headset,
Boolean(state.battery.headsetCharging));
}
if (state.battery.ring !== null && Number.isInteger(state.battery.ring)
@@ -1245,7 +1251,7 @@ function drawAmbientCards(image: GrayImage, right: number, parts?: Plane[]): voi
if (!cards.length) return;
const font = getDefaultSmallFont();
const bandTop = minWindowTop();
const bandBottom = bandTop + MIN_WINDOW_HEIGHT - windowFooterHeight();
const bandBottom = bandTop + minWindowHeight() - windowFooterHeight();
// Right-aligned with the top bar: clear of a right-hand sidebar.
const x = right - AMBIENT_CARD_WIDTH - AMBIENT_CARD_MARGIN;
const textWidth = AMBIENT_CARD_WIDTH - 2 * AMBIENT_CARD_PADDING_X;
+36 -22
View File
@@ -1,4 +1,4 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../../graphics/image";
import { screenHeight, screenWidth } from "../../graphics/screen-size";
import {
appSwitcherPositionSetting,
appFullscreenSetting,
@@ -13,6 +13,9 @@ import {
windowBorderSetting,
} from "../dashboard-settings";
/** The paired glasses' screen, which the shell lays out in (graphics/screen-size.ts). */
export { screenHeight, screenWidth };
/** Top bar: 24px notification icons plus a little padding. */
export const TOP_BAR_HEIGHT = 28;
/**
@@ -175,15 +178,15 @@ export function switcherRect(heightMode: WindowHeightMode, appId?: string): { x:
const height = reserved || switcherBarHeights.overlay;
return {
x: appViewportLeft(appId),
y: reserved > 0 ? windowTop(heightMode, appId) + windowBandHeight(heightMode, appId) : G2_LENS_HEIGHT - height,
y: reserved > 0 ? windowTop(heightMode, appId) + windowBandHeight(heightMode, appId) : screenHeight() - height,
width: appViewportWidth(appId),
height,
};
}
case "right":
return { x: G2_LENS_WIDTH - SIDEBAR_WIDTH, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: MIN_WINDOW_HEIGHT };
return { x: screenWidth() - SIDEBAR_WIDTH, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: minWindowHeight(appId) };
default:
return { x: 0, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: MIN_WINDOW_HEIGHT };
return { x: 0, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: minWindowHeight(appId) };
}
}
@@ -294,15 +297,15 @@ export function isOnSwitcherEdge(x: number, y: number, heightMode: WindowHeightM
case "bottom":
return y >= switcherRect(heightMode, appId).y;
case "right":
return x >= G2_LENS_WIDTH - SIDEBAR_WIDTH;
return x >= screenWidth() - SIDEBAR_WIDTH;
default:
return x < SIDEBAR_WIDTH;
}
}
/** Width of app windows: the panel's when Full Screen or immersive, else 576 (see SIDEBAR_WIDTH). */
/** Width of app windows: the screen's when Full Screen or immersive, else SIDEBAR_WIDTH less (576 on the G2). */
function appViewportWidth(appId?: string): number {
return fullWidth(appId) ? G2_LENS_WIDTH : G2_LENS_WIDTH - SIDEBAR_WIDTH;
return fullWidth(appId) ? screenWidth() : screenWidth() - SIDEBAR_WIDTH;
}
/**
@@ -354,7 +357,7 @@ export function effectiveHeightMode(mode: WindowHeightMode, appId?: string): Win
* rather than use the viewport's own centre.
*/
export function screenCenterInViewportX(): number {
return Math.round(G2_LENS_WIDTH / 2) - appViewportLeft();
return Math.round(screenWidth() / 2) - appViewportLeft();
}
/**
@@ -375,15 +378,23 @@ export const SHELL_OPAQUE_BLACK = 1;
*/
export type WindowHeightMode = "min" | "medium" | "max";
/** Total height (header + content) of a min-height window. */
/** Total height (header + content) of a min-height window on a screen with room for it: the G2's stock band. */
export const MIN_WINDOW_HEIGHT = 288;
/**
* Total height of a min-height window here: the stock 288px band, or the
* whole window area on a screen too short for it (the RayNeo iO's 220 rows).
*/
export function minWindowHeight(appId?: string): number {
return Math.min(MIN_WINDOW_HEIGHT, windowAreaHeight(appId));
}
/**
* Height of the screen area windows are placed in: the whole screen, less
* a bottom switcher's height.
*/
function windowAreaHeight(appId?: string): number {
return G2_LENS_HEIGHT - switcherRowHeight(appId);
return screenHeight() - switcherRowHeight(appId);
}
/** Total height (header + content + footer) of a window's band in the given mode. */
@@ -392,9 +403,9 @@ export function windowBandHeight(mode: WindowHeightMode, appId?: string): number
case "max":
return windowAreaHeight(appId);
case "medium":
return MIN_WINDOW_HEIGHT + windowHeaderHeight(appId) + windowFooterHeight(appId);
return Math.min(windowAreaHeight(appId), minWindowHeight(appId) + windowHeaderHeight(appId) + windowFooterHeight(appId));
default:
return MIN_WINDOW_HEIGHT;
return minWindowHeight(appId);
}
}
@@ -426,7 +437,7 @@ export function minWindowTop(appId?: string): number {
*/
export function windowTop(mode: WindowHeightMode, appId?: string): number {
const band = windowBandHeight(mode, appId);
const oneRowArea = G2_LENS_HEIGHT - (switcherRowHeight(appId) > 0 ? SWITCHER_ROW_HEIGHT : 0);
const oneRowArea = screenHeight() - (switcherRowHeight(appId) > 0 ? SWITCHER_ROW_HEIGHT : 0);
const top = Math.round((oneRowArea - band) * verticalPositionFraction(appId));
return Math.min(top, windowAreaHeight(appId) - band);
}
@@ -474,13 +485,13 @@ function unionRect(a: ScreenRect, b: ScreenRect): ScreenRect {
* the whole panel. The phone mirror's Scaled preview zooms to this.
*/
export function usedScreenRect(heightMode: WindowHeightMode, appId?: string): ScreenRect {
if (isImmersive(appId)) return { x: 0, y: 0, width: G2_LENS_WIDTH, height: G2_LENS_HEIGHT };
if (isImmersive(appId)) return { x: 0, y: 0, width: screenWidth(), height: screenHeight() };
const frame = windowFramed(appId) ? 1 : 0;
const x = appViewportLeft(appId) - frame;
const width = appViewportWidth(appId) + 2 * frame;
let used = unionRect(
{ x, y: windowTop(heightMode, appId), width, height: windowBandHeight(heightMode, appId) },
{ x, y: minWindowTop(appId), width, height: MIN_WINDOW_HEIGHT },
{ x, y: minWindowTop(appId), width, height: minWindowHeight(appId) },
);
if (switcherPosition() !== "popup") used = unionRect(used, switcherRect(heightMode, appId));
return used;
@@ -488,15 +499,18 @@ export function usedScreenRect(heightMode: WindowHeightMode, appId?: string): Sc
/**
* The screen area the phone mirror shows to present `used` as large as it
* fits, centred, at the panel's own 4:3 aspect (so the mirror keeps its
* shape whatever the display mode): `used` grown along one axis, past the
* panel's edges if need be (the mirror shows black there).
* fits, centred, at the screen's own aspect (4:3 on the G2, 27:11 on the iO),
* so the mirror keeps its shape whatever the display mode: `used` grown along
* one axis, past the screen's edges if need be (the mirror shows black there).
*/
export function phonePreviewRect(used: ScreenRect): ScreenRect {
// Whole 4:3 units, so the aspect is exact.
const units = Math.ceil(Math.max(used.width / 4, used.height / 3));
const width = units * 4;
const height = units * 3;
// Whole aspect units, so the aspect is exact.
const gcd = (a: number, b: number): number => (b ? gcd(b, a % b) : a);
const unit = gcd(screenWidth(), screenHeight());
const aspectW = screenWidth() / unit, aspectH = screenHeight() / unit;
const units = Math.ceil(Math.max(used.width / aspectW, used.height / aspectH));
const width = units * aspectW;
const height = units * aspectH;
return {
x: Math.round(used.x + (used.width - width) / 2),
y: Math.round(used.y + (used.height - height) / 2),
+1
View File
@@ -226,6 +226,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
options.reconfigureSurface?.(heightMode);
requestRender();
},
layoutSize: () => stack.getBaseSize(),
hitTest: async (x, y) => {
const handled = await stack.hitTest(x, y);
if (handled) requestRender();
+23 -14
View File
@@ -1,9 +1,9 @@
import { G2_LENS_WIDTH, GrayImage, type UiFont } from "../../graphics/image";
import { GrayImage, type UiFont } from "../../graphics/image";
import { wrapText, truncateText } from "../../graphics/textwrap";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { Menu, type MenuDrawArgs } from "../menu-core";
import { listRowHeight, textInkBounds } from "../metrics";
import { MIN_WINDOW_HEIGHT, minWindowTop } from "./geometry";
import { minWindowHeight, minWindowTop, screenWidth } from "./geometry";
/**
* The shared look of the shell's text dialogs (voice input, phone keyboard
@@ -13,17 +13,26 @@ import { MIN_WINDOW_HEIGHT, minWindowTop } from "./geometry";
*/
const DIALOG_X = 40;
const DIALOG_W = G2_LENS_WIDTH - 80;
/** The screen less DIALOG_X on each side. */
function dialogW(): number {
return screenWidth() - 2 * DIALOG_X;
}
// The dialog fits inside the min-height window band (like the other shell
// overlays), wherever the vertical position setting puts it.
const DIALOG_MARGIN_Y = 28;
const DIALOG_H = MIN_WINDOW_HEIGHT - 2 * DIALOG_MARGIN_Y;
const TEXT_MAX_WIDTH = DIALOG_W - 32;
function dialogH(): number {
return minWindowHeight() - 2 * DIALOG_MARGIN_Y;
}
function textMaxWidth(): number {
return dialogW() - 32;
}
const TEXT_LEFT = DIALOG_X + 16;
// Menu row boxes: 4px left of the text column, 2px shorter than the row
// pitch, with each row's label inset 8px / 4px into its box.
const MENU_X = TEXT_LEFT - 4;
const MENU_W = DIALOG_W - 24;
function menuW(): number {
return dialogW() - 24;
}
const MENU_ROW_GAP = 2;
const MENU_LABEL_INSET_X = 8;
const MENU_LABEL_INSET_Y = 4;
@@ -89,28 +98,28 @@ export function paintInputDialog<T extends InputDialogRow>(image: GrayImage, con
// Solid dialog box over the underlying UI. Fill 1, not 0: identical after
// 4bpp quantization, but 0 is transparent on the color-key shell surface.
image.fillRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 1);
image.drawRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 90);
image.fillRect(DIALOG_X, top, dialogW(), dialogH(), 1);
image.drawRect(DIALOG_X, top, dialogW(), dialogH(), 90);
// Title and status share one header line, the status in the space after the title.
const left = TEXT_LEFT;
const headerY = top + 12;
image.drawText(font, left, headerY, content.title, 220);
const statusLeft = left + Math.ceil(font.measureText(content.title)) + HEADER_STATUS_GAP;
const statusWidth = TEXT_LEFT + TEXT_MAX_WIDTH - statusLeft;
const statusWidth = TEXT_LEFT + textMaxWidth() - statusLeft;
image.drawText(font, statusLeft, headerY, truncateText(font, content.status, statusWidth), content.statusValue ?? 130);
const menu = content.menu;
const rowCount = menu?.items.length ?? 0;
// Reserve space for the actual number of rows this menu has, or one row for the hint.
const reservedRows = rowCount > 0 ? rowCount : content.hint ? 1 : 0;
const textBottom = top + DIALOG_H - reservedRows * menuRowH - 8;
const textBottom = top + dialogH() - reservedRows * menuRowH - 8;
const textTop = headerY + font.lineHeight + 12;
const maxLines = Math.max(1, ((textBottom - textTop) / 16) | 0);
// The tail of a long message stays in view: it is what was said last (or
// where the phone keyboard is typing).
const wrapped = wrapText(font, content.text, TEXT_MAX_WIDTH);
const wrapped = wrapText(font, content.text, textMaxWidth());
const firstLine = Math.max(0, wrapped.length - maxLines);
for (let index = firstLine; index < wrapped.length; index++) {
image.drawText(font, left, textTop + (index - firstLine) * 16, wrapped[index]!, 235);
@@ -118,11 +127,11 @@ export function paintInputDialog<T extends InputDialogRow>(image: GrayImage, con
if (menu && rowCount > 0) {
// Row boxes are one pitch apart, the last ending 6px above the dialog's bottom edge.
const menuTop = top + DIALOG_H - rowCount * menuRowH - 4;
menu.paint(image, { x: MENU_X, y: menuTop, width: MENU_W, height: rowCount * menuRowH - MENU_ROW_GAP }, true);
const menuTop = top + dialogH() - rowCount * menuRowH - 4;
menu.paint(image, { x: MENU_X, y: menuTop, width: menuW(), height: rowCount * menuRowH - MENU_ROW_GAP }, true);
} else if (content.hint) {
// On the line the last menu row's label would occupy, floating in front of the dialog.
drawDepthText(image, font, truncateText(font, content.hint, TEXT_MAX_WIDTH), left, top + DIALOG_H - menuRowH, HINT_VALUE, HINT_DEPTH);
drawDepthText(image, font, truncateText(font, content.hint, textMaxWidth()), left, top + dialogH() - menuRowH, HINT_VALUE, HINT_DEPTH);
}
}
+12 -2
View File
@@ -40,12 +40,21 @@ export function modalRect(): { x: number; y: number; width: number; height: numb
export class ShellModalLayer implements Layer {
private readonly stack: LayerStack;
constructor(baseLayer: Layer, actions: LayerActions, private readonly removed?: () => void) {
constructor(
baseLayer: Layer,
actions: LayerActions,
private readonly hooks: {
/** The modal left the shell stack, however it went. */
removed?: () => void;
/** Input reached the modal (before its inner stack handles it). */
input?: (event: InputEvent) => void;
} = {},
) {
this.stack = new LayerStack(baseLayer, actions, modalInterior());
}
onRemoved(): void {
this.removed?.();
this.hooks.removed?.();
}
paint(_ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
@@ -73,6 +82,7 @@ export class ShellModalLayer implements Layer {
}
async handleInput(event: InputEvent, _ctx: LayerContext): Promise<void> {
this.hooks.input?.(event);
await this.stack.handleInput(event);
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ export function notificationPopupDelayMs(notification: { foregroundService?: boo
/** Runs `run` after `delayMs`; returns a function that cancels it. */
export type ScheduleFn = (run: () => void, delayMs: number) => () => void;
const scheduleTimeout: ScheduleFn = (run, delayMs) => {
export const scheduleTimeout: ScheduleFn = (run, delayMs) => {
const timer = setTimeout(run, delayMs);
return () => clearTimeout(timer);
};
@@ -0,0 +1,38 @@
import { scheduleTimeout, type ScheduleFn } from "./notification-popup-delay";
/**
* Closes a new-notification popup that is left untouched for its timeout
* ("Display new notifications"). The host restarts the countdown when the
* popup opens and on each interaction with it (any input, including moving
* its menu selection), and stops it when the popup goes away.
*/
export class NotificationPopupTimeout {
private cancel: (() => void) | null = null;
/** `timeoutMs` null never expires (the popup stays until dismissed). */
constructor(
private readonly timeoutMs: number | null,
private readonly expired: () => void,
private readonly schedule: ScheduleFn = scheduleTimeout,
) {}
/** Start the countdown over. */
restart(): void {
this.stop();
if (this.timeoutMs === null) return;
this.cancel = this.schedule(() => {
this.cancel = null;
this.expired();
}, this.timeoutMs);
}
stop(): void {
this.cancel?.();
this.cancel = null;
}
/** Whether a countdown is running (for tests). */
isRunning(): boolean {
return this.cancel !== null;
}
}
+43 -11
View File
@@ -1,5 +1,5 @@
import { encodeShellScene } from "../../graphics/shell-scene";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { GrayImage } from "../../graphics/image";
import { singlePlane, type Plane } from "../../graphics/plane";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { EvenAIStatus, EventSourceType, OsEventTypeList, WatchGestureType } from "../../g2/events";
@@ -49,8 +49,11 @@ import {
veniceWebSearchSetting,
batteryIndicatorSettingsKey,
brightnessSetting,
newNotificationDisplaySetting,
newNotificationDisplayTimeoutMs,
onAnySettingChanged,
openAiApiKeySetting,
shouldPopUpNewNotification,
statusBarPositionSetting,
statusBarVisibilitySetting,
timeFormatSetting,
@@ -70,8 +73,8 @@ import {
} from "./chrome-layer";
import { ShellModalLayer } from "./modal-layer";
import { NotificationModalQueue } from "./notification-modal-queue";
import { NotificationPopupTimeout } from "./notification-popup-timeout";
import { ALL_NOTIFICATIONS, readActiveNotifications } from "../../native/notification-icons";
import { shouldShowNotificationOnGlasses } from "../../native/notification-sources";
import { ToolDebugMenuLayer } from "./tool-debug-layer";
import type { InProcessWindow } from "./in-process-window";
import { BrightnessPickerLayer } from "./brightness-picker-layer";
@@ -87,6 +90,8 @@ import {
windowFramed,
windowTop,
type WindowHeightMode,
screenHeight,
screenWidth,
} from "./geometry";
import type { AppSwitcherPosition } from "../dashboard-settings";
@@ -169,6 +174,12 @@ export type ShellWindow = {
* they opened with when the bottom switcher changes height.
*/
relayout?: () => void;
/**
* The viewport size the window is laid out at (it changes on relayout), so
* the controller can tell a window whose size fell behind the geometry from
* one whose surface merely moved.
*/
layoutSize?: () => { width: number; height: number };
/**
* A touch from the phone's mirror at (x, y) in app-viewport coordinates.
* True if the window acted on it; otherwise the controller sends a select.
@@ -364,7 +375,10 @@ class ShellOverlayMenuLayer extends MenuLayer {
/** How long a show_alert popup stays before auto-dismissing. */
const ALERT_DISMISS_MS = 6000;
const ALERT_X = 40;
const ALERT_W = G2_LENS_WIDTH - 80;
/** Alert width: the screen less ALERT_X on each side. */
function alertW(): number {
return screenWidth() - 2 * ALERT_X;
}
const ALERT_Y = 96;
const ALERT_H = 96;
@@ -388,14 +402,14 @@ class ShellAlertLayer implements Layer {
const font = getDefaultSmallFont();
// Positioned within the min-height window band, like the other shell overlays.
const alertY = minWindowTop() + ALERT_Y;
image.fillRect(ALERT_X, alertY, ALERT_W, ALERT_H, 1);
image.drawRect(ALERT_X, alertY, ALERT_W, ALERT_H, 90);
image.fillRect(ALERT_X, alertY, alertW(), ALERT_H, 1);
image.drawRect(ALERT_X, alertY, alertW(), ALERT_H, 90);
image.drawText(font, ALERT_X + 16, alertY + 12, "Assistant", 200);
image.drawTextWrapped({
font,
x: ALERT_X + 16,
y: alertY + 18 + font.lineHeight + 4,
width: ALERT_W - 32,
width: alertW() - 32,
text: this.text,
value: 235,
});
@@ -482,7 +496,7 @@ class Shell {
isAvailable: (notificationKey) => {
if (this.appNotifications.has(notificationKey)) return true;
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
return !!notification && shouldShowNotificationOnGlasses(notification.packageName);
return !!notification && shouldPopUpNewNotification(notification.packageName);
},
sleep: () => this.sleep(),
});
@@ -936,18 +950,36 @@ class Shell {
const content = appNotification
? null
: new SingleNotificationLayer(notificationKey, { origin: "new-notification-modal", onClose: close });
// A phone notification's popup closes once left untouched for the
// "Display new notifications" time, as if closed by hand: the notification
// stays on the phone and in the status bar. An app's own notification
// (e.g. a Nightscout alert) is nowhere else to be found, so it stays up.
const timeout = new NotificationPopupTimeout(
appNotification ? null : newNotificationDisplayTimeoutMs(newNotificationDisplaySetting.get()),
() => {
// Something over the popup (a voice dialog, the system menu) is in
// use; count that as interaction rather than closing underneath it.
if (this.stack.topMatches((layer) => layer === popup.modal)) close();
else timeout.restart();
},
);
const popup: NotificationPopup = {
content,
modal: new ShellModalLayer(
appNotification ? appNotification.createLayer(close) : content!,
this.config.actions,
() => {
this.appNotifications.delete(notificationKey);
this.notificationModals.removed(popup, this.screenOn);
{
removed: () => {
timeout.stop();
this.appNotifications.delete(notificationKey);
this.notificationModals.removed(popup, this.screenOn);
},
input: () => timeout.restart(),
},
),
};
this.stack.push(popup.modal);
timeout.restart();
return popup;
}
@@ -984,7 +1016,7 @@ class Shell {
paintSurface(): Plane[] {
if (!this.screenOn) {
return singlePlane(new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0));
return singlePlane(new GrayImage(screenWidth(), screenHeight(), 0));
}
return this.stack.paint();
}
+44 -4
View File
@@ -79,6 +79,16 @@ export type WorkerAppReply =
/** Window height: the standard 288px band ("min", default) or full screen ("max"). */
heightMode?: WindowHeightMode;
}
| {
/**
* Move a window to another height band at runtime. The host resizes its
* surface and then always answers with resize-window, even if the size
* came out the same, so the worker can wait for the new viewport.
*/
type: "set-height-mode";
windowId: string;
heightMode: WindowHeightMode;
}
| { type: "set-title"; windowId: string; title: string }
| { type: "set-attention"; windowId: string; attention: boolean }
/** App-driven animation phase for sidebar icons that support an activity cursor. */
@@ -193,8 +203,12 @@ export type WorkerAppHostOptions = {
navigationSensors?: { handle(request: NavigationSensorRequest): void; stop(): void };
openUrl?: (url: string) => void;
playBuzzerSequence?: (payload: Uint8Array) => Promise<void> | void;
/** Create/refresh a window surface on the compositor (no-op when disconnected). */
configureSurface: (surfaceId: string, visible: boolean, heightMode: WindowHeightMode) => Promise<void>;
/**
* Create/refresh a window surface on the compositor (no-op when disconnected).
* `visible` may be a function, read once the surface is configured, for a
* window that can lose the foreground in the meantime.
*/
configureSurface: (surfaceId: string, visible: boolean | (() => boolean), heightMode: WindowHeightMode) => Promise<void>;
setSurfaceVisible: (surfaceId: string, visible: boolean) => void;
removeSurface: (surfaceId: string) => void;
requestShellRender: () => void;
@@ -320,6 +334,9 @@ export class WorkerAppHost {
heightMode: message.heightMode,
});
break;
case "set-height-mode":
this.setWindowHeightMode(message.windowId, message.heightMode);
break;
case "set-attention":
shell.setWindowAttention(message.windowId, message.attention);
break;
@@ -445,12 +462,13 @@ export class WorkerAppHost {
const surfaceId = `window:${spec.windowId}`;
const heightMode = spec.heightMode ?? "min";
this.openWindows.add(spec.windowId);
let viewport = appViewportSize(heightMode, this.options.appId);
this.post({
type: "open-window",
windowId: spec.windowId,
surfaceId,
title: spec.title,
viewport: appViewportSize(heightMode, this.options.appId),
viewport,
});
const window: ShellWindow = {
appId: this.options.appId,
@@ -463,7 +481,11 @@ export class WorkerAppHost {
// Every app worker resizes its live content in place, keeping its state
// (a game in progress, a route): the bottom switcher's height changes
// with what it holds, and full-height windows give way to it.
relayout: () => this.post({ type: "resize-window", windowId: spec.windowId, viewport: appViewportSize(heightMode, this.options.appId) }),
relayout: () => {
viewport = appViewportSize(window.heightMode, this.options.appId);
this.post({ type: "resize-window", windowId: spec.windowId, viewport });
},
layoutSize: () => viewport,
hasAppMenu: () => this.windowGestures.get(spec.windowId)?.hasAppMenu ?? false,
claimsLongPress: () => this.windowGestures.get(spec.windowId)?.claimsLongPress ?? false,
close: () => {
@@ -536,6 +558,24 @@ export class WorkerAppHost {
return window;
}
/** The worker asked for another height band (see set-height-mode). */
private setWindowHeightMode(windowId: string, heightMode: WindowHeightMode): void {
const window = this.openWindows.has(windowId) ? shell.getWindows().find((w) => w.windowId === windowId) : undefined;
if (!window) return;
window.heightMode = heightMode;
// Resize the surface first, so the frame answering resize-window fits it.
void this.options
.configureSurface(window.surfaceId, () => shell.foregroundWindow()?.windowId === windowId, heightMode)
.catch((error) => {
console.error(`surface resize for ${windowId} failed: ${error}`);
})
.then(() => {
window.relayout?.();
// The chrome (top bar, bottom switcher) follows the foreground's band.
this.options.requestShellRender();
});
}
/**
* Post a tool-call to the worker and resolve when its tool-result comes back.
* Resolves with a tool error on timeout so a hung worker yields a tool error