Stage 1: the driver learns to type

`zwp_virtual_keyboard_v1`, spoken by the process that already speaks
`zwlr_virtual_pointer_v1`. One device for the seat, one keymap uploaded
once, keysym names on our socket and evdev codes only on the Wayland
request -- the division buttons.py already draws.

keymap.py is the new seam, and it holds the three decisions that have a
wrong version which looks right:

  * A capital is the MASK, not a synthetic Shift keycode. Hyprland's
    virtual keyboard never runs updateXkbStateWithKey, so a virtual
    KEY_LEFTSHIFT changes no modifier state at all -- and sending both
    is how a toolkit applies Shift twice.
  * A modifier is whatever the keymap says is one, measured by pressing
    each key in a throwaway xkb state. Not a name list: `@` on `de` is a
    level-three symbol, and a Shift-only special case types the wrong
    character. (The measured set is also smaller than the canonical one,
    because no keycode on us/pc105 carries Meta or Hyper.)
  * A lock is not a modifier. Caps_Lock reports a *locked* mask, so
    `type` refuses while it is held rather than guessing the case.

The whole string resolves before anything is emitted, and every refusal
names the scalar INDEX, never the character: these messages reach the
driver's log and the string is a password as often as not.

Folding in the review's changes 1, 2, 3 and 6:

  1 a Rejected now carries a `kind`. A bad keysym or an unmappable
    character is `invalid_argument`; a missing keyboard global is
    `refused`. Without the token the broker would have to tell exit 2
    from exit 10 by reading English, and _drive maps every `ok: false`
    to driver_refused today.
  2 the keymap `size` on the wire includes the trailing NUL, and the fd
    outlives a roundtrip rather than a flush. Hyprland mmaps exactly
    that many bytes and hands the pointer to xkb_keymap_new_from_string.
  3 release_all lifts buttons, then keys in press order, then zeroes the
    mask -- and the mask only if something set it, so a compositor with
    no keyboard global still gets its buttons lifted. One release_all is
    the whole of expiry; an exception in the key half would abandon it.
  6 `key` and `type` never call _aimed(). A keyboard has no output, and
    one test deliberately never warps so that stays true.

Also: `--xkb-layout/-model/-variant/-options`, compiled BEFORE any
Wayland call so a bad layout is exit 2 rather than exit 10; a comma in
the layout refused outright, because v1 always sends group 0 and
xkbcommon would hand back a second group nothing could reach; the
keymap uploaded after connect and before listen, with one
modifiers(0,0,0,0) after it; and xkbcommon as a hard, non-optional
dependency -- an optional one would let test_keymap.py skip, and the
unmappable-character path is the one that must not rot.

  nix develop -c python -m pytest tests/pointer tests/sessions/unit -q
  549 passed in 25.70s

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GhNPM6rGcuzxocM1nATnuM
This commit is contained in:
HermenixandClaude Opus 5 committed 2026-10-04 03:39:00 +00:00
1 parent 19e484b388
commit f931858f30
19 files changed
+2461 -107

No files matched your search

