summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/gui/gui.zig28
-rw-r--r--dev/host_io.zig2
-rw-r--r--dev/tui/tui.zig22
3 files changed, 41 insertions, 11 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index 47fd14d5..bdbd7880 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -1028,7 +1028,7 @@ const Own = struct {
.fs = l.fs,
.test_mode = o.test_mode,
.test_clock = if (o.test_mode) host_io.testClock() else null,
- .test_hz = if (std.c.getenv("PARDES_TEST_HZ")) |hz| @max(1, std.fmt.parseInt(u64, std.mem.span(hz), 10) catch 60) else 60,
+ .test_hz = testHz(),
.peers = &l.peers,
};
// A virtual clock never blinks: goldens and feel series hold still.
@@ -1249,6 +1249,12 @@ const Client = struct {
const minimized = !cl.test_mode and c.SDL_GetWindowFlags(g.window) & (c.SDL_WINDOW_MINIMIZED | c.SDL_WINDOW_OCCLUDED) != 0;
cl.moving = !minimized and frontendMoving(g);
cl.blink = if (minimized or cl.shell.surface == null) null else blinkNow(g, g.facts.cursor_blink);
+ // Idle, as the session's own window says it (writeTestStatus), once
+ // it has what the session was told: its digest asked when quiet
+ // and answered since the last unit (Link.quietCheck).
+ // A replica's `needs_frame` is the session's steps' since it last
+ // drew (Replica.draw): its own owed frame is the link's.
+ if (cl.test_mode) writeTestStatus(g, cl.in.core, cl.shell.presented and l.link.r.quiet() and !l.link.changed and !l.link.asked, l.link.dirty or l.link.owed);
if (latency_fd >= 0) return client_loop.forever;
var ms: u32 = if (cl.test_mode) 16 else client_loop.forever;
if (demoDue(g)) |due| ms = @min(ms, @as(u32, @intCast(due)));
@@ -1291,6 +1297,11 @@ const Client = struct {
_ = c.SDL_SetWindowTitle(g.window, "pardes");
}
if (cl.moving or (cl.blink != null and (cl.blink.?.edge or timed_out))) cl.again_due = true;
+ // A virtual clock: its own motion moves a display frame a pass, as
+ // the own window's (waitInput); the core's time is its session's.
+ if (cl.shell.test_clock) |*virtual| if (cl.moving) {
+ virtual.* += std.time.ns_per_s / cl.shell.test_hz;
+ };
}
/// Its own view drawn in the window, as the tty's client draws its
@@ -1416,6 +1427,8 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_
.queue = &queue,
.watches = &no_watches,
.test_mode = test_mode,
+ .test_clock = if (test_mode) host_io.testClock() else null,
+ .test_hz = testHz(),
.client = &window,
.peers = &no_peers,
};
@@ -2841,7 +2854,7 @@ fn pollFrame(ctx: ?*anyopaque) void {
const geom = windowCells(g);
if (updateCoreResize(core, geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height)) resetScroll(g);
stepScroll(g, core, s.gpa);
- if (s.test_mode) writeTestStatus(g, core, s.presented);
+ if (s.test_mode) writeTestStatus(g, core, s.presented, core.needs_frame);
// A blink edge, or the window's own motion (its glide, its caret, a
// jump's trail): the last frame again, moved on, no core render.
if ((g.blink_due or frontendMoving(g)) and !core.needs_frame and s.presented) if (s.surface) |frame| {
@@ -4731,14 +4744,19 @@ fn captureFrame(g: *Gui, gpa: std.mem.Allocator, cmd: *c.SDL_GPUCommandBuffer, t
/// sees a step past the one it acted on, idle, has its frame, however slow
/// the machine is.
var test_status_step: u64 = 0;
-fn writeTestStatus(g: *const Gui, core: *const pardes.Pardes, presented: bool) void {
+/// PARDES_TEST_HZ: the display rate a virtual clock stands in for.
+fn testHz() u64 {
+ return if (std.c.getenv("PARDES_TEST_HZ")) |hz| @max(1, std.fmt.parseInt(u64, std.mem.span(hz), 10) catch 60) else 60;
+}
+
+fn writeTestStatus(g: *const Gui, core: *const pardes.Pardes, presented: bool, needs_frame: bool) void {
test_status_step +%= 1;
if (g.capture_dir.len == 0) return;
- const idle = presented and !core.needs_frame and !frontendMoving(g) and core.nextWake() == null and
+ const idle = presented and !needs_frame and !frontendMoving(g) and core.nextWake() == null and
!g.glide.moving() and g.scroll_lag == 0 and g.scroll_delta == 0 and g.scroll_notch == 0;
var line_buf: [64]u8 = undefined;
// What keeps it busy, after: owes a frame, moves, waits, not shown.
- const line = std.fmt.bufPrint(&line_buf, "{d} {d} {d} {d}{d}{d}{d}\n", .{ test_status_step, g.captured, @intFromBool(idle), @intFromBool(core.needs_frame), @intFromBool(frontendMoving(g)), @intFromBool(core.nextWake() != null), @intFromBool(!presented) }) catch unreachable; // seven numbers fit 64
+ const line = std.fmt.bufPrint(&line_buf, "{d} {d} {d} {d}{d}{d}{d}\n", .{ test_status_step, g.captured, @intFromBool(idle), @intFromBool(needs_frame), @intFromBool(frontendMoving(g)), @intFromBool(core.nextWake() != null), @intFromBool(!presented) }) catch unreachable; // seven numbers fit 64
var tmp_buf: [4096]u8 = undefined;
var final_buf: [4096]u8 = undefined;
const tmp_path = std.fmt.bufPrintSentinel(&tmp_buf, "{s}/status.tmp", .{g.capture_dir}, 0) catch return;
diff --git a/dev/host_io.zig b/dev/host_io.zig
index a22bf5ce..419c4570 100644
--- a/dev/host_io.zig
+++ b/dev/host_io.zig
@@ -52,7 +52,7 @@ pub fn stopWorkers() void {
/// session is one view, the live one's (the tty's terminal, the window's
/// window): the others are let go, as a detach of each.
pub fn restoreCore(gpa: std.mem.Allocator, core: *pardes.Pardes, path: []const u8, peers: *replica.Peers, inotify_fd: c_int, watches: *file_watch.Table) ?*pardes.Pardes {
- peers.dropAll(core);
+ peers.restoring(core);
const bytes = pardes.dump.restoreBytes(core, gpa, path) catch |err| {
core.reportError(.at(core.view().active), "Restore", err);
return null;
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig
index 7e5a75fb..92ac6a0c 100644
--- a/dev/tui/tui.zig
+++ b/dev/tui/tui.zig
@@ -738,14 +738,23 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8,
if (comptime builtin.os.tag == .freebsd)
posix.sigaction(.WINCH, &.{ .handler = .{ .handler = keepSignal }, .mask = posix.sigemptyset(), .flags = 0 }, null);
posix.sigprocmask(posix.SIG.BLOCK, &winch_set, null);
- var start: client_loop.Start = undefined;
- if (!start.open(init, opts, .{ .path = path, .session = session, .far = far_link })) Said.no(io, "{s}", .{start.said()});
- defer start.close();
var tty_buf: [0x10000]u8 = undefined;
var screen: Screen = .{ .io = io, .gpa = gpa, .env = init.environ_map, .buf = &tty_buf, .kitty = .init(gpa) };
defer screen.kitty.deinit();
- try screen.enter(try vaxis.Tty.init(io, &tty_buf));
+ // A pair's terminal is its own before its join, as the own frontend's
+ // is before its core: that join is the pair's whole start (its own
+ // boot, replica.ownBoot), and keys typed meanwhile are its input, not
+ // echoed by the line discipline and lost as it enters. An attach enters
+ // once joined, a refusal said on the terminal as it was.
+ if (opts.pair != null) try screen.enter(try vaxis.Tty.init(io, &tty_buf));
defer screen.leave();
+ var start: client_loop.Start = undefined;
+ if (!start.open(init, opts, .{ .path = path, .session = session, .far = far_link })) {
+ screen.leave();
+ Said.no(io, "{s}", .{start.said()});
+ }
+ defer start.close();
+ if (opts.pair == null) try screen.enter(try vaxis.Tty.init(io, &tty_buf));
defer screen.glide.deinit(gpa);
defer screen.art.deinit(gpa);
var paste_buf: std.Io.Writer.Allocating = .init(gpa);
@@ -1631,9 +1640,12 @@ const Shell = struct {
return false;
}
- /// Terminal `screen` (its view live) is `ws` big.
+ /// Terminal `screen` (its view live) is `ws` big; the size it has is no
+ /// resize (a client's start takes its size before its input thread's
+ /// first one comes: Tty.start).
fn resized(s: *Shell, screen: ?*Screen, ws: vaxis.Winsize) void {
if (screen) |sc| {
+ if (sc.size) |was| if (std.meta.eql(was, ws)) return;
sc.size = ws;
sc.vx.resize(s.gpa, sc.tty.writer(), ws) catch {};
}