scroll: one verb, two axes, and the sign carries the direction
A session could move a cursor and press it, but not scroll. The protocol already had the request -- zwlr_virtual_pointer_v1.axis(time, axis, value) -- it had simply never been implemented, in the driver or the broker. hhstream session pointer scroll <id> --axis vertical --amount 3 Positive is down (vertical) or right (horizontal): the protocol's direction, not a choice of ours, which is why direction travels in the sign and there is deliberately no up/down vocabulary layered over it. The output is whatever the last warp aimed at, exactly like a button, so scrolling somewhere else is a warp first -- and the lease is what keeps the whole gesture atomic. Bounded at 100 wheel clicks per request on both sides, because a decimal-point slip should be a refusal rather than a session scrolled somewhere unrecoverable. The resume point is re-stamped, not moved: the cursor did not go anywhere, so the coordinates are re-affirmed and only the stamp advances. Recorded in the contract as an amendment to the frozen op set, because adding an op to a frozen interface should be visible rather than implied. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d0efba0877
commit
6b395305e0
17 files changed
+642
-2
No files matched your search
@@ -34,6 +34,9 @@ class RecordingSink:
|
||||
def button(self, output, code, state):
|
||||
self.calls.append(("button", output, code, state))
|
||||
|
||||
def axis(self, output, axis, value):
|
||||
self.calls.append(("axis", output, axis, value))
|
||||
|
||||
def frame(self, output):
|
||||
self.calls.append(("frame", output))
|
||||
|
||||
@@ -105,6 +108,51 @@ def test_buttons_follow_the_last_warp_not_the_first(driver, sink):
|
||||
assert sink.calls[-1] == ("button", "hh-beta", LEFT, DOWN)
|
||||
|
||||
|
||||
# -- axis (scrolling) -------------------------------------------------------
|
||||
|
||||
|
||||
def test_axis_scrolls_the_aimed_output_and_sends_no_implicit_frame(driver, sink):
|
||||
warp(driver)
|
||||
sink.calls.clear()
|
||||
|
||||
assert driver.handle({"op": "axis", "axis": "vertical", "value": 3}) == {"ok": True}
|
||||
assert sink.calls == [("axis", "hh-alpha", buttons.AXES["vertical"], 3.0)]
|
||||
|
||||
|
||||
def test_axis_defaults_to_one_vertical_click(driver, sink):
|
||||
warp(driver)
|
||||
sink.calls.clear()
|
||||
|
||||
assert driver.handle({"op": "axis"}) == {"ok": True}
|
||||
assert sink.calls == [("axis", "hh-alpha", buttons.AXES["vertical"], 1.0)]
|
||||
|
||||
|
||||
def test_a_horizontal_scroll_is_the_other_axis_and_keeps_the_sign(driver, sink):
|
||||
warp(driver)
|
||||
sink.calls.clear()
|
||||
|
||||
assert driver.handle({"op": "axis", "axis": "horizontal", "value": -2}) == {"ok": True}
|
||||
assert sink.calls == [("axis", "hh-alpha", buttons.AXES["horizontal"], -2.0)]
|
||||
# Two names, two axes -- and positive is down/right, per the protocol rather
|
||||
# than per us, which is why direction travels in the sign and not the name.
|
||||
assert buttons.AXES["vertical"] != buttons.AXES["horizontal"]
|
||||
|
||||
|
||||
def test_a_scroll_goes_to_the_pointer_the_last_warp_aimed(driver, sink):
|
||||
warp(driver, output="hh-alpha")
|
||||
warp(driver, output="hh-beta")
|
||||
sink.calls.clear()
|
||||
|
||||
driver.handle({"op": "axis", "value": 5})
|
||||
|
||||
assert sink.calls == [("axis", "hh-beta", buttons.AXES["vertical"], 5.0)]
|
||||
|
||||
|
||||
def test_scroll_before_any_warp_is_refused(driver, sink):
|
||||
assert driver.handle({"op": "axis", "value": 3})["ok"] is False
|
||||
assert sink.calls == [], "a scroll with nothing aimed must emit nothing"
|
||||
|
||||
|
||||
# -- pressed / release_all --------------------------------------------------
|
||||
|
||||
|
||||
@@ -220,6 +268,13 @@ def test_a_failed_warp_does_not_change_the_aim():
|
||||
({"op": "button", "button": "left"}, "'state' must be"),
|
||||
({"op": "button", "button": "pinky", "state": "down"}, "unknown button 'pinky'"),
|
||||
({"op": "button", "button": "left", "state": "sideways"}, "unknown button state"),
|
||||
({"op": "axis", "axis": "diagonal"}, "unknown axis 'diagonal'"),
|
||||
({"op": "axis", "axis": 0}, "'axis' must be a string"),
|
||||
({"op": "axis", "value": "a lot"}, "'value' must be a number"),
|
||||
({"op": "axis", "value": True}, "'value' must be a number"),
|
||||
({"op": "axis", "value": float("nan")}, "'value' must be finite"),
|
||||
({"op": "axis", "value": 101}, "wheel-click limit"),
|
||||
({"op": "axis", "value": -1e9}, "wheel-click limit"),
|
||||
],
|
||||
)
|
||||
def test_malformed_requests_are_answered_not_fatal(sink, request_, fragment):
|
||||
@@ -240,5 +295,21 @@ def test_a_non_object_request_is_refused(driver, request_):
|
||||
assert "must be a JSON object" in driver.handle(request_)["error"]
|
||||
|
||||
|
||||
def test_the_contracts_five_ops_are_exactly_what_is_implemented():
|
||||
assert set(Dispatcher._ops) == {"warp", "button", "frame", "pressed", "release_all"}
|
||||
def test_the_contracts_ops_are_exactly_what_is_implemented() -> None:
|
||||
"""The op set cannot drift quietly.
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
assert set(Dispatcher._ops) == {
|
||||
"warp",
|
||||
"button",
|
||||
"axis",
|
||||
"frame",
|
||||
"pressed",
|
||||
"release_all",
|
||||
}
|
||||
@@ -353,6 +353,10 @@ class RecordingSink:
|
||||
self._check()
|
||||
self.calls.append(("button", output, code, state))
|
||||
|
||||
def axis(self, output: str, axis: int, value: float) -> None:
|
||||
self._check()
|
||||
self.calls.append(("axis", output, axis, value))
|
||||
|
||||
def frame(self, output: str) -> None:
|
||||
self._check()
|
||||
self.calls.append(("frame", output))
|
||||
|
||||
@@ -24,6 +24,10 @@ from hhstreamd.registry import ContainerState, Session, State, container_record
|
||||
LEFT = 0x110
|
||||
DOWN, UP = 1, 0
|
||||
|
||||
#: ``wl_pointer_axis``, mirrored from the driver for the same reason the button
|
||||
#: codes above are: these tests assert the events, so they name the wire values.
|
||||
VERTICAL, HORIZONTAL = 0, 1
|
||||
|
||||
|
||||
def make_session(session_id: str = "foot-aaaaaa", *, container: bool = True) -> Session:
|
||||
return Session(
|
||||
@@ -590,3 +594,103 @@ def test_the_sweeper_expires_a_lease_nobody_came_back_for(short_tmpdir: Path):
|
||||
if manager.driver is not None:
|
||||
manager.driver.close()
|
||||
fake.stop()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# scrolling
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_scroll_drives_axis_then_frame_on_the_sessions_own_output(harness):
|
||||
harness.add()
|
||||
lease = harness.run(harness.manager.pointer_acquire("foot-aaaaaa"))["lease_id"]
|
||||
harness.fake.sink.calls.clear()
|
||||
|
||||
reply = harness.run(harness.manager.pointer_scroll("foot-aaaaaa", lease, "vertical", 3))
|
||||
|
||||
assert (reply["axis"], reply["amount"]) == ("vertical", 3.0)
|
||||
assert harness.fake.sink.calls == [
|
||||
("axis", "hh-foot-aaaaaa", VERTICAL, 3.0),
|
||||
("frame", "hh-foot-aaaaaa"),
|
||||
]
|
||||
|
||||
|
||||
def test_scrolling_up_is_the_sign_and_not_a_different_verb(harness):
|
||||
"""One verb, one axis name, and the protocol's sign carries the direction."""
|
||||
|
||||
harness.add()
|
||||
lease = harness.run(harness.manager.pointer_acquire("foot-aaaaaa"))["lease_id"]
|
||||
harness.fake.sink.calls.clear()
|
||||
|
||||
harness.run(harness.manager.pointer_scroll("foot-aaaaaa", lease, "vertical", -3))
|
||||
|
||||
assert harness.fake.sink.calls == [
|
||||
("axis", "hh-foot-aaaaaa", VERTICAL, -3.0),
|
||||
("frame", "hh-foot-aaaaaa"),
|
||||
]
|
||||
|
||||
|
||||
def test_a_horizontal_scroll_uses_the_other_axis(harness):
|
||||
harness.add()
|
||||
lease = harness.run(harness.manager.pointer_acquire("foot-aaaaaa"))["lease_id"]
|
||||
harness.fake.sink.calls.clear()
|
||||
|
||||
harness.run(harness.manager.pointer_scroll("foot-aaaaaa", lease, "horizontal", 2))
|
||||
|
||||
assert harness.fake.sink.calls == [
|
||||
("axis", "hh-foot-aaaaaa", HORIZONTAL, 2.0),
|
||||
("frame", "hh-foot-aaaaaa"),
|
||||
]
|
||||
|
||||
|
||||
def test_a_scroll_restamps_the_resume_point_without_moving_it(harness):
|
||||
"""The cursor stays put -- and the record must not pretend otherwise."""
|
||||
|
||||
session = harness.add()
|
||||
lease = harness.run(harness.manager.pointer_acquire("foot-aaaaaa"))["lease_id"]
|
||||
before = dict(session.pointer["bookmark"])
|
||||
|
||||
harness.clock.advance(7.0)
|
||||
reply = harness.run(harness.manager.pointer_scroll("foot-aaaaaa", lease, "vertical", 3))
|
||||
|
||||
assert (reply["bookmark"]["x"], reply["bookmark"]["y"]) == (before["x"], before["y"])
|
||||
assert reply["bookmark"]["output"] == before["output"]
|
||||
assert reply["bookmark"]["at"] != before["at"], "the session acted, so the stamp moved"
|
||||
assert harness.manager.pointer.state()["holder"] == "foot-aaaaaa"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("bad", [0, 0.0, 101, -101, "three", True, None])
|
||||
def test_a_scroll_amount_off_the_wire_is_bounded(harness, bad):
|
||||
harness.add()
|
||||
lease = harness.run(harness.manager.pointer_acquire("foot-aaaaaa"))["lease_id"]
|
||||
|
||||
with pytest.raises(ManagerError) as exc:
|
||||
harness.run(harness.manager.pointer_scroll("foot-aaaaaa", lease, "vertical", bad))
|
||||
|
||||
assert exc.value.error == "invalid_argument"
|
||||
|
||||
|
||||
def test_an_unknown_axis_is_refused_by_the_driver_not_invented(harness):
|
||||
harness.add()
|
||||
lease = harness.run(harness.manager.pointer_acquire("foot-aaaaaa"))["lease_id"]
|
||||
harness.fake.sink.calls.clear()
|
||||
|
||||
with pytest.raises(ManagerError) as exc:
|
||||
harness.run(harness.manager.pointer_scroll("foot-aaaaaa", lease, "diagonal", 3))
|
||||
|
||||
assert exc.value.error == "driver_refused"
|
||||
assert harness.fake.sink.calls == [], "a refused scroll must emit nothing"
|
||||
|
||||
|
||||
def test_a_scroll_without_the_lease_is_refused(harness):
|
||||
session = harness.add()
|
||||
harness.run(harness.manager.pointer_acquire("foot-aaaaaa"))
|
||||
harness.fake.sink.calls.clear()
|
||||
|
||||
with pytest.raises(ManagerError):
|
||||
harness.run(
|
||||
harness.manager.pointer_scroll("foot-aaaaaa", "not-this-lease", "vertical", 3)
|
||||
)
|
||||
|
||||
assert harness.fake.sink.calls == []
|
||||
assert session.pointer.get("bookmark") is not None, "a refused scroll changes nothing"
|
||||
Reference in new issue
Block a user