Add support for short-then-long gesture to watch input and simulated inputs

This commit is contained in:
James Babcock committed 2026-08-31 20:42:49 -07:00
1 parent 6483d00647
commit 216dc59255
9 files changed
+93 -14

No files matched your search

+1 -1
View File
@@ -18,7 +18,7 @@ answered on `/faceclaw/ack`.
| 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`, `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, only a double-click is accepted and it wakes the display. |
| `/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 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, only a double-click is accepted and it wakes the display. |
| `/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. |
@@ -34,6 +34,8 @@ enum class Gesture(val wire: String) {
/** Finger down: the hold lasts until LONG_PRESS_RELEASE. */
LONG_PRESS_START("long-press-start"),
LONG_PRESS_RELEASE("long-press-release"),
/** Tap then hold: opens the glasses' system menu (G2 2.2.9 gesture). */
SHORT_THEN_LONG_PRESS("short-then-long-press"),
/** The spoken "Hey Even": opens the glasses' own voice dialog. */
WAKEWORD("wakeword"),
/**
@@ -190,6 +190,9 @@ fun RemoteScreen(
}
},
onDoubleTap = { _ -> doubleClick() },
onShortThenLongPress = {
if (!glassesScreenIsOff()) { haptics.heavy(); link.sendGesture(Gesture.SHORT_THEN_LONG_PRESS) }
},
// Two fingers = back as well: easier than timing a double-tap.
onTwoFingerTap = { doubleClick() },
onTwoFingerSwipe = { dx, dy ->
@@ -13,6 +13,8 @@ import kotlin.math.abs
class TouchpadCallbacks(
val onTap: (position: Offset) -> Unit,
val onDoubleTap: (position: Offset) -> Unit,
/** A tap whose immediate second press was held: the G2 tap-then-hold gesture. */
val onShortThenLongPress: () -> Unit,
val onTwoFingerTap: () -> Unit,
/** Two fingers travelled past touch slop; dx/dy are the primary finger's displacement. */
val onTwoFingerSwipe: (dx: Float, dy: Float) -> Unit,
@@ -25,9 +27,10 @@ class TouchpadCallbacks(
/**
* One detector for everything the pad does, so a gesture is reported exactly
* once: tap, double-tap (a second tap inside the double-tap timeout), a hold
* (reported at the long-press timeout and again on release), a swipe, and a
* two-finger tap or swipe. Written as a single awaitEachGesture loop because the
* stock detectors would each claim the same finger.
* (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
* detectors would each claim the same finger.
*/
suspend fun PointerInputScope.detectTouchpadGestures(callbacks: TouchpadCallbacks) {
val longPressTimeout = viewConfiguration.longPressTimeoutMillis
@@ -96,9 +99,32 @@ suspend fun PointerInputScope.detectTouchpadGestures(callbacks: TouchpadCallback
callbacks.onTap(down.position)
} else {
second.consume()
val up = waitForUpOrCancellation()
if (up != null) up.consume()
callbacks.onDoubleTap(down.position)
// Released within the long-press timeout it's a
// double-tap; held past it, the G2 tap-then-hold
// gesture (reported once at the timeout, movement
// tolerated, the rest of the hold swallowed).
var held = false
while (true) {
val remaining2 = if (held) {
HOLD_POLL_MS
} else {
longPressTimeout - (System.currentTimeMillis() - wallClockAt(second.uptimeMillis))
}
val event2 = withTimeoutOrNull(remaining2.coerceAtLeast(1L)) { awaitPointerEvent() }
if (event2 == null) {
if (!held) {
held = true
callbacks.onShortThenLongPress()
}
continue
}
if (event2.changes.any { it.isConsumed }) break
for (change in event2.changes) change.consume()
if (event2.changes.none { it.pressed }) {
if (!held) callbacks.onDoubleTap(down.position)
break
}
}
}
}
}