diff options
Diffstat (limited to 'src/views.zig')
| -rw-r--r-- | src/views.zig | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/src/views.zig b/src/views.zig index b9760143..361d14a3 100644 --- a/src/views.zig +++ b/src/views.zig @@ -508,28 +508,64 @@ pub fn drawOthers(p: *Pardes, h: pardes.Host) !void { } for (0..max) |i| { const k: u8 = @intCast(i); - if (k == live or !isOpen(p, k)) continue; - // `unpark` hands each slot's selections to its body; drawn, the - // view is out again, and they are the slot's again (else a frame - // drawn would take them from a view, and a replica that draws - // nothing would keep them). - var sels: [MAX_PANES]struct { s: @TypeOf(@as(Pane, undefined).body.sels), n: @TypeOf(@as(Pane, undefined).body.nsel) } = undefined; - for (p.panes, 0..) |s, id| if (s) |pane| { - sels[id] = .{ .s = pane.pv[k].body.sels, .n = pane.pv[k].body.nsel }; - }; - defer for (p.panes, 0..) |s, id| if (s) |pane| { - pane.pv[k].body.sels = sels[id].s; - pane.pv[k].body.nsel = sels[id].n; - }; - unpark(p, k); - _ = p.frame_arena.reset(.{ .retain_with_limit = pardes.memory.limits.frame_kept }); - const surface = try p.render(p.frame_arena.allocator()); - if (v.present) |f| f(h.ctx, surface); + if (k == live or !isOpen(p, k) or p.undrawn & (@as(u8, 1) << @intCast(k)) != 0) continue; // No post_present: what a shell acknowledges there moves the // session's pointer and hover, which are the live view's to move; // a view's panels are acknowledged when it is live and drawn. - copy(&drawn_fields, &p.parked[k].?.view, p); + try drawParked(p, k, .{ .ctx = h.ctx, .f = v.present }); + } +} + +pub const Present = struct { ctx: ?*anyopaque, f: ?*const fn (?*anyopaque, *const pardes.Surface) void }; + +/// Parked view `k` unparked, drawn and presented. `unpark` hands each +/// slot's selections to its body; drawn, the view is out again, and they +/// are the slot's again (else a frame drawn would take them from a view, +/// and a replica that draws nothing would keep them). +fn drawParked(p: *Pardes, k: u8, present: Present) !void { + var sels: [MAX_PANES]struct { []Text.SelRange, u16 } = undefined; + for (p.panes, 0..) |s, id| if (s) |pane| { + sels[id] = .{ pane.pv[k].body.sels, pane.pv[k].body.nsel }; + }; + unpark(p, k); + defer for (p.panes, 0..) |s, id| if (s) |pane| { + pane.pv[k].body.sels = sels[id][0]; + pane.pv[k].body.nsel = sels[id][1]; + }; + _ = 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); + copy(&drawn_fields, &p.parked[k].?.view, p); +} + +/// View `k` drawn and presented outside any step, by a replica client +/// (src/replica.zig) whose own it is: as `drawOthers` draws one, the live +/// view put back after exactly as it was, so the replica's digest is the +/// authority's still. No post_present, as there. +pub fn drawOne(p: *Pardes, k: u8, present: Present) !void { + if (k == p.view or !isOpen(p, k)) { + _ = 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); + return; + } + const live = p.view; + park(p); + defer { + copy(&fields, p, &p.parked[live].?.view); + p.view = live; + for (p.panes) |s| if (s) |pane| { + const pv = &pane.pv[live]; + copy(&pane_fields, pane, pv); + copy(&body_fields, &pane.body, &pv.body); + if (!pane.isTerminal()) { + pane.cols = pv.cols; + pane.rows = pv.rows; + } + if (pane.file) |*f| f.scroll = pv.scroll; + }; } + try drawParked(p, k, present); } // ---- tests ---- |
