mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
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
@@ -63,6 +63,8 @@ class FaceclawWearBridge private constructor(context: Context) {
|
||||
const val PATH_STATE_REQUEST = "/faceclaw/state/request"
|
||||
/** Watch -> phone: the watch's own battery; carries no seq and is never acked. */
|
||||
const val PATH_WATCH_BATTERY = "/faceclaw/battery"
|
||||
/** Watch -> phone: touch-down ahead of a gesture; carries no seq and is never acked. */
|
||||
const val PATH_WATCH_PRESS = "/faceclaw/press"
|
||||
/** Phone -> watch: answered with PATH_WATCH_BATTERY even while the watch app is closed. */
|
||||
const val PATH_WATCH_BATTERY_REQUEST = "/faceclaw/battery/request"
|
||||
const val PATH_ACK = "/faceclaw/ack"
|
||||
@@ -331,6 +333,9 @@ class FaceclawWearBridge private constructor(context: Context) {
|
||||
// dashboard to receive it, it is simply dropped (the dashboard polls
|
||||
// again when it starts), and the watch does not expect an ack.
|
||||
if (PATH_WATCH_BATTERY == path) return
|
||||
// A touch-down only matters live; the gesture that follows it gets
|
||||
// the failure ack below.
|
||||
if (PATH_WATCH_PRESS == path) return
|
||||
|
||||
// No JS listener yet: tell the watch so it can explain why nothing is
|
||||
// happening. Only state requests are kept for replay (see class doc);
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -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]!);
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -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
@@ -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":
|
||||
|
||||
@@ -40,6 +40,9 @@ test('new SysEvent decodes independently of click, double-tap, hold and release'
|
||||
const decoded = d.rawInputEventToPayload({ kind: 'sys-event', eventType: 14, eventSource: source });
|
||||
assert.equal(decoded.type, 'ring-press'); assert.equal(decoded.source, 'ring');
|
||||
}
|
||||
// Synthetic watch touch-down (TOUCH_EVENT_FROM_WATCH, never sent by firmware).
|
||||
const watch = d.rawInputEventToPayload({ kind: 'sys-event', eventType: 14, eventSource: 4 });
|
||||
assert.equal(watch.type, 'ring-press'); assert.equal(watch.source, 'watch');
|
||||
for (const source of [1, 3, 99, undefined]) {
|
||||
assert.equal(d.rawInputEventToPayload({ kind: 'sys-event', eventType: 14, eventSource: source }).type, 'unknown');
|
||||
}
|
||||
@@ -192,3 +195,20 @@ test('debug history retains both clocks and uses unsigned gaps across counter wr
|
||||
assert.equal(log.entries[0].filtered,true);
|
||||
log.clear(); log.add(ring(1,500)); assert.equal(log.entries[0].ringGapTicks,null);
|
||||
});
|
||||
|
||||
test('PressTracker pairs each gesture with the touch-down that began it', () => {
|
||||
const { PressTracker } = load('app/ui/gestures.ts');
|
||||
const t = new PressTracker();
|
||||
const ev = (type, source) => ({ type, source, timestampMs: 0 });
|
||||
assert.equal(t.followsPress(ev('ring-press', 'watch')), false);
|
||||
assert.equal(t.followsPress(ev('click', 'watch')), true);
|
||||
// Input with no touch-down of its own (finger-pinch tap, crown, older watch app) still acts.
|
||||
assert.equal(t.followsPress(ev('click', 'watch')), false);
|
||||
// A press pairs only with the next event, and only from its own source.
|
||||
t.followsPress(ev('ring-press', 'watch'));
|
||||
assert.equal(t.followsPress(ev('click', 'left-arm')), false);
|
||||
assert.equal(t.followsPress(ev('click', 'watch')), false);
|
||||
// Stock ring scroll notifications omit their source.
|
||||
t.followsPress(ev('ring-press', 'ring'));
|
||||
assert.equal(t.followsPress({ type: 'scroll-up', timestampMs: 0 }), true);
|
||||
});
|
||||
@@ -20,37 +20,42 @@ function setup() {
|
||||
}
|
||||
test('single tap retains mirror coordinates and waits to disambiguate double tap', () => {
|
||||
const s = setup(); s.touch('down'); s.touch('up');
|
||||
assert.deepEqual(s.types(), []); s.advance(280);
|
||||
assert.deepEqual(s.events, [{ type: 'tap', x: 20, y: 30 }]);
|
||||
assert.deepEqual(s.types(), ['press']); s.advance(280);
|
||||
assert.deepEqual(s.events, [{ type: 'press', x: 20, y: 30 }, { type: 'tap', x: 20, y: 30 }]);
|
||||
});
|
||||
test('every first-finger touch-down presses; a far second touch flushes the pending tap first', () => {
|
||||
const s = setup(); s.touch('down'); s.touch('up'); s.advance(100);
|
||||
s.touch('down', 200, 30); s.touch('down', 201, 30, 2); s.touch('up', 201, 30, 2); s.touch('up', 200, 30); s.advance(1000);
|
||||
assert.deepEqual(s.types(), ['press', 'tap', 'press', 'double-tap']);
|
||||
});
|
||||
test('double tap emits back without accidental selection', () => {
|
||||
const s = setup(); s.touch('down'); s.touch('up'); s.advance(150);
|
||||
s.touch('down'); s.touch('up'); s.advance(1000);
|
||||
assert.deepEqual(s.types(), ['double-tap']);
|
||||
assert.deepEqual(s.types(), ['press', 'press', 'double-tap']);
|
||||
});
|
||||
test('a hold emits a press and release, never a tap', () => {
|
||||
const s = setup(); s.touch('down'); s.advance(500); s.touch('up'); s.advance(1000);
|
||||
assert.deepEqual(s.types(), ['long-press', 'long-press-release']);
|
||||
assert.deepEqual(s.types(), ['press', 'long-press', 'long-press-release']);
|
||||
});
|
||||
test('tap then hold emits the app-menu gesture without an earlier selection', () => {
|
||||
const s = setup(); s.touch('down'); s.touch('up'); s.advance(100);
|
||||
s.touch('down'); s.advance(500); s.touch('up'); s.advance(1000);
|
||||
assert.deepEqual(s.types(), ['short-then-long-press', 'long-press-release']);
|
||||
assert.deepEqual(s.types(), ['press', 'press', 'short-then-long-press', 'long-press-release']);
|
||||
});
|
||||
test('four directional swipes cancel pending holds and taps', () => {
|
||||
for (const [x, y, expected] of [[80, 30, 'swipe-right'], [-40, 30, 'swipe-left'], [20, 90, 'swipe-down'], [20, -30, 'swipe-up']]) {
|
||||
const s = setup(); s.touch('down'); s.touch('move', x, y); s.advance(500); s.touch('up', x, y); s.advance(500);
|
||||
assert.deepEqual(s.types(), [expected]);
|
||||
assert.deepEqual(s.types(), ['press', expected]);
|
||||
}
|
||||
});
|
||||
test('two fingers send back exactly once and cancel the long-press timer', () => {
|
||||
const s = setup(); s.touch('down'); s.touch('down', 21, 30, 2); s.advance(500);
|
||||
s.touch('up', 21, 30, 2); s.touch('up'); s.advance(1000);
|
||||
assert.deepEqual(s.types(), ['double-tap']);
|
||||
assert.deepEqual(s.types(), ['press', 'double-tap']);
|
||||
});
|
||||
test('cancellation prevents delayed selections and releases active holds', () => {
|
||||
const s = setup(); s.touch('down'); s.touch('up'); s.r.cancel(); s.advance(1000);
|
||||
assert.deepEqual(s.types(), []);
|
||||
assert.deepEqual(s.types(), ['press']);
|
||||
s.touch('down'); s.advance(500); s.touch('cancel'); s.advance(1000);
|
||||
assert.deepEqual(s.types(), ['long-press', 'long-press-release']);
|
||||
assert.deepEqual(s.types(), ['press', 'press', 'long-press', 'long-press-release']);
|
||||
});
|
||||
+6
-4
@@ -11,22 +11,24 @@ Capabilities (`res/values/wear.xml` on each side): the phone advertises
|
||||
`faceclaw_phone`, the watch `faceclaw_watch`. Each side finds the other with
|
||||
`CapabilityClient.getCapability(…, FILTER_REACHABLE)`.
|
||||
|
||||
Every watch → phone message except `/faceclaw/battery` carries `seq`
|
||||
(monotonic per watch process) and is answered on `/faceclaw/ack`.
|
||||
Every watch → phone message except `/faceclaw/battery` and `/faceclaw/press`
|
||||
carries `seq` (monotonic per watch process) and is answered on `/faceclaw/ack`.
|
||||
|
||||
## Watch → phone (MessageClient)
|
||||
|
||||
| Path | Payload | Effect |
|
||||
| --- | --- | --- |
|
||||
| `/faceclaw/input` | `{gesture, steps?}` | A ring gesture through the same path as the phone UI's test buttons. `gesture` ∈ `click`, `double-click`, `scroll-up`, `scroll-down`, `long-press` (complete short hold), `long-press-start`, `long-press-release`, `short-then-long-press` (tap then hold: the app's context menu; a plain `long-press` is the glasses' system menu), `wakeword` ("Hey Even"), `swipe-up`, `swipe-down`, `swipe-left`, `swipe-right` (spatial input only a watch can produce: delivered to the glasses UI as `swipe-*` events for components that navigate spatially — launcher grid, settings columns, sidebar, Music — with a scroll / click / double-click fallback elsewhere). `steps` (1–12) repeats a scroll. Refused while the glasses are disconnected. The lock screen is honoured exactly as for the ring. While the display is off, a double-click wakes the display, a `click` shows the phone's Glanceboard for a few seconds, and `long-press-start`/`long-press-release` hold it up; everything else is ignored. |
|
||||
| `/faceclaw/press` | none | A finger landed on the pad (each first-finger touch-down, the second tap of a double-tap included) or the stem button went down: delivered on the glasses as a `ring-press` from source `watch`, exactly like the R1 ring's touch-down, ahead of whatever gesture the touch becomes (which is still sent on `/faceclaw/input`). Components that act on touch-down (Flappy, Pinball) then ignore the gesture that follows. Sent only while the mirrored state says the glasses are connected with the display on. Carries no `seq` and is never acked; the phone drops it silently wherever the following gesture would be refused. |
|
||||
| `/faceclaw/command` | `{command, …}` | `launch-app {appId}`, `focus-window {windowId}`, `close-window {windowId}`, `sidebar`, `wake`, `sleep`, `lock`, `unlock`, `connect`, `disconnect`, `close-assistant`, `display-mode {value}` (`value` ∈ `576x288`, `576x480`, `640x480`; sets the phone's Display > Display mode). Everything but connect/disconnect needs a connection; everything but lock/unlock is refused while locked; `unlock` also needs the phone's "Watch can unlock glasses" setting. |
|
||||
| `/faceclaw/assistant` | `{text}` | Send a query to the assistant (`shell.sendToAssistant`) — the reply shows on the glasses and streams back to the watch as events. |
|
||||
| `/faceclaw/text` | `{text}` | Type text into the foreground window (`receiveTextInput`, e.g. the terminal). Refused when the window doesn't take text. |
|
||||
| `/faceclaw/state/request` | `{}` | Re-publish the state item even if unchanged. |
|
||||
| `/faceclaw/battery` | `{battery, charging}` | The watch's own battery (`battery` 0–100 or null, `charging` bool) for the glasses' top-bar and Glanceboard "Watch" indicator. Sent in answer to `/faceclaw/battery/request` by `PhoneListenerService` (which Play services starts even while the watch app is closed) and, while the app is open, whenever the level or charging state changes. Carries no `seq` and is never acked. |
|
||||
|
||||
All of the above except `state/request` and `battery` are refused with
|
||||
`ok:false` when the phone's "Watch remote control" setting is off.
|
||||
All of the above except `state/request`, `battery` and `press` are refused
|
||||
with `ok:false` when the phone's "Watch remote control" setting is off (a
|
||||
`press` is just dropped).
|
||||
|
||||
## Phone → watch
|
||||
|
||||
|
||||
@@ -142,6 +142,8 @@ class MainActivity : ComponentActivity() {
|
||||
// A dark display takes the stem too: a press shows the
|
||||
// phone's Glanceboard, a hold keeps it up until release.
|
||||
stemOneIgnored = false
|
||||
// Key-down is the stem's touch-down, as on the pad.
|
||||
link.sendPress()
|
||||
val runnable = Runnable {
|
||||
stemHoldSent = true
|
||||
haptics.heavy()
|
||||
|
||||
@@ -176,6 +176,25 @@ class PhoneLink(context: Context) :
|
||||
send(Protocol.PATH_INPUT, JSONObject().put("gesture", gesture.wire).put("steps", steps))
|
||||
}
|
||||
|
||||
/**
|
||||
* A finger landed: the phone delivers it as the ring's touch-down
|
||||
* (ring-press) ahead of whatever gesture the touch becomes. Fire-and-forget
|
||||
* and silent, since the gesture that follows reports any failure; skipped
|
||||
* unless the glasses are showing something for it to act on.
|
||||
*/
|
||||
fun sendPress() {
|
||||
if (state.value?.let { it.connected && it.screenOn } != true) return
|
||||
val nodeId = _link.value.phoneNodeId ?: return
|
||||
if (!_link.value.phoneAppInstalled) return
|
||||
Log.d(TAG, "send ${Protocol.PATH_PRESS}")
|
||||
try {
|
||||
messageClient.sendMessage(nodeId, Protocol.PATH_PRESS, ByteArray(0))
|
||||
.addOnFailureListener { error -> Log.w(TAG, "press failed", error) }
|
||||
} catch (error: Exception) {
|
||||
Log.w(TAG, "press failed", error)
|
||||
}
|
||||
}
|
||||
|
||||
fun sendCommand(command: String, vararg extras: Pair<String, String>) {
|
||||
val body = JSONObject().put("command", command)
|
||||
for ((key, value) in extras) body.put(key, value)
|
||||
|
||||
@@ -11,6 +11,8 @@ object Protocol {
|
||||
const val CAPABILITY_PHONE = "faceclaw_phone"
|
||||
|
||||
const val PATH_INPUT = "/faceclaw/input"
|
||||
/** Watch -> phone: a finger landed on the pad, ahead of the gesture it becomes; no seq, never acked. */
|
||||
const val PATH_PRESS = "/faceclaw/press"
|
||||
const val PATH_COMMAND = "/faceclaw/command"
|
||||
const val PATH_ASSISTANT = "/faceclaw/assistant"
|
||||
const val PATH_TEXT = "/faceclaw/text"
|
||||
|
||||
@@ -179,6 +179,7 @@ fun RemoteScreen(
|
||||
|
||||
val callbacks = remember(link, haptics) {
|
||||
TouchpadCallbacks(
|
||||
onPress = { link.sendPress() },
|
||||
onTap = { _ -> click() },
|
||||
onDoubleTap = { _ -> doubleClick() },
|
||||
onShortThenLongPress = {
|
||||
|
||||
@@ -12,6 +12,11 @@ import kotlin.math.abs
|
||||
|
||||
/** What the remote's touch surface can report. */
|
||||
class TouchpadCallbacks(
|
||||
/**
|
||||
* A finger landed (each first finger down, the second tap of a pair
|
||||
* included), before it is known what the touch will become.
|
||||
*/
|
||||
val onPress: () -> Unit,
|
||||
val onTap: (position: Offset) -> Unit,
|
||||
val onDoubleTap: (position: Offset) -> Unit,
|
||||
/** A tap whose immediate second press was held: the G2 tap-then-hold gesture. */
|
||||
@@ -65,7 +70,8 @@ class PendingTap {
|
||||
* once: tap, double-tap (a second tap inside the double-tap timeout), a hold
|
||||
* (reported at the long-press timeout and again on release), tap-then-hold (a
|
||||
* second tap held past the long-press timeout), a swipe, and a two-finger tap
|
||||
* or swipe. Written as a single awaitEachGesture loop because the stock
|
||||
* or swipe; each finger-down is also reported as it lands (a press), before
|
||||
* any of those is known. Written as a single awaitEachGesture loop because the stock
|
||||
* detectors would each claim the same finger. A press that pairs with
|
||||
* [pendingTap] skips straight to the second-tap handling.
|
||||
*/
|
||||
@@ -77,6 +83,7 @@ suspend fun PointerInputScope.detectTouchpadGestures(callbacks: TouchpadCallback
|
||||
awaitEachGesture {
|
||||
val down = awaitFirstDown()
|
||||
down.consume()
|
||||
callbacks.onPress()
|
||||
val downTime = down.uptimeMillis
|
||||
if (pendingTap.claim(downTime)) {
|
||||
secondTap(callbacks, longPressTimeout, down.position, down)
|
||||
@@ -139,6 +146,7 @@ suspend fun PointerInputScope.detectTouchpadGestures(callbacks: TouchpadCallback
|
||||
if (second == null) {
|
||||
callbacks.onTap(down.position)
|
||||
} else {
|
||||
callbacks.onPress()
|
||||
secondTap(callbacks, longPressTimeout, down.position, second)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user