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",
|
||||
}
|
||||
Reference in new issue
Block a user