summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig69
1 files changed, 69 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig
index a13acada..5b4afbb6 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -5906,3 +5906,72 @@ test "a far client's window found again is instant: its refocus asks the session
try std.testing.expectEqual(@as(u32, 0), r.stats.stopped);
try std.testing.expectEqual(@as(u32, 2), r.stats.fast);
}
+
+/// Kind `ops`'s code in the client for its pane `id`, as a client that
+/// has its library runs it (initDump: Addon.plainOps, dump.plainHere).
+fn runsHere(r: *Replica, id: usize, ops: *const pardes.Kind.Ops) !void {
+ const was = Stepping.begin(&r.t, &r.epoch);
+ defer was.end();
+ const c = r.core();
+ const slot = c.panes[id].?.addon.?;
+ c.kinds.ops[c.kinds.byName(slot.nameOf()).?] = ops;
+ c.panes[id].?.addon = try pardes.dump.plainHere(c, id, slot, ops);
+}
+
+/// A plain kind that takes the mouse (normal mode has its keys).
+const Pointed = struct {
+ const pa = pardes.Kind.c;
+ fn mouse(_: ?*anyopaque, _: [*c]const pa.pa_mouse) callconv(.c) c_int {
+ return 1;
+ }
+ const words = [_]pa.pa_word{std.mem.zeroInit(pa.pa_word, .{ .name = "Pointed", .opens = 1, .doc = "a pane that takes the mouse" })};
+ const ops = std.mem.zeroInit(pardes.Kind.Ops, .{
+ .head = std.mem.zeroInit(pa.pa_head, .{ .size = @sizeOf(pa.pa_head), .abi = pardes.Kind.abi, .name = "pointed".* ++ @as([9]u8, @splat(0)), .version = 1, .exts = "", .flags = pa.PA_PLAIN, .words = &words, .nwords = 1 }),
+ .open = Still.open,
+ .paint = Still.paint,
+ .mouse = mouse,
+ });
+};
+
+// A press grabs a kind's pane (the drag and release after it are the
+// kind's wherever they land); a step between can leave that pane too
+// short for a row of body, and the drag's row clamped into an empty range
+// tripped std.math.clamp's assertion (the soak, once, at rtt 207, in a
+// client's speculation).
+test "a far client's drag in a kind's pane it grabbed, the pane since too short for a row of body: the kind is told its edge, at once and as on the session" {
+ const gpa = std.testing.allocator;
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false);
+ defer a.deinit();
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ const pointed = pardes.Kind.loadedOf(&Pointed.ops, "/x/pointed.so", @splat(8), &words);
+ _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &pointed } });
+ _ = try a.local(.{ .command = "Pointed" });
+ const kid = a.core.view().active;
+ const r = try joinedFresh(a);
+ defer r.deinit();
+ try runsHere(r, kid, &Pointed.ops);
+ const rect = r.core().view().rects[kid];
+ const col = rect.x + 4;
+ const row = rect.y + r.core().panes[kid].?.tag_rows + 1;
+ var sent: std.ArrayListUnmanaged([]u8) = .empty;
+ defer {
+ for (sent.items) |m| gpa.free(m);
+ sent.deinit(gpa);
+ }
+ for ([_]pardes.Event{
+ .{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row } },
+ .{ .resize = .{ .cols = 80, .rows = 4 } },
+ .{ .mouse = .{ .button = .left, .kind = .drag, .col = col, .row = 30 } },
+ .{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = 30 } },
+ }) |ev| {
+ try sent.append(gpa, try gpa.dupe(u8, try r.input(ev)));
+ }
+ try std.testing.expectEqual(@as(u16, 1), r.core().view().rects[kid].h);
+ try std.testing.expectEqual(@as(u32, 0), r.stats.stopped);
+ for (sent.items) |m| {
+ r.confirm(try a.take(m));
+ r.settle();
+ }
+ try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted);
+ try agrees(a, r);
+}