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
+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