From 58626ce146d89fdf2e6e8fc27add32f4bd1abad6 Mon Sep 17 00:00:00 2001 From: Brenden Date: Fri, 6 Nov 2026 12:47:46 -0800 Subject: [PATCH] Glanceboard: Head tilt timeout setting How long a head-tilt showing may last when no head-down arrives: 60 s (the default, as before), 30, 15, 10 s, or never (it then stays until the head comes down or a double-tap). Where the head-down is unlikely, the tap duration still applies when it is shorter. Co-Authored-By: Claude Opus 5.5 --- app/apps/app-definition.ts | 2 + app/apps/glanceboard/glanceboard-app.ts | 2 + app/apps/glanceboard/glanceboard-settings.ts | 25 ++++++++++ app/apps/glanceboard/index.ts | 2 + app/g2/dashboard-controller.ts | 3 +- app/g2/glance-host.ts | 3 +- app/g2/glance-state.ts | 49 +++++++++++++------- tests/glance-state.test.cjs | 25 +++++++--- 8 files changed, 86 insertions(+), 25 deletions(-) diff --git a/app/apps/app-definition.ts b/app/apps/app-definition.ts index 869cb374..e8616706 100644 --- a/app/apps/app-definition.ts +++ b/app/apps/app-definition.ts @@ -50,6 +50,8 @@ export type GlanceboardProvider = { showOnTap: () => boolean; /** How long a tap keeps the board up (and a head-tilt, when its head-down is unlikely to come). */ tapTimeoutMs: () => number; + /** How long a head-tilt showing may last without a head-down (null = no limit). */ + tiltTimeoutMs: () => number | null; /** Whether a long-press holds the board up until released. */ showOnLongPress: () => boolean; /** Whether the head-tilt wake goes to the board rather than the regular UI. */ diff --git a/app/apps/glanceboard/glanceboard-app.ts b/app/apps/glanceboard/glanceboard-app.ts index cecb75f3..93c1b360 100644 --- a/app/apps/glanceboard/glanceboard-app.ts +++ b/app/apps/glanceboard/glanceboard-app.ts @@ -30,6 +30,7 @@ import { glanceShowLinesSetting, glanceAngleSetting, glanceShowOnHeadTiltSetting, + glanceTiltTimeoutSetting, glanceShowOnLongPressSetting, glanceSlotChoiceLabel, glanceSlotSettings, @@ -322,6 +323,7 @@ function openGlanceSettings(ctx: LayerContext): void { enumSettingMenuItem(glanceTapDurationSetting), toggleSettingMenuItem(glanceShowOnLongPressSetting), toggleSettingMenuItem(glanceShowOnHeadTiltSetting), + enumSettingMenuItem(glanceTiltTimeoutSetting), // Only Android can change the glasses' head-up setting (glasses-controls.ts). // The controller's settings listener sends a new angle to the glasses. ...(headUpControlsAvailable() ? [enumSettingMenuItem(glanceAngleSetting), headAngleCaptureMenuItem()] : []), diff --git a/app/apps/glanceboard/glanceboard-settings.ts b/app/apps/glanceboard/glanceboard-settings.ts index 2584e87e..022ab30e 100644 --- a/app/apps/glanceboard/glanceboard-settings.ts +++ b/app/apps/glanceboard/glanceboard-settings.ts @@ -107,6 +107,31 @@ export const glanceShowOnHeadTiltSetting = new ConfigSettingBoolean({ description: "Tilting your head up while asleep shows the Glanceboard instead of waking the regular UI. It stays up until you look back down.", }); +export type GlanceTiltTimeout = "60s" | "30s" | "15s" | "10s" | "never"; + +/** + * How long a head-tilt showing may last if the head-down never comes (the + * board normally hides when the head comes back down). "never" removes the + * limit; a double-tap still dismisses the board. + */ +export const glanceTiltTimeoutSetting = new ConfigSettingEnum({ + id: "glanceboard-head-tilt-timeout", + label: "Head tilt timeout", + storageKey: "glanceboard.headTiltTimeout", + defaultValue: "60s", + values: ["60s", "30s", "15s", "10s", "never"], + formatValue: (value) => (value === "never" ? "Never" : value.replace("s", " s")), + description: + "The longest a head-tilt keeps the Glanceboard up when looking back down is not detected. Never: it stays until you look down or double-tap. " + + "When looking down is unlikely to register (a low Head tilt angle, or the display was suspended), the tap duration applies if shorter.", +}); + +/** The Head tilt timeout in ms, or null for none. */ +export function glanceTiltTimeoutMs(): number | null { + const value = glanceTiltTimeoutSetting.get(); + return value === "never" ? null : Number.parseInt(value, 10) * 1000; +} + const GLANCE_ANGLE_VALUES = ["glasses", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60"] as const; export type GlanceAngle = (typeof GLANCE_ANGLE_VALUES)[number]; diff --git a/app/apps/glanceboard/index.ts b/app/apps/glanceboard/index.ts index 65affdfa..2042cce1 100644 --- a/app/apps/glanceboard/index.ts +++ b/app/apps/glanceboard/index.ts @@ -9,6 +9,7 @@ import { glanceShowOnLongPressSetting, glanceShowOnTap, glanceTapTimeoutMs, + glanceTiltTimeoutMs, } from "./glanceboard-settings"; const glanceboardApp: AppDefinition = { @@ -24,6 +25,7 @@ const glanceboardApp: AppDefinition = { isEnabled: () => glanceboardEnabledSetting.get(), showOnTap: glanceShowOnTap, tapTimeoutMs: glanceTapTimeoutMs, + tiltTimeoutMs: glanceTiltTimeoutMs, showOnLongPress: () => glanceShowOnLongPressSetting.get(), showOnHeadTilt: () => glanceShowOnHeadTiltSetting.get(), depth: glanceDepth, diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index d68b41f5..3c257c87 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -22,7 +22,7 @@ import { openEvenAppSettings, readEvenAppNotificationState } from "../native/eve import { defaultRingName, setGlassesRingLink } from "../native/ring-status"; import { applyGlanceAngle, glassesHeadUpTrigger, syncGlanceAngleOriginal } from "./head-angle"; import { glanceAngleTriggerDegrees, glanceTapTimeoutMs } from "../apps/glanceboard/glanceboard-settings"; -import { glanceTiltMaxMs } from "./glance-state"; +import { GLANCE_TILT_MAX_MS, glanceTiltMaxMs } from "./glance-state"; import { getBooleanSetting, setBooleanSetting } from "../native/settings-store"; import { grayImageToPreviewSource } from "../native/gray-image-preview"; import { firmwareIncompatibilityMessage, hasCompatibleFirmware } from "./firmware-compat"; @@ -2542,6 +2542,7 @@ class DashboardController { const glanceEvent = this.glance.eventForGesture("head-tilt"); if (glanceEvent?.type !== "tilt") return glanceEvent; const maxMs = glanceTiltMaxMs({ + capMs: glanceEvent.maxMs === undefined ? GLANCE_TILT_MAX_MS : glanceEvent.maxMs, resumedSession: this.evenHubSessionSuspended || this.evenHubResumePromise !== null, triggerDegrees: glassesHeadUpTrigger() ?? (glanceAngleTriggerDegrees() || null), tapTimeoutMs: glanceTapTimeoutMs(), diff --git a/app/g2/glance-host.ts b/app/g2/glance-host.ts index f0349eb0..9a21c5f4 100644 --- a/app/g2/glance-host.ts +++ b/app/g2/glance-host.ts @@ -92,7 +92,8 @@ export class GlanceHost { if (gesture === "click" && !provider.showOnTap()) return null; if ((gesture === "long-press" || gesture === "short-then-long-press") && !provider.showOnLongPress()) return null; if (gesture === "head-tilt" && !provider.showOnHeadTilt()) return null; - return glanceEventForGesture(gesture, this.isVisible()); + const event = glanceEventForGesture(gesture, this.isVisible()); + return event?.type === "tilt" ? { type: "tilt", maxMs: provider.tiltTimeoutMs() } : event; } /** diff --git a/app/g2/glance-state.ts b/app/g2/glance-state.ts index 23e1f9ef..c63ad269 100644 --- a/app/g2/glance-state.ts +++ b/app/g2/glance-state.ts @@ -15,9 +15,10 @@ export const GLANCE_TIMEOUT_MS = 3000; /** - * Safety cap for a head-tilt showing: the board normally stays up until the + * Default cap for a head-tilt showing: the board normally stays up until the * head comes back down (as the stock dashboard does), but a lost head-down - * event must not leave it on forever. + * event should not leave it on indefinitely. The user's Head tilt timeout + * setting replaces it (and may remove it). */ export const GLANCE_TILT_MAX_MS = 60_000; @@ -29,17 +30,24 @@ export const GLANCE_TILT_MAX_MS = 60_000; export const GLANCE_LOW_TILT_TRIGGER_DEGREES = 25; /** - * How long a head-tilt showing may last without a head-down. The full cap, - * except when the head-down is unlikely to arrive, where the tap duration is - * used instead: a tilt that woke a suspended EvenHub session (the head-down - * is only forwarded once the page is back, so a quick glance can end before - * that), or a trigger too low for a level gaze to count as looking down. - * triggerDegrees is the glasses' trigger, or null when not known. + * How long a head-tilt showing may last without a head-down: capMs (the Head + * tilt timeout; null = no limit), except when the head-down is unlikely to + * arrive, where the tap duration is used if shorter: a tilt that woke a + * suspended EvenHub session (the head-down is only forwarded once the page is + * back, so a quick glance can end before that), or a trigger too low for a + * level gaze to count as looking down. triggerDegrees is the glasses' + * trigger, or null when not known. */ -export function glanceTiltMaxMs(options: { resumedSession: boolean; triggerDegrees: number | null; tapTimeoutMs: number }): number { +export function glanceTiltMaxMs(options: { + capMs: number | null; + resumedSession: boolean; + triggerDegrees: number | null; + tapTimeoutMs: number; +}): number | null { const lowTrigger = options.triggerDegrees !== null && options.triggerDegrees > 0 && options.triggerDegrees < GLANCE_LOW_TILT_TRIGGER_DEGREES; - return options.resumedSession || lowTrigger ? options.tapTimeoutMs : GLANCE_TILT_MAX_MS; + if (!options.resumedSession && !lowTrigger) return options.capMs; + return options.capMs === null ? options.tapTimeoutMs : Math.min(options.capMs, options.tapTimeoutMs); } export type GlanceState = { @@ -51,8 +59,8 @@ export type GlanceState = { * the head back down (or tiltMaxMs passes). */ tilted: boolean; - /** The current head-tilt's cap (0 when not tilted); a hold ending mid-tilt re-arms it. */ - tiltMaxMs: number; + /** The current head-tilt's cap (0 when not tilted, null for none); a hold ending mid-tilt re-arms it. */ + tiltMaxMs: number | null; /** When the board hides on its own (epoch ms), or null while held / hidden. */ hideAtMs: number | null; }; @@ -60,8 +68,11 @@ export type GlanceState = { export type GlanceEvent = /** Single tap: show, and (re)start the auto-hide timer. */ | { type: "press" } - /** Head-tilt (IMU head-up): show until the head comes back down, or maxMs (default GLANCE_TILT_MAX_MS). */ - | { type: "tilt"; maxMs?: number } + /** + * Head-tilt (IMU head-up): show until the head comes back down, or until + * maxMs passes (default GLANCE_TILT_MAX_MS; null = no limit). + */ + | { type: "tilt"; maxMs?: number | null } /** The IMU reported the head back down: ends a head-tilt showing. */ | { type: "head-down" } /** Long-press: show and keep showing until the release. */ @@ -87,8 +98,8 @@ export function reduceGlance( if (state.holding || state.tilted) return state; return { visible: true, holding: false, tilted: false, tiltMaxMs: 0, hideAtMs: nowMs + timeoutMs }; case "tilt": { - const maxMs = event.maxMs ?? GLANCE_TILT_MAX_MS; - return { visible: true, holding: state.holding, tilted: true, tiltMaxMs: maxMs, hideAtMs: state.holding ? null : nowMs + maxMs }; + const maxMs = event.maxMs === undefined ? GLANCE_TILT_MAX_MS : event.maxMs; + return { visible: true, holding: state.holding, tilted: true, tiltMaxMs: maxMs, hideAtMs: state.holding ? null : tiltHideAt(nowMs, maxMs) }; } case "head-down": // Only a head-tilt showing ends with the head; a tap's timer or a hold keeps running. @@ -101,7 +112,7 @@ export function reduceGlance( if (!state.holding) return state; // Head still up: the board stays, as if the tilt had just shown it. return state.tilted - ? { visible: true, holding: false, tilted: true, tiltMaxMs: state.tiltMaxMs, hideAtMs: nowMs + state.tiltMaxMs } + ? { visible: true, holding: false, tilted: true, tiltMaxMs: state.tiltMaxMs, hideAtMs: tiltHideAt(nowMs, state.tiltMaxMs) } : GLANCE_HIDDEN; case "timeout": if (!state.visible || state.holding || state.hideAtMs === null || nowMs < state.hideAtMs) return state; @@ -111,6 +122,10 @@ export function reduceGlance( } } +function tiltHideAt(nowMs: number, maxMs: number | null): number | null { + return maxMs === null ? null : nowMs + maxMs; +} + /** * Which glance event, if any, a shell input gesture means while the screen is * off. A double-tap only concerns the board while it is showing (it then diff --git a/tests/glance-state.test.cjs b/tests/glance-state.test.cjs index 7d753b04..af3c229e 100644 --- a/tests/glance-state.test.cjs +++ b/tests/glance-state.test.cjs @@ -106,11 +106,24 @@ test("a tilt with a shorter cap keeps it, also across a hold", () => { assert.equal(reduceGlance(held, { type: "release" }, T0 + 1000).hideAtMs, T0 + 1000 + 5000); }); -test("the tilt cap falls back to the tap duration where the head-down is unlikely", () => { +test("the tilt cap is the Head tilt timeout, or the tap duration if shorter where the head-down is unlikely", () => { const tapTimeoutMs = 5000; - assert.equal(glanceTiltMaxMs({ resumedSession: false, triggerDegrees: 30, tapTimeoutMs }), GLANCE_TILT_MAX_MS); - assert.equal(glanceTiltMaxMs({ resumedSession: false, triggerDegrees: null, tapTimeoutMs }), GLANCE_TILT_MAX_MS); - assert.equal(glanceTiltMaxMs({ resumedSession: true, triggerDegrees: 30, tapTimeoutMs }), tapTimeoutMs); - assert.equal(glanceTiltMaxMs({ resumedSession: false, triggerDegrees: 20, tapTimeoutMs }), tapTimeoutMs); - assert.equal(glanceTiltMaxMs({ resumedSession: false, triggerDegrees: 25, tapTimeoutMs }), GLANCE_TILT_MAX_MS); + const cap = (capMs, resumedSession, triggerDegrees) => glanceTiltMaxMs({ capMs, resumedSession, triggerDegrees, tapTimeoutMs }); + assert.equal(cap(60_000, false, 30), 60_000); + assert.equal(cap(15_000, false, null), 15_000); + assert.equal(cap(null, false, 30), null); + assert.equal(cap(60_000, true, 30), tapTimeoutMs); + assert.equal(cap(60_000, false, 20), tapTimeoutMs); + assert.equal(cap(null, false, 20), tapTimeoutMs); + assert.equal(cap(3000, true, 30), 3000); + assert.equal(cap(60_000, false, 25), 60_000); +}); + +test("a tilt with no timeout stays until the head-down, also across a hold", () => { + const up = reduceGlance(GLANCE_HIDDEN, { type: "tilt", maxMs: null }, T0); + assert.equal(up.hideAtMs, null); + assert.equal(reduceGlance(up, { type: "timeout" }, T0 + 3_600_000), up); + const held = reduceGlance(up, { type: "hold" }, T0 + 100); + assert.equal(reduceGlance(held, { type: "release" }, T0 + 1000).hideAtMs, null); + assert.deepEqual(reduceGlance(up, { type: "head-down" }, T0 + 9000), GLANCE_HIDDEN); });