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

@@ -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)
}
}