summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/mouse.zig7
-rw-r--r--core/replica.zig69
2 files changed, 74 insertions, 2 deletions
diff --git a/core/mouse.zig b/core/mouse.zig
index 3d7c5af9..8d0aebc8 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -247,8 +247,11 @@ fn kindMouse(p: *Pardes, m: Mouse) bool {
if (m.kind == .press) v.active = id;
if (m.kind == .press and m.button != .wheel_up and m.button != .wheel_down and m.button != .wheel_left and m.button != .wheel_right) v.kind_grab = @intCast(id);
if (m.kind == .release) v.kind_grab = null;
- const col = std.math.clamp(m.col, x0, r.x + r.w -| 1) - x0;
- const row = std.math.clamp(m.row, top, r.y + r.h -| 1) - top;
+ // Grabbed, it may be anywhere, and the pane since made too narrow
+ // or short for a cell of body (a resize, a pane added above): its
+ // body's last cell, the first of none.
+ const col = @min(m.col -| x0, (r.x + r.w) -| x0 -| 1);
+ const row = @min(m.row -| top, (r.y + r.h) -| top -| 1);
return pardes.Kind.mouse(p, id, m, col, row);
}
kindLeave(p);
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);
+}