Forward Remote punctuation keys by default

This commit is contained in:
ak47 committed 2026-11-07 19:00:51 -05:00
1 parent 8f51511801
commit a3c4e888c7
8 files changed
+139 -9

No files matched your search

+4
View File
@@ -38,6 +38,10 @@ a successful join adds the host, mode, key and any remembered certificate to
entry to fill Mode and Host; leave Key empty to use its saved key. The list
never shows or speaks a key. More options contains Forget recent connections,
explicit saved-key actions, certificate inspection and keyboard mapping.
Keyboard mapping includes US punctuation by default, including comma, period
and their shifted forms `<` and `>`. More options retains the limited
Letters, numbers and navigation mapping for sessions that need it. AltGr,
dead keys and other OEM layouts remain unsupported.
Uncheck Remember before connecting to keep a new key out of history. If saving
fails, Remote reports the failure and keeps the connection active.
+6
View File
@@ -8,6 +8,12 @@ ordinary saved settings. A channel key is saved by an explicit saved-key action
or, when Remember this host and key is checked, as a recent connection after a
successful join; abandoned, refused or failed attempts are never remembered.
Both roles forward all currently supported keys by default, including US
punctuation and its shifted forms. The Keyboard mapping list in More options
defaults to Include US punctuation. Letters, numbers and navigation explicitly
selects the limited portable mapping. AltGr, dead keys and other OEM layouts
remain unsupported.
Recent connections appears after Mode when any exist: up to ten host, port and
mode entries, newest first, in a private file with their keys and any
remembered certificate pin. Enter on an entry fills Mode and Host, and the
+7 -4
View File
@@ -13,7 +13,9 @@ release; a full 256-key queue stops the connection.
## Mapping contract
Construct an immutable map with an explicit profile:
Construct an immutable map with a selected profile. Connections default to `us`
so every currently supported key, including punctuation, is forwarded without
opening More options:
- `portable`: lowercase Latin letter key names, top-row digits, F1–F24,
left/right Shift, Control, Alt and Super, Menu, Caps Lock, Num Lock, Scroll
@@ -23,9 +25,10 @@ Construct an immutable map with an explicit profile:
0xA6–0xB7 (`XF86Back` through `XF86Calculator`; see `mediaKeys` in
`src/keyboard.go`). These are layout independent and sent extended, as
Windows does.
- `us`: the same keys plus the eleven US OEM punctuation key identities.
This requires an explicit US-layout agreement; it is never an automatic
fallback. OEM meanings on other layouts remain unsupported.
- `us` (default): the same keys plus the eleven US OEM punctuation key
identities. These use US-layout meanings on the Windows wire protocol;
other OEM layouts remain unsupported. More options can explicitly select
`portable` to omit those keys.
Input names must identify the unshifted key under the agreed layout, rather
than the resulting text. `a` names the letter key; `A`, `exclam`, `ISO_Left_Tab`,
-1
View File
@@ -312,7 +312,6 @@ func (command *connectionCommand) select_relay(ctx context.Context, raw json.Raw
}
workflow.key = key
workflow.remember = value.Values["remember"].Checked
workflow.profile = "portable"
if value.Activated == "connect" {
return workflow.submit(ctx, sdk.Submission{Activated: "connect"})
}
+43
View File
@@ -59,6 +59,49 @@ func TestRemoteCommandCollectsCredentialsBeforeApproval(t *testing.T) {
}
}
func TestRemoteCommandIncludesPunctuationByDefault(t *testing.T) {
for _, role := range []string{"controller", "controlled"} {
t.Run(role, func(t *testing.T) {
c, _ := fixtureCoordinator(t, nil)
store, _, saved := settingsFixture(t)
command := &connectionCommand{coordinator: c, store: store, selected: saved}
raw, _ := json.Marshal(sdk.Submission{Activated: "options", Values: map[string]sdk.Value{
"host": {Text: "relay.invalid"}, "role": {Selected: role},
}})
result, err := command.select_relay(t.Context(), raw)
if err != nil || command.workflow == nil {
t.Fatal("options did not open", err)
}
w := command.workflow
t.Cleanup(func() { w.close(); awaitDone(t, w.done) })
assertProfile := func(form sdk.Interaction, want string) {
t.Helper()
for _, element := range form.Form.Elements {
if element.ID == "key-profile" && len(element.Items) == 2 && element.Items[0].ID == want {
return
}
}
t.Fatalf("keyboard mapping did not select %s", want)
}
assertProfile(result.(sdk.Interaction), "us")
mapping := keyboardFixture(t, w.profile)
for _, name := range []string{"semicolon", "equal", "comma", "minus", "period", "slash", "grave", "bracketleft", "backslash", "bracketright", "apostrophe"} {
if _, err := mapping.toWire(name, true); err != nil {
t.Fatalf("default connection dropped %s: %v", name, err)
}
}
// An empty key keeps setup local while testing explicit profile choice.
limited, err := w.submit(t.Context(), sdk.Submission{Activated: "connect", Values: map[string]sdk.Value{
"key-profile": {Selected: "portable"},
}})
if err != nil || w.profile != "portable" {
t.Fatal("explicit portable selection was lost", err)
}
assertProfile(limited, "portable")
})
}
}
func TestRemoteCommandRejectsInvalidSelectionAndDropsEndpointPin(t *testing.T) {
c, _ := fixtureCoordinator(t, nil)
store, _, saved := settingsFixture(t)
+4 -4
View File
@@ -75,7 +75,7 @@ func new_connection_workflow(ctx context.Context, owner *coordinator, action sdk
}
lifetime, cancel := context.WithCancel(owner.ctx)
w := &connectionWorkflow{ctx: lifetime, cancel: cancel, done: make(chan struct{}), setupCtx: setupCtx,
owner: owner, action: approval, target: target, store: store, mode: "credentials", role: approval.Role}
owner: owner, action: approval, target: target, store: store, mode: "credentials", role: approval.Role, profile: defaultKeyboardProfile}
stopParent := context.AfterFunc(ctx, cancel)
go func() {
defer close(w.done)
@@ -152,8 +152,8 @@ func (w *connectionWorkflow) form_locked() sdk.Interaction {
}
elements = append(elements, sdk.Element{ID: "forget-recent", Label: "Forget recent connections and their keys", Kind: sdk.Button})
}
profiles := []sdk.ListItem{{ID: "portable", Label: "Letters, numbers and navigation"}, {ID: "us", Label: "Include US punctuation"}}
if w.profile == "us" {
profiles := []sdk.ListItem{{ID: "us", Label: "Include US punctuation"}, {ID: "portable", Label: "Letters, numbers and navigation"}}
if w.profile == "portable" {
profiles[0], profiles[1] = profiles[1], profiles[0]
}
elements = append(elements, sdk.Element{ID: "key-profile", Label: "Keyboard mapping", Kind: sdk.List, Items: profiles}, sdk.Element{ID: "cancel", Label: "Cancel", Kind: sdk.Button})
@@ -490,7 +490,7 @@ func new_setup_workflow(owner *coordinator, target endpoint, store *settingsStor
return nil, errLease
}
lifetime, cancel := context.WithCancel(owner.ctx)
w := &connectionWorkflow{ctx: lifetime, cancel: cancel, done: make(chan struct{}), setupCtx: lifetime, owner: owner, target: target, store: store, role: role, mode: "credentials", needsApproval: true}
w := &connectionWorkflow{ctx: lifetime, cancel: cancel, done: make(chan struct{}), setupCtx: lifetime, owner: owner, target: target, store: store, role: role, mode: "credentials", profile: defaultKeyboardProfile, needsApproval: true}
if target.pin != nil {
// A setup target's pin comes only from remembered trust.
w.savedPin = hex.EncodeToString(target.pin.sha256[:])
+4
View File
@@ -15,6 +15,10 @@ type wireKey struct {
var errKeyboard = errors.New("unsupported remote keyboard mapping")
// Include every supported key by default, including the US OEM punctuation
// identities. The portable profile remains an explicit limited alternative.
const defaultKeyboardProfile = "us"
// mediaKeys are VK 0xa6 (browser back) through 0xb7 (launch app 2).
var mediaKeys = []string{
"XF86Back", "XF86Forward", "XF86Reload", "XF86Stop", "XF86Search", "XF86Favorites",
+71
View File
@@ -256,3 +256,74 @@ func TestCoordinatorFocusRequiresCaptureGrant(t *testing.T) {
case <-time.After(200 * time.Millisecond):
}
}
func TestCoordinatorDefaultProfileForwardsPunctuationAndShift(t *testing.T) {
c, f := fixtureCoordinator(t, nil)
c.set_keyboard(defaultKeyboardProfile)
action := approveGrants(t, c, f, 1, "controller", "remote-present", "keyboard-capture")
received := make(chan string, 32)
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" })
// Comma, period, then Shift+comma and Shift+period, including a held-key
// repeat. Shift is forwarded separately so the peer receives < and >.
keys := []sdk.RemoteCapturedKey{
{Code: 59, Name: "comma", Pressed: true}, {Code: 59},
{Code: 60, Name: "period", Pressed: true}, {Code: 60},
{Code: 50, Name: "Shift_L", Pressed: true},
{Code: 59, Name: "comma", Pressed: true}, {Code: 59},
{Code: 60, Name: "period", Pressed: true},
{Code: 60, Pressed: true, Repeat: true}, {Code: 60}, {Code: 50},
}
for index, key := range keys {
f.events <- sdk.SessionEvent{Sequence: uint64(2 + index), Kind: "remote.input", Lease: strings.Repeat("b", 32), Epoch: 1, Input: &key}
}
wantVK := []int{0xbc, 0xbc, 0xbe, 0xbe, 0xa0, 0xbc, 0xbc, 0xbe, 0xbe, 0xbe, 0xa0}
for index, vk := range wantVK {
select {
case frame := <-received:
want, err := encodeMessage("key", keyTransition{VK: vk, Pressed: keys[index].Pressed})
if err != nil || frame != strings.TrimSpace(string(want)) {
t.Fatalf("frame %d = %s, want %s: %v", index, frame, want, err)
}
case <-time.After(4 * time.Second):
t.Fatalf("missing punctuation frame %d", index)
}
}
}
func TestCoordinatorDefaultProfileReceivesPunctuationAndShift(t *testing.T) {
c, f := fixtureCoordinator(t, nil)
c.set_keyboard(defaultKeyboardProfile)
action := approveGrants(t, c, f, 1, "controlled", "output-observe", "keyboard-inject")
vks := []int{0xbc, 0xbc, 0xbe, 0xbe, 0xa0, 0xbc, 0xbc, 0xbe, 0xbe, 0xa0}
names := []string{"comma", "comma", "period", "period", "Shift_L", "comma", "comma", "period", "period", "Shift_L"}
pressed := []bool{true, false, true, false, true, true, false, true, false, false}
frames := make([]string, len(vks))
for index, vk := range vks {
frames[index] = keyFrame(vk, pressed[index])
}
if err := c.connect(action, keyRelay(t, frames), "synthetic-fixture"); err != nil {
t.Fatal(err)
}
nextCall(t, f, "remote.open")
for index, name := range names {
var call readerCall
for {
select {
case call = <-f.calls:
case <-time.After(4 * time.Second):
t.Fatalf("missing punctuation call %d", index)
}
if call.method != "remote.heartbeat" {
break
}
}
request, ok := call.params.(sdk.RemoteKeyRequest)
if call.method != "remote.key" || !ok || request.Key.Name != name || request.Key.Pressed != pressed[index] {
t.Fatalf("call %d = %s %+v, want %s pressed %t", index, call.method, call.params, name, pressed[index])
}
}
}