diff --git a/remote.md b/remote.md index 6af83ca..9f3f97b 100644 --- a/remote.md +++ b/remote.md @@ -906,6 +906,36 @@ suites, build-script tests, the full Remote race suite and `make check` passed. No physical keyboard, desktop or NVDA peer was used. Physical collisions, provenance, lock/AltGr policy and all live acceptance remain open. +Fortieth to forty-second implementation increments (2026-11-06): controller +keyboard control. Reader `a789fb3` adds `remote.focus` requests and +`remote.focus`/`remote.input` events to the host and both SDKs; `fcffb8c` adds +an exclusive Xorg capture mode with the repeat normalizer and capture router, +a core F11 escape on the X thread, policy/overflow exits that release forwarded +keys first, suppressed local echo and app attachment for `keyboard-capture` +sessions; `fad8ef7` makes Remote shortcuts return the keyboard instead of racing +the focus change and adds reader announcements. See +[the capture contract](../cthulhu/docs/tentacle-remote-capture.md). + +In this repository the keyboard option now applies to both roles: a controller +requests `keyboard-capture`, and the new `remote-focus` command (suggested +Cthulhu+Ctrl+Shift+F) asks the reader to send this keyboard. Captured keys are +encoded with the existing epoch-bound encoder, keeping wire identities through +repeat/release; presses outside the agreed profile are ignored with their +repeats and releases. Status and scope text now name the granted keyboard +direction and current focus. Releases are not written after the connection +ends; the controlled reader releases injected keys when its lease ends. + +Checks: wire, host and Go/Python SDK conformance tests; a private Xvfb test with +XTEST input and a focused `xev` window (forwarding, pairing, prefix withdrawal, +shortcut exit, unsupported keys, F11, lock exit, no leaked keys; repeated runs); +app tests with a synthetic owner and real Go SDK child; coordinator tests with a +private TLS relay receiving encoded frames. The full reader suite passed on a +private D-Bus session; on the desktop session bus ten existing `TestRun*` tests +fail because the reader there sees the screen as locked, and they fail +identically at the earlier commit. The complete native input harness, Remote +race suite and `make check` passed. No physical keyboard, NVDA or Orca peer was +used; recovery from network loss mid-chord relies on controlled-side cleanup. + ## 1. Intended result and recommended approach Build a native Go Tentacle named **Remote**, with package ID `remote`, in this diff --git a/remote/README.md b/remote/README.md index 3a4d28e..91cca27 100644 --- a/remote/README.md +++ b/remote/README.md @@ -41,6 +41,10 @@ Implemented: failed-write cleanup with sequence-checked acknowledgements. Capture, injection, AltGr and native layout/held-key ownership remain pending; these are library prerequisites, not keyboard control. See [keyboard.md](keyboard.md). +- Controller keyboard control: with keyboard control approved, the + `remote-focus` command (Cthulhu+Ctrl+Shift+F) sends this keyboard through the + reader's exclusive capture; F11 or any Remote shortcut returns it. Live + acceptance is pending. See [command.md](command.md). - Controlled-role keyboard control: an explicit session-only option requests `keyboard-inject`; relay keys reach the reader's production input helper through `remote.key`. Live acceptance is pending. diff --git a/remote/command.md b/remote/command.md index 79cd5e5..82d85eb 100644 --- a/remote/command.md +++ b/remote/command.md @@ -285,3 +285,16 @@ arrives once. Hold Shift or Control on the controller and disconnect, lock the controlled desktop, and trigger XTerm handoff; afterwards confirm no modifier is stuck (for example with `xinput query-state` or by typing). Repeat without the keyboard option and confirm keys are ignored. + +## Controller keyboard live checks, pending + +On the controller choose **Control another computer** with keyboard control +checked and approve it in the reader dialog. Once the peer joins, press +Cthulhu+Ctrl+Shift+F: the reader should announce that the keyboard controls the +remote computer. Type into a remote text editor, use Shift+Tab, Insert/Caps +Lock reader commands and arrows, and confirm nothing reaches the local +application. Press F11 and confirm the keyboard returns with an announcement; +repeat with Cthulhu+Ctrl+Shift+R. Hold Shift on the controller, press F11, and +confirm Shift is not stuck on either computer. Lock the controller and trigger +XTerm handoff during remote focus; both must return the keyboard. On Windows +peers, check whether a withdrawn Alt prefix opens a menu bar. diff --git a/remote/keyboard.md b/remote/keyboard.md index 330b91f..ff2a722 100644 --- a/remote/keyboard.md +++ b/remote/keyboard.md @@ -93,6 +93,16 @@ encoder is not safe for concurrent mutation; its future owner must serialize events, acknowledgements and retirement. It has no automatic retry, consent, capture acquisition or native recovery mechanism. +## Controller capture + +With a controller `keyboard-capture` lease, `remote.input` events from the +reader's exclusive capture feed `key_output`, which uses this encoder and writes +frames to the relay, acknowledging each after its write. Presses the agreed +profile cannot represent are ignored with their repeats and release, so the +encoder never stops on them. `remote-focus` sends `remote.focus` through the +shared operation sequence. See +[the reader capture contract](../../cthulhu/docs/tentacle-remote-capture.md). + ## Incoming reader IPC `reader_key` converts an understood relay key through the selected immutable diff --git a/remote/src/command.go b/remote/src/command.go index 5c253b7..cd5ac18 100644 --- a/remote/src/command.go +++ b/remote/src/command.go @@ -59,12 +59,17 @@ func (command *connectionCommand) commands() []sdk.Command { {"remote-select", "Choose Remote relay and role", command.select_relay}, {"remote-approved", "Continue after reader-owned Remote approval", command.approved}, {"remote-connection", "Remote connection controls", command.submit}, + {"remote-focus", "Send this keyboard to the remote computer (F11 returns)", command.remote_focus}, } var commands []sdk.Command for _, entry := range entries { value := sdk.Command{ID: entry.id, Title: entry.title, Description: entry.title, Presentation: true, Interaction: true, Handle: entry.handler} - if entry.id == "remote" { + switch entry.id { + case "remote": value.Bindings = []sdk.Binding{{Layout: "desktop", Scope: "global", Key: "Cthulhu+Ctrl+Shift+R"}, {Layout: "laptop", Scope: "global", Key: "Cthulhu+Ctrl+Shift+R"}} + case "remote-focus": + value.Interaction = false + value.Bindings = []sdk.Binding{{Layout: "desktop", Scope: "global", Key: "Cthulhu+Ctrl+Shift+F"}, {Layout: "laptop", Scope: "global", Key: "Cthulhu+Ctrl+Shift+F"}} } commands = append(commands, value) } @@ -85,8 +90,8 @@ func (command *connectionCommand) selection_form(notice string) sdk.Interaction {ID: "host", Label: "Relay host", Kind: sdk.Entry, Text: command.selected.Host, MaxLength: 253}, {ID: "port", Label: "Relay port", Kind: sdk.Entry, Text: strconv.Itoa(command.selected.Port), MaxLength: 5}, {ID: "role", Label: "Connection role", Kind: sdk.List, Items: roles}, - {ID: "keyboard", Label: "When allowing access, also let the helper control this keyboard for this session", Kind: sdk.CheckBox, Checked: command.keyboard}, - {ID: "key-profile", Label: "Keys the helper may send", Kind: sdk.List, Items: profiles}, + {ID: "keyboard", Label: "Include keyboard control for this session: controlling sends this keyboard when remote focus is on; allowing access lets the helper type here", Kind: sdk.CheckBox, Checked: command.keyboard}, + {ID: "key-profile", Label: "Keys that may be sent", Kind: sdk.List, Items: profiles}, {ID: "review-access", Label: "Review access for this session", Kind: sdk.Button}, {ID: "save-settings", Label: "Save relay and role without connecting", Kind: sdk.Button}, }}, Next: "remote-select"} @@ -170,15 +175,16 @@ func (command *connectionCommand) select_relay(ctx context.Context, raw json.Raw return command.selection_form("Relay and role saved. No connection was started."), nil } grants := []string{"remote-present"} - command.coordinator.set_keyboard("") + keyboardGrant := "keyboard-capture" if selected.Role == "controlled" { - grants = []string{"output-observe"} - if command.keyboard { - // The reader's consent dialog discloses keyboard control separately; - // the profile limits which relay keys can be converted. - grants = append(grants, "keyboard-inject") - command.coordinator.set_keyboard(command.keyProfile) - } + grants, keyboardGrant = []string{"output-observe"}, "keyboard-inject" + } + command.coordinator.set_keyboard("") + if command.keyboard { + // The reader's consent dialog discloses keyboard control separately; + // the profile limits which keys can be converted in either direction. + grants = append(grants, keyboardGrant) + command.coordinator.set_keyboard(command.keyProfile) } command.awaiting = true return sdk.Interaction{Remote: &sdk.RemoteRequest{Role: selected.Role, Grants: grants}, Next: "remote-approved"}, nil @@ -256,3 +262,17 @@ func (command *connectionCommand) close() { <-barrier <-command.coordinator.done } + +// remote_focus asks the reader to send this keyboard to the remote computer. +// It only enters remote focus: F11 or any Remote shortcut returns it, handled +// by the reader without this process. +func (command *connectionCommand) remote_focus(ctx context.Context, _ json.RawMessage) (any, error) { + if ctx.Err() != nil { + return nil, ctx.Err() + } + if err := command.coordinator.request_focus(true); err != nil { + text := "Remote keyboard control needs a connected controller session with keyboard control approved." + return sdk.Presentation{Speech: text, Braille: text}, nil + } + return sdk.Presentation{Speech: "Requesting remote keyboard focus.", Braille: "Requesting remote keyboard focus."}, nil +} diff --git a/remote/src/command_test.go b/remote/src/command_test.go index 4098158..62f8986 100644 --- a/remote/src/command_test.go +++ b/remote/src/command_test.go @@ -20,7 +20,7 @@ func TestRemoteCommandSelectsEndpointWithoutAccessOrNetworking(t *testing.T) { store, _, saved := settingsFixture(t) command := &connectionCommand{coordinator: c, store: store, selected: saved} for _, entry := range command.commands() { - if entry.ID != "remote" && len(entry.Bindings) != 0 { + if entry.ID != "remote" && entry.ID != "remote-focus" && len(entry.Bindings) != 0 { t.Fatal("continuation has a shortcut") } } diff --git a/remote/src/connection_ui.go b/remote/src/connection_ui.go index accc56f..1ecb281 100644 --- a/remote/src/connection_ui.go +++ b/remote/src/connection_ui.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "errors" "net" + "slices" "strconv" "sync" @@ -106,7 +107,7 @@ func (w *connectionWorkflow) form_locked() sdk.Interaction { {ID: "endpoint", Label: "Relay: " + address}, {ID: "role", Label: "Approved role: " + w.action.Role}, {ID: "privacy", Label: "The relay can read the channel key and session contents. A channel key does not verify the other person's identity."}, - {ID: "scope", Label: "Experimental speech; live verification is pending. Keyboard, clipboard and Braille services are unavailable."}, + {ID: "scope", Label: session_scope_text(w.action)}, }} switch w.mode { case "credentials": @@ -151,6 +152,14 @@ func (w *connectionWorkflow) form_locked() sdk.Interaction { text := "This connection attempt has ended. Fresh local approval is required to connect again." if status.epoch == w.action.Epoch { text = connection_status_text(status) + if status.state == "ready" && slices.Contains(w.action.Grants, "keyboard-capture") { + switch status.focus { + case "remote": + text += " This keyboard controls the remote computer; F11 returns it." + default: + text += " This keyboard controls this computer. Use the Remote keyboard focus command to send it." + } + } } details.Items = append(details.Items, sdk.ListItem{ID: "status", Label: text}) result.Form = &sdk.Form{Title: "Remote relay status", Elements: []sdk.Element{details, @@ -171,6 +180,17 @@ func (w *connectionWorkflow) form_locked() sdk.Interaction { return result } +// session_scope_text names what this approved session can actually do. +func session_scope_text(action sdk.SessionEvent) string { + text := "Experimental speech" + if slices.Contains(action.Grants, "keyboard-capture") { + text += " and keyboard control of the remote computer" + } else if slices.Contains(action.Grants, "keyboard-inject") { + text += " and keyboard control of this computer by the helper" + } + return text + "; live verification is pending. Clipboard and Braille services are unavailable." +} + func connection_status_text(status connectionStatus) string { switch status.state { case "opening": @@ -178,9 +198,9 @@ func connection_status_text(status connectionStatus) string { case "connecting": return "Connecting and authenticating the relay." case "waiting": - return "Connected to the relay; waiting for one opposite-role peer. Experimental speech; keyboard, clipboard and Braille services are unavailable." + return "Connected to the relay; waiting for one opposite-role peer." case "ready": - return "One opposite-role peer has joined. Experimental speech; keyboard, clipboard and Braille services are unavailable." + return "One opposite-role peer has joined." case "stopping": return "Disconnecting and releasing the reader lease." case "failed": diff --git a/remote/src/connection_ui_test.go b/remote/src/connection_ui_test.go index f7b4cb8..4ef591a 100644 --- a/remote/src/connection_ui_test.go +++ b/remote/src/connection_ui_test.go @@ -155,7 +155,7 @@ func TestConnectionWorkflowConnectUsesLoadedKeyWithoutEcho(t *testing.T) { awaitStatus(t, c, func(s connectionStatus) bool { return s.state == "waiting" }) result = workflowSubmit(t, w, "refresh", "") encoded, _ := json.Marshal(result) - if !strings.Contains(string(encoded), "waiting for one opposite-role peer") || !strings.Contains(string(encoded), "keyboard, clipboard and Braille services are unavailable") { + if !strings.Contains(string(encoded), "waiting for one opposite-role peer") || !strings.Contains(string(encoded), "Clipboard and Braille services are unavailable") || strings.Contains(string(encoded), "keyboard control") { t.Fatal("status advertised desktop control or omitted waiting state") } if w.key != "" { diff --git a/remote/src/coordinator.go b/remote/src/coordinator.go index a2e135a..b4b0037 100644 --- a/remote/src/coordinator.go +++ b/remote/src/coordinator.go @@ -28,7 +28,8 @@ type connectionStatus struct { epoch uint64 peer int ignored uint64 - err error // Local constant errors only; never RPC/server diagnostic text. + focus string // Controller keyboard: "", "local" or "remote", as reported by core. + err error // Local constant errors only; never RPC/server diagnostic text. } type connectionAttempt struct { @@ -113,6 +114,10 @@ func (c *coordinator) read_events() { } case "remote.output": c.observe_locked(event) + case "remote.input": + c.capture_locked(event) + case "remote.focus": + c.focus_locked(event) } c.mu.Unlock() } @@ -378,6 +383,14 @@ func (c *coordinator) run(a *connectionAttempt, approval sdk.SessionEvent, e end outputDone = make(chan struct{}) go func() { defer close(outputDone) + if stream.capture_enabled() { + keysDone := make(chan struct{}) + go func() { + defer close(keysDone) + c.key_output(a, stream, conn) + }() + defer func() { <-keysDone }() + } c.speech_output(a, stream, conn) }() for a.ctx.Err() == nil { diff --git a/remote/src/keyboard_capture.go b/remote/src/keyboard_capture.go new file mode 100644 index 0000000..68b9440 --- /dev/null +++ b/remote/src/keyboard_capture.go @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package remote + +import ( + "slices" + + sdk "git.stormux.org/storm/cthulhu/sdk/go/tentacle" +) + +// maxCapturedKeys bounds queued plus in-flight controller transitions. A full +// queue stops the connection rather than dropping a release. +const maxCapturedKeys = 256 + +func (stream *speechStream) capture_enabled() bool { + return stream.mapping != nil && stream.role == "controller" && slices.Contains(stream.grants, "keyboard-capture") +} + +// capture_locked admits one transition from the reader's exclusive capture. +// Core supplies the origin; only events for this controller lease are taken. +// Pre-peer transitions are dropped: no down was sent for them. +func (c *coordinator) capture_locked(event sdk.SessionEvent) { + a := c.active + if a == nil || a.speech == nil || event.Input == nil { + return + } + stream := a.speech + if !stream.capture_enabled() || event.Lease != stream.lease.Lease || event.Epoch != stream.lease.Epoch || !c.speech_ready_locked(a, stream) { + return + } + if stream.capturedItems == maxCapturedKeys { + c.stop_locked(errLimit) + return + } + stream.capturedItems++ + stream.captured <- *event.Input // Capacity reserved above. +} + +func (c *coordinator) focus_locked(event sdk.SessionEvent) { + a := c.active + if a == nil || a.speech == nil || event.Lease != a.speech.lease.Lease || event.Epoch != a.speech.lease.Epoch { + return + } + c.status.focus = event.Focus +} + +// request_focus asks the reader to enter or leave remote focus. The sequenced +// operation owner sends it; the reader reports the actual state as an event. +func (c *coordinator) request_focus(remote bool) error { + c.mu.Lock() + defer c.mu.Unlock() + a := c.active + if a == nil || a.speech == nil || !a.speech.capture_enabled() || !c.speech_ready_locked(a, a.speech) { + return errLease + } + select { + case a.speech.focusRequests <- remote: + return nil + default: + return errLimit + } +} + +// key_output encodes captured transitions and writes them to the relay. The +// encoder retains each down's wire identity through repeats and release, so +// a layout change cannot strand a remote key. A press the agreed key profile +// cannot represent is ignored with its repeats and release. Releases are not +// written after the connection ends: the controlled side's reader releases +// every injected key when its own lease ends. +func (c *coordinator) key_output(a *connectionAttempt, stream *speechStream, conn *relayConn) { + encoder, err := newKeyboardEncoder(a.epoch) + if err != nil { + return + } + var ignored [256]bool + release := func() { + c.mu.Lock() + stream.capturedItems-- + c.mu.Unlock() + } + stop := func(err error) { + c.mu.Lock() + c.stop_locked(err) + c.mu.Unlock() + } + for { + select { + case <-a.ctx.Done(): + return + case key := <-stream.captured: + c.mu.Lock() + ready := c.speech_ready_locked(a, stream) + c.mu.Unlock() + if !ready { + release() + return + } + code := key.Code + if key.Pressed && !key.Repeat { + if _, err := stream.mapping.toWire(key.Name, true); err != nil { + ignored[code] = true + release() + continue + } + ignored[code] = false + } else if ignored[code] { + if !key.Pressed { + ignored[code] = false + } + release() + continue + } + plan, planned, err := encoder.apply(a.epoch, stream.mapping, keyboardEvent{code: code, name: key.Name, pressed: key.Pressed, repeat: key.Repeat}) + release() + if err != nil { + stop(errKeyboard) + return + } + if !planned { + continue + } + frame, err := encodeMessage("key", plan.key) + if err != nil { + stop(errProtocol) + return + } + if err := conn.write(a.ctx, frame); err != nil { + stop(err) + return + } + if err := encoder.acknowledge(a.epoch, plan.sequence); err != nil { + stop(errKeyboard) + return + } + } + } +} diff --git a/remote/src/keyboard_receive_test.go b/remote/src/keyboard_receive_test.go index e7dff1b..207ac8d 100644 --- a/remote/src/keyboard_receive_test.go +++ b/remote/src/keyboard_receive_test.go @@ -149,3 +149,110 @@ func TestCoordinatorKeyQueueOverflowStopsConnection(t *testing.T) { t.Fatal("overflow did not stop the connection", status.err) } } + +// controllerRelay joins one controlled peer and records the key frames it +// receives from this controller. +func controllerRelay(t *testing.T, received chan<- string) endpoint { + t.Helper() + cert, roots := testCertificate(t, true) + e := testRelay(t, cert, func(conn net.Conn) { + reader := relayHandshake(t, conn, controller) + if reader == nil { + return + } + _, _ = io.WriteString(conn, `{"type":"channel_joined","channel":"synthetic-fixture","clients":[{"id":7,"connection_type":"slave"}]}`+"\n") + for { + line, err := reader.ReadString('\n') + if err != nil { + return + } + if strings.Contains(line, `"type":"key"`) { + received <- strings.TrimSpace(line) + } + } + }) + e.roots = roots + return e +} + +func TestCoordinatorEncodesCapturedKeysAndRequestsFocus(t *testing.T) { + c, f := fixtureCoordinator(t, nil) + c.set_keyboard("portable") + action := approveGrants(t, c, f, 1, "controller", "remote-present", "keyboard-capture") + received := make(chan string, 16) + if err := c.connect(action, controllerRelay(t, received), "synthetic-fixture"); err != nil { + t.Fatal(err) + } + nextCall(t, f, "remote.open") + awaitStatus(t, c, func(s connectionStatus) bool { return s.state == "ready" }) + if err := c.request_focus(true); err != nil { + t.Fatal(err) + } + for { + call := <-f.calls + if call.method == "remote.heartbeat" { + continue + } + request, ok := call.params.(sdk.RemoteFocusRequest) + if call.method != "remote.focus" || !ok || !request.Remote || !sdk.ValidRemoteFocusRequest(request) { + t.Fatalf("bad focus call %s %+v", call.method, call.params) + } + break + } + lease := strings.Repeat("b", 32) + f.events <- sdk.SessionEvent{Sequence: 2, Kind: "remote.focus", Lease: lease, Epoch: 1, Focus: "remote", Reason: "requested"} + awaitStatus(t, c, func(s connectionStatus) bool { return s.focus == "remote" }) + for index, key := range []sdk.RemoteCapturedKey{ + {Code: 50, Name: "Shift_L", Pressed: true}, + {Code: 59, Name: "comma", Pressed: true}, // Not in the portable profile: ignored. + {Code: 59, Pressed: true, Repeat: true}, + {Code: 59}, + {Code: 38, Name: "a", Pressed: true}, + {Code: 38, Pressed: true, Repeat: true}, + {Code: 38}, + {Code: 50}, + } { + f.events <- sdk.SessionEvent{Sequence: uint64(3 + index), Kind: "remote.input", Lease: lease, Epoch: 1, Input: &key} + } + want := []string{ + `"vk_code":160`, `"vk_code":65`, `"vk_code":65`, `"vk_code":65`, `"vk_code":160`, + } + pressed := []string{"true", "true", "true", "false", "false"} + for index := range want { + select { + case frame := <-received: + if !strings.Contains(frame, want[index]) || !strings.Contains(frame, `"pressed":`+pressed[index]) { + t.Fatalf("frame %d = %s, want %s pressed %s", index, frame, want[index], pressed[index]) + } + case <-time.After(4 * time.Second): + t.Fatalf("missing frame %d", index) + } + } + select { + case frame := <-received: + t.Fatal("unexpected frame", frame) + case <-time.After(100 * time.Millisecond): + } +} + +func TestCoordinatorFocusRequiresCaptureGrant(t *testing.T) { + c, f := fixtureCoordinator(t, nil) + c.set_keyboard("portable") + action := approveGrants(t, c, f, 1, "controller", "remote-present") + received := make(chan string, 4) + if err := c.connect(action, controllerRelay(t, received), "synthetic-fixture"); err != nil { + t.Fatal(err) + } + nextCall(t, f, "remote.open") + awaitStatus(t, c, func(s connectionStatus) bool { return s.state == "ready" }) + if c.request_focus(true) == nil { + t.Fatal("focus requested without keyboard-capture") + } + key := sdk.RemoteCapturedKey{Code: 38, Name: "a", Pressed: true} + f.events <- sdk.SessionEvent{Sequence: 2, Kind: "remote.input", Lease: strings.Repeat("b", 32), Epoch: 1, Input: &key} + select { + case frame := <-received: + t.Fatal("key sent without keyboard-capture", frame) + case <-time.After(200 * time.Millisecond): + } +} diff --git a/remote/src/speech_stream.go b/remote/src/speech_stream.go index ad143a8..58ab07e 100644 --- a/remote/src/speech_stream.go +++ b/remote/src/speech_stream.go @@ -38,13 +38,18 @@ type speechStream struct { sequence uint64 keys chan sdk.RemoteKey // Controlled keyboard-inject only. keyItems int // Queued plus in-flight; coordinator.mu. - mapping *keyboardMap // Immutable; nil without keyboard-inject. + mapping *keyboardMap // Immutable; nil without a keyboard grant. + // Controller keyboard-capture only. + captured chan sdk.RemoteCapturedKey + capturedItems int // Queued plus in-flight; coordinator.mu. + focusRequests chan bool // Sent by speech_operations in sequence. } func newSpeechStream(lease sdk.RemoteLease, approval sdk.SessionEvent) *speechStream { return &speechStream{lease: lease, role: approval.Role, grants: slices.Clone(approval.Grants), incoming: make(chan speechItem, maxSpeechItems), outgoing: make(chan []byte, maxSpeechItems), - keys: make(chan sdk.RemoteKey, maxKeyItems)} + keys: make(chan sdk.RemoteKey, maxKeyItems), captured: make(chan sdk.RemoteCapturedKey, maxCapturedKeys), + focusRequests: make(chan bool, 4)} } func (stream *speechStream) keyboard_enabled() bool { @@ -62,6 +67,9 @@ func (stream *speechStream) drain() { stream.bytes -= len(frame) case <-stream.keys: stream.keyItems-- + case <-stream.captured: + stream.capturedItems-- + case <-stream.focusRequests: default: return } @@ -210,6 +218,21 @@ func (c *coordinator) speech_operations(a *connectionAttempt, stream *speechStre if !heartbeat() { return } + case remote := <-stream.focusRequests: + c.mu.Lock() + ready := c.speech_ready_locked(a, stream) + c.mu.Unlock() + if !ready { + return + } + stream.sequence++ + request := sdk.RemoteFocusRequest{RemoteOperation: sdk.RemoteOperation{Lease: stream.lease.Lease, Epoch: a.epoch, Sequence: stream.sequence}, Remote: remote} + if c.call("remote.focus", request, nil) != nil { + c.mu.Lock() + c.stop_locked(errLease) + c.mu.Unlock() + return + } case key := <-stream.keys: select { case <-ticker.C: