diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/gui/gui.zig | 42 | ||||
| -rw-r--r-- | dev/host_io.zig | 2 | ||||
| -rw-r--r-- | dev/tui/tui.zig | 44 |
3 files changed, 76 insertions, 12 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index d779cf47..bdbd7880 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -808,7 +808,9 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di var want_w: c_int = 1120; var want_h: c_int = 720; var want_at: ?[2]c_int = null; - if (opts_in.geometry) |spec| geometry: { + // ...or the size an Upgrade's exec says its window had (client.zig + // `execAgain`). + if (opts_in.geometry orelse if (std.c.getenv("PARDES_JOIN_SIZE")) |e| std.mem.span(e) else null) |spec| geometry: { const x_at = std.mem.indexOfScalar(u8, spec, 'x') orelse break :geometry; const plus = std.mem.indexOfAnyPos(u8, spec, x_at, "+-") orelse spec.len; want_w = std.math.clamp(std.fmt.parseInt(c_int, spec[0..x_at], 10) catch break :geometry, 200, 16384); @@ -1026,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. @@ -1247,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))); @@ -1289,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 @@ -1414,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, }; @@ -2839,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| { @@ -4729,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; @@ -4874,6 +4894,16 @@ fn buildDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, g } else false; if (grid_bottom < win_h and tag_last) try addDecor(g, gpa, 0, grid_bottom, win_w, win_h, chrome.tag_bg, 1, win_w, win_h); try paneDecor(g, gpa, regions, surface.rail_ticks[0..surface.nrail_ticks], chrome, layout, surface.cols, surface.rows, win_w, win_h); + // The changes' lanes (jj.paint): a strip a level in the gutter's + // lane cells, each a third of a cell wide with half that of air + // before it, so three take one and a half cells (the ruled + // sample A); whole pixels, so every row's strip lines up. + for (surface.lanes.items) |lane| { + const w = @max(1, @round(layout.w / 3)); + const x0 = @round(@as(f32, @floatFromInt(lane.x)) * layout.w + w / 2 + @as(f32, @floatFromInt(lane.level)) * (w + w / 2)); + const y0 = @as(f32, @floatFromInt(lane.y)) * layout.h; + try addDecor(g, gpa, x0, y0, x0 + w, y0 + layout.h, lane.rgb, 1, win_w, win_h); + } // A single spine runs down each column, through every tag and body. for (regions) |column| { if (column.kind != .column) continue; 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 09704424..92ac6a0c 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -731,17 +731,30 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, posix.sigaddset(&winch_set, posix.SIG.HUP); posix.sigaddset(&winch_set, posix.SIG.TERM); hangup_quits = true; + // Last of all, after its goodbye and its terminal put back: dead of the + // TERM or HUP that ended it, as the own path's stub dies (the shell's + // $? is 128+N), not exit 0. + defer dieOfQuitSignal(); 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); @@ -808,6 +821,7 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, var status: c_int = 0; while (libc.waitpid(@intCast(start.joined.pid), &status, 0) < 0 and libc.errno(-1) == .INTR) {} } + dieOfQuitSignal(); std.process.exit(code); }, .failed => { @@ -1626,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 {}; } @@ -1954,6 +1971,22 @@ fn keepSignal(_: posix.SIG) callconv(.c) void {} /// A replica client's (`runClient`): a hangup or a TERM is its end. var hangup_quits = false; +/// The signal a client's `.quit` came of (`winchWatch`), 0 for none. +var quit_signal: std.atomic.Value(c_int) = .init(0); + +/// A client ended by TERM or HUP dies of it, its goodbye said and its +/// terminal put back first; no other way out. +fn dieOfQuitSignal() void { + const sig: posix.SIG = @enumFromInt(quit_signal.load(.acquire)); + if (@backingInt(sig) == 0) return; + const default: posix.Sigaction = .{ .handler = .{ .handler = posix.SIG.DFL }, .mask = posix.sigemptyset(), .flags = 0 }; + posix.sigaction(sig, &default, null); + var set = posix.sigemptyset(); + posix.sigaddset(&set, sig); + posix.sigprocmask(posix.SIG.UNBLOCK, &set, null); + _ = std.c.raise(sig); +} + fn winchWatch(loop: *Loop) void { var set = posix.sigemptyset(); posix.sigaddset(&set, posix.SIG.WINCH); @@ -1965,6 +1998,7 @@ fn winchWatch(loop: *Loop) void { // The terminals are the loop's: it asks each its size, and takes a // hangup as the end of the one that hung up. const ev: Msg = if (sig == @backingInt(posix.SIG.WINCH)) .winched else if (hangup_quits) .quit else .hangup; + if (ev == .quit) quit_signal.store(sig, .release); loop.postEvent(ev) catch {}; } } |
