summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-18 11:31:49 -0300
committerGabriel Schneider <[email protected]>2026-11-18 11:52:03 -0300
commit0cc7413bbf1d546f29976b9639896a209e2e7f27 (patch)
tree4c19d4b7fec4c6c3143859347f04f3561303ed46
parentdd4858222aa5a24fdefbb52bb3abf7a31c7e692c (diff)
downloadpardes-0cc7413bbf1d546f29976b9639896a209e2e7f27.tar.gz
pardes-0cc7413bbf1d546f29976b9639896a209e2e7f27.zip
pdf: a view laid out as the active one is (a window client the size of its session's window) takes the active view's top as it is, fraction and all, where it took it from the place rounded to a pixel: the client's own view, whose wheel moved it, showed its pages at the top's floor and the session's window at the place's rounding, a pixel lower or higher whenever a glide or a touchpad left the top at half a pixel or more (68,362 pixels of the lower page in 4 of 10 and 4 of 8 runs of a window client of a window session with a picture beside the PDF, 0 of 10 without the picture); 20 runs after: 0 differ; a session with one view lays out as before; a test of a window client and its session's window of one size, 0.6 of a notch scrolled in the client: the same rows shown (fails before: src.y 25 against 24); tui core-test 820/959 (139 skipped), shell-test 994/997, behaviour-test 274/274, --replay 20 seeds 0 failures, pane-test 181/182, replicas pass, addon-test 1/1, process-test 2 of 144 failed (lspcomplete and lspcompletemoved, the base's), test/daemon.py, --far, --games and --window-clients pass; gui unit-test 1589/1593 (its perf check's BaselineBuildMismatch, the base's), the frame corpus 77/77 against mbase2
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--addons/pdf/pdf.zig7
-rw-r--r--test/panes.zig57
2 files changed, 63 insertions, 1 deletions
diff --git a/addons/pdf/pdf.zig b/addons/pdf/pdf.zig
index c9a49b7c..1e0fb311 100644
--- a/addons/pdf/pdf.zig
+++ b/addons/pdf/pdf.zig
@@ -1209,7 +1209,12 @@ fn layout(st: *Pdf, l: *Layout, k: usize) void {
}
if (l.rev != st.rev) { // a pixel's: P:F rounds
const sp = stripOf(st, ownOf(st), k);
- l.top = @round(f64Of(sp.y[st.page]) + std.math.clamp(st.frac, 0, 1) * f64Of(sp.ph[st.page]));
+ // Laid as the active view is (a window of its size in another
+ // process): the active's top as it is, a fraction and all, so the
+ // two show the same pixels (from P:F, rounded, one showed its page
+ // a pixel off the other's).
+ const same = if (pixels(st, st.active)) |a| a != l and a.rev == st.rev and a.vw == vw and a.vh == vh and a.fit == l.fit else false;
+ l.top = if (same) st.views[st.active - 1].top else @round(f64Of(sp.y[st.page]) + std.math.clamp(st.frac, 0, 1) * f64Of(sp.ph[st.page]));
l.rev = st.rev;
}
l.top = std.math.clamp(l.top, 0, f64Of(l.height -| l.vh));
diff --git a/test/panes.zig b/test/panes.zig
index fb8adc36..34c81801 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -4178,6 +4178,63 @@ const PdfAddon = struct {
try std.testing.expect(notch > 0 and first > at[0] and first < at[1]);
try std.testing.expectApproxEqRel(notch / 4, at[2] - at[1], 0.05);
}
+
+ test "a window client the size of its session's window shows a PDF's pages where the session's window shows them, a fraction of a pixel scrolled and all" {
+ if (!addons.has_pdf) return error.SkipZigTest;
+ const R = pardes.replica;
+ const gpa = std.testing.allocator;
+ const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &host_vtable }, false);
+ defer a.deinit();
+ const win = try R.Replica.init(gpa, 2, try a.unit(0, 0), false);
+ defer win.deinit();
+ const land = struct {
+ a: *R.Authority,
+ r: *R.Replica,
+ fn step(l: @This(), ev: pardes.Event) !void {
+ l.r.confirm(try l.a.local(ev));
+ }
+ }{ .a = a, .r = win };
+ // The session's window, and the client's of its size on a view of its own.
+ const window: pardes.Event = .{ .frontend = .{ .windowed = true, .native_images = true } };
+ try land.step(window);
+ // The client has the addon (a test's replica finds no library of
+ // its own: it is handed the session's, loaded in this process).
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ var why: pardes.Kind.Buf(160) = .{};
+ const lib = pardes.Addon.readLoaded(pdf_lib, &words, &why);
+ try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } });
+ const kind = a.core.kinds.n - 1;
+ win.core().kinds.ops[kind] = a.core.kinds.ops[kind];
+ const id = try opened(a, land);
+ const k = try a.openView(2);
+ win.confirm(k.unit);
+ win.view = k.view;
+ win.confirm(try a.take(try win.input(window)));
+ try land.step(.tick);
+ // A touchpad's 0.6 of a notch in the client: its view's top a
+ // fraction of a pixel past a row (as a glide's half steps leave it).
+ const r = win.core().view().rects[id];
+ win.confirm(try a.take(try win.input(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = r.x + 4, .row = r.y + r.h - 2, .amount = 0.6 } })));
+ for (0..2) |_| {
+ try land.step(.tick);
+ try jobs(a.core, land);
+ }
+ win.settle();
+ try std.testing.expect(win.diverged == null);
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var at: [2][8][4]u32 = @splat(@splat(@splat(0)));
+ for ([_]*Pardes{ a.core, win.core() }, [_]u8{ 0, k.view }, &at) |core, view, *rows| {
+ core.toView(view);
+ var n: usize = 0;
+ for ((try core.render(arena.allocator())).placements.items) |pl| if (pl.pane == id and pl.raster.w > 1 and n < rows.len) {
+ rows[n] = if (pl.at) |x| .{ x.y, x.h, pl.src.y, pl.src.h } else .{ 0, 0, pl.src.y, pl.src.h };
+ n += 1;
+ };
+ try std.testing.expect(n > 0);
+ }
+ try std.testing.expectEqualSlices([4]u32, &at[0], &at[1]);
+ }
};
test {