forked from Blendman974/faceclaw
Forward ring input events before filtering, and include swipe info
This commit is contained in:
1 parent
b972cd7682
commit
7b19c00443
20 files changed
+368
-75
No files matched your search
+6
-2
@@ -1,3 +1,5 @@
|
||||
import type { RingInput } from "../g2/ring-input";
|
||||
|
||||
/**
|
||||
* Where an input came from. The ring and the glasses' arms are the stock
|
||||
* sources; "watch" is the Wear OS remote, which components may treat with a
|
||||
@@ -10,10 +12,12 @@ export type InputSource = "ring" | "left-arm" | "right-arm" | "watch";
|
||||
export type BaseInputEvent = {
|
||||
/**
|
||||
* When the event was received from the device (or synthesized), as a
|
||||
* Date.now() epoch-ms value. The G2 wire formats carry no device-side
|
||||
* clock, so this is phone receive time.
|
||||
* Date.now() epoch-ms value. This remains separate from the original
|
||||
* ring clock so app timers can continue comparing against Date.now().
|
||||
*/
|
||||
timestampMs: number;
|
||||
/** Present for unfiltered ring reports forwarded by Faceclaw/19. */
|
||||
ringInput?: RingInput;
|
||||
};
|
||||
|
||||
/** The per-type part of InputEvent; makeInputEvent adds the BaseInputEvent fields. */
|
||||
|
||||
+52
-7
@@ -1,26 +1,65 @@
|
||||
import type { InputEvent } from "./gestures";
|
||||
|
||||
type InputListener = (event: Readonly<InputEvent>) => void;
|
||||
type InputListener = (event: Readonly<InputEvent>, filtered: boolean) => void;
|
||||
const listeners = new Set<InputListener>();
|
||||
|
||||
/** Observe input before shell routing consumes menu, hold, or back gestures. */
|
||||
/** Observe every input before deduplication or wake/menu/app routing. */
|
||||
export function addInputListener(listener: InputListener): () => void {
|
||||
listeners.add(listener);
|
||||
return () => { listeners.delete(listener); };
|
||||
}
|
||||
|
||||
export function notifyInputListeners(event: InputEvent): void {
|
||||
export function notifyInputListeners(event: InputEvent, filtered = false): void {
|
||||
if (!listeners.size) return;
|
||||
const snapshot = Object.freeze({ ...event });
|
||||
const snapshot = Object.freeze({ ...event,
|
||||
...(event.ringInput ? { ringInput: Object.freeze({ ...event.ringInput }) } : {}) });
|
||||
for (const listener of listeners) {
|
||||
try { listener(snapshot); }
|
||||
try { listener(snapshot, filtered); }
|
||||
catch (error) { console.warn("Input observer failed", error); }
|
||||
}
|
||||
}
|
||||
|
||||
/** Reproduce G2 2.3.0's receiver filter in the original unsigned ring clock.
|
||||
* Press (wire 10) neither filters nor advances the clock; hold-release (8)
|
||||
* always passes and advances it. Rejected reports do not extend the window.
|
||||
* Backward ticks (including ring restart) use the same uint32 subtraction as
|
||||
* stock. Legacy, temple, and watch events have no raw metadata and pass through.
|
||||
*/
|
||||
export class RingInputFilter {
|
||||
private lastTick = 0;
|
||||
reset(): void { this.lastTick = 0; }
|
||||
accept(event: InputEvent): boolean {
|
||||
const raw = event.ringInput;
|
||||
if (!raw) return true;
|
||||
if (raw.type !== 8 && raw.type !== 10 && this.lastTick !== 0 &&
|
||||
((raw.tick - this.lastTick) >>> 0) < 100) return false;
|
||||
if (raw.type !== 10) this.lastTick = raw.tick;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
const ringFilter = new RingInputFilter();
|
||||
const decisions = new WeakMap<InputEvent, boolean>();
|
||||
export function resetRingInputFilter(): void { ringFilter.reset(); }
|
||||
|
||||
/** Controllers call before lock/glance handling; Shell also accepts direct
|
||||
* synthetic input. Cache by event identity so both stages observe/filter once.
|
||||
* Debug capture sees even rejected events, without sending them to other apps.
|
||||
*/
|
||||
export function acceptInput(event: InputEvent): boolean {
|
||||
const previous = decisions.get(event);
|
||||
if (previous !== undefined) return previous;
|
||||
const timingAccepted = ringFilter.accept(event);
|
||||
const accepted = timingAccepted && !(event.ringInput && event.type === "unknown");
|
||||
decisions.set(event, accepted);
|
||||
notifyInputListeners(event, !timingAccepted);
|
||||
return accepted;
|
||||
}
|
||||
|
||||
export type InputLogEntry = {
|
||||
event: Readonly<InputEvent>;
|
||||
gapMs: number | null;
|
||||
ringGapTicks: number | null;
|
||||
filtered: boolean;
|
||||
};
|
||||
|
||||
/** A bounded arrival-ordered history; equal timestamps must keep both events. */
|
||||
@@ -29,14 +68,19 @@ export class InputEventLog {
|
||||
paused = false;
|
||||
count = 0;
|
||||
private previousMs: number | null = null;
|
||||
private previousRingTick: number | null = null;
|
||||
|
||||
add(event: Readonly<InputEvent>): void {
|
||||
add(event: Readonly<InputEvent>, filtered = false): void {
|
||||
if (this.paused) return;
|
||||
this.entries.unshift({
|
||||
event: { ...event },
|
||||
event: { ...event, ...(event.ringInput ? { ringInput: { ...event.ringInput } } : {}) },
|
||||
filtered,
|
||||
ringGapTicks: !event.ringInput || this.previousRingTick === null ? null :
|
||||
(event.ringInput.tick - this.previousRingTick) >>> 0,
|
||||
gapMs: this.previousMs === null ? null : event.timestampMs - this.previousMs,
|
||||
});
|
||||
this.previousMs = event.timestampMs;
|
||||
if (event.ringInput) this.previousRingTick = event.ringInput.tick;
|
||||
this.count++;
|
||||
if (this.entries.length > 200) this.entries.length = 200;
|
||||
}
|
||||
@@ -44,6 +88,7 @@ export class InputEventLog {
|
||||
clear(): void {
|
||||
this.entries.length = 0;
|
||||
this.previousMs = null;
|
||||
this.previousRingTick = null;
|
||||
this.count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-5
@@ -2,7 +2,7 @@ import { G2_LENS_HEIGHT, G2_LENS_WIDTH, 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";
|
||||
import { notifyInputListeners } from "../input-monitor";
|
||||
import { acceptInput } from "../input-monitor";
|
||||
import type { RawInputEvent } from "../../native/faceclaw-communicator";
|
||||
import {
|
||||
directionalFallback,
|
||||
@@ -709,7 +709,7 @@ class Shell {
|
||||
}
|
||||
|
||||
async receiveInput(event: InputEvent, frameId = 0): Promise<ShellInputOutcome> {
|
||||
notifyInputListeners(event);
|
||||
if (!acceptInput(event)) return { shell: false, window: false };
|
||||
try {
|
||||
return await this.routeInput(event, frameId);
|
||||
} finally {
|
||||
@@ -1552,7 +1552,8 @@ function formatAssistantTime(date: Date): string {
|
||||
}
|
||||
|
||||
export function rawInputEventToInputEvent(event: RawInputEvent): InputEvent {
|
||||
return makeInputEvent(rawInputEventToPayload(event));
|
||||
return { ...makeInputEvent(rawInputEventToPayload(event)),
|
||||
...(event.ringInput ? { ringInput: { ...event.ringInput } } : {}) };
|
||||
}
|
||||
|
||||
function rawInputEventToPayload(event: RawInputEvent): InputEventPayload {
|
||||
@@ -1625,9 +1626,13 @@ function rawInputEventToPayload(event: RawInputEvent): InputEventPayload {
|
||||
};
|
||||
}
|
||||
|
||||
/** Scroll events only carry a source when it is the watch (the stock ones never needed one). */
|
||||
/** Preserve explicit sources; stock scroll notifications usually omit them. */
|
||||
function scrollEvent(type: "scroll-up" | "scroll-down", eventSource: number): InputEventPayload {
|
||||
return eventSource === EventSourceType.TOUCH_EVENT_FROM_WATCH ? { type, source: "watch" } : { type };
|
||||
return eventSource === EventSourceType.TOUCH_EVENT_FROM_WATCH ||
|
||||
eventSource === EventSourceType.TOUCH_EVENT_FROM_RING ||
|
||||
eventSource === EventSourceType.TOUCH_EVENT_FROM_GLASSES_L ||
|
||||
eventSource === EventSourceType.TOUCH_EVENT_FROM_GLASSES_R
|
||||
? { type, source: eventSourceToString(eventSource) } : { type };
|
||||
}
|
||||
|
||||
function eventSourceToString(eventSource: number): InputSource {
|
||||
|
||||
Reference in new issue
Block a user