Add touch-down event to simulated and watch inputs

This commit is contained in:
James Babcock committed 2026-09-28 02:34:08 -07:00
1 parent 45d2ece0d2
commit 2052e268b0
19 files changed
+191 -35

No files matched your search

+19 -11
View File
@@ -17,8 +17,9 @@
* fall back to raster (the planner needs a non-negative origin), which is
* small and rare.
*
* Controls (a watch swipe in either direction is the primary flap):
* ring-press flaps immediately; watch swipes/clicks also flap. Double-click pauses;
* Controls: a touch-down on the ring or watch pad (ring-press) flaps
* immediately; a click, a watch swipe in either direction or a crown turn
* without one flaps too. Double-click pauses;
* tap-then-hold opens the window menu. Ready / paused / game over: click or
* a swipe starts or resumes, double-click yields focus. Losing input focus
* mid-flight (a shell overlay such as the system menu or a notification,
@@ -45,6 +46,7 @@ import {
GESTURE_CLICK,
GESTURE_DOUBLE_CLICK,
type InputEvent,
PressTracker,
} from "../../ui/gestures";
import { clamp } from "../../util/numeric-util";
import {
@@ -153,6 +155,8 @@ type FlappyWindow = {
lastMinorSfxAtMs: number;
soundOn: boolean;
lastSubmittedFingerprint: string;
/** Which gestures already flapped on their ring-press. */
presses: PressTracker;
};
const windows = new Map<string, FlappyWindow>();
@@ -210,6 +214,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
lastMinorSfxAtMs: 0,
soundOn: loadSoundEnabled("flappy"),
lastSubmittedFingerprint: "",
presses: new PressTracker(),
};
resetGame(window);
windows.set(message.windowId, window);
@@ -374,6 +379,7 @@ function windowMenu(window: FlappyWindow): WindowMenu {
// --- Input ------------------------------------------------------------------
function handleInput(window: FlappyWindow, event: InputEvent, frameId: number): void {
const followsPress = window.presses.followsPress(event);
// An open window menu owns all input (it closes itself via pop); menus are
// list UIs, so watch swipes take their standard fallback meanings there.
if (window.menu?.isOpen()) {
@@ -398,7 +404,7 @@ function handleInput(window: FlappyWindow, event: InputEvent, frameId: number):
switch (window.phase) {
case "ready":
case "playing":
handleFlightInput(window, event, frameId);
handleFlightInput(window, event, frameId, followsPress);
break;
case "dying":
// Let the tumble finish; a flap mashed during it must not restart.
@@ -410,22 +416,24 @@ function handleInput(window: FlappyWindow, event: InputEvent, frameId: number):
}
}
/** Input while ready or flying: the flap gestures, plus pause. */
function handleFlightInput(window: FlappyWindow, event: InputEvent, frameId: number): void {
/**
* Input while ready or flying: the flap gestures, plus pause. `followsPress`
* marks a gesture whose touch-down already flapped (see PressTracker).
*/
function handleFlightInput(window: FlappyWindow, event: InputEvent, frameId: number, followsPress: boolean): void {
switch (event.type) {
case "ring-press":
flap(window);
break;
// Either swipe direction flaps: on the watch the flap is a reflex, and
// which way the thumb went shouldn't matter.
case "swipe-up":
case "swipe-down":
case "ring-press":
flap(window);
break;
case "click":
// The ring already flapped on down; its later click must not flap again.
if (event.source !== "ring") flap(window);
if (!followsPress) flap(window);
break;
case "scroll-up":
if (event.source === "watch") flap(window);
if (event.source === "watch" && !followsPress) flap(window);
break;
case "double-click":
if (window.phase === "playing") {
+11 -4
View File
@@ -12,7 +12,8 @@
* keep the BLE payload down to the dirty region around the ball.
*
* Controls (ball ready): scroll sets launch power, click launches. In play:
* ring-press flips both flippers for 300 ms; click launches from the plunger,
* a touch-down (ring-press) flips both flippers for 300 ms, as does a click
* without one; click launches from the plunger,
* double-click pauses. Swipes no longer trigger individual flippers;
* up/down raise and lower launch power at the plunger.
* Paused/game over: click resumes or starts a new game, double-click yields
@@ -42,6 +43,7 @@ import {
GESTURE_DOUBLE_CLICK,
GESTURE_SCROLL,
type InputEvent,
PressTracker,
} from "../../ui/gestures";
import { clamp } from "../../util/numeric-util";
@@ -273,6 +275,8 @@ type PinballWindow = {
lastMinorSfxAtMs: number;
soundOn: boolean;
lastSubmittedFingerprint: string;
/** Which gestures already flipped on their ring-press. */
presses: PressTracker;
};
const windows = new Map<string, PinballWindow>();
@@ -336,6 +340,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
lastMinorSfxAtMs: 0,
soundOn: loadSoundEnabled("pinball"),
lastSubmittedFingerprint: "",
presses: new PressTracker(),
};
windows.set(message.windowId, window);
break;
@@ -491,6 +496,7 @@ function windowMenu(window: PinballWindow): WindowMenu {
}
function handleInput(window: PinballWindow, event: InputEvent, frameId: number): void {
const followsPress = window.presses.followsPress(event);
// An open window menu owns all input (it closes itself via pop); menus are
// list UIs, so watch swipes take their standard fallback meanings there.
if (window.menu?.isOpen()) {
@@ -502,13 +508,14 @@ function handleInput(window: PinballWindow, event: InputEvent, frameId: number):
}
if (window.phase === "playing") {
handlePlayingInput(window, event, frameId);
handlePlayingInput(window, event, frameId, followsPress);
} else {
handleIdleInput(window, event, frameId);
}
}
function handlePlayingInput(window: PinballWindow, event: InputEvent, frameId: number): void {
/** `followsPress` marks a gesture whose touch-down already flipped (see PressTracker). */
function handlePlayingInput(window: PinballWindow, event: InputEvent, frameId: number, followsPress: boolean): void {
const ready = window.ballState === "ready";
switch (event.type) {
case "scroll-up":
@@ -539,7 +546,7 @@ function handlePlayingInput(window: PinballWindow, event: InputEvent, frameId: n
case "click":
if (ready) {
launchBall(window);
} else if (event.source !== "ring") {
} else if (!followsPress) {
flip(window, window.flippers[0]!);
flip(window, window.flippers[1]!);
}
+12
View File
@@ -1838,6 +1838,8 @@ class DashboardController {
* test buttons, the watch). "long-press" is a complete short hold;
* "long-press-start" / "long-press-release" let a source with a real
* finger-down/finger-up (the watch) hold for as long as the user does.
* Such a source also sends "ring-press" at each finger-down, as the ring
* does before it knows which gesture the touch will become.
*/
async injectSyntheticRingInput(kind: WearRemoteInputKind, origin: SyntheticInputOrigin = "ring"): Promise<void> {
// Match the ring while the display is dark: a double-click wakes it
@@ -2831,6 +2833,7 @@ class DashboardController {
private buildSyntheticRingInput(
kind:
| "ring-press"
| "click"
| "double-click"
| "scroll-up"
@@ -2879,6 +2882,15 @@ class DashboardController {
systemExitReasonCode: 0,
frameId,
};
case "ring-press":
return {
kind: "sys-event",
containerName: "",
eventType: OsEventTypeList.RING_PRESS_EVENT,
eventSource,
systemExitReasonCode: 0,
frameId,
};
case "long-press":
return {
kind: "sys-event",
+3 -1
View File
@@ -490,10 +490,12 @@ export class IosPreviewController {
gesture(gesture: PhoneGesture, origin: 'watch' | 'ring' | 'mirror', nx = 0, ny = 0): void {
this.inputQueue = this.inputQueue.then(async () => {
if (!this.active) return
// A mirror tap may land on a hit target rather than being a gesture.
if (gesture === 'press' && origin === 'mirror') return
if (gesture === 'tap' && origin === 'mirror' && shell.isScreenOn() && !this.glassesLocked) {
await this.mirrorTap(nx, ny)
} else {
let type: string = ({ tap: 'click', 'double-tap': 'double-click' } as Record<string, string>)[gesture] ?? gesture
let type: string = ({ press: 'ring-press', tap: 'click', 'double-tap': 'double-click' } as Record<string, string>)[gesture] ?? gesture
if (origin === 'ring' && type.startsWith('swipe-')) {
if (type === 'swipe-left' || type === 'swipe-right') return
type = type === 'swipe-up' ? 'scroll-up' : 'scroll-down'
+12
View File
@@ -43,6 +43,8 @@ import { FACECLAW_VERSION } from "../version";
export const WEAR_PROTOCOL_VERSION = 1;
export type WearRemoteInputKind =
/** Touch-down at the start of any pad gesture; arrives on its own path (see handleMessage). */
| "ring-press"
| "click"
| "double-click"
| "scroll-up"
@@ -309,6 +311,16 @@ export class WearRemote {
this.setWatchBattery(valid ? battery : null, valid ? message.payload.charging === true : null);
return;
}
if (message.path === WEAR_PATHS.press) {
// Touch-down ahead of the gesture that follows it. Fire-and-forget like
// the battery (no seq, never acked): wherever that gesture would be
// refused, the press is dropped silently and the gesture's ack says why.
const phase = this.host.getState().phase;
if (watchRemoteEnabledSetting.get() && (phase === "connected" || phase === "charging")) {
await this.host.injectInput("ring-press");
}
return;
}
if (!watchRemoteEnabledSetting.get()) {
ack(false, "Watch control is turned off in Faceclaw's Settings > Watch.");
return;
+2
View File
@@ -16,6 +16,8 @@ declare const com: any;
export const WEAR_PATHS = {
/** Watch -> phone: a ring-style gesture. */
input: "/faceclaw/input",
/** Watch -> phone: a finger landed on the pad (the ring-press ahead of a gesture); never acked. */
press: "/faceclaw/press",
/** Watch -> phone: a shell command (launch app, wake, lock, ...). */
command: "/faceclaw/command",
/** Watch -> phone: a text query for the assistant. */
+12 -1
View File
@@ -1057,6 +1057,9 @@ export class MainViewModel extends RemoteControlsViewModel {
// and the finger-up sends the release, so a hold really holds (the
// Glanceboard stays up until the finger lifts). The firmware sends the
// same release after a tap-then-hold, so that pair gets one too.
//
// Every finger-down (the second tap of a pair included) first sends a
// ring-press, as the ring does before it knows what the touch will become.
private ringPadDoubleTapPending = false;
private ringPadHeld = false;
@@ -1077,6 +1080,10 @@ export class MainViewModel extends RemoteControlsViewModel {
}
async onRingPadTouch(args: TouchGestureEventData): Promise<void> {
if (args.action === "down" && args.getPointerCount() === 1) {
await dashboardController.injectSyntheticRingInput("ring-press");
return;
}
if (args.action !== "up" && args.action !== "cancel") return;
const pending = this.ringPadDoubleTapPending;
this.ringPadDoubleTapPending = false;
@@ -1148,11 +1155,15 @@ export class MainViewModel extends RemoteControlsViewModel {
this.refreshPadFocusLine();
}
/** Two fingers down and up without moving: back (the watch's two-finger tap). */
/**
* The first finger down sends a ring-press, as the watch pad does. Two
* fingers down and up without moving: back (the watch's two-finger tap).
*/
async onPadTouch(args: TouchGestureEventData): Promise<void> {
const count = args.getPointerCount();
if (args.action === "down" || args.action === "move") {
if (count >= 2) this.padTwoFingerDown = true;
else if (args.action === "down") await dashboardController.injectSyntheticRingInput("ring-press", "watch");
return;
}
if (args.action === "up" || args.action === "cancel") {
+3 -1
View File
@@ -1,7 +1,8 @@
/** One touch recognizer for a phone pad or mirror. Coordinates are in DIP. */
declare function setTimeout(callback: () => void, ms: number): number
declare function clearTimeout(id: number): void
export type PhoneGesture = 'tap' | 'double-tap' | 'long-press' | 'long-press-release'
/** 'press' is every first-finger touch-down, ahead of whatever gesture it becomes (the ring's ring-press). */
export type PhoneGesture = 'press' | 'tap' | 'double-tap' | 'long-press' | 'long-press-release'
| 'short-then-long-press' | 'swipe-up' | 'swipe-down' | 'swipe-left' | 'swipe-right'
export type PhoneTouch = { action: 'down' | 'move' | 'up' | 'cancel'; x: number; y: number; pointers: number }
export type GestureClock = { set: (callback: () => void, ms: number) => unknown; clear: (id: unknown) => void }
@@ -27,6 +28,7 @@ export class PhoneGestureRecognizer {
this.secondTap = !!this.lastTap && Math.hypot(event.x - this.lastTap.x, event.y - this.lastTap.y) < 36
if (this.secondTap) { this.clearTap() }
else if (this.lastTap) { const tap = this.lastTap; this.clearTap(); this.emit('tap', tap.x, tap.y) }
this.emit('press', event.x, event.y)
this.hold = this.timer.set(() => {
this.hold = null
if (!this.start || this.moved || this.multi) return
+34 -2
View File
@@ -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" }
+5 -1
View File
@@ -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":