forked from Blendman974/faceclaw
Add touch-down event to simulated and watch inputs
This commit is contained in:
1 parent
45d2ece0d2
commit
2052e268b0
19 files changed
+191
-35
No files matched your search
+34
-2
@@ -22,8 +22,14 @@ 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" }
|
||||
/**
|
||||
* Raw touch-down at the start of a touch gesture, before it is known
|
||||
* whether it becomes a tap, scroll, double tap or hold; a later interpreted
|
||||
* gesture may follow. Sent by the ring and by the watch's touchpad (and the
|
||||
* phone's stand-ins for both). Sources without a touch-down (the glasses'
|
||||
* arms, the watch crown or finger-pinch taps) never send one.
|
||||
*/
|
||||
| { type: "ring-press"; source: "ring" | "watch" }
|
||||
| { type: "click"; source: InputSource }
|
||||
| { type: "double-click"; source: InputSource }
|
||||
/** Ring scroll (or a watch crown turn, then tagged source "watch"). */
|
||||
@@ -79,6 +85,32 @@ export function isWatchInput(event: InputEvent): boolean {
|
||||
return "source" in event && event.source === "watch";
|
||||
}
|
||||
|
||||
/**
|
||||
* Pairs each gesture with the ring-press that began it, for components that
|
||||
* act on touch-down (a flap, a flip) and must not act a second time on the
|
||||
* gesture that follows. Feed it every input event. Input with no touch-down
|
||||
* of its own (the arms, the watch crown or finger-pinch taps, an older watch
|
||||
* app) never follows a press, so it still acts.
|
||||
*/
|
||||
export class PressTracker {
|
||||
private pressedSource: InputSource | null = null;
|
||||
|
||||
/** True when `event` is the gesture a ring-press from the same source already announced. */
|
||||
followsPress(event: InputEvent): boolean {
|
||||
if (event.type === "ring-press") {
|
||||
this.pressedSource = event.source;
|
||||
return false;
|
||||
}
|
||||
const pressed = this.pressedSource;
|
||||
this.pressedSource = null;
|
||||
if (pressed === null) return false;
|
||||
// Stock ring scroll notifications usually omit their source.
|
||||
const scroll = event.type === "scroll-up" || event.type === "scroll-down";
|
||||
const source = ("source" in event ? event.source : undefined) ?? (scroll ? "ring" : null);
|
||||
return source === pressed;
|
||||
}
|
||||
}
|
||||
|
||||
export type DirectionalInputEvent = Extract<
|
||||
InputEvent,
|
||||
{ type: "swipe-up" | "swipe-down" | "swipe-left" | "swipe-right" }
|
||||
|
||||
@@ -1569,6 +1569,10 @@ function rawInputEventToPayload(event: RawInputEvent): InputEventPayload {
|
||||
// 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.RING_PRESS_EVENT &&
|
||||
event.eventSource === EventSourceType.TOUCH_EVENT_FROM_WATCH) {
|
||||
// Synthetic: the watch pad's (or the phone's watch pad's) touch-down.
|
||||
return { type: "ring-press", source: "watch" };
|
||||
} else if (event.eventType === OsEventTypeList.CLICK_EVENT) {
|
||||
return {
|
||||
type: "click",
|
||||
@@ -1656,7 +1660,7 @@ function eventSourceToString(eventSource: number): InputSource {
|
||||
export function inputEventToString(event: InputEvent): string {
|
||||
switch (event.type) {
|
||||
case "ring-press":
|
||||
return "Ring press";
|
||||
return `Press from ${event.source}`;
|
||||
case "click":
|
||||
return `Click from ${event.source}`;
|
||||
case "double-click":
|
||||
|
||||
Reference in new issue
Block a user