app: cherry-pick rune's pause and sound fixes onto the checkout
Rune comes from app/vendor/rune now, a checkout of 63ad0209 on branch ported, carrying the four commits of upstream issues 1320 (a pause while a clip is layered holds the layer's picture and time) and 1325 (a video's sound is read ahead of the clock and leads it). Both were written against eb9f1104 and ported across the refactors since. The faults are the first two and the third in docs/rune-upstream.md; the app's workarounds in review.rs stay until the fixes arrive upstream.
This commit is contained in:
1 parent
80fef698ce
commit
5bf262b82b
3795 files changed
+663463
-28
No files matched your search
+133
@@ -0,0 +1,133 @@
|
||||
# Motion audit
|
||||
|
||||
Per-frame traces of every element in the example apps, and a checker that flags motion a user
|
||||
would notice: snaps, pops, neighbours that jump, exits that vanish before they play, overshoot,
|
||||
motion that never settles, and work spent on things nobody can see.
|
||||
|
||||
```sh
|
||||
scripts/motion-audit/run.sh # record all scenarios into target/motion-audit
|
||||
python3 scripts/motion-audit/analyze.py target/motion-audit/*.jsonl [--quiet] [--json out.json]
|
||||
python3 scripts/motion-audit/track.py target/motion-audit/oc-send.jsonl composer/editor 80 120
|
||||
python3 scripts/motion-audit/test_analyze.py # analyze.py on synthetic traces
|
||||
```
|
||||
|
||||
`run.sh` records each scenario headless at 120 fps on the virtual clock with
|
||||
`--trace-all --trace`. `--trace-all` adds unkeyed elements (named by path) to the usual
|
||||
motion-lint JSONL, and every trace now says why each frame animated (`quality.why`) and which
|
||||
tracks it sampled (`tk`: `[element id or path, property, active]`; inactive means settling).
|
||||
It also says how far scrolling carries each element when that changes (`sc`: `[id, x, y]` in
|
||||
window points, scaled and turned as its rect is). The motion checks (overshoot, jiggle, reversal, stall, dog-leg) add it back, so a node
|
||||
gliding inside a list that follows its end is judged against the list, not the screen.
|
||||
|
||||
`analyze.py` reports, per trace:
|
||||
|
||||
| Finding | Meaning |
|
||||
| --- | --- |
|
||||
| `invisible-work` | tracks sampled on an element that is transparent, off-window, clipped or occluded |
|
||||
| `idle-frames`, `never-settles` | frames that animate with no visible change; motion still running at the end |
|
||||
| `pop-in`, `pop-out` | an element appears or disappears at full opacity and size with no transition |
|
||||
| `appear-then-jump` | mounts in one place, then moves there in a frame |
|
||||
| `jump`, `step`, `sibling-jump` | a one-frame change in position or size, on its own or next to something animating, seen on both frames and in what shows: the visible part in the window moves, or what the element holds that shows moves with it, or it brings what it holds into view with no input (a scroll offset that lands in one frame with nothing asking for it; a loop wrapping while transparent or clipped, or a fold dropping rows above the window with the scroll offset, is not one) |
|
||||
| `overshoot`, `jiggle` | passes its target, or reverses direction more than once |
|
||||
| `latency`, `hitch` | input with no motion for several frames; a frame over budget |
|
||||
| `cut-exit` | unmounts partway through its fade: nothing leaves above opacity 0 |
|
||||
| `reversal`, `dog-leg` | one motion heads the wrong way first or goes out and back; a route much longer than its chord, on screen and against its parent |
|
||||
| `stall` | one motion's speed drops for a frame and picks up again, as a retarget that lost part of its velocity does |
|
||||
|
||||
An app's scenario can say what each input should do with `"expect"` on its script event:
|
||||
|
||||
| Expect | Checks | Finding |
|
||||
| --- | --- | --- |
|
||||
| `instant` | everything in `scope` (an element name part) lands within a frame or two of the input; pops and jumps there are intended | `not-instant` |
|
||||
| `follow` | a drag's `element` moves 1:1 with the pointer while it moves (it may stop at a limit) | `lags-hand` |
|
||||
| `smooth` | after the input, `element` travels over several frames, not in one | `snap` |
|
||||
| `leaves` | `element` is what leaves, not a sibling (index keys remove the last row) | `wrong-exit` |
|
||||
|
||||
```sh
|
||||
python3 scripts/motion-audit/analyze.py --script s.json trace.jsonl --allow allow.json --fail
|
||||
```
|
||||
|
||||
`--allow` takes a JSON list of `{"trace", "kind" (or a list), "element" (a substring),
|
||||
"reason"}` rules for intended behaviour; every rule needs a reason, and a rule for a trace
|
||||
the run recorded that matched nothing is listed as unused. `--fail` exits non-zero when a finding isn't allowed.
|
||||
|
||||
A motion that hides what it moves (a fade to 0, a collapse, a slide out) runs on for a few
|
||||
frames below what anyone can see, down to its settle threshold. Up to 250 ms of that tail,
|
||||
ending as its track settles, isn't `invisible-work`. A loop (a spinner) runs for as long as
|
||||
it's shown, so frames animating only loops aren't `idle-frames` or `never-settles`.
|
||||
|
||||
Elements that draw nothing and hold nothing (hit and hover zones, spacers) carry the trace's
|
||||
blank flag (64). Nobody can see them come, go or move, so they don't pop, jump or count as
|
||||
drawn.
|
||||
|
||||
`track.py` prints one element's frames (rect, opacity, flags, sampled tracks) to confirm a
|
||||
finding. Add scenarios as script JSON under `scenarios/` and a `run` line in `run.sh`.
|
||||
|
||||
## An app's own motion gate (`rune::motion_gate`)
|
||||
|
||||
The scenarios above are Rune's examples, recorded as traces and read by `analyze.py`. An app
|
||||
gates its own motion inside `cargo test`, on its real view and state, with `rune::motion_gate`:
|
||||
|
||||
- `Run` wraps the app's `Runtime`: `idle` settles it unrecorded, `step`, `play` and `act` record
|
||||
frames on the virtual clock (an `act` marks an input, so motion it retargets isn't held to one
|
||||
path), and `quiet` marks where the cell's motion should end.
|
||||
- `check` lists what a person would see go wrong in a `Recording`: `pop-in`, `pop-out`,
|
||||
`cut-exit`, `jump`, `offset-jump`, `appear-then-jump`, `jerk`, `reversal`, `overshoot`,
|
||||
`jiggle`, `text-swap`, `fade-snap`, `flicker`, `load-motion`, `never-settles`, `loop-jump`,
|
||||
`wakes-after-end`, `lands-unseen`, `remount`, `unpinned`, `twice` and `scroll-commit` (the
|
||||
app ran its view through a scroll). Thresholds and meanings are the `RULES` table. Elements are tracked by tree
|
||||
path, so a keyed row keeps its identity however the rows around it change.
|
||||
- Beside geometry and opacity, `check` follows everything an element paints (fill, border,
|
||||
text, shadow, gradient and outline colours in OKLab, corners, border width, blurs, effect
|
||||
payload, image and paint order) and the composited window as a grid of cells: `snap` (a
|
||||
one-frame step between still frames), `flash` (it steps away and comes back, or drifts and
|
||||
snaps back) and `changes-twice` (it changes, rests, then carries on). A colour counts by how
|
||||
far it moves in OKLab and how much of it shows. The grid is a CPU raster of the painter
|
||||
stream, or real frames through `Run::pixels`; a region finding is named after the surface
|
||||
that changed, with ` (pixels)`. An input, a hover or press highlight landing, a
|
||||
`Tx::instant` commit, `El::instant_changes` and `El::motion_intent` (`BOUNCE`, `KICK`,
|
||||
`STEP`, `CUT`, `PULSE`, `TYPING`, …) mark a change as the design. Mark authored motion where
|
||||
it's written rather than allowing it.
|
||||
- `gate_rows(cells, ALLOW)` runs the app's cells (a name and a closure that records one) in
|
||||
parallel, checks them, and fails the test on any finding its allowlist doesn't cover. Each
|
||||
row is `AllowRow::new(kind, element contains, cells, why)`, needs its reason, scopes to the
|
||||
cells it names (`"island-auto|island-click"`) and caps what it covers with `.max(n)`. A
|
||||
whole run lists rows that matched nothing, so stale ones come out. `gate(cells, ALLOW)` takes
|
||||
the older `(kind, element, cell, why)` tuples.
|
||||
- Headless `rune` records the same checks with `RUNE_MOTION_GATE=<path>` (`run.sh` writes
|
||||
`<name>.gate.txt` per scenario), and an app stepping its own runtime can use `Sampler`.
|
||||
|
||||
The app keeps its scenarios, its circumstance matrix (cell names like `send/pinned/long/wide`)
|
||||
and its allowlist; Rune keeps the checker and the runner. The module docs show a whole test.
|
||||
`gate` runs one:
|
||||
|
||||
```sh
|
||||
scripts/motion-audit/gate -- -p my-app motion_gate # every cell
|
||||
scripts/motion-audit/gate send/pinned -- -p my-app motion_gate # cells whose name contains it
|
||||
scripts/motion-audit/gate --allowed -- -p my-app motion_gate # allowed findings too
|
||||
scripts/motion-audit/gate --dump 'send/pinned/long/wide|composer|120|160' -- -p my-app motion_gate
|
||||
scripts/motion-audit/gate --sheet 'send/pinned/long/wide|134|composer' -- -p my-app motion_gate
|
||||
```
|
||||
|
||||
`--dump` writes one cell's tracks frame by frame (rect, visible rect, opacity, scale, flags,
|
||||
and each painted property);
|
||||
`--sheet` writes a PNG strip of the frames around one, every element outlined as strongly as
|
||||
its opacity and the named one in red. An empty cell part (`'|composer|120|160'`) matches any
|
||||
cell, and headless `rune` writes both beside its `RUNE_MOTION_GATE` report. Both are evidence
|
||||
for reading a finding; the findings
|
||||
are the gate. `MOTION_GATE_OUT` names the report (default `$TMPDIR/motion-gate`), and
|
||||
`MOTION_GATE_WRAP` runs the test under a command prefix.
|
||||
|
||||
## Tracing the real app (`motion-trace.py`)
|
||||
|
||||
The gate runs headless on the virtual clock, so it says nothing about how long a real frame
|
||||
takes. For that, an app can write its own trace in the installed build, one JSON line per key,
|
||||
span and frame (the format is at the top of `motion-trace.py`), and read it:
|
||||
|
||||
```sh
|
||||
python3 scripts/motion-audit/motion-trace.py trace.jsonl --key Enter --frames 40 --budget 16.7
|
||||
```
|
||||
|
||||
For each matching key it prints how many frames passed before a watched element moved, then
|
||||
each frame's update and render cost, marking the ones over budget, with the spans over 1 ms in
|
||||
them.
|
||||
+1050
File diff suppressed because it is too large.
Load diff
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
# Runs an app's motion gate (`rune::motion_gate::gate` in one of its tests) and prints one line per
|
||||
# finding: kind, element, frame, detail and cell. Everything after `--` goes to `cargo test`, so it
|
||||
# names the app's package and test:
|
||||
# scripts/motion-audit/gate [CELL-FILTER] -- -p my-app motion_gate
|
||||
# scripts/motion-audit/gate --sheet 'add-row/wide|134[|path part]' -- -p my-app motion_gate
|
||||
# scripts/motion-audit/gate --dump 'add-row/wide|path part[|from|to]' -- -p my-app motion_gate
|
||||
# scripts/motion-audit/gate --allowed [CELL-FILTER] -- … also list allowlisted findings
|
||||
# `--sheet` writes a contact strip of the frames around one, the path part's outlines in red;
|
||||
# `--dump` writes those tracks' frames. Both name a cell, which is also the filter.
|
||||
# MOTION_GATE_OUT names the report file (default $TMPDIR/motion-gate). MOTION_GATE_WRAP runs the
|
||||
# test under a command prefix (a build-queue lease, say); without it, it's plain cargo.
|
||||
set -euo pipefail
|
||||
OUT=${MOTION_GATE_OUT:-${TMPDIR:-/tmp}/motion-gate}
|
||||
export MOTION_GATE_OUT=$OUT
|
||||
filter=""
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--sheet) export MOTION_GATE_SHEET=$2; filter=${2%%|*}; shift 2 ;;
|
||||
--dump) export MOTION_GATE_DUMP=$2; filter=${2%%|*}; shift 2 ;;
|
||||
--allowed) export MOTION_GATE_ALLOWED=1; shift ;;
|
||||
-h|--help) sed -n '2,13p' "$0"; exit 0 ;;
|
||||
--) shift; break ;;
|
||||
*) filter=$1; shift ;;
|
||||
esac
|
||||
done
|
||||
[[ $# -gt 0 ]] || { echo "motion gate: name the app's test after --, e.g. -- -p my-app motion_gate" >&2; exit 2; }
|
||||
export MOTION_GATE=$filter
|
||||
rm -f "$OUT" "$OUT.sheet.png" "$OUT.dump"
|
||||
wrap=()
|
||||
[[ -n ${MOTION_GATE_WRAP:-} ]] && read -r -a wrap <<<"$MOTION_GATE_WRAP"
|
||||
status=0
|
||||
${wrap[@]+"${wrap[@]}"} cargo test -q "$@" >/dev/null 2>&1 || status=$?
|
||||
if [[ -s "$OUT" ]]; then cat "$OUT"; else echo "motion gate: the test didn't run (exit $status); run cargo test $* to see why" >&2; exit 1; fi
|
||||
[[ -f "$OUT.sheet.png" ]] && echo "sheet: $OUT.sheet.png"
|
||||
[[ -f "$OUT.dump" ]] && echo "dump: $OUT.dump"
|
||||
exit $status
|
||||
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Reads an app's own motion trace, recorded in the installed app on real data, and prints, for
|
||||
each key press, how many frames until a watched element first moved, and every frame of the move
|
||||
that went over budget.
|
||||
|
||||
scripts/motion-audit/motion-trace.py TRACE.jsonl [--key Enter] [--frames 40] [--budget 16.7]
|
||||
|
||||
The trace is JSON lines the app writes (README.md, "Tracing the real app"):
|
||||
{"k":"key","ms":…,"key":"Enter"} a key, as the app's handler got it
|
||||
{"k":"span","ms":…,"name":"load","dur":…} time spent in one step on the main thread
|
||||
{"k":"frame","ms":…,"update":…,"render":…,"rows":{"row-1":[y,h,opacity],…}}
|
||||
`ms` is wall time since launch at the start of the step. A frame's cost is Rune's update
|
||||
(handlers, poll, view, layout) plus the compositor's render; over the budget, the display shows
|
||||
the previous frame again. `rows` holds whatever the app watches, by id, as numbers that change
|
||||
when it moves. Spans over 1 ms in the frame are listed beside it.
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("trace")
|
||||
ap.add_argument("--key", default="Enter")
|
||||
ap.add_argument("--frames", type=int, default=40)
|
||||
ap.add_argument("--budget", type=float, default=1000 / 60)
|
||||
a = ap.parse_args()
|
||||
lines = [json.loads(l) for l in open(a.trace) if l.strip()]
|
||||
frames = [l for l in lines if l["k"] == "frame"]
|
||||
spans = [l for l in lines if l["k"] == "span"]
|
||||
keys = [l for l in lines if l["k"] == "key" and a.key in l["key"]]
|
||||
|
||||
|
||||
def start(f):
|
||||
return f["ms"] - f["update"]
|
||||
|
||||
|
||||
def moved(a_, b):
|
||||
rows_a, rows_b = a_.get("rows", {}), b.get("rows", {})
|
||||
for id_, r in rows_a.items():
|
||||
o = rows_b.get(id_)
|
||||
if o is None or any(abs(x - y) > 0.01 for x, y in zip(o, r)):
|
||||
return True
|
||||
return any(id_ not in rows_a for id_ in rows_b)
|
||||
|
||||
|
||||
print(a.trace)
|
||||
for k in keys:
|
||||
i = next((i for i, f in enumerate(frames) if f["ms"] >= k["ms"]), None)
|
||||
if i is None:
|
||||
continue
|
||||
key_frame = frames[i]
|
||||
first = next((j for j in range(i + 1, len(frames)) if moved(frames[j - 1], frames[j])), None)
|
||||
# The key frame itself already moved rows: the move started on it.
|
||||
if moved(frames[i - 1], key_frame) if i else False:
|
||||
first = i
|
||||
sel = f" (sel {key_frame['sel']})" if "sel" in key_frame else ""
|
||||
print(f"\n{k['key']} at {k['ms']:.0f} ms, handled in the frame starting {start(key_frame):.0f} ms{sel}")
|
||||
if first is None:
|
||||
print(" nothing watched moved")
|
||||
continue
|
||||
print(f" first moved frame: +{first - i} frames, {frames[first]['ms'] + frames[first]['render'] - k['ms']:.0f} ms from the key to its render's end")
|
||||
over = 0
|
||||
for j in range(i, min(len(frames), i + a.frames)):
|
||||
f = frames[j]
|
||||
cost = f["update"] + f["render"]
|
||||
gap = start(f) - (frames[j - 1]["ms"] + frames[j - 1]["render"]) if j else 0
|
||||
if cost > a.budget:
|
||||
over += 1
|
||||
mark = "OVER" if cost > a.budget else " "
|
||||
big = [s for s in spans if start(f) <= s["ms"] < f["ms"] + f["render"] and s["dur"] > 1.0]
|
||||
moving = "move" if j and moved(frames[j - 1], f) else " "
|
||||
names = ", ".join(f"{s['name']} {s['dur']:.1f}" for s in big)
|
||||
print(f" {mark} +{j - i:2d} {moving} update {f['update']:6.1f} render {f['render']:5.1f} idle-before {gap:6.1f} {names}")
|
||||
print(f" frames over {a.budget:.1f} ms in the first {a.frames}: {over}")
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#!/bin/sh
|
||||
# Records a motion trace of every element (--trace-all) for each scenario below, at 120 fps on
|
||||
# the virtual clock, plus the final element tree and what rune::motion_gate finds (<name>.gate.txt).
|
||||
# Then scripts/motion-audit/analyze.py reads them.
|
||||
# Run from the repo root: scripts/motion-audit/run.sh [out-dir] (default target/motion-audit).
|
||||
set -e
|
||||
O=${1:-target/motion-audit}
|
||||
mkdir -p "$O"
|
||||
MOTION_GATE_OUT="$O/live-tail.gate.txt" sh scripts/motion-audit/scenarios/live-tail.sh
|
||||
cargo build --release -p todo -p settings -p kit-gallery -p odometer
|
||||
cargo build --release -p rune-kit --features rune/tooling --example shell --example tab_strip
|
||||
cargo build --release -p rune --features tooling --example growth_reorder --example keep_stuck --example sticky --example scroll_keys --example scroll_anchor --example text_glide --example one_snap
|
||||
B=${CARGO_TARGET_DIR:-target}/release
|
||||
SH=$B/examples/shell
|
||||
GR=$B/examples/growth_reorder
|
||||
KS=$B/examples/keep_stuck
|
||||
S=scripts/motion-audit/scenarios
|
||||
FPS=120
|
||||
|
||||
# name | seconds | command (trace args appended)
|
||||
run() {
|
||||
name=$1; secs=$2; shift 2
|
||||
frames=$(python3 -c "print(int($secs * $FPS))")
|
||||
echo "== $name ($frames frames)"
|
||||
RUNE_MOTION_GATE="$O/$name.gate.txt" "$@" --fps $FPS --frames "$frames" --trace-all --trace "$O/$name.jsonl" --tree "$O/$name-end.json"
|
||||
}
|
||||
|
||||
run todo-add-remove 4.4 $B/todo --script $S/todo-add-remove.json
|
||||
run settings-toggle-retarget 1.5 $B/settings --script examples/settings/scripts/toggle-retarget.json
|
||||
run settings-segmented-retarget 1.5 $B/settings --script examples/settings/scripts/segmented-retarget.json
|
||||
run settings-slider 3.0 $B/settings --script examples/settings/scripts/slider.json
|
||||
run settings-hover 3.0 $B/settings --script examples/settings/scripts/hover.json
|
||||
run gallery-combobox 3.0 $B/kit-gallery --scene rune-combobox--searchable --script examples/kit-gallery/scripts/combobox.json
|
||||
run gallery-combobox-animated 3.0 $B/kit-gallery --scene rune-combobox--animated-filter --script examples/kit-gallery/scripts/combobox-animated-filter.json
|
||||
run gallery-scroll-bar 4.0 $B/kit-gallery --scene rune-scroll-bar--basic --script $S/gallery-scroll-bar.json
|
||||
run gallery-scroll-bar-hover 3.2 $B/kit-gallery --scene rune-scroll-bar--basic --script $S/gallery-scroll-bar-hover.json
|
||||
run gallery-scroll-bar-grow 2.4 $B/kit-gallery --scene rune-scroll-bar--grow --scroll-bars always --script $S/gallery-scroll-bar-grow.json
|
||||
run gallery-modal 5.5 $B/kit-gallery --scene motion-focus-modal --script examples/kit-gallery/scripts/motion-focus-modal.json
|
||||
run gallery-stagger-list 3.0 $B/kit-gallery --scene motion-stagger-list --script examples/kit-gallery/scripts/motion-stagger-list.json
|
||||
run gallery-mermaid-stream 4.5 $B/kit-gallery --scene rune-markdown--mermaid-streaming --size 1100x1400 --script $S/gallery-mermaid-stream.json
|
||||
run gallery-markdown-stream-tail 3.0 $B/kit-gallery --scene rune-markdown--stream-tail --script $S/gallery-markdown-stream-tail.json
|
||||
run odometer 5.4 $B/odometer --script $S/odometer.json
|
||||
run shell-idle 2.0 $SH
|
||||
run shell-toggle 3.0 $SH --script $S/shell-toggle.json
|
||||
run shell-peek 5.0 $SH --script $S/shell-peek.json
|
||||
run shell-resize 3.6 $SH --script $S/shell-resize.json
|
||||
run shell-reorder 3.6 $SH --script $S/shell-reorder.json
|
||||
run shell-virtual-peek 5.0 $SH virtual --script $S/shell-peek.json
|
||||
run shell-virtual-reorder 3.6 $SH virtual --script $S/shell-reorder-virtual.json
|
||||
run shell-window-resize 3.0 $SH --script $S/shell-window-resize.json
|
||||
run shell-virtual-window-resize 3.0 $SH virtual --script $S/shell-window-resize.json
|
||||
run tab-strip 9.0 $B/examples/tab_strip --script $S/tab-strip.json
|
||||
run growth-reorder 4.2 $GR --script $S/growth-reorder.json
|
||||
run growth-reorder-virtual 4.0 $GR virtual --script $S/growth-reorder-virtual.json
|
||||
run keep-stuck 3.2 $KS --script $S/keep-stuck.json
|
||||
run growth-reorder-grow 3.5 $GR steer --script $S/growth-reorder-grow.json
|
||||
run growth-reorder-gap 4.7 $GR steer --script $S/growth-reorder-gap.json
|
||||
run growth-reorder-flight 2.6 $GR steer --script $S/growth-reorder-flight.json
|
||||
run sticky-scroll 1.6 $B/examples/sticky --script crates/rune/examples/sticky.json
|
||||
run scroll-keys 3.2 $B/examples/scroll_keys --script $S/scroll-keys.json
|
||||
run wheel-distance 1.2 $B/examples/scroll_keys --script $S/wheel-distance.json
|
||||
run scroll-anchor 3.4 $B/examples/scroll_anchor --script $S/scroll-anchor.json
|
||||
run text-glide 3.8 $B/examples/text_glide --script $S/text-glide.json
|
||||
run one-snap 4.4 $B/examples/one_snap --script $S/one-snap.json
|
||||
ls "$O"
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
[
|
||||
{"t":0.2,"type":"tap","key":"stream-more"},
|
||||
{"t":0.6,"type":"tap","key":"stream-more"},
|
||||
{"t":1.0,"type":"tap","key":"stream-more"},
|
||||
{"t":1.4,"type":"tap","key":"stream-more"},
|
||||
{"t":1.8,"type":"tap","key":"stream-more"}
|
||||
]
|
||||
@@ -0,0 +1,16 @@
|
||||
[
|
||||
{"t":0.2,"type":"tap","key":"stream-more"},
|
||||
{"t":0.45,"type":"tap","key":"stream-more"},
|
||||
{"t":0.7,"type":"tap","key":"stream-more"},
|
||||
{"t":0.95,"type":"tap","key":"stream-more"},
|
||||
{"t":1.2,"type":"tap","key":"stream-more"},
|
||||
{"t":1.45,"type":"tap","key":"stream-more"},
|
||||
{"t":1.7,"type":"tap","key":"stream-more"},
|
||||
{"t":1.95,"type":"tap","key":"stream-more"},
|
||||
{"t":2.2,"type":"tap","key":"stream-more"},
|
||||
{"t":2.45,"type":"tap","key":"stream-more"},
|
||||
{"t":2.7,"type":"tap","key":"stream-more"},
|
||||
{"t":2.95,"type":"tap","key":"stream-more"},
|
||||
{"t":3.2,"type":"tap","key":"stream-more"},
|
||||
{"t":3.45,"type":"tap","key":"stream-more"}
|
||||
]
|
||||
@@ -0,0 +1,5 @@
|
||||
[
|
||||
{ "t": 0.3, "type": "tap", "key": "more" },
|
||||
{ "t": 1.3, "type": "tap", "key": "more" },
|
||||
{ "t": 2.4, "type": "mark", "name": "end" }
|
||||
]
|
||||
@@ -0,0 +1,6 @@
|
||||
[
|
||||
{ "t": 0.25, "type": "move", "key": "item-3" },
|
||||
{ "t": 0.6, "type": "move", "key": "thumb" },
|
||||
{ "t": 1.4, "type": "move", "key": "item-3" },
|
||||
{ "t": 3.2, "type": "mark", "name": "end" }
|
||||
]
|
||||
@@ -0,0 +1,5 @@
|
||||
[
|
||||
{ "t": 0.25, "type": "scroll", "key": "feed", "dy": -260, "dur": 0.45 },
|
||||
{ "t": 1.9, "type": "scroll", "key": "feed", "dy": 140, "dur": 0.35 },
|
||||
{ "t": 4.0, "type": "mark", "name": "end" }
|
||||
]
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.38, "type": "tap", "key": "composer", "hold": 0 },
|
||||
{ "t": 0.47, "type": "tap", "key": "working", "hold": 0, "expect": "smooth" },
|
||||
{ "t": 1.5, "type": "move", "x": 10, "y": 10 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "tap", "key": "composer" },
|
||||
{ "t": 0.9, "type": "tap", "key": "composer" },
|
||||
{ "t": 2.6, "type": "tap", "key": "working", "expect": "smooth" },
|
||||
{ "t": 4.6, "type": "move", "x": 10, "y": 10 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "tap", "key": "composer" },
|
||||
{ "t": 1.8, "type": "tap", "key": "working", "expect": "smooth" },
|
||||
{ "t": 3.4, "type": "move", "x": 10, "y": 10 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "tap", "key": "v1", "expect": "smooth" },
|
||||
{ "t": 1.4, "type": "tap", "key": "v0", "expect": "smooth" },
|
||||
{ "t": 2.5, "type": "scroll", "x": 200, "y": 200, "dy": -300 },
|
||||
{ "t": 3.6, "type": "move", "x": 10, "y": 10 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "tap", "key": "working", "expect": "smooth" },
|
||||
{ "t": 1.4, "type": "tap", "key": "working", "expect": "smooth" },
|
||||
{ "t": 1.5, "type": "tap", "key": "working", "expect": "smooth" },
|
||||
{ "t": 2.6, "type": "tap", "key": "m1", "expect": "smooth" },
|
||||
{ "t": 3.8, "type": "move", "x": 10, "y": 10 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "scroll", "x": 210, "y": 180, "dy": 450, "dur": 0.4 },
|
||||
{ "t": 1.2, "type": "tap", "key": "hdr", "expect": "smooth", "element": "answer" },
|
||||
{ "t": 3.0, "type": "move", "x": 10, "y": 10 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
# A poll delivers a pending row; unchanged window, resizing, and reading above the end.
|
||||
exec scripts/motion-audit/gate live-tail -- -p rune --lib live_tail_motion_gate
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"events": [
|
||||
{"t": 0.3, "type": "tap", "key": "up", "expect": "smooth", "element": "secs.3"},
|
||||
{"t": 1.1, "type": "tap", "key": "down", "expect": "smooth", "element": "secs.5"},
|
||||
{"t": 1.9, "type": "tap", "key": "up"},
|
||||
{"t": 1.98, "type": "tap", "key": "down", "expect": "smooth", "element": "secs.8"},
|
||||
{"t": 2.8, "type": "tap", "key": "down", "expect": "smooth", "element": "count.8"},
|
||||
{"t": 3.4, "type": "tap", "key": "step"},
|
||||
{"t": 4.2, "type": "tap", "key": "big"}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.25, "type": "tap", "key": "stage", "expect": "smooth", "element": "hud" },
|
||||
{ "t": 1.6, "type": "tap", "key": "badge", "expect": "instant", "scope": "hud" },
|
||||
{ "t": 2.4, "type": "tap", "key": "stage", "expect": "smooth", "element": "hud" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "scroll", "key": "feed", "dy": -600, "dur": 0.4 },
|
||||
{ "t": 1.4, "type": "key", "name": "Enter" },
|
||||
{ "t": 2.4, "type": "key", "name": "Enter" },
|
||||
{ "t": 3.4, "type": "mark", "name": "end" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"events": [
|
||||
{"t": 0.1, "type": "move", "x": 200, "y": 220},
|
||||
{"t": 0.3, "type": "key", "name": "Down", "expect": "smooth", "element": "card-5"},
|
||||
{"t": 0.55, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.5833, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.6167, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.65, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.6833, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.7167, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.75, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.7833, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.8167, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.85, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.8833, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.9167, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.95, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 0.9833, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.0167, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.05, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.0833, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.1167, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.15, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.1833, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.2167, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.25, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.2833, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.3167, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.35, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.3833, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.4167, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.45, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.4833, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 1.5167, "type": "key", "name": "Down", "repeat": true},
|
||||
{"t": 2.2, "type": "key", "name": "Up"},
|
||||
{"t": 2.32, "type": "key", "name": "Up"},
|
||||
{"t": 2.44, "type": "key", "name": "Up"},
|
||||
{"t": 3.2, "type": "mark", "name": "end"}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "tap", "key": "sidebar-toggle" },
|
||||
{ "t": 0.9, "type": "move", "x": 700, "y": 400 },
|
||||
{ "t": 1.3, "type": "move", "x": 10, "y": 300 },
|
||||
{ "t": 1.9, "type": "move", "x": 150, "y": 300 },
|
||||
{ "t": 2.5, "type": "move", "x": 700, "y": 300 },
|
||||
{ "t": 3.2, "type": "move", "key": "sidebar-toggle" },
|
||||
{ "t": 3.7, "type": "tap", "key": "sidebar-toggle" },
|
||||
{ "t": 4.4, "type": "move", "x": 700, "y": 400 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "drag", "key": "v1", "dy": 120, "dur": 0.6 },
|
||||
{ "t": 1.6, "type": "drag", "key": "v0", "dy": 160, "dur": 0.8 },
|
||||
{ "t": 2.1, "type": "key", "name": "Escape" },
|
||||
{ "t": 3.2, "type": "move", "x": 700, "y": 400 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "drag", "key": "s2", "dy": 120, "dur": 0.6 },
|
||||
{ "t": 1.6, "type": "drag", "key": "s1", "dy": 160, "dur": 0.8 },
|
||||
{ "t": 2.1, "type": "key", "name": "Escape" },
|
||||
{ "t": 3.2, "type": "move", "x": 700, "y": 400 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "move", "key": "sidebar-grip" },
|
||||
{ "t": 0.6, "type": "drag", "key": "sidebar-grip", "dx": 140, "dur": 0.5 },
|
||||
{ "t": 1.5, "type": "drag", "key": "sidebar-grip", "dx": -320, "dur": 0.6 },
|
||||
{ "t": 2.5, "type": "double-click", "key": "sidebar-grip" },
|
||||
{ "t": 3.3, "type": "move", "x": 700, "y": 400 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "tap", "key": "sidebar-toggle" },
|
||||
{ "t": 1.0, "type": "move", "x": 700, "y": 400 },
|
||||
{ "t": 1.3, "type": "tap", "key": "sidebar-toggle" },
|
||||
{ "t": 2.2, "type": "move", "x": 700, "y": 400 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "resize", "dw": -320, "dur": 0.8 },
|
||||
{ "t": 1.5, "type": "resize", "dw": 320, "dh": 160, "dur": 0.8 },
|
||||
{ "t": 2.6, "type": "move", "x": 400, "y": 300 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "drag", "key": "top-list/t-s1", "dx": 300, "dur": 0.8 },
|
||||
{ "t": 1.6, "type": "drag", "key": "side-list/t-s6", "dy": -125, "dur": 0.7 },
|
||||
{ "t": 2.8, "type": "drag", "key": "side-list/t-s2", "dy": 90, "dur": 0.8 },
|
||||
{ "t": 3.3, "type": "key", "name": "Escape" },
|
||||
{ "t": 4.2, "type": "click", "key": "top-list/t-s7", "button": "middle" },
|
||||
{ "t": 4.6, "type": "click", "button": "middle" },
|
||||
{ "t": 5.2, "type": "move", "x": 700, "y": 500 },
|
||||
{ "t": 6.0, "type": "drag", "key": "top-list/t-s2", "dx": 70, "dy": 160, "dur": 0.8 },
|
||||
{ "t": 7.2, "type": "click", "key": "new-tab" },
|
||||
{ "t": 7.9, "type": "move", "x": 700, "y": 500 }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.3, "type": "tap", "key": "card", "expect": "smooth", "element": "card" },
|
||||
{ "t": 2.0, "type": "tap", "key": "card", "expect": "smooth", "element": "card" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"events": [
|
||||
{
|
||||
"t": 0.3,
|
||||
"type": "tap",
|
||||
"key": "add"
|
||||
},
|
||||
{
|
||||
"t": 0.9,
|
||||
"type": "tap",
|
||||
"key": "add"
|
||||
},
|
||||
{
|
||||
"t": 1.5,
|
||||
"type": "tap",
|
||||
"key": "todo-1/#2"
|
||||
},
|
||||
{
|
||||
"t": 2.1,
|
||||
"type": "tap",
|
||||
"key": "todo-2/check"
|
||||
},
|
||||
{
|
||||
"t": 2.7,
|
||||
"type": "tap",
|
||||
"key": "todo-0/#2"
|
||||
},
|
||||
{
|
||||
"t": 2.75,
|
||||
"type": "tap",
|
||||
"key": "add"
|
||||
},
|
||||
{
|
||||
"t": 3.6,
|
||||
"type": "move",
|
||||
"x": 10,
|
||||
"y": 10
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"events": [
|
||||
{ "t": 0.25, "type": "wheel", "x": 200, "y": 220, "dy": -120, "precise": false, "expect": "instant", "scope": "cards" },
|
||||
{ "t": 0.65, "type": "wheel", "x": 200, "y": 220, "dy": 12, "precise": true, "expect": "instant", "scope": "cards" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Checks analyze.py on small synthetic traces. Run: python3 scripts/motion-audit/test_analyze.py"""
|
||||
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
import analyze # noqa: E402
|
||||
|
||||
|
||||
def trace(states):
|
||||
"""A 120 Hz trace of one 10×10 element; `states` holds (x, opacity, visible width) per frame."""
|
||||
lines = [json.dumps({"width": 200, "height": 100, "hz": 120})]
|
||||
for k, (x, op, vis_w) in enumerate(states):
|
||||
fr = {"e": [[1, x, 40, 10, 10, op, 0, 0, max(x, 20), 40, vis_w, 10]], "quality": {"animating": True}}
|
||||
if k == 0:
|
||||
fr["m"] = [{"id": 1, "nm": "label/sheen"}]
|
||||
lines.append(json.dumps(fr))
|
||||
f = tempfile.NamedTemporaryFile("w", suffix=".jsonl", delete=False)
|
||||
f.write("\n".join(lines) + "\n")
|
||||
f.close()
|
||||
return f.name
|
||||
|
||||
|
||||
def jumps(states):
|
||||
path = trace(states)
|
||||
try:
|
||||
return [f for f in analyze.analyze(path)["findings"] if f["kind"] in ("jump", "step")]
|
||||
finally:
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
def sheen(wrap_from, wrap_to):
|
||||
"""A loop sliding right 0.5 pt a frame, then wrapping back to its start."""
|
||||
before = [(86 - 0.5 * (9 - i), *wrap_from) for i in range(10)]
|
||||
after = [(15 + 0.5 * i, *wrap_to) for i in range(10)]
|
||||
return before + after
|
||||
|
||||
|
||||
def scene(frames, flags=None, clips=None):
|
||||
"""A 120 Hz trace of named elements; each frame maps name -> (x, y, w, h, opacity), plus
|
||||
how far scrolling carries it as (x, y) when it scrolls, and a name missing from a frame is
|
||||
gone. A name's parent is its longest named prefix. `clips` maps a name to a window-space
|
||||
clip (x0, y0, x1, y1) cutting the visible part of it and what it holds. A frame's "@ev"
|
||||
lists the inputs the app recorded in it ("wheel 3.0")."""
|
||||
names = sorted({nm for fr in frames for nm in fr if nm != "@ev"})
|
||||
ids = {nm: i + 1 for i, nm in enumerate(names)}
|
||||
def parent(nm):
|
||||
cut = [nm[:j] for j in range(len(nm)) if nm[j] == "/" and nm[:j] in ids]
|
||||
return ids[cut[-1]] if cut else None
|
||||
lines = [json.dumps({"width": 400, "height": 400, "hz": 120})]
|
||||
alive, meta = set(), set()
|
||||
for fr in frames:
|
||||
out = {"e": [], "quality": {"animating": True}, "m": [], "g": [], "sc": [], "ev": fr.get("@ev", [])}
|
||||
fr = {nm: v for nm, v in fr.items() if nm != "@ev"}
|
||||
for nm, (x, y, w, h, op, *sc) in fr.items():
|
||||
out["sc"] += [[ids[nm], *sc[0]]] if sc else []
|
||||
if nm not in meta:
|
||||
meta.add(nm)
|
||||
out["m"].append({"id": ids[nm], "nm": nm, "pv": parent(nm)})
|
||||
vis = [x, y, w, h]
|
||||
for c in [c for p, c in (clips or {}).items() if nm == p or nm.startswith(p + "/")]:
|
||||
x0, y0 = max(vis[0], c[0]), max(vis[1], c[1])
|
||||
x1, y1 = min(vis[0] + vis[2], c[2]), min(vis[1] + vis[3], c[3])
|
||||
vis = [x0, y0, max(x1 - x0, 0), max(y1 - y0, 0)]
|
||||
out["e"].append([ids[nm], x, y, w, h, op, 0, (flags or {}).get(nm, 0), *vis])
|
||||
alive.add(nm)
|
||||
for nm in sorted(alive - set(fr)):
|
||||
out["g"].append(ids[nm])
|
||||
alive.discard(nm)
|
||||
lines.append(json.dumps(out))
|
||||
f = tempfile.NamedTemporaryFile("w", suffix=".jsonl", delete=False)
|
||||
f.write("\n".join(lines) + "\n")
|
||||
f.close()
|
||||
return f.name
|
||||
|
||||
|
||||
def kinds(frames, events=None, flags=None, clips=None):
|
||||
path = scene(frames, flags, clips)
|
||||
try:
|
||||
return [f["kind"] for f in analyze.analyze(path, {"events": events} if events else None)["findings"]]
|
||||
finally:
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
def ease(a, b, n):
|
||||
"""n frames easing from a to b (no overshoot)."""
|
||||
return [a + (b - a) * (1 - (1 - (i + 1) / n) ** 3) for i in range(n)]
|
||||
|
||||
|
||||
def hold(fr, n):
|
||||
return [dict(fr) for _ in range(n)]
|
||||
|
||||
|
||||
def main():
|
||||
# instant: a key whose answer fades in over 20 frames isn't a cut.
|
||||
still = {"root": (0, 0, 400, 400, 1.0)}
|
||||
key = [{"t": 0.1, "type": "key", "name": "Escape", "expect": "instant"}]
|
||||
fade = hold(still, 12) + [{**still, "root/panel": (10, 10, 100, 100, op)} for op in ease(0, 1, 20)] + hold({**still, "root/panel": (10, 10, 100, 100, 1)}, 20)
|
||||
assert "not-instant" in kinds(fade, key), "a fade answering an instant input"
|
||||
cut = hold(still, 12) + hold({**still, "root/panel": (10, 10, 100, 100, 1)}, 40)
|
||||
assert "not-instant" not in kinds(cut, key) and "pop-in" not in kinds(cut, key), "a cut is the answer, not a pop"
|
||||
|
||||
# follow: a drag that tracks the smoothstepped hand passes; one that trails it lags.
|
||||
drag = [{"t": 0.1, "type": "drag", "key": "handle", "dx": 120, "dur": 0.5, "expect": "follow", "element": "root/handle"}]
|
||||
def hand(k):
|
||||
f = max(0, min(60, math.floor((k / 120 - 0.1) / 0.5 * 60 + 1e-6))) / 60
|
||||
return 120 * f * f * (3 - 2 * f)
|
||||
track = [{**still, "root/handle": (10 + hand(k), 10, 20, 20, 1)} for k in range(100)]
|
||||
assert "lags-hand" not in kinds(track, drag), "a handle on the hand"
|
||||
lag, x = [], 10.0
|
||||
for k in range(100):
|
||||
x += (10 + hand(k) - x) * 0.3
|
||||
lag.append({**still, "root/handle": (x, 10, 20, 20, 1)})
|
||||
assert "lags-hand" in kinds(lag, drag), "a handle on a spring behind the hand"
|
||||
|
||||
# one monotonic path: a wind-up the wrong way, and an L-shaped route.
|
||||
at = lambda x, y: {**still, "root/card": (x, y, 40, 40, 1)}
|
||||
windup = hold(at(100, 100), 5) + [at(x, 100) for x in ease(100, 94, 4) + ease(94, 200, 16)] + hold(at(200, 100), 10)
|
||||
assert "reversal" in kinds(windup), "a wind-up before the move"
|
||||
straight = hold(at(100, 100), 5) + [at(x, 100) for x in ease(100, 200, 20)] + hold(at(200, 100), 10)
|
||||
assert not {"reversal", "dog-leg", "overshoot"} & set(kinds(straight)), "a straight eased move"
|
||||
ell = hold(at(100, 100), 5) + [at(x, 100) for x in ease(100, 200, 10)] + [at(200, y) for y in ease(100, 200, 10)] + hold(at(200, 200), 10)
|
||||
assert "dog-leg" in kinds(ell), "across, then down"
|
||||
# a chevron sliding along its row as the list scrolls: across on the list, up with it.
|
||||
list_y = ease(300, 200, 20) + [200] * 20
|
||||
slide = [0] * 18 + ease(0, 100, 20) + [100] * 2
|
||||
scroll = hold({**still, "root/list": (0, 300, 400, 100, 1), "root/list/chevron": (100, 310, 10, 10, 1)}, 5)
|
||||
scroll += [{**still, "root/list": (0, y, 400, 100, 1), "root/list/chevron": (100 + x, y + 10, 10, 10, 1)} for y, x in zip(list_y, slide)]
|
||||
assert "dog-leg" not in kinds(scroll + hold(scroll[-1], 10)), "a slide on a scrolling list"
|
||||
# an L of its own on a moving list is still one.
|
||||
ell_x, ell_y = ease(0, 100, 15) + [100] * 15, [0] * 15 + ease(0, 100, 15)
|
||||
ell_on = [{**still, "root/list": (0, y, 400, 100, 1), "root/list/chevron": (100 + x, y + 10 + dy, 10, 10, 1)}
|
||||
for y, x, dy in zip(ease(300, 200, 30), ell_x, ell_y)]
|
||||
assert "dog-leg" in kinds(scroll[:5] + ell_on + hold(ell_on[-1], 10)), "across, then down, on a moving list"
|
||||
# a drift out and back that rests a frame where it turns is still one motion.
|
||||
drift = hold(at(100, 100), 5) + [at(x, 100) for x in ease(100, 97.5, 6)] + hold(at(97.5, 100), 2) + [at(x, 100) for x in ease(97.5, 100, 12)] + hold(at(100, 100), 10)
|
||||
assert "reversal" in kinds(drift), "out and back with a rest at the turn"
|
||||
# in a list following its growing end, 2 pt a frame up: judged against the scroll.
|
||||
def scrolling(own, flags=0, told=True):
|
||||
frames = []
|
||||
for k in range(140):
|
||||
t = min(max(k - 40, 0), 60)
|
||||
frames.append({**still, "root/list/node": (100, 300 + own(t) - 2 * t, 40, 40, 1, *([(0, 2 * t)] if told else []))})
|
||||
return kinds(frames, flags={"root/list/node": flags})
|
||||
glide = lambda k: 60 * (1 - math.exp(-k / 8))
|
||||
assert "reversal" in scrolling(glide, told=False), "on screen the glide and the scroll turn back"
|
||||
assert not {"reversal", "jiggle", "overshoot", "stall"} & set(scrolling(glide)), "against the scroll it is one glide"
|
||||
assert not {"reversal", "jiggle", "overshoot", "stall"} & set(scrolling(glide, analyze.SCROLLING))
|
||||
wobble = lambda k: 2.5 * math.sin(k * 0.6)
|
||||
assert "jiggle" not in scrolling(wobble, told=False), "on screen it only ever rises"
|
||||
assert "jiggle" in scrolling(wobble), "against the scroll it wobbles"
|
||||
assert "jiggle" in scrolling(wobble, analyze.SCROLLING), "a scroll that moves doesn't excuse it"
|
||||
|
||||
# jumps are judged on what shows. A fold drops 900 pt above a 200 pt viewport in one frame
|
||||
# with the scroll offset: the content's and the fold's tops and heights step, while what
|
||||
# shows stays put.
|
||||
view = {"root/list": (0, 0, 400, 200)}
|
||||
def frame(content, fold, extra=None):
|
||||
return {**still, "root/list": (0, *content, 1), "root/list/fold": (0, *fold, 1),
|
||||
"root/list/fold/a": (0, 60, 400, 40, 1), "root/list/after": (0, 150, 400, 100, 1), **(extra or {})}
|
||||
drop = hold(frame((-1100, 400, 1500), (-900, 400, 1200)), 40) + hold(frame((-200, 400, 600), (0, 400, 300)), 40)
|
||||
found = set(kinds(drop, clips=view))
|
||||
assert not {"jump", "step", "sibling-jump"} & found, f"nothing that shows moves: {found}"
|
||||
# Shut from its stuck header, the fold drops its rows above the window and its top comes
|
||||
# in from the window's edge, gliding down from where it showed.
|
||||
def shut(top):
|
||||
return {**still, "root/list": (0, top - 1100, 400, 1500, 1), "root/list/fold": (0, top, 400, 200 - top, 1),
|
||||
"root/list/after": (0, 200, 400, 100, 1)}
|
||||
glide = hold(shut(-900), 40) + [shut(t) for t in (13, 43, 73, 100, 120, 135, 145, 150)] + hold(shut(150), 40)
|
||||
found = set(kinds(glide, clips=view))
|
||||
assert not {"jump", "step", "sibling-jump"} & found, f"it glides from where it showed: {found}"
|
||||
# A row that shows, teleported 100 pt in the scrolled list, jumps.
|
||||
row = lambda y: {"root/list/fold/row": (0, y, 400, 30, 1)}
|
||||
tele = hold(frame((-200, 400, 600), (0, 400, 300), row(20)), 40) + hold(frame((-200, 400, 600), (0, 400, 300), row(120)), 40)
|
||||
assert "jump" in kinds(tele, clips=view), "a row that shows jumps"
|
||||
# The content jumps 100 pt and the rows that show with it.
|
||||
shift = lambda dy: {**still, "root/list": (0, -600 + dy, 400, 2000, 1), "root/list/a": (0, 20 + dy, 400, 30, 1), "root/list/b": (0, 60 + dy, 400, 30, 1)}
|
||||
assert "jump" in kinds(hold(shift(0), 40) + hold(shift(100), 40), clips=view), "the content jumps with what shows of it"
|
||||
# The offset jumps 40 pt with no input: the first row, just under the viewport, pops 40 pt
|
||||
# into view, though nothing showed on both frames. Under a key, it's the key's scroll.
|
||||
pad = lambda dy: {**still, "root/list": (0, -dy, 400, 1100, 1), "root/list/row": (0, 300 - dy, 400, 40, 1)}
|
||||
padded = hold(pad(0), 40) + hold(pad(40), 40)
|
||||
port, scroll = {"root/list": (0, 0, 400, 300)}, {"root/list": analyze.SCROLLING, "root/list/row": analyze.SCROLLING}
|
||||
assert "jump" in kinds(padded, flags=scroll, clips=port), "content that teleports a row into view"
|
||||
end = [{"t": 40 / 120, "type": "key", "name": "End"}]
|
||||
assert not {"jump", "step"} & set(kinds(padded, end, flags=scroll, clips=port)), "a key's scroll"
|
||||
glide = hold(pad(0), 40) + [pad(y) for y in ease(0, 40, 20)] + hold(pad(40), 20)
|
||||
assert not {"jump", "step"} & set(kinds(glide, flags=scroll, clips=port)), "a scroll that glides"
|
||||
|
||||
# one steady speed: a retarget that drops part of its speed for a frame stalls; one that
|
||||
# keeps its speed and only pulls harder toward a farther target doesn't.
|
||||
xs = ease(100, 200, 20)
|
||||
slow = xs[7] + 0.3 * (xs[8] - xs[7])
|
||||
dip = xs[:8] + [slow] + [slow + v for v in ease(0, 230 - slow, 24)]
|
||||
assert "stall" in kinds(hold(at(100, 100), 5) + [at(x, 100) for x in dip] + hold(at(dip[-1], 100), 10)), "a re-aim that lost its speed for a frame"
|
||||
def spring(x, v, target, n, k=320.0, c=36.0, dt=1 / 120):
|
||||
out = []
|
||||
for _ in range(n):
|
||||
v += (k * (target - x) - c * v) * dt
|
||||
x += v * dt
|
||||
out.append(x)
|
||||
return out, v
|
||||
first, v = spring(100.0, 0.0, 200.0, 10)
|
||||
retarget, _ = spring(first[-1], v, 240.0, 60)
|
||||
assert "stall" not in kinds(hold(at(100, 100), 5) + [at(x, 100) for x in first + retarget] + hold(at(retarget[-1], 100), 10)), "a retarget at its own speed"
|
||||
assert "stall" not in kinds(straight), "a straight eased move"
|
||||
# A scroll bar's thumb follows the wheel: a wheel that slows to a stop and a fling that
|
||||
# picks it up again is the hand's speed, not a lost retarget.
|
||||
wheeled = [{**at(x, 100), "@ev": [f"wheel {v:.1f}"]} for x, v in zip(dip[:9], range(9, 0, -1))]
|
||||
wheeled[8]["@ev"] = ["fling 1800"]
|
||||
flung = hold(at(100, 100), 5) + wheeled + [at(x, 100) for x in dip[9:]] + hold(at(dip[-1], 100), 10)
|
||||
assert "stall" not in kinds(flung), "the thumb slows and picks up with the wheel"
|
||||
|
||||
# nothing unmounts above opacity 0.
|
||||
half = hold({**still, "root/chip": (10, 10, 50, 20, 1)}, 5) + [{**still, "root/chip": (10, 10, 50, 20, op)} for op in ease(1, 0.4, 6)] + hold(still, 10)
|
||||
assert "cut-exit" in kinds(half), "a fade cut short at 0.4"
|
||||
full = hold({**still, "root/chip": (10, 10, 50, 20, 1)}, 5) + [{**still, "root/chip": (10, 10, 50, 20, op)} for op in ease(1, 0, 12)] + hold(still, 10)
|
||||
assert not {"cut-exit", "pop-out"} & set(kinds(full)), "a fade to 0, then gone"
|
||||
|
||||
# an instant scroll (wrapping to a long list's end) mounts the rows it lands on and drops the
|
||||
# rows it left: the scroll, not pops. The same swap with no scroll pops.
|
||||
top = {**still, "root/list/a": (0, 0, 200, 30, 1), "root/list/b": (0, 30, 200, 30, 1)}
|
||||
end = {**still, "root/list/y": (0, 0, 200, 30, 1), "root/list/z": (0, 30, 200, 30, 1)}
|
||||
swap = hold(top, 10) + hold(end, 20)
|
||||
assert {"pop-in", "pop-out"} <= set(kinds(swap)), "rows swapped in place"
|
||||
assert not {"pop-in", "pop-out"} & set(kinds(swap, flags={"root/list/y": 4 | 8, "root/list/z": 4 | 8})), "rows scrolled in"
|
||||
|
||||
# stable identity: closing row a must remove a, not b (index keys remove the last row).
|
||||
rows = lambda *ks: {**still, **{f"root/list/{k}": (0, 30 * i, 200, 30, 1) for i, k in enumerate(ks)}, "root/list": (0, 0, 200, 90, 1)}
|
||||
close = [{"t": 0.1, "type": "tap", "key": "a/close", "expect": "leaves", "element": "root/list/a"}]
|
||||
assert "wrong-exit" in kinds(hold(rows("a", "b", "c"), 12) + hold(rows("a", "b"), 40), close), "the last row left instead"
|
||||
assert "wrong-exit" not in kinds(hold(rows("a", "b", "c"), 12) + hold(rows("b", "c"), 40), close), "row a left"
|
||||
|
||||
# smooth: a release that lands in one frame snaps.
|
||||
release = [{"t": 0.1, "type": "drag", "key": "card", "dx": 50, "dur": 0.1, "expect": "smooth", "element": "root/card"}]
|
||||
assert "snap" in kinds(hold(at(100, 100), 30) + hold(at(200, 100), 40), release), "a landing in one frame"
|
||||
assert "snap" not in kinds(hold(at(100, 100), 30) + [at(x, 100) for x in ease(100, 200, 24)] + hold(at(200, 100), 20), release), "a glide"
|
||||
|
||||
assert not jumps(sheen((1.0, 0.0), (1.0, 5.0))), "a wrap from clipped away isn't a jump"
|
||||
assert not jumps(sheen((0.0, 10.0), (1.0, 5.0))), "a wrap from transparent isn't a jump"
|
||||
assert not jumps(sheen((1.0, 10.0), (0.0, 10.0))), "a wrap into transparent isn't a jump"
|
||||
found = jumps(sheen((1.0, 10.0), (1.0, 10.0)))
|
||||
assert len(found) == 1 and found[0]["at"] == "10", f"a wrap in sight is: {found}"
|
||||
|
||||
# scale-settle: a <= 100 ms pixel-snap settle right after motion isn't idle; a cold or long one is.
|
||||
def scale_settle_trace(settle_frames, preceded_by_motion=True):
|
||||
lines = [json.dumps({"width": 200, "height": 100, "hz": 120})]
|
||||
lines.append(json.dumps({"m": [{"id": 1, "nm": "stage"}], "e": [[1, 10, 10, 40, 20, 1, 0, 0]], "quality": {"animating": False, "why": []}}))
|
||||
if preceded_by_motion:
|
||||
lines.append(json.dumps({"e": [[1, 14, 10, 64, 32, 1, 0, 1]], "tk": [[1, "scale", 1]], "quality": {"animating": True, "why": ["tracks"]}}))
|
||||
for _ in range(settle_frames):
|
||||
lines.append(json.dumps({"quality": {"animating": True, "why": ["scale-settle"]}}))
|
||||
lines.append(json.dumps({"quality": {"animating": False, "why": []}}))
|
||||
f = tempfile.NamedTemporaryFile("w", suffix=".jsonl", delete=False)
|
||||
f.write("\n".join(lines) + "\n")
|
||||
f.close()
|
||||
try:
|
||||
return [x["kind"] for x in analyze.analyze(f.name)["findings"]]
|
||||
finally:
|
||||
os.unlink(f.name)
|
||||
|
||||
assert "idle-frames" not in scale_settle_trace(12, True), "100 ms scale-settle after motion"
|
||||
assert "idle-frames" in scale_settle_trace(20, True), "overrun scale-settle"
|
||||
assert "idle-frames" in scale_settle_trace(6, False), "cold scale-settle"
|
||||
print("ok")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,93 @@
|
||||
"""Retargets split trajectories, never excuse bad motion between destinations."""
|
||||
import json
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import analyze
|
||||
from test_analyze import scene
|
||||
|
||||
|
||||
class Retargets(unittest.TestCase):
|
||||
def findings(self, xs, goals=None, parent=None, opacity=1, flags=None):
|
||||
frames = [{"root": (0, 0, 400, 400, 1), "root/piece": (x, 40, 10, 10, opacity)} for x in xs]
|
||||
frames = [frames[0]] * 80 + frames + [frames[-1]] * 80
|
||||
path = scene(frames, flags=flags)
|
||||
try:
|
||||
with open(path) as f:
|
||||
rows = [json.loads(line) for line in f]
|
||||
for k, mask in (goals or {}).items():
|
||||
rows[81 + k]["retarget"] = [[1 if parent else 2, mask, mask if parent == "scale" else mask & 3]]
|
||||
with open(path, "w") as f:
|
||||
f.write("\n".join(json.dumps(row) for row in rows))
|
||||
return {f["kind"] for f in analyze.analyze(path)["findings"]}
|
||||
finally:
|
||||
os.unlink(path)
|
||||
|
||||
def test_a_new_destination_is_not_one_out_and_back(self):
|
||||
xs = [40, 42, 44, 46, 48, 50, 48, 46, 44, 42, 40]
|
||||
self.assertIn("reversal", self.findings(xs))
|
||||
self.assertNotIn("reversal", self.findings(xs, {6: 1}))
|
||||
# A different property's goal cannot excuse this axis.
|
||||
self.assertIn("reversal", self.findings(xs, {6: 2}))
|
||||
|
||||
def test_parent_motion_carries_children_but_size_does_not(self):
|
||||
xs = [40, 42, 44, 46, 48, 50, 48, 46, 44, 42, 40]
|
||||
self.assertNotIn("reversal", self.findings(xs, {6: 15}, parent="scale"))
|
||||
self.assertIn("reversal", self.findings(xs, {6: 4}, parent="size"))
|
||||
|
||||
def test_retarget_preserves_decelerating_incoming_velocity(self):
|
||||
xs = [40, 44, 48, 51, 53, 54, 53, 51, 48, 44, 40, 36, 33, 31, 30]
|
||||
self.assertNotIn("reversal", self.findings(xs, {3: 1}))
|
||||
xs[4:6] = [55, 60] # Accelerates away instead of braking.
|
||||
self.assertIn("reversal", self.findings(xs, {3: 1}))
|
||||
|
||||
def test_bad_motion_before_another_retarget_is_still_checked(self):
|
||||
xs = [40, 44, 48, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32]
|
||||
self.assertIn("reversal", self.findings(xs, {10: 1}))
|
||||
|
||||
def test_a_jump_on_the_retarget_frame_still_fails(self):
|
||||
self.assertIn("jump", self.findings([40, 40, 40, 100, 100, 100], {3: 1}))
|
||||
|
||||
def test_a_retarget_that_loses_velocity_still_fails(self):
|
||||
self.assertIn("stall", self.findings([40, 43, 46, 46.2, 49.2, 52.2, 55.2], {3: 1}))
|
||||
|
||||
def thumb(self, ys, goal=None, flags=0):
|
||||
"""A scroll bar's thumb beside a scrolled list, with `goal` = (frame, name) retargeted."""
|
||||
def at(y):
|
||||
return {"area": (0, 0, 400, 400, 1), "area/view": (0, 0, 390, 400, 1), "area/view/list": (0, -50, 390, 900, 1, (0, 50)),
|
||||
"area/bar": (390, 0, 10, 400, 1), "area/bar/thumb": (392, y, 6, 120, 1), "other": (0, 0, 10, 10, 1)}
|
||||
frames = [at(ys[0])] * 80 + [at(y) for y in ys] + [at(ys[-1])] * 80
|
||||
path = scene(frames, flags={"area/bar/thumb": flags})
|
||||
try:
|
||||
with open(path) as f:
|
||||
rows = [json.loads(line) for line in f]
|
||||
ids = {m["nm"]: m["id"] for m in rows[1]["m"]}
|
||||
if goal:
|
||||
rows[81 + goal[0]]["retarget"] = [[ids[goal[1]], 8, 0]]
|
||||
with open(path, "w") as f:
|
||||
f.write("\n".join(json.dumps(row) for row in rows))
|
||||
return {f["kind"] for f in analyze.analyze(path)["findings"]}
|
||||
finally:
|
||||
os.unlink(path)
|
||||
|
||||
def test_a_thumb_brakes_when_the_list_it_reads_retargets(self):
|
||||
ys = [40, 44, 48, 51, 53, 54, 53, 51, 48, 44, 40, 36, 33, 31, 30]
|
||||
self.assertIn("reversal", self.thumb(ys, flags=1))
|
||||
self.assertTrue({"reversal", "dog-leg"}.isdisjoint(self.thumb(ys, (3, "area/view/list"), flags=1)))
|
||||
# Only the content it reads moves its destination.
|
||||
self.assertIn("reversal", self.thumb(ys, (3, "other"), flags=1))
|
||||
|
||||
def test_a_placed_readout_has_no_shape_of_its_own(self):
|
||||
ys = [40, 44, 48, 51, 53, 54, 53, 51, 48, 44, 40, 36, 33, 31, 30]
|
||||
self.assertNotIn("reversal", self.thumb(ys, flags=3 << 8))
|
||||
# Springing, it answers for its own path.
|
||||
self.assertIn("reversal", self.thumb(ys, flags=3 << 8 | 1))
|
||||
|
||||
def test_invisible_or_intentionally_instant_retargets_are_not_stalls(self):
|
||||
xs = [40, 43, 46, 46.2, 49.2, 52.2, 55.2]
|
||||
self.assertNotIn("stall", self.findings(xs, {3: 1}, opacity=0))
|
||||
self.assertNotIn("stall", self.findings(xs, {3: 1}, flags={"root/piece": 1 << 8}))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Prints one element's per-frame state from a Rune trace: frame, t, rect, opacity, flags,
|
||||
visible rect, and the tracks sampled for it.
|
||||
|
||||
Usage: scripts/motion-audit/track.py TRACE.jsonl NAME-SUBSTRING [FROM [TO]] [--all-names]
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
path, needle = sys.argv[1], sys.argv[2]
|
||||
rest = [a for a in sys.argv[3:] if not a.startswith("--")]
|
||||
lo = int(rest[0]) if rest else 0
|
||||
hi = int(rest[1]) if len(rest) > 1 else 10**9
|
||||
names, state, alive = {}, {}, set()
|
||||
with open(path) as f:
|
||||
f.readline()
|
||||
frames = [json.loads(l) for l in f if l.strip()]
|
||||
if "--all-names" in sys.argv:
|
||||
for fr in frames:
|
||||
for m in fr.get("m", []):
|
||||
if needle in m["nm"]:
|
||||
names[m["id"]] = m["nm"]
|
||||
for id, n in names.items():
|
||||
print(id, n)
|
||||
return
|
||||
for k, fr in enumerate(frames):
|
||||
for m in fr.get("m", []):
|
||||
names[m["id"]] = m["nm"]
|
||||
rows = {r[0]: r for r in fr.get("e", [])}
|
||||
for id, r in rows.items():
|
||||
state[id] = r
|
||||
alive.add(id)
|
||||
gone = set(fr.get("g", []))
|
||||
tk = {}
|
||||
for who, prop, active in fr.get("tk", []):
|
||||
tk.setdefault(who, []).append(prop + ("" if active else "·"))
|
||||
if not (lo <= k <= hi):
|
||||
alive -= gone
|
||||
continue
|
||||
for id in sorted(set(rows) | (gone & alive)):
|
||||
if needle not in names.get(id, ""):
|
||||
continue
|
||||
if id in gone:
|
||||
print(f"{k:4} {fr['t']:8.1f} {names[id][-50:]:<50} GONE")
|
||||
continue
|
||||
r = state[id]
|
||||
vis = f" vis={r[8:12]}" if len(r) >= 12 else ""
|
||||
q = fr.get("quality", {})
|
||||
print(f"{k:4} {fr['t']:8.1f} {names[id][-50:]:<50} x={r[1]:<8} y={r[2]:<8} w={r[3]:<8} h={r[4]:<8} op={r[5]:<6} fl={r[7]}{vis} tk={tk.get(id, '')} {'+'.join(q.get('why', []))}")
|
||||
alive -= gone
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user