summaryrefslogtreecommitdiff
path: root/core/views.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/views.zig')
-rw-r--r--core/views.zig27
1 files changed, 16 insertions, 11 deletions
diff --git a/core/views.zig b/core/views.zig
index b8698854..9d627a17 100644
--- a/core/views.zig
+++ b/core/views.zig
@@ -473,7 +473,7 @@ pub fn deinit(p: *Pardes) void {
for (&p.views) |*slot| if (slot.*) |*v| freeView(p, v);
}
-pub const Present = struct { ctx: ?*anyopaque, f: ?*const fn (?*anyopaque, *const pardes.Surface) void };
+pub const Present = struct { ctx: ?*anyopaque, f: ?*const fn (?*anyopaque, *const pardes.Surface) bool };
/// The view this process's frontend shows: the one open view that is no
/// replica client's (`undrawn`) and kept for none (`away`), if there is one.
@@ -482,23 +482,28 @@ pub fn shown(p: *const Pardes) ?u8 {
return null;
}
-fn drawLive(present: Present, p: *Pardes) anyerror!void {
+fn drawLive(drawn: *Drawn, p: *Pardes) anyerror!void {
_ = p.frame_arena.reset(.{ .retain_with_limit = pardes.memory.limits.frame_kept });
const surface = try p.render(p.frame_arena.allocator());
- if (present.f) |f| f(present.ctx, surface);
+ if (drawn.present.f) |f| drawn.shown = f(drawn.present.ctx, surface);
}
+const Drawn = struct { present: Present, shown: bool = true };
+
/// View `k` drawn and presented outside any step (the pump's other views,
/// a replica client's own): the live view put back after exactly as it
-/// was, so the digest is the same. No post_present.
-pub fn drawOne(p: *Pardes, k: u8, present: Present) !void {
- try within(p, k, present, drawLive);
+/// was, so the digest is the same. No post_present. Whether the frontend
+/// showed it (Host.present).
+pub fn drawOne(p: *Pardes, k: u8, present: Present) !bool {
+ var drawn: Drawn = .{ .present = present };
+ try within(p, k, &drawn, drawLive);
+ return drawn.shown;
}
/// `f(ctx, p)` with view `k` live, outside any step, and the live view put
-/// back after exactly as it was, as `drawOne` draws one: what a replica
-/// client's frontend reads of its own view (its pointer's cells, its size)
-/// while another client's input was the session's last. What going into
+/// back after exactly as it was: how `drawOne` draws one while another
+/// client's input was the session's last (a frontend reads what it needs
+/// of its view from the frame: surface.Facts). What going into
/// `k` and drawing it made of it (its layout worked out, a cursor brought
/// inside a changed text) is not kept: it is done again, in every replica
/// alike, when `k` is next live by an input.
@@ -791,7 +796,7 @@ test "drawing another view leaves the live one as it was, to the digest" {
p.toView(0);
cursorTo(p, pane, 95);
const before = pardes.walk.digest(Pardes, p);
- try drawOne(p, k, .{ .ctx = null, .f = null });
+ _ = try drawOne(p, k, .{ .ctx = null, .f = null });
try testing.expectEqual(@as(u8, 0), p.live);
try testing.expectEqual(before, pardes.walk.digest(Pardes, p));
p.toView(k);
@@ -809,7 +814,7 @@ test "a view drawn while another is live keeps its own cursors" {
try testing.expectEqual(@as(u16, 1), pane.body.nsel);
p.toView(0);
const before = pardes.walk.digest(Pardes, p);
- try drawOne(p, k, .{ .ctx = null, .f = null });
+ _ = try drawOne(p, k, .{ .ctx = null, .f = null });
try testing.expectEqual(before, pardes.walk.digest(Pardes, p));
p.toView(k);
try testing.expectEqual(@as(u16, 1), pane.body.nsel);