forked from Blendman974/faceclaw
Rebase firmware on 2.3.0, fixing issue with lost ring input events
This commit is contained in:
1 parent
8ceecb6393
commit
b972cd7682
21 files changed
+790
-156
No files matched your search
@@ -18,6 +18,8 @@ export type BaseInputEvent = {
|
||||
|
||||
/** The per-type part of InputEvent; makeInputEvent adds the BaseInputEvent fields. */
|
||||
export type InputEventPayload =
|
||||
/** Raw ring touch-down; a later interpreted gesture may follow. */
|
||||
| { type: "ring-press"; source: "ring" }
|
||||
| { type: "click"; source: InputSource }
|
||||
| { type: "double-click"; source: InputSource }
|
||||
/** Ring scroll (or a watch crown turn, then tagged source "watch"). */
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import type { InputEvent } from "./gestures";
|
||||
|
||||
type InputListener = (event: Readonly<InputEvent>) => void;
|
||||
const listeners = new Set<InputListener>();
|
||||
|
||||
/** Observe input before shell routing consumes menu, hold, or back gestures. */
|
||||
export function addInputListener(listener: InputListener): () => void {
|
||||
listeners.add(listener);
|
||||
return () => { listeners.delete(listener); };
|
||||
}
|
||||
|
||||
export function notifyInputListeners(event: InputEvent): void {
|
||||
if (!listeners.size) return;
|
||||
const snapshot = Object.freeze({ ...event });
|
||||
for (const listener of listeners) {
|
||||
try { listener(snapshot); }
|
||||
catch (error) { console.warn("Input observer failed", error); }
|
||||
}
|
||||
}
|
||||
|
||||
export type InputLogEntry = {
|
||||
event: Readonly<InputEvent>;
|
||||
gapMs: number | null;
|
||||
};
|
||||
|
||||
/** A bounded arrival-ordered history; equal timestamps must keep both events. */
|
||||
export class InputEventLog {
|
||||
readonly entries: InputLogEntry[] = [];
|
||||
paused = false;
|
||||
count = 0;
|
||||
private previousMs: number | null = null;
|
||||
|
||||
add(event: Readonly<InputEvent>): void {
|
||||
if (this.paused) return;
|
||||
this.entries.unshift({
|
||||
event: { ...event },
|
||||
gapMs: this.previousMs === null ? null : event.timestampMs - this.previousMs,
|
||||
});
|
||||
this.previousMs = event.timestampMs;
|
||||
this.count++;
|
||||
if (this.entries.length > 200) this.entries.length = 200;
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.entries.length = 0;
|
||||
this.previousMs = null;
|
||||
this.count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
export function inputTimestamp(timestampMs: number): string {
|
||||
const date = new Date(timestampMs);
|
||||
const two = (n: number) => String(n).padStart(2, "0");
|
||||
return `${two(date.getHours())}:${two(date.getMinutes())}:${two(date.getSeconds())}.${String(date.getMilliseconds()).padStart(3, "0")}`;
|
||||
}
|
||||
+21
-1
@@ -2,6 +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 type { RawInputEvent } from "../../native/faceclaw-communicator";
|
||||
import {
|
||||
directionalFallback,
|
||||
@@ -708,6 +709,7 @@ class Shell {
|
||||
}
|
||||
|
||||
async receiveInput(event: InputEvent, frameId = 0): Promise<ShellInputOutcome> {
|
||||
notifyInputListeners(event);
|
||||
try {
|
||||
return await this.routeInput(event, frameId);
|
||||
} finally {
|
||||
@@ -718,6 +720,16 @@ class Shell {
|
||||
}
|
||||
|
||||
private async routeInput(event: InputEvent, frameId: number): Promise<ShellInputOutcome> {
|
||||
// Touch-down supplements gestures. It must not wake the screen, operate
|
||||
// menus, or cancel the hold-to-escape timer. Apps can opt into it later.
|
||||
if (event.type === "ring-press") {
|
||||
const window = this.foregroundWindow();
|
||||
if (this.screenOn && this.focus === "window" && this.stack.isAtBase() && window) {
|
||||
await window.handleInput(event, frameId);
|
||||
return { shell: false, window: true };
|
||||
}
|
||||
return { shell: false, window: false };
|
||||
}
|
||||
const previous = this.lastInput;
|
||||
this.lastInput = event;
|
||||
// A visible window may paint a source-dependent indicator (see
|
||||
@@ -1545,7 +1557,13 @@ export function rawInputEventToInputEvent(event: RawInputEvent): InputEvent {
|
||||
|
||||
function rawInputEventToPayload(event: RawInputEvent): InputEventPayload {
|
||||
if (event.kind === "sys-event") {
|
||||
if (event.eventType === OsEventTypeList.CLICK_EVENT) {
|
||||
if (event.eventType === OsEventTypeList.RING_PRESS_EVENT &&
|
||||
(event.eventSource === EventSourceType.TOUCH_EVENT_FORM_DUMMY_NULL ||
|
||||
event.eventSource === EventSourceType.TOUCH_EVENT_FROM_RING)) {
|
||||
// The firmware emits this dedicated ID only for full raw source 4.
|
||||
// Its stock sender leaves the source unspecified for extension 14.
|
||||
return { type: "ring-press", source: "ring" };
|
||||
} else if (event.eventType === OsEventTypeList.CLICK_EVENT) {
|
||||
return {
|
||||
type: "click",
|
||||
source: eventSourceToString(event.eventSource),
|
||||
@@ -1627,6 +1645,8 @@ function eventSourceToString(eventSource: number): InputSource {
|
||||
|
||||
export function inputEventToString(event: InputEvent): string {
|
||||
switch (event.type) {
|
||||
case "ring-press":
|
||||
return "Ring press";
|
||||
case "click":
|
||||
return `Click from ${event.source}`;
|
||||
case "double-click":
|
||||
|
||||
Reference in new issue
Block a user