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
@@ -114,10 +114,25 @@ def test_acquire_with_no_bookmark_aims_at_the_centre_of_the_container(harness):
|
||||
"output": "hh-foot-aaaaaa",
|
||||
"at": reply["bookmark"]["at"],
|
||||
}
|
||||
# TWO motions, and the order is the point. One warp onto an idle cursor
|
||||
# delivers wl_pointer.enter and no wl_keyboard.enter: Hyprland zeroes
|
||||
# `m_mousePosDelta` when the previous movement was over 0.5s ago, and
|
||||
# keyboard focus is that delta against `follow_mouse_threshold`. So the
|
||||
# nudge goes first and the real target second, the second motion carries a
|
||||
# non-zero delta, and the cursor finishes at the bookmark.
|
||||
assert harness.fake.sink.calls == [
|
||||
("warp", "hh-foot-aaaaaa", 0.5, 0.504),
|
||||
("frame", "hh-foot-aaaaaa"),
|
||||
("warp", "hh-foot-aaaaaa", 0.5, 0.5),
|
||||
("frame", "hh-foot-aaaaaa"),
|
||||
]
|
||||
# And the two really are different pixels at the frozen 1280x720 container
|
||||
# mode: `mouseMoveUnified` returns before it touches the delta when the
|
||||
# floored position has not changed, so a sub-pixel nudge would move the
|
||||
# cursor and leave the keys where they were.
|
||||
first, second = harness.fake.sink.of("warp")
|
||||
assert round(first[3] * 720) != round(second[3] * 720)
|
||||
assert reply["focus"] == "warp"
|
||||
|
||||
|
||||
def test_acquire_restores_the_position_the_session_was_left_at(harness):
|
||||
@@ -130,8 +145,15 @@ def test_acquire_restores_the_position_the_session_was_left_at(harness):
|
||||
reply = harness.run(harness.manager.pointer_acquire("foot-aaaaaa"))
|
||||
|
||||
assert (reply["bookmark"]["x"], reply["bookmark"]["y"]) == (0.25, 0.75)
|
||||
assert harness.fake.sink.of("warp") == [("warp", "hh-foot-aaaaaa", 0.25, 0.75)]
|
||||
# The nudge, then the restored position. The bookmark is where the cursor
|
||||
# is left, so the second warp is the one that has to be the bookmark --
|
||||
# the reverse order would restore the session a few pixels off, every time.
|
||||
assert harness.fake.sink.of("warp") == [
|
||||
("warp", "hh-foot-aaaaaa", 0.25, 0.754),
|
||||
("warp", "hh-foot-aaaaaa", 0.25, 0.75),
|
||||
]
|
||||
assert session.pointer["bookmark"]["x"] == 0.25
|
||||
assert session.pointer["bookmark"]["y"] == 0.75
|
||||
|
||||
|
||||
def test_restore_false_goes_to_the_centre_even_with_a_bookmark(harness):
|
||||
@@ -365,6 +387,10 @@ def test_an_idle_lease_expires_and_the_button_it_left_down_is_lifted(harness):
|
||||
"session": "foot-aaaaaa",
|
||||
"lease_id": lease,
|
||||
"buttons_lifted": ["left"],
|
||||
# Empty, and reported rather than omitted: this lease held no key, and
|
||||
# "no keys were lifted" is a different answer from "keys were not
|
||||
# considered".
|
||||
"keys_lifted": [],
|
||||
}
|
||||
assert harness.manager.pointer.state()["holder"] is None
|
||||
assert harness.fake.sink.calls[-2:] == [
|
||||
@@ -441,7 +467,8 @@ def test_expiry_with_no_driver_is_loud_rather_than_silent(harness, caplog):
|
||||
with caplog.at_level("ERROR"):
|
||||
harness.run(harness.manager._expire_pointer())
|
||||
|
||||
assert "a button may still be down" in caplog.text
|
||||
assert "they may still be held" in caplog.text
|
||||
assert "buttons ['left']" in caplog.text
|
||||
assert harness.manager.pointer.state()["holder"] is None
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user