Stage 1 review fixes, and Stage 2: the broker, the CLI and the module
The Stage 1 review (docs/reviews/2026-10-04-stage1-review.md, verdict
yes-with-fixes) found a real bug, and it was the kind Stage 2 would have
cemented. All five findings:
(1) HIGH, and reproduced before fixing: `key` resolved the action and
then used only its `code`. So `keyboard key A` sent a bare code 30
and the window received `a`; on `de`, `at` lost its level-three mask
and typed `q`. `type` was the only path that used the mask, which is
why every `type` test stayed green. `key` now sends
modifiers(baseline | mask) before the down and restores the baseline
on the up -- the one-character `type` sequence -- and `Shift_L`
keeps its key-then-mask order, which is the other path on purpose.
The same hole aliased two names onto one keycode: `down A` then
`down a` recorded both and pressed 30 twice, Hyprland dropped the
second, and the held set lied until the lease ended. A second name
for a code already down is now refused.
(2) HIGH: the shutdown comment claimed hyprland-conf.nix sets
input:virtualkeyboard:release_pressed_on_close. It did not. The line
is there now, with the note that it releases keys and still never
clears a mask -- which is why release_all zeroes the mask on every
path we control rather than relying on it.
(3) MEDIUM: nothing would have noticed the keymap upload stopping. A
`main` that connected and listened without uploading passed every
test in the tree. Now asserted on the real sink: uploaded once,
before `listen` (one shared ordering log across both stand-ins), the
payload NUL-terminated with `size == len(utf8) + 1` read back
through the fd, format 1, one terminator not two, and modifiers(0)
straight after.
(4) LOW: `key` up now forgets the name only after a successful send,
like `button` -- otherwise a raise between the two leaves us
believing a key is up that the compositor still has down, and
release_all will not try again.
(5) LOW: `\r` no longer aliases to Return (CRLF would have become two
newlines silently), and an empty layout is refused -- xkbcommon
compiles "" as the same keymap as `us`, so `--xkb-layout ''` looked
configured and typed `us`.
Several of the review's named false passes are closed too: Control's
mask is compared against mod_get_index("Control") rather than merely
"not Shift's"; the keymap text assertion names pc_us_inet/pc_de_inet
instead of substring-matching "us"; the capital-under-Control case
asserts the whole sequence; the exit-code mirror is compared against
hhstreamd.protocol; and the module's defaults are read out of
nix/module.nix rather than asserted against themselves.
Stage 2 proper:
* broker verbs keyboard.key / keyboard.type, both in the mutation set,
both through _refresh (so they refresh the lease and, like every
pointer verb, do NOT count as activity)
* the driver's `kind` token mapped: a bad keysym or character is
invalid_argument (exit 2), a missing keyboard global stays
driver_refused (exit 10). The 4096-scalar cap and the shape checks
are broker-side, because only a broker-side invalid_argument is 2
* keys[] on pointer.state, keys_lifted[] on pointer.release and on
pointer_lease_timeout, one release_all for both halves
* CLI `session keyboard type|key|down|up`, reusing the pointer lease
and its cache; `type` takes one raw argument and interprets nothing;
the audit records a character count and never the text
* sessions.keyboard.{layout,model,variant,options} on the unit's argv,
layout defaulting to "us" with a type that refuses a comma. NO
[keyboard] TOML table: hhstreamd reads that file and the driver is a
different unit, so it would be a setting with no effect
* CONTRACT-sessions.md bumped to v3; README.dev.md item 3 and
vm-pointer.nix's header corrected (both still said the conf ships
follow_mouse = 0 and that the keyboard work would choose)
And the operator decision that acquire grabs both devices: it now sends
two warps a real pixel apart, because one warp onto an idle cursor moves
the cursor and not keyboard focus. follow_mouse_threshold = 0 is set
explicitly in hyprland-conf.nix since the second warp depends on it,
`dispatch focuswindow` is the fallback when the nudge cannot be sent,
and the reply and audit carry which mechanism ran. The acquire test
asserts the pair and that they floor to different pixels -- a test that
only saw wl_pointer.enter would pass while the first keystroke went to
the wrong window.
nix develop -c python -m pytest tests/pointer tests/sessions/unit -q
605 passed in 27.11s
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GhNPM6rGcuzxocM1nATnuM
This commit is contained in:
1 parent
b1f2744cf0
commit
e6f4c3bb3f
24 files changed
+2474
-105
No files matched your search
+120
-3
@@ -507,6 +507,109 @@ def test_an_ordinary_key_down_sends_no_mask(driver, sink):
|
||||
assert sink.calls == [("key", KEY_A, DOWN)]
|
||||
|
||||
|
||||
def test_key_of_a_capital_sends_the_mask_the_symbol_needs(driver, sink, us):
|
||||
"""`keyboard key A` must type `A`, not `a`.
|
||||
|
||||
The bug this locks: `key` resolved the action and then used only its
|
||||
`code`, so a keysym above level 0 went on the wire as a bare keypress and
|
||||
the window received the level-0 character. `A` typed `a`; on `de`, `at`
|
||||
lost its level-three mask and typed `q`. `type` was the only path that used
|
||||
the mask, so every `type` test stayed green.
|
||||
"""
|
||||
|
||||
assert driver.handle({"op": "key", "key": "A", "state": "down"})["keys"] == ["A"]
|
||||
assert sink.calls == [
|
||||
# Mask first, exactly as `type` does it: a client that decodes with the
|
||||
# mask from the last `wl_keyboard.modifiers` emits `a` otherwise.
|
||||
("modifiers", us.modifier_mask("Shift_L"), 0, 0, 0),
|
||||
("key", KEY_A, DOWN),
|
||||
]
|
||||
# And still no Shift keycode.
|
||||
assert not any(c[0] == "key" and c[1] == KEY_LEFTSHIFT for c in sink.calls)
|
||||
|
||||
|
||||
def test_the_up_of_a_capital_restores_the_baseline(driver, sink, us):
|
||||
driver.handle({"op": "key", "key": "A", "state": "down"})
|
||||
sink.calls.clear()
|
||||
|
||||
driver.handle({"op": "key", "key": "A", "state": "up"})
|
||||
|
||||
assert sink.calls == [("key", KEY_A, UP), ("modifiers", 0, 0, 0, 0)]
|
||||
assert driver.handle({"op": "pressed"})["keys"] == []
|
||||
|
||||
|
||||
def test_a_capital_is_not_treated_as_a_held_modifier(driver, sink):
|
||||
"""`A` held is a held *letter*, so `type` must refuse under it.
|
||||
|
||||
The distinction is why the held record stores what a key *contributes*
|
||||
rather than what it needs: storing `A`'s Shift requirement there would make
|
||||
a held capital look like a held modifier, and `type` would carry on and OR
|
||||
a Shift it did not ask for into every character.
|
||||
"""
|
||||
|
||||
driver.handle({"op": "key", "key": "A", "state": "down"})
|
||||
sink.calls.clear()
|
||||
|
||||
reply = driver.handle({"op": "type", "text": "b"})
|
||||
|
||||
assert reply["ok"] is False
|
||||
assert reply["kind"] == KIND_INVALID
|
||||
assert sink.calls == []
|
||||
|
||||
|
||||
def test_two_names_for_one_keycode_cannot_both_be_held(driver, sink):
|
||||
"""`A` and `a` are the same keycode at two levels.
|
||||
|
||||
Holding both sent `key(30, pressed)` twice. Hyprland drops the second
|
||||
because the code is already in its `m_pressed`, then `release_all` sends
|
||||
two ups of which one is also dropped -- so nothing visibly breaks and the
|
||||
held set is a lie for as long as the lease lasts. A refusal is better.
|
||||
"""
|
||||
|
||||
driver.handle({"op": "key", "key": "A", "state": "down"})
|
||||
sink.calls.clear()
|
||||
|
||||
reply = driver.handle({"op": "key", "key": "a", "state": "down"})
|
||||
|
||||
assert reply["ok"] is False
|
||||
assert reply["kind"] == KIND_INVALID
|
||||
assert "same key" in reply["error"]
|
||||
assert sink.calls == []
|
||||
assert driver.handle({"op": "pressed"})["keys"] == ["A"]
|
||||
|
||||
|
||||
def test_the_same_name_down_twice_is_still_one_key(driver):
|
||||
"""Not a clash with itself: a repeated `down` is idempotent, as for buttons."""
|
||||
|
||||
driver.handle({"op": "key", "key": "a", "state": "down"})
|
||||
assert driver.handle({"op": "key", "key": "a", "state": "down"})["ok"] is True
|
||||
assert driver.handle({"op": "pressed"})["keys"] == ["a"]
|
||||
|
||||
|
||||
def test_a_key_is_only_forgotten_after_the_up_reaches_the_sink(us):
|
||||
"""Order matters here for the same reason it does for `button`.
|
||||
|
||||
If the name were dropped before the send, a raise from the sink would leave
|
||||
us believing the key is up while the compositor still has it down -- and
|
||||
`release_all` would not try again, because the set is empty.
|
||||
"""
|
||||
|
||||
class _Breaking(RecordingSink):
|
||||
def key(self, code, state):
|
||||
if state == UP:
|
||||
raise RuntimeError("the keyboard went away")
|
||||
super().key(code, state)
|
||||
|
||||
driver = Dispatcher(_Breaking(), us)
|
||||
driver.handle({"op": "key", "key": "Shift_L", "state": "down"})
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
driver.handle({"op": "key", "key": "Shift_L", "state": "up"})
|
||||
|
||||
# Still held, so the next `release_all` will try the up again.
|
||||
assert driver.handle({"op": "pressed"})["keys"] == ["Shift_L"]
|
||||
|
||||
|
||||
# -- type -------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -574,8 +677,17 @@ def test_type_of_a_capital_under_a_held_control_ors_both_masks(driver, sink, us)
|
||||
driver.handle({"op": "type", "text": "A"})
|
||||
|
||||
both = us.modifier_mask("Control_L") | us.modifier_mask("Shift_L")
|
||||
assert sink.calls[0] == ("modifiers", both, 0, 0, 0)
|
||||
assert sink.calls[-1] == ("modifiers", us.modifier_mask("Control_L"), 0, 0, 0)
|
||||
# The whole sequence, not just the two masks: `modifiers(both)` followed by
|
||||
# `modifiers(control)` with no key events in between would satisfy a
|
||||
# first-and-last assertion while typing nothing at all.
|
||||
assert sink.calls == [
|
||||
("modifiers", both, 0, 0, 0),
|
||||
("key", KEY_A, DOWN),
|
||||
("key", KEY_A, UP),
|
||||
("modifiers", us.modifier_mask("Control_L"), 0, 0, 0),
|
||||
]
|
||||
# And no second Control down, and no Shift keycode.
|
||||
assert not any(c[0] == "key" and c[1] in (KEY_LEFTCTRL, KEY_LEFTSHIFT) for c in sink.calls)
|
||||
|
||||
|
||||
def test_type_while_a_non_modifier_is_held_emits_nothing(driver, sink):
|
||||
@@ -601,13 +713,18 @@ def test_type_while_a_lock_is_held_is_refused_too(driver, sink):
|
||||
driver.handle({"op": "key", "key": "Caps_Lock", "state": "down"})
|
||||
sink.calls.clear()
|
||||
|
||||
assert driver.handle({"op": "type", "text": "a"})["ok"] is False
|
||||
reply = driver.handle({"op": "type", "text": "a"})
|
||||
assert reply["ok"] is False
|
||||
# The caller's mistake, so exit 2 -- not `refused`, which would report a
|
||||
# held Caps_Lock as a compositor failure.
|
||||
assert reply["kind"] == KIND_INVALID
|
||||
assert sink.calls == []
|
||||
|
||||
|
||||
def test_a_string_that_fails_on_its_third_character_emits_nothing(driver, sink):
|
||||
reply = driver.handle({"op": "type", "text": "abé"})
|
||||
assert reply["ok"] is False
|
||||
assert reply["kind"] == KIND_INVALID
|
||||
# Not "no event carried é" -- that would also pass with a and b typed.
|
||||
assert sink.calls == []
|
||||
|
||||
|
||||
Reference in new issue
Block a user