+144
View File
@@ -0,0 +1,144 @@
"""The driver's XKB flags — the only path a layout has to the uploaded keymap.
This file exists where a `tests/sessions/unit/test_settings.py` case would have
gone, and that is the point. The broker's TOML is read by `hhstreamd` for its
lease numbers; `hhstream-pointer` is a different unit and never opens that
file. So a `[keyboard]` table there would be a setting an operator could change
with no effect at all, and a test asserting its default would be green while
every injected key stayed on `us`.
The layout therefore arrives as `--xkb-layout`, and these are the assertions
about that flag: what it defaults to, that a bad value is exit **2**, and that
a bad value is exit 2 **without the compositor being touched** — because a
layout xkbcommon will not compile is the operator's typo, and reporting it as
exit 10 sends them to the wrong unit.
"""
from __future__ import annotations
import pytest
from hhstream_pointer import __main__ as entry
class _Unreached(Exception):
"""Raised if the Wayland side is reached when it should not have been."""
class _RefusingSink:
"""A sink that fails the test if anything asks it to talk to a compositor.
The review asked for an injected connect that can be asserted *not* to have
been called; this is that, as a type rather than a flag, so a future code
path that connects earlier fails loudly instead of silently reordering
start-up.
"""
instances = 0
def __init__(self, runtime_dir, display_name=None) -> None:
type(self).instances += 1
def connect(self) -> None:
raise _Unreached("connect")
def upload_keymap(self, text: str) -> None:
raise _Unreached("upload_keymap")
def close(self) -> None:
pass
@pytest.fixture
def no_compositor(monkeypatch):
_RefusingSink.instances = 0
monkeypatch.setattr(entry, "WaylandSink", _RefusingSink)
return _RefusingSink
# -- defaults ---------------------------------------------------------------
def test_the_xkb_flags_default_to_the_frozen_values():
args = entry.build_parser().parse_args([])
assert args.xkb_layout == "us"
assert args.xkb_model == "pc105"
assert (args.xkb_variant, args.xkb_options) == ("", "")
def test_the_defaults_are_the_ones_the_module_option_defaults_to():
# Stated as constants so the NixOS option and the hand-run binary cannot
# drift into typing different characters.
assert (entry.DEFAULT_LAYOUT, entry.DEFAULT_MODEL) == ("us", "pc105")
def test_a_layout_is_taken_from_the_flag():
assert entry.build_parser().parse_args(["--xkb-layout", "de"]).xkb_layout == "de"
def test_the_contract_command_line_still_parses():
"""CONTRACT-sessions.md §3.4's exact line, plus the keymap flags."""
args = entry.build_parser().parse_args(
[
"--socket",
"/run/hhstream/pointer.sock",
"--compositor-runtime-dir",
"/run/hypr-stream",
"--xkb-layout",
"us",
"--xkb-model",
"pc105",
"--xkb-variant",
"",
"--xkb-options",
"",
]
)
assert str(args.socket) == "/run/hhstream/pointer.sock"
assert str(args.compositor_runtime_dir) == "/run/hypr-stream"
assert args.xkb_layout == "us"
# -- refusals, before any Wayland call --------------------------------------
def test_a_comma_separated_layout_exits_2_without_connecting(no_compositor, caplog):
"""v1 sends group 0 in every `modifiers`, so a second group is unreachable.
xkbcommon accepts `us,ru` and hands back a two-group keymap, so nothing
downstream would notice: a caller asking for Cyrillic would get Latin and
no error. Refused here, and the NixOS option's type refuses it too — this
one is for the binary run by hand, which that type cannot reach.
"""
code = entry.main(["--xkb-layout", "us,ru"])
assert code == entry.EXIT_USAGE
assert no_compositor.instances == 0, "the compositor must not be touched"
def test_a_layout_xkbcommon_rejects_exits_2_without_connecting(no_compositor):
code = entry.main(["--xkb-layout", "zzz-no-such-layout"])
assert code == entry.EXIT_USAGE
assert no_compositor.instances == 0
def test_a_usable_layout_gets_as_far_as_the_compositor(no_compositor):
"""The other half: exit 2 must not be how a *good* layout fails.
A test that only asserted the refusals would pass against a `main` that
returned 2 for everything, so this one proves the good path reaches the
Wayland side and fails there instead.
"""
with pytest.raises(_Unreached, match="connect"):
entry.main(["--xkb-layout", "us"])
assert no_compositor.instances == 1
def test_the_exit_codes_match_the_brokers_table():
# Mirrored, not imported: the driver is a separate package on purpose
# (see the module docstring in __main__).
assert (entry.EXIT_OK, entry.EXIT_USAGE, entry.EXIT_COMPOSITOR) == (0, 2, 10)
+293
View File
@@ -0,0 +1,293 @@
"""Keysym names and text to ``(evdev code, modifier mask)``, against real xkbcommon.
A real keymap, not a stub, and that is the whole design of this file. A stub
can be made to agree with any resolver; only xkbcommon can tell you that ``é``
is unmappable on ``us``, that ``@`` on ``de`` is a *level-three* symbol rather
than a shifted one, and that ``y`` and ``z`` swap keycodes between the two.
Those three facts are what the resolver exists for, so ``xkbcommon`` is a hard
dependency (``pyproject.toml`` says why) and these tests do not skip.
Codes here are **evdev**, never XKB. ``a`` is 30 and not 38: 30 is what
``zwp_virtual_keyboard_v1.key`` carries and what the client reads back off
``wl_keyboard.key``, and asserting 38 would be asserting an internal index that
never reaches the wire.
Masks are read out of the keymap, never written down. ``A`` needs
``1 << mod_get_index("Shift")``, which happens to be 1 on every layout here —
so the test computes it, because a hard-coded 1 passes today and is wrong the
first time a resolver is asked for a level-three character.
"""
from __future__ import annotations
import pytest
from hhstream_pointer import keymap as keymaps
from hhstream_pointer.ops import KIND_INVALID, Dispatcher
#: evdev codes from ``linux/input-event-codes.h``, spelled out so a failure
#: reads against the header rather than against another part of this suite.
KEY_A = 30
KEY_ENTER = 28
KEY_TAB = 15
KEY_LEFTSHIFT = 42
KEY_Y = 21 # the physical key that is `y` on us and `z` on de
KEY_Z = 44 # ...and `z` on us, `y` on de
@pytest.fixture(scope="module")
def us() -> keymaps.Keymap:
return keymaps.build(layout="us")
@pytest.fixture(scope="module")
def de() -> keymaps.Keymap:
return keymaps.build(layout="de")
def shift_mask(keymap: keymaps.Keymap) -> int:
"""Shift's bit, asked of the keymap rather than assumed to be 1."""
return 1 << keymap._keymap.mod_get_index("Shift")
# -- the letter path --------------------------------------------------------
def test_a_lower_case_letter_is_its_evdev_code_and_no_modifier(us):
action = us.resolve_name("a")
assert (action.code, action.mask) == (KEY_A, 0)
def test_a_capital_is_the_same_code_with_shift_in_the_mask(us):
action = us.resolve_name("A")
assert action.code == KEY_A
assert action.mask == shift_mask(us)
# The point of the mask: a capital is NOT a Shift keycode. Hyprland's
# virtual keyboard never runs updateXkbStateWithKey, so a synthetic
# KEY_LEFTSHIFT would change no modifier state at all.
assert action.code != KEY_LEFTSHIFT
def test_shift_is_a_key_in_its_own_right_with_no_mask_of_its_own(us):
action = us.resolve_name("Shift_L")
# Pressing Shift needs no modifier held; what it *contributes* is separate.
assert (action.code, action.mask) == (KEY_LEFTSHIFT, 0)
assert us.is_modifier("Shift_L")
assert us.modifier_mask("Shift_L") == shift_mask(us)
# -- the named keys ---------------------------------------------------------
@pytest.mark.parametrize(
"name, code",
[("Return", KEY_ENTER), ("Tab", KEY_TAB), ("BackSpace", 14), ("Left", 105)],
)
def test_a_named_keysym_resolves_to_its_evdev_code(us, name, code):
assert us.resolve_name(name).code == code
@pytest.mark.parametrize("character, code", [("\n", KEY_ENTER), ("\t", KEY_TAB)])
def test_the_two_allowed_control_characters_are_named_keys(us, character, code):
(action,) = us.resolve_text(character)
assert action.code == code
assert action.mask == 0
def test_an_empty_string_is_no_actions_and_not_an_error(us):
assert us.resolve_text("") == []
# -- refusals ---------------------------------------------------------------
@pytest.mark.parametrize("character", ["é", "ü", "😀", "\x01", "\x1b", "\x7f"])
def test_a_character_this_layout_cannot_produce_is_refused(us, character):
with pytest.raises(keymaps.UnknownKey) as caught:
us.resolve_text(character)
message = str(caught.value)
# The index and the codepoint, and NOT the character: this message reaches
# the driver's log, and the string it came from is a password as often as
# not.
assert "scalar 0" in message
assert character not in message
def test_the_refusal_names_the_index_of_the_offending_scalar(us):
with pytest.raises(keymaps.UnknownKey) as caught:
us.resolve_text("abcé")
assert "scalar 3" in str(caught.value)
assert "é" not in str(caught.value)
def test_a_dead_keysym_is_refused_by_name(us):
with pytest.raises(keymaps.UnknownKey) as caught:
us.resolve_name("dead_acute")
assert "dead key" in str(caught.value)
def test_an_unknown_keysym_name_is_refused(us):
with pytest.raises(keymaps.UnknownKey):
us.resolve_name("NoSuchKeysymAtAll")
def test_a_comma_separated_layout_is_refused_before_anything_is_compiled():
# xkbcommon accepts `us,ru` happily and hands back a two-group keymap. v1
# always sends group 0, so the second group would be silently unreachable:
# a caller asking for Cyrillic would get Latin and no error.
with pytest.raises(keymaps.KeymapError) as caught:
keymaps.build(layout="us,ru")
assert "group" in str(caught.value)
def test_a_layout_xkbcommon_rejects_is_a_keymap_error_naming_it():
with pytest.raises(keymaps.KeymapError) as caught:
keymaps.build(layout="zzz-no-such-layout")
assert "zzz-no-such-layout" in str(caught.value)
# -- the cap ----------------------------------------------------------------
def test_the_cap_is_exactly_at_the_limit(us):
assert len(us.resolve_text("a" * keymaps.MAX_TEXT_SCALARS)) == keymaps.MAX_TEXT_SCALARS
def test_one_scalar_over_the_cap_is_refused(us):
with pytest.raises(keymaps.UnknownKey) as caught:
us.resolve_text("a" * (keymaps.MAX_TEXT_SCALARS + 1))
assert str(keymaps.MAX_TEXT_SCALARS) in str(caught.value)
def test_the_cap_counts_scalars_and_not_bytes(us):
# 4096 astral-plane scalars are 16384 UTF-8 bytes. A byte cap would refuse
# this for being too long; the scalar cap lets it through to the character
# check, which refuses it for being unmappable instead. The distinction is
# the whole test: a byte cap and a scalar cap agree on ASCII, so only a
# non-ASCII case can tell them apart.
text = "😀" * keymaps.MAX_TEXT_SCALARS
assert len(text) == keymaps.MAX_TEXT_SCALARS
assert len(text.encode("utf-8")) > keymaps.MAX_TEXT_SCALARS
with pytest.raises(keymaps.UnknownKey) as caught:
us.resolve_text(text)
assert "scalar 0" in str(caught.value)
assert "limit" not in str(caught.value)
# -- the modifier set -------------------------------------------------------
def test_the_modifier_set_is_measured_and_not_empty(us):
assert us.modifier_names() == keymaps.EXPECTED_MODIFIERS
def test_a_lock_is_not_a_modifier(us):
# Caps_Lock reports a *locked* mask, so `type` refuses while it is held
# rather than producing a case nobody asked for.
assert us.lock_names() == keymaps.EXPECTED_LOCKS
for name in keymaps.EXPECTED_LOCKS:
assert not us.is_modifier(name)
assert us.modifier_mask(name) == 0
def test_control_contributes_a_mask_that_is_not_shifts(us):
assert us.modifier_mask("Control_L") not in (0, shift_mask(us))
# -- a second layout, which is what stops a Shift special case ---------------
def test_de_swaps_y_and_z_against_us(us, de):
assert (us.resolve_name("y").code, us.resolve_name("z").code) == (KEY_Y, KEY_Z)
# Same keysyms, other codes: a resolver with a table beside the keymap
# rather than inside it would return the us answer here.
assert (de.resolve_name("y").code, de.resolve_name("z").code) == (KEY_Z, KEY_Y)
def test_on_de_the_at_sign_needs_a_level_three_mask_not_shift(us, de):
at_us = us.resolve_text("@")[0]
at_de = de.resolve_text("@")[0]
assert at_us.mask == shift_mask(us)
# The case a Shift-only special case gets wrong: `@` is AltGr+q on de.
assert at_de.mask not in (0, shift_mask(de))
assert at_de.mask == de.modifier_mask("ISO_Level3_Shift")
def test_a_character_us_cannot_type_is_ordinary_on_de(us, de):
with pytest.raises(keymaps.UnknownKey):
us.resolve_text("ü")
(action,) = de.resolve_text("ü")
assert action.name == "udiaeresis"
assert action.mask == 0
# -- the keymap text we upload ----------------------------------------------
def test_the_keymap_text_is_an_xkb_keymap_naming_its_layout(us, de):
assert us.text().lstrip().startswith("xkb_keymap {")
# The symbols section names the layout, which is what the VM check greps to
# prove the keymap a client decoded with is the one we uploaded.
assert "us" in _symbols_line(us)
assert "de" in _symbols_line(de)
def _symbols_line(keymap: keymaps.Keymap) -> str:
return next(line for line in keymap.text().splitlines() if "xkb_symbols" in line)
# -- through the dispatcher: nothing is emitted for a bad string -------------
class _Sink:
"""Just enough of :class:`hhstream_pointer.ops.PointerSink` to count calls."""
def __init__(self) -> None:
self.calls: list[tuple] = []
def has_keyboard(self) -> bool:
return True
def key(self, code, state):
self.calls.append(("key", code, state))
def modifiers(self, depressed, latched, locked, group):
self.calls.append(("modifiers", depressed, latched, locked, group))
def test_an_unmappable_character_emits_nothing_through_the_dispatcher(us):
sink = _Sink()
reply = Dispatcher(sink, us).handle({"op": "type", "text": "abcé"})
assert reply["ok"] is False
# The assertion that matters: not "no event carried é" -- which would also
# pass if a, b and c had been typed -- but that the sink was never called.
assert sink.calls == []
assert reply["kind"] == KIND_INVALID
def test_a_string_over_the_cap_emits_nothing_through_the_dispatcher(us):
sink = _Sink()
reply = Dispatcher(sink, us).handle(
{"op": "type", "text": "a" * (keymaps.MAX_TEXT_SCALARS + 1)}
)
assert reply["ok"] is False
assert reply["kind"] == KIND_INVALID
assert sink.calls == []
def test_the_keymap_object_is_built_once_and_reused_across_types(us):
"""Two ``type``s, one keymap.
The false pass this guards is a backend that recompiles and re-*uploads*
per string: a second ``keymap`` request replaces Hyprland's XKB state
without walking the keys it believes are down, so re-uploading under a held
modifier strands it. The dispatcher is handed one object and never asks for
another, which is what makes the single upload in ``__main__`` sufficient.
"""
sink = _Sink()
dispatcher = Dispatcher(sink, us)
assert dispatcher.handle({"op": "type", "text": "a"})["ok"] is True
assert dispatcher.handle({"op": "type", "text": "b"})["ok"] is True
assert dispatcher._keymap is us
+99
View File
@@ -243,3 +243,102 @@ def test_a_new_lease_starts_without_the_previous_bookmark(lease):
def test_defaults_match_the_contract():
lease = PointerLease()
assert (lease.ttl_s, lease.max_s) == (30.0, 300.0)
# -- keys: the same mirror, and the same ordering rule ----------------------
#
# PLAN §6.7 proposed a `keyboard` flag on the lease. These tests are the
# argument against it: a boolean cannot say to lift `Control_L` and not `a`,
# and it cannot say which went down first.
def test_press_and_lift_one_key(lease):
lease_id = lease.acquire("alpha")
lease.press_key("alpha", "Shift_L")
assert lease.keys_pressed() == ["Shift_L"]
assert lease.unpress_key("alpha", "Shift_L") == ["Shift_L"]
assert lease.keys_pressed() == []
assert lease.release("alpha", lease_id, "done").keys_lifted == []
def test_lifting_a_key_that_is_not_down_reports_nothing(lease):
lease.acquire("alpha")
assert lease.unpress_key("alpha", "Shift_L") == []
lease.press_key("alpha", "Shift_L")
lease.unpress_key("alpha", "Shift_L")
assert lease.unpress_key("alpha", "Shift_L") == []
def test_keys_are_kept_in_press_order(lease):
lease_id = lease.acquire("alpha")
for name in ("Control_L", "Shift_L", "a"):
lease.press_key("alpha", name)
assert lease.keys_pressed() == ["Control_L", "Shift_L", "a"]
assert lease.unpress_key("alpha", "Shift_L") == ["Shift_L"]
assert lease.keys_pressed() == ["Control_L", "a"]
outcome = lease.release("alpha", lease_id, "timeout")
assert outcome.keys_lifted == ["Control_L", "a"]
assert lease.keys_pressed() == []
def test_pressing_a_key_twice_leaves_one_down(lease):
lease.acquire("alpha")
lease.press_key("alpha", "a")
lease.press_key("alpha", "a")
assert lease.keys_pressed() == ["a"]
def test_keys_and_buttons_are_tracked_separately(lease):
lease_id = lease.acquire("alpha")
lease.press("alpha", "left")
lease.press_key("alpha", "Shift_L")
assert (lease.pressed(), lease.keys_pressed()) == (["left"], ["Shift_L"])
outcome = lease.release("alpha", lease_id, "done")
assert (outcome.buttons_lifted, outcome.keys_lifted) == (["left"], ["Shift_L"])
def test_a_non_holder_cannot_press_a_key(lease):
lease.acquire("alpha")
with pytest.raises(LeaseInvalid):
lease.press_key("beta", "a")
with pytest.raises(LeaseInvalid):
lease.unpress_key("beta", "a")
def test_expire_still_returns_no_key_list_so_the_broker_must_read_first(lease, clock):
"""CONTRACT-sessions.md §3.3, unchanged by the keyboard.
`expire()` is still `LeaseInfo` and carries neither buttons nor keys. The
ordering it forces -- read, *then* expire -- is the only thing stopping a
key from being forgotten before the driver has been told to lift it, and
widening the return would make that ordering optional.
"""
lease.acquire("alpha")
lease.press_key("alpha", "Shift_L")
clock.advance(31.0)
# The broker's order, and it is not interchangeable.
held = lease.keys_pressed()
info = lease.expire()
assert held == ["Shift_L"]
assert info is not None
assert not hasattr(info, "keys_lifted")
assert not hasattr(info, "buttons_lifted")
assert lease.keys_pressed() == []
def test_expiry_does_not_leak_keys_to_the_next_holder(lease, clock):
"""A held Shift must not become the next session's Shift."""
lease.acquire("alpha")
lease.press_key("alpha", "Shift_L")
clock.advance(31.0)
assert lease.expire() is not None
lease.acquire("beta")
assert lease.keys_pressed() == []
+438 -17
View File
@@ -13,17 +13,34 @@ from __future__ import annotations
import pytest
from hhstream_pointer import buttons
from hhstream_pointer.ops import Dispatcher
from hhstream_pointer import buttons, keymap as keymaps
from hhstream_pointer.ops import KIND_INVALID, KIND_REFUSED, Dispatcher
LEFT = buttons.CODES["left"]
RIGHT = buttons.CODES["right"]
DOWN = buttons.STATES["down"]
UP = buttons.STATES["up"]
#: evdev codes, from ``linux/input-event-codes.h``. Asserted as the integers
#: the wire carries, never as XKB codes: ``a`` is 30 there and 38 in xkbcommon's
#: tables, and only one of the two ever leaves this process.
KEY_A = 30
KEY_B = 48
KEY_ENTER = 28
KEY_LEFTSHIFT = 42
KEY_LEFTCTRL = 29
class RecordingSink:
"""Every call, in order, as a tuple. Nothing else."""
"""Every call, in order, as a tuple. Nothing else.
``has_keyboard`` answers True by default because most tests want one. The
keyboard calls carry **no output**: a virtual keyboard is seat-global, and
a sink that tagged them with one would be hiding the fact that a key after
a warp to another output still goes to whatever has focus.
"""
keyboard = True
def __init__(self) -> None:
self.calls: list[tuple] = []
@@ -40,6 +57,31 @@ class RecordingSink:
def frame(self, output):
self.calls.append(("frame", output))
def has_keyboard(self):
return self.keyboard
def key(self, code, state):
self.calls.append(("key", code, state))
def modifiers(self, depressed, latched, locked, group):
self.calls.append(("modifiers", depressed, latched, locked, group))
class KeyboardlessSink(RecordingSink):
"""A compositor with no ``zwp_virtual_keyboard_manager_v1``.
Not a failing sink: the methods are simply never meant to be reached, and
a call that got through would be the bug.
"""
keyboard = False
def key(self, code, state):
raise AssertionError("no virtual keyboard exists; key must not be sent")
def modifiers(self, depressed, latched, locked, group):
raise AssertionError("no virtual keyboard exists; modifiers must not be sent")
class FailingSink(RecordingSink):
"""A sink whose motion raises, standing in for an output that vanished."""
@@ -56,9 +98,21 @@ def sink() -> RecordingSink:
return RecordingSink()
@pytest.fixture(scope="module")
def us() -> keymaps.Keymap:
"""A real ``us`` keymap.
Real, not a fake, for the reason ``test_keymap.py`` gives at length: the
mask for ``A`` and the refusal of ``é`` are properties of the layout, and a
fake that agreed with the dispatcher would prove only that they agree.
"""
return keymaps.build(layout="us")
@pytest.fixture
def driver(sink) -> Dispatcher:
return Dispatcher(sink)
def driver(sink, us) -> Dispatcher:
return Dispatcher(sink, us)
def warp(driver, output="hh-alpha", x=0.5, y=0.5):
@@ -90,7 +144,7 @@ def test_a_click_is_warp_button_frame(driver, sink):
("button", "hh-alpha", LEFT, UP),
("frame", "hh-alpha"),
]
assert driver.handle({"op": "pressed"}) == {"ok": True, "buttons": []}
assert driver.handle({"op": "pressed"}) == {"ok": True, "buttons": [], "keys": []}
def test_the_boundary_coordinates_are_accepted(driver, sink):
@@ -160,7 +214,11 @@ def test_pressed_reports_what_is_down_oldest_first(driver):
warp(driver)
driver.handle({"op": "button", "button": "right", "state": "down"})
driver.handle({"op": "button", "button": "left", "state": "down"})
assert driver.handle({"op": "pressed"}) == {"ok": True, "buttons": ["right", "left"]}
assert driver.handle({"op": "pressed"}) == {
"ok": True,
"buttons": ["right", "left"],
"keys": [],
}
def test_release_all_lifts_everything_and_frames_once(driver, sink):
@@ -169,17 +227,28 @@ def test_release_all_lifts_everything_and_frames_once(driver, sink):
driver.handle({"op": "button", "button": "right", "state": "down"})
sink.calls.clear()
assert driver.handle({"op": "release_all"}) == {"ok": True, "lifted": ["left", "right"]}
assert driver.handle({"op": "release_all"}) == {
"ok": True,
"lifted": ["left", "right"],
"lifted_keys": [],
}
assert sink.calls == [
("button", "hh-alpha", LEFT, UP),
("button", "hh-alpha", RIGHT, UP),
("frame", "hh-alpha"),
]
assert driver.handle({"op": "pressed"}) == {"ok": True, "buttons": []}
assert driver.handle({"op": "pressed"}) == {"ok": True, "buttons": [], "keys": []}
def test_release_all_on_a_quiet_driver_lifts_nothing(driver, sink):
assert driver.handle({"op": "release_all"}) == {"ok": True, "lifted": []}
assert driver.handle({"op": "release_all"}) == {
"ok": True,
"lifted": [],
"lifted_keys": [],
}
# Including no zeroed `modifiers`: a mask nothing ever set is not ours to
# clear, and on a sink with no keyboard at all sending one would raise and
# abandon the button lifting above.
assert sink.calls == []
@@ -196,7 +265,11 @@ def test_release_all_lifts_through_the_pointer_the_press_went_to(driver, sink):
driver.handle({"op": "button", "button": "right", "state": "down"})
sink.calls.clear()
assert driver.handle({"op": "release_all"}) == {"ok": True, "lifted": ["left", "right"]}
assert driver.handle({"op": "release_all"}) == {
"ok": True,
"lifted": ["left", "right"],
"lifted_keys": [],
}
assert sink.calls == [
("button", "hh-alpha", LEFT, UP),
("button", "hh-beta", RIGHT, UP),
@@ -209,7 +282,11 @@ def test_a_lifted_button_is_forgotten(driver):
warp(driver)
driver.handle({"op": "button", "button": "left", "state": "down"})
driver.handle({"op": "button", "button": "left", "state": "up"})
assert driver.handle({"op": "release_all"}) == {"ok": True, "lifted": []}
assert driver.handle({"op": "release_all"}) == {
"ok": True,
"lifted": [],
"lifted_keys": [],
}
def test_every_known_button_name_round_trips(driver, sink):
@@ -227,6 +304,10 @@ def test_button_before_any_warp_is_refused(driver, sink):
assert driver.handle({"op": "button", "button": "left", "state": "down"}) == {
"ok": False,
"error": "no output is aimed; warp before button or frame",
# `refused` and not `invalid_argument`: the request was well formed,
# what is missing is a warp, and the broker reports that as exit 10
# exactly as it already does for an unknown button.
"kind": "refused",
}
assert sink.calls == []
@@ -277,8 +358,8 @@ def test_a_failed_warp_does_not_change_the_aim():
({"op": "axis", "value": -1e9}, "wheel-click limit"),
],
)
def test_malformed_requests_are_answered_not_fatal(sink, request_, fragment):
driver = Dispatcher(sink)
def test_malformed_requests_are_answered_not_fatal(sink, us, request_, fragment):
driver = Dispatcher(sink, us)
# Aim first, so a refusal is about the field under test rather than the aim.
warp(driver)
sink.calls.clear()
@@ -300,9 +381,11 @@ def test_the_contracts_ops_are_exactly_what_is_implemented() -> None:
An op that exists here and nowhere in the contract -- or the reverse --
fails this test rather than surprising whoever reads the contract next.
``axis`` is the one addition since the freeze, made deliberately so that a
session can scroll; the set is edited by hand, which is the reminder to
write it down.
``axis`` was the first addition since the freeze, so a session could
scroll; ``key`` and ``type`` are the second, and there is deliberately no
keyboard ``frame`` or ``release_all_keys`` beside them -- the protocol has
no frame, and expiry has exactly one call site. The set is edited by hand,
which is the reminder to write it down.
"""
assert set(Dispatcher._ops) == {
@@ -310,6 +393,344 @@ def test_the_contracts_ops_are_exactly_what_is_implemented() -> None:
"button",
"axis",
"frame",
"key",
"type",
"pressed",
"release_all",
}
# -- key: one keysym at a time ----------------------------------------------
#
# Names on this socket, evdev codes on the Wayland request -- the same division
# `buttons.py` draws, and the reason `pressed` answers "Control_L" rather than
# 29. These tests assert both halves: the response names, the sink codes.
def test_key_down_sends_the_code_and_lists_the_name(driver, sink):
assert driver.handle({"op": "key", "key": "Return", "state": "down"}) == {
"ok": True,
"keys": ["Return"],
"lifted": [],
}
assert sink.calls == [("key", KEY_ENTER, DOWN)]
assert driver.handle({"op": "pressed"})["keys"] == ["Return"]
def test_key_needs_no_warp(sink, us):
"""A keyboard has no output, so `type` must not demand an aim.
Deliberately the one test in this file that never warps: a virtual keyboard
is seat-global, so requiring a warp first would refuse a caller who only
ever wanted to type -- and every other test here warps out of habit, which
is exactly how that bug would survive.
"""
driver = Dispatcher(sink, us)
assert driver.handle({"op": "type", "text": "Hi"})["ok"] is True
assert driver.handle({"op": "key", "key": "a", "state": "down"})["ok"] is True
assert ("key", KEY_A, DOWN) in sink.calls
def test_a_key_is_not_tagged_with_an_output_even_after_a_warp(driver, sink):
warp(driver, output="hh-beta")
sink.calls.clear()
driver.handle({"op": "key", "key": "a", "state": "down"})
# Two items, not three: no output travels with a key. A sink that accepted
# one would let a future change route keys per output, which the protocol
# cannot do.
assert sink.calls == [("key", KEY_A, DOWN)]
def test_key_up_forgets_the_key(driver, sink):
driver.handle({"op": "key", "key": "a", "state": "down"})
assert driver.handle({"op": "key", "key": "a", "state": "up"}) == {
"ok": True,
"keys": [],
"lifted": ["a"],
}
assert sink.calls == [("key", KEY_A, DOWN), ("key", KEY_A, UP)]
def test_up_of_a_key_that_was_never_down_lifts_nothing_and_emits_nothing(driver, sink):
"""Same rule as `unpress` for a button that was never pressed.
Reported rather than invented, and silent on the wire: a key-up the
compositor has no matching key-down for puts its own `m_pressed` out of
step with ours, and on this build that makes the *next* press of the code
a no-op.
"""
assert driver.handle({"op": "key", "key": "a", "state": "up"}) == {
"ok": True,
"keys": [],
"lifted": [],
}
assert sink.calls == []
def test_keys_are_reported_oldest_first(driver):
for name in ("Control_L", "Shift_L", "a"):
driver.handle({"op": "key", "key": name, "state": "down"})
assert driver.handle({"op": "pressed"})["keys"] == ["Control_L", "Shift_L", "a"]
# -- the modifier half, which a key-up does not undo ------------------------
def test_a_modifier_down_sends_the_key_and_the_mask(driver, sink, us):
driver.handle({"op": "key", "key": "Shift_L", "state": "down"})
assert sink.calls == [
("key", KEY_LEFTSHIFT, DOWN),
("modifiers", us.modifier_mask("Shift_L"), 0, 0, 0),
]
def test_a_modifier_up_restores_the_mask_of_whatever_is_still_held(driver, sink, us):
driver.handle({"op": "key", "key": "Shift_L", "state": "down"})
driver.handle({"op": "key", "key": "Control_L", "state": "down"})
sink.calls.clear()
driver.handle({"op": "key", "key": "Shift_L", "state": "up"})
# Not zero: Control is still down, so the mask drops to Control's bit
# alone. A key-up changes no modifier state on this compositor, so the
# mask is only ever what we last said it was.
assert sink.calls == [
("key", KEY_LEFTSHIFT, UP),
("modifiers", us.modifier_mask("Control_L"), 0, 0, 0),
]
def test_an_ordinary_key_down_sends_no_mask(driver, sink):
driver.handle({"op": "key", "key": "a", "state": "down"})
assert sink.calls == [("key", KEY_A, DOWN)]
# -- type -------------------------------------------------------------------
def test_type_of_a_capital_is_the_mask_and_not_a_shift_keycode(driver, sink, us):
assert driver.handle({"op": "type", "text": "A"}) == {"ok": True, "keys": []}
shift = us.modifier_mask("Shift_L")
assert sink.calls == [
# The mask goes FIRST. A client that decodes with the mask from the
# last `wl_keyboard.modifiers` -- foot, GTK -- emits `a` if the key
# arrives before the mask.
("modifiers", shift, 0, 0, 0),
("key", KEY_A, DOWN),
("key", KEY_A, UP),
("modifiers", 0, 0, 0, 0),
]
# And no synthetic Shift key anywhere: sending both a mask and KEY_LEFTSHIFT
# is how a toolkit applies Shift twice, or not at all.
assert not any(call[0] == "key" and call[1] == KEY_LEFTSHIFT for call in sink.calls)
def test_type_leaves_no_key_held(driver):
driver.handle({"op": "type", "text": "Hello"})
assert driver.handle({"op": "pressed"})["keys"] == []
def test_type_emits_a_down_up_pair_per_character(driver, sink):
driver.handle({"op": "type", "text": "ab"})
assert [c for c in sink.calls if c[0] == "key"] == [
("key", KEY_A, DOWN),
("key", KEY_A, UP),
("key", KEY_B, DOWN),
("key", KEY_B, UP),
]
def test_type_of_an_empty_string_emits_nothing_and_succeeds(driver, sink):
assert driver.handle({"op": "type", "text": ""}) == {"ok": True, "keys": []}
assert sink.calls == []
def test_type_ors_an_explicitly_held_modifier_and_leaves_it_down(driver, sink, us):
"""`down Control_L` then `type c` is Ctrl+C, and Control is still down."""
driver.handle({"op": "key", "key": "Control_L", "state": "down"})
sink.calls.clear()
assert driver.handle({"op": "type", "text": "c"}) == {"ok": True, "keys": ["Control_L"]}
control = us.modifier_mask("Control_L")
assert sink.calls == [
("modifiers", control, 0, 0, 0),
("key", us.resolve_name("c").code, DOWN),
("key", us.resolve_name("c").code, UP),
# Back to the BASELINE, not to zero: Control was not ours to lift.
("modifiers", control, 0, 0, 0),
]
assert not any(call[0] == "key" and call[1] == KEY_LEFTCTRL for call in sink.calls)
assert driver.handle({"op": "pressed"})["keys"] == ["Control_L"]
def test_type_of_a_capital_under_a_held_control_ors_both_masks(driver, sink, us):
driver.handle({"op": "key", "key": "Control_L", "state": "down"})
sink.calls.clear()
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)
def test_type_while_a_non_modifier_is_held_emits_nothing(driver, sink):
driver.handle({"op": "key", "key": "a", "state": "down"})
sink.calls.clear()
reply = driver.handle({"op": "type", "text": "bc"})
assert reply["ok"] is False
assert reply["kind"] == KIND_INVALID
assert sink.calls == []
# And the held key is untouched: a refused request changes nothing.
assert driver.handle({"op": "pressed"})["keys"] == ["a"]
def test_type_while_a_lock_is_held_is_refused_too(driver, sink):
"""Caps_Lock reports a *locked* mask, so it is not a modifier.
Typing under it would produce a case the caller did not ask for, and v1
refuses rather than guessing which one they meant.
"""
driver.handle({"op": "key", "key": "Caps_Lock", "state": "down"})
sink.calls.clear()
assert driver.handle({"op": "type", "text": "a"})["ok"] is False
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
# Not "no event carried é" -- that would also pass with a and b typed.
assert sink.calls == []
def test_a_bad_character_is_a_usage_error_and_a_missing_keyboard_is_not(sink, us):
"""The two refusals the broker must tell apart (the review's change 1).
An unmappable character is the caller's; a compositor with no keyboard
global is not. They become exit 2 and exit 10, and the only thing carrying
the difference across the socket is this token.
"""
usable = Dispatcher(sink, us)
assert usable.handle({"op": "type", "text": "é"})["kind"] == KIND_INVALID
assert usable.handle({"op": "key", "key": "Nope", "state": "down"})["kind"] == KIND_INVALID
assert usable.handle({"op": "key", "key": "a", "state": "sideways"})["kind"] == KIND_INVALID
absent = Dispatcher(KeyboardlessSink(), us)
assert absent.handle({"op": "type", "text": "a"})["kind"] == KIND_REFUSED
assert absent.handle({"op": "key", "key": "a", "state": "down"})["kind"] == KIND_REFUSED
def test_without_a_keymap_at_all_the_keyboard_ops_refuse_and_the_cursor_works(sink):
"""A driver started with no layout still moves the cursor."""
driver = Dispatcher(sink, None)
assert warp(driver)["ok"] is True
assert driver.handle({"op": "button", "button": "left", "state": "down"})["ok"] is True
reply = driver.handle({"op": "type", "text": "a"})
assert reply["ok"] is False and reply["kind"] == KIND_REFUSED
# -- release_all, with keys ------------------------------------------------
def test_release_all_lifts_keys_in_press_order_then_zeroes_the_mask(driver, sink):
driver.handle({"op": "key", "key": "Control_L", "state": "down"})
driver.handle({"op": "key", "key": "a", "state": "down"})
sink.calls.clear()
assert driver.handle({"op": "release_all"}) == {
"ok": True,
"lifted": [],
"lifted_keys": ["Control_L", "a"],
}
assert sink.calls == [
("key", KEY_LEFTCTRL, UP),
("key", KEY_A, UP),
# The part that is easy to leave out. A virtual key-up clears no
# modifier state, so without this the next holder gets a keyboard
# where every letter is a capital.
("modifiers", 0, 0, 0, 0),
]
assert driver.handle({"op": "pressed"})["keys"] == []
def test_release_all_lifts_keys_after_buttons_and_adds_no_keyboard_frame(driver, sink):
warp(driver)
driver.handle({"op": "button", "button": "left", "state": "down"})
driver.handle({"op": "key", "key": "Shift_L", "state": "down"})
sink.calls.clear()
driver.handle({"op": "release_all"})
assert sink.calls == [
("button", "hh-alpha", LEFT, UP),
("frame", "hh-alpha"),
("key", KEY_LEFTSHIFT, UP),
("modifiers", 0, 0, 0, 0),
]
# Exactly one frame, for the pointer. `zwp_virtual_keyboard_v1` has none,
# and a key that waited for one would never arrive.
assert sum(1 for call in sink.calls if call[0] == "frame") == 1
def test_release_all_lifts_keys_even_after_a_warp_to_another_output(driver, sink):
"""Keys are not per output, and this is the test that says so.
The button path has to lift through the pointer the press went to; the key
path has nothing to choose, and a sink that silently ignored an output
argument would make a per-output implementation look correct here.
"""
warp(driver, output="hh-alpha")
driver.handle({"op": "key", "key": "a", "state": "down"})
warp(driver, output="hh-beta")
sink.calls.clear()
assert driver.handle({"op": "release_all"})["lifted_keys"] == ["a"]
assert sink.calls == [("key", KEY_A, UP)]
def test_release_all_without_a_keyboard_still_lifts_buttons(us):
"""The review's change 3, and the reason the mask is conditional.
`SessionManager._expire_pointer` calls `release_all` exactly once, so an
exception from the key half would abandon the buttons -- and a lease that
expired with a mouse button down is the failure the whole TTL exists to
prevent.
"""
sink = KeyboardlessSink()
driver = Dispatcher(sink, us)
warp(driver)
driver.handle({"op": "button", "button": "left", "state": "down"})
sink.calls.clear()
assert driver.handle({"op": "release_all"}) == {
"ok": True,
"lifted": ["left"],
"lifted_keys": [],
}
assert sink.calls == [("button", "hh-alpha", LEFT, UP), ("frame", "hh-alpha")]
def test_release_all_after_a_type_zeroes_the_mask_once_more(driver, sink):
"""A `type` restored the baseline itself, and `release_all` still zeroes.
Cheap, and it is the crash-mid-string case: the mask the last character set
is the compositor's until something says otherwise.
"""
driver.handle({"op": "type", "text": "A"})
sink.calls.clear()
driver.handle({"op": "release_all"})
assert sink.calls == [("modifiers", 0, 0, 0, 0)]
+11 -3
View File
@@ -78,7 +78,7 @@ class _Client:
def test_one_request_gets_one_response(connection):
client, _ = connection
assert client.call({"op": "pressed"}) == {"ok": True, "buttons": []}
assert client.call({"op": "pressed"}) == {"ok": True, "buttons": [], "keys": []}
def test_many_requests_share_one_connection(connection):
@@ -86,8 +86,16 @@ def test_many_requests_share_one_connection(connection):
assert client.call({"op": "warp", "output": "hh-a", "x": 0.5, "y": 0.5}) == {"ok": True}
assert client.call({"op": "button", "button": "left", "state": "down"}) == {"ok": True}
assert client.call({"op": "frame"}) == {"ok": True}
assert client.call({"op": "pressed"}) == {"ok": True, "buttons": ["left"]}
assert client.call({"op": "release_all"}) == {"ok": True, "lifted": ["left"]}
assert client.call({"op": "pressed"}) == {
"ok": True,
"buttons": ["left"],
"keys": [],
}
assert client.call({"op": "release_all"}) == {
"ok": True,
"lifted": ["left"],
"lifted_keys": [],
}
assert [c[0] for c in sink.calls] == ["motion", "button", "frame", "button", "frame"]
+108 -1
View File
@@ -29,6 +29,9 @@ assert _spec is not None and _spec.origin, "hhstream_pointer is not importable"
PACKAGE = Path(_spec.origin).parent
PROTOCOL_DIR = PACKAGE / "_protocol/wlr_virtual_pointer_unstable_v1"
MANAGER = PROTOCOL_DIR / "zwlr_virtual_pointer_manager_v1.py"
KEYBOARD_DIR = PACKAGE / "_protocol/virtual_keyboard_unstable_v1"
KEYBOARD_MANAGER = KEYBOARD_DIR / "zwp_virtual_keyboard_manager_v1.py"
KEYBOARD = KEYBOARD_DIR / "zwp_virtual_keyboard_v1.py"
#: Only present in a checkout; a build sandbox gets the test directory alone.
PYPROJECT = Path(__file__).resolve().parents[2] / "pyproject.toml"
@@ -57,10 +60,81 @@ def test_the_shim_resolves_the_generated_relative_import():
@pytest.mark.skipif(not PYPROJECT.is_file(), reason="not running from a checkout")
def test_pyproject_declares_the_entry_point_and_the_dependency():
def test_pyproject_declares_the_entry_point_and_the_dependencies():
pyproject = PYPROJECT.read_text()
assert 'hhstream-pointer = "hhstream_pointer.__main__:main"' in pyproject
assert "pywayland" in pyproject
# Not optional, and the comment beside it in pyproject.toml says why: an
# optional xkbcommon would let test_keymap.py skip, and the
# unmappable-character path is the one that must not rot.
assert "xkbcommon" in pyproject
# -- the virtual keyboard --------------------------------------------------
def test_the_keyboard_protocol_is_vendored_beside_the_pointer_one():
assert (KEYBOARD_DIR / "__init__.py").is_file()
assert KEYBOARD_MANAGER.is_file()
assert KEYBOARD.is_file()
for path in KEYBOARD_DIR.glob("*.py"):
assert path.read_text().startswith("# This file has been autogenerated")
def test_the_keyboard_manager_is_version_1_with_the_seat_only_request():
source = KEYBOARD_MANAGER.read_text()
assert 'name = "zwp_virtual_keyboard_manager_v1"' in source
assert " version = 1" in source
# Seat and nothing else: a virtual keyboard has no output argument, which
# is why `ops.py` must not route a key through `_aimed()`.
assert "def create_virtual_keyboard(self, seat: WlSeat)" in source
assert "WlOutput" not in source
def test_the_keyboard_carries_keymap_key_and_modifiers():
source = KEYBOARD.read_text()
assert 'name = "zwp_virtual_keyboard_v1"' in source
assert " version = 1" in source
assert "def keymap(self, format: int, fd: int, size: int)" in source
assert "def key(self, time: int, key: int, state: int)" in source
assert (
"def modifiers(self, mods_depressed: int, mods_latched: int, "
"mods_locked: int, group: int)" in source
)
# The keymap fd really is an fd on the wire, not a number we invented.
assert "ArgumentType.FileDescriptor" in source
# No frame, and there is nothing to add one from: `ops.py` says why a key
# queued until one would never arrive.
assert "def frame(" not in source
def test_the_integers_the_xml_names_but_does_not_define_live_in_our_code():
"""The one real cost of using Hyprland's copy of the XML.
It names `keymap_format` and `key_state` in the request descriptions and
defines neither enum, so the scanner emits no `IntEnum` for either. Both
are therefore written down with a citation, and this test is what notices
if a future regeneration against a *complete* XML makes them redundant --
at which point they should be deleted rather than left to drift.
"""
source = KEYBOARD.read_text()
assert "keymap_format" in source, "the description still refers to it"
assert "class keymap_format" not in source, "...and still does not define it"
assert "class key_state" not in source
from hhstream_pointer import buttons
from hhstream_pointer.keymap import XKB_V1
assert XKB_V1 == 1
# `wl_pointer.button_state` and `wl_keyboard.key_state` agree on these two,
# which is why there is one table rather than a second that can drift.
assert buttons.STATES["up"] == 0
assert buttons.STATES["down"] == 1
def test_the_shim_resolves_the_keyboard_relative_import():
assert "from ..wayland import WlSeat" in KEYBOARD_MANAGER.read_text()
@pytest.mark.skipif(
@@ -80,6 +154,39 @@ def test_the_protocol_binds_against_the_installed_pywayland():
)
@pytest.mark.skipif(
not HAVE_PYWAYLAND,
reason="pywayland is not in this environment (it is in the built package)",
)
def test_the_keyboard_protocol_binds_against_the_installed_pywayland():
from hhstream_pointer._protocol.virtual_keyboard_unstable_v1 import (
ZwpVirtualKeyboardManagerV1,
ZwpVirtualKeyboardV1,
)
assert ZwpVirtualKeyboardManagerV1.name == "zwp_virtual_keyboard_manager_v1"
assert ZwpVirtualKeyboardManagerV1.version == 1
assert ZwpVirtualKeyboardV1.version == 1
for request in ("keymap", "key", "modifiers", "destroy"):
assert hasattr(ZwpVirtualKeyboardV1.proxy_class, request)
assert hasattr(ZwpVirtualKeyboardManagerV1.proxy_class, "create_virtual_keyboard")
@pytest.mark.skipif(
not HAVE_PYWAYLAND,
reason="pywayland is not in this environment (it is in the built package)",
)
def test_the_backend_binds_the_keyboard_manager_at_version_1_and_survives_its_absence():
from hhstream_pointer.backend import KEYBOARD_MANAGER_VERSION, WaylandSink
assert KEYBOARD_MANAGER_VERSION == 1
# A sink that never connected has no keyboard and says so rather than
# raising: `ops.release_all` asks this question precisely so that a
# compositor with no keyboard global still gets its buttons lifted.
sink = WaylandSink(Path("/nonexistent"))
assert sink.has_keyboard() is False
@pytest.mark.skipif(
not HAVE_PYWAYLAND,
reason="pywayland is not in this environment (it is in the built package)",