feat: add shared tilt-down hide and current-angle measurement

This commit is contained in:
Blendman974 committed 2026-11-06 22:01:21 +01:00
1 parent 5929259d84
commit f029e3ce91
21 files changed
+356 -24

No files matched your search

+11 -3
View File
@@ -12,11 +12,13 @@
/** Fallback press timeout when the host supplies none; each further press restarts it. */
export const GLANCE_TIMEOUT_MS = 3000;
export const GLANCE_TILT_MAX_MS = 60_000;
export type GlanceState = {
visible: boolean;
/** A long-press is holding the board up; the timer does not run meanwhile. */
holding: boolean;
tilted?: boolean;
/** When the board hides on its own (epoch ms), or null while held / hidden. */
hideAtMs: number | null;
};
@@ -24,6 +26,7 @@ export type GlanceState = {
export type GlanceEvent =
/** Single tap or head-tilt wake: show, and (re)start the auto-hide timer. */
| { type: "press" }
| { type: "tilt" }
/** Long-press: show and keep showing until the release. */
| { type: "hold" }
/** The long-press ended. */
@@ -44,12 +47,15 @@ export function reduceGlance(
switch (event.type) {
case "press":
// A tap during a hold changes nothing: the hold decides when it ends.
if (state.holding) return state;
if (state.holding || state.tilted) return state;
return { visible: true, holding: false, hideAtMs: nowMs + timeoutMs };
case "tilt":
return { visible: true, holding: state.holding, tilted: true, hideAtMs: state.holding ? null : nowMs + GLANCE_TILT_MAX_MS };
case "hold":
return { visible: true, holding: true, hideAtMs: null };
return { visible: true, holding: true, ...(state.tilted ? { tilted: true } : {}), hideAtMs: null };
case "release":
// Releases delivered late or after a disabled hold gesture mean nothing here.
if (state.holding && state.tilted) return { visible: true, holding: false, tilted: true, hideAtMs: nowMs + GLANCE_TILT_MAX_MS };
return state.holding ? GLANCE_HIDDEN : state;
case "timeout":
if (!state.visible || state.holding || state.hideAtMs === null || nowMs < state.hideAtMs) return state;
@@ -68,11 +74,13 @@ export function reduceGlance(
export function glanceEventForGesture(
gesture: "click" | "double-click" | "long-press" | "short-then-long-press" | "long-press-release" | "head-tilt" | (string & {}),
boardVisible: boolean,
tiltDownToHide = false,
): GlanceEvent | null {
switch (gesture) {
case "click":
case "head-tilt":
return { type: "press" };
case "head-tilt":
return { type: tiltDownToHide ? "tilt" : "press" };
case "long-press":
case "short-then-long-press":
return { type: "hold" };