diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-18 23:31:53 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 07:26:38 -0300 |
| commit | 2d30f3781ab40c38710835806a1029359509d27b (patch) | |
| tree | 282b4cee975ee2d74a53691acd99cfc03d55ef89 /dev/gui/gui.zig | |
| parent | 5e162e2e8b208367720b8be8de3bfe51b010aa68 (diff) | |
| download | pardes-2d30f3781ab40c38710835806a1029359509d27b.tar.gz pardes-2d30f3781ab40c38710835806a1029359509d27b.zip | |
frontends: the terminal and the window draw and turn input into events from the frame and one record beside it (the reorganisation's runners, step 10a, on the line as it is now): surface.Facts, the core's (Pardes.facts) and pointed at by the frame it is filled for (Surface.facts), filled by draw.place in the walk over the panes it makes anyway and by a runner after an input it applied (draw.facts), carries what a frontend took from the core (the view's size, cell pixels and row metrics, each open pane's rectangle, tag rows, context rows, serial, whether a terminal whose program takes the wheel or a kind's, its mode, the jumps' back and forward, the settings it draws by); the window keeps a copy (Gui.facts) with the frame it shows (Gui.frame) and its hit tests, wheel, touchpad rows, timedemo, blink, overlays and dim read only those; Host.present returns whether the frame was shown, so present_skipped leaves the core and nothing writes it; the frame statistics are the runner's (Options.frames, Pardes.frames a pointer to them), which the frontends write and the core's draw reads; Replica.draw returns the shown and keeps needs_frame itself, so the two client loops put nothing back; OwnView and Replica.within are deleted (the window client's own pass reads its facts, its inputs fed after each event as before); rollback-bench compiles again; the tape's watched fields lose present_skipped and present answers a bool, so the semantics word moves (0900e560fd6395ef, pardes-seam-b's, -> 2f615168fe07b35f). The first version (psvoxrup, on pardes-tree) kept the record by value in every Surface, and every Surface a tag line builds for a moment copied its 1.3 KB more: +1,556 instructions an image-frame, +3,763 a render (perf record: memcpy); now perfops against tree1 97 counts within 0.1%, largest image-frame +0.029%. Brought onto pardes-seam-b: the client set-up keeps the Distrusted list beside the runner's frame statistics, Options' local fields both, and the rollback test's present answers a bool. Gate: frames 77/77 byte-identical in Debug, the alternated windows' pictures identical in all 10 ReleaseFast runs, corpus2x -0.039% (PASS); tui core-test 836/979 (143 skipped), shell-test 1014/1017, term-test 15/15, pane-test 183/184, kitty-test 45/45, behaviour-test 275/275 and --replay 275/275, process-test lspcomplete and lspcompletemoved (the base's) and grep (passed alone three times of three); gui unit-test 1612/1616 with the base's BaselineHarnessMismatch; replicas --clients 5 diverged 0, unequal 0, deltas wrong 0, quiet 470/0, 600/0, 764/0; daemon.py plain, --far, --games, --window-clients, --upgrade both ways (from pardes-tree's pfx-base); the macOS library for Linux and aarch64-macos and the FreeBSD tui configure; rollback-bench runs
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'dev/gui/gui.zig')
| -rw-r--r-- | dev/gui/gui.zig | 382 |
1 files changed, 209 insertions, 173 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 2e22e537..a632f67a 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -196,8 +196,9 @@ fn updateCoreResize(core: *pardes.Pardes, cols: u16, rows: u16, cell_w: u32, cel } /// The resize a window of `cols` by `rows` cells of these sizes is to the -/// live view, or null when it is that already. -fn resizeOf(v: *const pardes.Pardes.View, cols: u16, rows: u16, cell_w: u32, cell_h: u32, tag_w: u32, tag_h: u32) ?pardes.Event { +/// live view (a View, or the Facts a frame carries of it), or null when it +/// is that already. +fn resizeOf(v: anytype, cols: u16, rows: u16, cell_w: u32, cell_h: u32, tag_w: u32, tag_h: u32) ?pardes.Event { const metrics: pardes.RowMetrics = .{ .body_w = @intCast(cell_w), .body_h = @intCast(cell_h), .tagline_w = @intCast(tag_w), .tagline_h = @intCast(tag_h) }; const same_metrics = std.meta.eql(metrics, v.row_metrics); const cell_px_w: u16 = @intCast(@min(@max(1, cell_w), std.math.maxInt(u16))); @@ -329,7 +330,7 @@ fn takeScrollTicks(accum: *f32) i32 { return ticks; } -fn handleFinger(t: *Touch, in: *Input, f: Finger, win_w: f32, win_h: f32, cell_w: f32, cell_h: f32, tagline_w: f32) void { +fn handleFinger(g: *const Gui, t: *Touch, in: *Input, f: Finger, win_w: f32, win_h: f32, cell_w: f32, cell_h: f32, tagline_w: f32) void { std.debug.assert(cell_w > 0 and cell_h > 0); switch (f.kind) { .down => { @@ -342,27 +343,27 @@ fn handleFinger(t: *Touch, in: *Input, f: Finger, win_w: f32, win_h: f32, cell_w t.syncPair(); if (!had_pair) return; const res = t.noteMotion(f) orelse return; - emitTouchScroll(in, res.center, res.ticks, win_w, win_h, cell_w, cell_h, tagline_w); + emitTouchScroll(g, in, res.center, res.ticks, win_w, win_h, cell_w, cell_h, tagline_w); }, .up, .cancel => { const tap_center = t.finishPair(f); t.updatePoint(f); t.syncPair(); - if (tap_center) |center| emitTouchClick(in, center, .middle, win_w, win_h, cell_w, cell_h, tagline_w); + if (tap_center) |center| emitTouchClick(g, in, center, .middle, win_w, win_h, cell_w, cell_h, tagline_w); }, } } -fn emitTouchScroll(in: *Input, center: TouchNormPoint, ticks: i32, win_w: f32, win_h: f32, cell_w: f32, cell_h: f32, tagline_w: f32) void { - const cell = gridCellAtDimensions(in.core, center.x * win_w, center.y * win_h, cell_w, cell_h, tagline_w); +fn emitTouchScroll(g: *const Gui, in: *Input, center: TouchNormPoint, ticks: i32, win_w: f32, win_h: f32, cell_w: f32, cell_h: f32, tagline_w: f32) void { + const cell = gridCellAtDimensions(g, center.x * win_w, center.y * win_h, cell_w, cell_h, tagline_w); const button: pardes.Mouse.Button = if (ticks > 0) .wheel_up else .wheel_down; var remaining: u32 = @abs(ticks); while (remaining > 0) : (remaining -= 1) in.post(.{ .mouse = .{ .button = button, .kind = .press, .col = cell.col, .row = cell.row, .tag_hit = cell.tag_hit, .body_hit = cell.body_hit } }); } -fn emitTouchClick(in: *Input, point: TouchNormPoint, button: pardes.Mouse.Button, win_w: f32, win_h: f32, cell_w: f32, cell_h: f32, tagline_w: f32) void { - const cell = gridCellAtDimensions(in.core, point.x * win_w, point.y * win_h, cell_w, cell_h, tagline_w); +fn emitTouchClick(g: *const Gui, in: *Input, point: TouchNormPoint, button: pardes.Mouse.Button, win_w: f32, win_h: f32, cell_w: f32, cell_h: f32, tagline_w: f32) void { + const cell = gridCellAtDimensions(g, point.x * win_w, point.y * win_h, cell_w, cell_h, tagline_w); in.post(.{ .mouse = .{ .button = button, .kind = .press, .col = cell.col, .row = cell.row, .tag_hit = cell.tag_hit, .body_hit = cell.body_hit } }); in.post(.{ .mouse = .{ .button = button, .kind = .release, .col = cell.col, .row = cell.row, .tag_hit = cell.tag_hit, .body_hit = cell.body_hit } }); } @@ -527,6 +528,13 @@ const Gui = struct { /// The core the hit test asks (hitTest), while a local session runs; /// null attached, where the session's tag is another process's. hit_core: ?*pardes.Pardes = null, + /// The frame it shows, and what it reads beside the cells to draw it and + /// to turn its input into events (pardes.Facts): set as it presents, + /// refreshed by its runner after each input it applied. Never the core. + frame: ?*const pardes.Surface = null, + facts: pardes.Facts = .{}, + /// The key Ctrl takes to toggle a terminal (Options.tty_toggle). + tty_toggle: u21 = pardes.config.tty_toggle_default, /// Pixels the capture holds past the grid (PARDES_TEST_PAD). capture_pad: u32 = 0, @@ -585,8 +593,7 @@ fn acknowledgeGuiFont(g: *const Gui, core: *pardes.Pardes) void { /// A replica client's font is the window's raster state: it follows the /// session's request by the face's name on this machine (fonts.fromSession), /// never acknowledging it or otherwise changing the replicated core. -fn syncReplicaFont(g: *Gui, core: *const pardes.Pardes, gpa: std.mem.Allocator) bool { - const f = &core.settings.font; +fn syncReplicaFont(g: *Gui, f: *const @FieldType(pardes.config.Runtime, "font"), gpa: std.mem.Allocator) bool { const path = f.requested_path.get(); const name = f.requested_name.get(); if (path.len == 0 and name.len == 0) return false; @@ -928,6 +935,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di var g: Gui = .{ .window = window, + .tty_toggle = opts_in.tty_toggle, .arrow_cursor = arrow_cursor, .link_cursor = link_cursor, .box_cursor = box_cursor, @@ -1027,6 +1035,9 @@ fn localSession( defer host_io.stopWorkers(); var opts = opts_in; opts.addons = pardes.Addon.scan(); + // Its frame timings, the window's to write as it draws (Pardes.frames). + var frames: pardes.FrameStats = .{}; + opts.frames = &frames; opts.image_allocator = allocs.image; opts.tree_sitter_allocator = allocs.tree_sitter; opts.frame_allocator = allocs.frame; @@ -1113,7 +1124,7 @@ fn localSession( defer shell.shutdownPtys(); // A virtual clock never blinks: goldens and feel series hold still. g.no_blink = shell.test_clock != null; - frame_probe = &core.frames; + frame_probe = &frames; frame_capture_dir = if (std.c.getenv("PARDES_FRAMES_CAPTURE")) |dir| std.mem.span(dir) else null; const host = shell.host(); core.host = host; @@ -1184,7 +1195,6 @@ fn localSession( nc.view().frontend.windowed = true; core.deinit(); core = nc; - frame_probe = &nc.frames; // the old core's ring went with it g.hit_core = nc; shell.core = nc; shell.surface = null; @@ -1201,14 +1211,13 @@ fn localSession( } /// A window's link to a session elsewhere (`clientSession`): what the -/// window's input made, fed to the replica once its own view is put back, -/// and what the link's reader took off the stream. +/// window's input made, fed to the replica after each event, and what the +/// link's reader took off the stream. const Client = struct { link: replica.Link, io: std.Io, gpa: std.mem.Allocator, - /// The window's inputs since the last feed, their texts in `texts`: - /// read over its own view (`Replica.within`), applied after it. + /// The window's inputs since the last feed, their texts in `texts`. pending: std.ArrayListUnmanaged(pardes.Event) = .empty, texts: std.heap.ArenaAllocator, /// The reader's, under `lock`: what it took, and whether the link ended. @@ -1239,16 +1248,18 @@ const Client = struct { cl.pending.append(cl.gpa, e) catch {}; } - /// What the window's input made, applied at once and sent. - fn feed(cl: *Client) void { + /// What the window's input made, applied at once and sent; what the + /// window reads beside its frame (Gui.facts) as its view is now. + fn feed(cl: *Client, g: *Gui) void { + const r = cl.link.r; for (cl.pending.items) |ev| { - const r = cl.link.r; const predicted = r.echo.stats.predicted; cl.link.input(ev); // PARDES_TEST_LATENCY: the input, and whether it shows at once // (applied, or its echo predicted), for the frame that shows it. latencyNote("I {d} {d} {d}\n", .{ r.next_seq - 1, monoNs(), @intFromBool(r.applied == r.pending.items.len or r.echo.stats.predicted > predicted) }); } + if (cl.pending.items.len > 0 and r.core().live == r.view) pardes.draw.facts(r.core(), &g.facts); cl.pending.clearRetainingCapacity(); _ = cl.texts.reset(.retain_capacity); } @@ -1286,22 +1297,16 @@ const Client = struct { } /// Its own view drawn in the window, outside any step, as the tty's - /// client draws its terminal (tui.zig `Client.draw`): what presenting - /// writes in the core (a frame skipped, one owed) is put back. + /// client draws its terminal (tui.zig `Client.draw`), its timings this + /// process's (`frame_probe`). fn draw(cl: *Client, s: *Shell) void { - const r = cl.link.r; - const core = r.core(); - const skipped = core.present_skipped; - const needs = core.needs_frame; - core.frames.mark_start = pardes.FrameStats.nowNs(); - core.frames.mark_update = core.frames.mark_start; + const frames = frame_probe.?; + frames.mark_start = pardes.FrameStats.nowNs(); + frames.mark_update = frames.mark_start; // Its render's end is marked as it presents (`present`). - core.frames.mark_render = core.frames.mark_update; - r.draw(.{ .ctx = s, .f = present }); - cl.link.owed = core.present_skipped; - core.frames.record(pardes.FrameStats.nowNs(), if (s.gui) |g| frontendMoving(g) else false, cl.link.owed); - core.present_skipped = skipped; - core.needs_frame = needs; + frames.mark_render = frames.mark_update; + cl.link.owed = !cl.link.r.draw(.{ .ctx = s, .f = present }); + frames.record(pardes.FrameStats.nowNs(), if (s.gui) |g| frontendMoving(g) else false, cl.link.owed); cl.link.drawn(s.presented); } }; @@ -1315,38 +1320,6 @@ fn clientReader(cl: *Client, fd: c_int, rest: *replica.Framer) void { sdlWake(null); } -/// What the window does over its own view (`Replica.within`), its inputs -/// posted to the client (`Input.client`): an SDL event dispatched, its size -/// (the tagline's face too), the pointer under a frame that moved, the -/// timedemo's and the test feed's steps. -const OwnView = struct { - g: *Gui, - in: *Input, - s: *Shell, - sev: ?*const c.SDL_Event = null, - pointer: bool = false, - eof: bool = false, - - fn run(v: *OwnView, core: *pardes.Pardes) anyerror!void { - if (v.sev) |sev| return dispatch(v.g, v.in, sev); - const g = v.g; - if (syncReplicaFont(g, core, v.s.gpa)) v.s.client.?.link.dirty = true; - if (scrollRows(g, v.in, v.s.gpa)) v.s.client.?.link.dirty = true; - if (fitTaglineFont(g, core.settings.font.tagline_percent)) v.s.client.?.link.dirty = true; - const geom = windowCells(g); - const cl = v.s.client.?; - if (resizeOf(core.view(), geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height)) |ev| { - if (cl.posted == null or !std.meta.eql(cl.posted.?, ev.resize)) v.in.post(ev); - cl.posted = ev.resize; - } else cl.posted = null; - if (v.pointer) refreshPresentedPointer(g, v.in); - runDemo(g, v.in, core); - if (v.s.test_mode) { - if (v.s.feed.pump(v.s.gpa, v.in, g) catch return error.TestFeed) v.eof = true; - } - } -}; - /// `pardes-gui --attach=<where>:<session>`: the window, made as a session's /// is, a replica client of that session (docs/next-daemon.md, "Phase 6: GUI /// replica notes"). Its own core, loaded from the session's dump, applies @@ -1383,6 +1356,10 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ o.image_allocator = allocs.image; var distrusted: pardes.Addon.Distrusted = .{}; o.distrusted = &distrusted; + // Its frame timings, this process's (Pardes.frames). + var frames: pardes.FrameStats = .{}; + o.frames = &frames; + frame_probe = &frames; var joined: replica.Joined = undefined; var r = replica.join(gpa, &joined, to.path, to.session, o, have, &why, null) orelse Said.no(io, "{s}", .{std.mem.sliceTo(&why, 0)}); @@ -1432,7 +1409,7 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ shell.gview = joined.view; shell.surface = null; g.hit_core = core; - frame_probe = &core.frames; + g.frame = null; link.reset(r, &joined); client.posted = null; client.ended = false; @@ -1452,11 +1429,26 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ var drew = false; var again = false; while (!link.quit) { - core.frames.period_ns = refreshNs(g); - var own: OwnView = .{ .g = g, .in = &in, .s = &shell, .pointer = drew }; - r.within(&own, OwnView.run); - client.feed(); - if (own.eof) break; + frames.period_ns = refreshNs(g); + // The window's own work over the frame it shows (Gui.facts): + // the session's font followed, a touchpad's fraction, the + // tagline's face, its size posted, the pointer under a frame + // that moved, the timedemo's and the test feed's steps. + if (syncReplicaFont(g, &core.settings.font, gpa)) link.dirty = true; + if (scrollRows(g, &in, gpa)) link.dirty = true; + if (fitTaglineFont(g, g.facts.tagline_percent)) link.dirty = true; + const geom = windowCells(g); + if (resizeOf(&g.facts, geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height)) |ev| { + if (client.posted == null or !std.meta.eql(client.posted.?, ev.resize)) in.post(ev); + client.posted = ev.resize; + } else client.posted = null; + if (drew) refreshPresentedPointer(g, &in); + runDemo(g, &in, core); + const eof = test_mode and (shell.feed.pump(gpa, &in, g) catch false); + client.feed(g); + if (eof) break; + if (in.redraw) link.dirty = true; + in.redraw = false; // Its predicted echo judged and caught up, once a frame. if (r.echoFrame()) link.dirty = true; drew = false; @@ -1467,7 +1459,7 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ // A blink, the window's own motion: the last frame again, // moved on, as the session's own window draws it (pollFrame). g.now_ns = shell.ownNow(); - shell.presented = renderFrame(g, gpa, core, frame) catch false; + shell.presented = renderFrame(g, gpa, frame) catch false; drew = shell.presented; }; again = false; @@ -1475,7 +1467,7 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ // trail) and its blink are on its clock: no unit need come. const minimized = !test_mode and c.SDL_GetWindowFlags(g.window) & (c.SDL_WINDOW_MINIMIZED | c.SDL_WINDOW_OCCLUDED) != 0; const moving = !minimized and frontendMoving(g); - const blink = if (minimized or shell.surface == null) null else blinkNow(g, core.settings.cursor_blink); + const blink = if (minimized or shell.surface == null) null else blinkNow(g, g.facts.cursor_blink); const predicting = r.echo.n > 0 or r.echo.cursor != null or r.echo.nd > 0; // A latency trace's feed paces the loop, as the session's own // window's (waitInput): its poll on stdin is the wait, and SDL's, @@ -1503,9 +1495,10 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ const timed_out = !got; while (got) : (got = c.SDL_PollEvent(&sev)) { if (sev.type == c.SDL_EVENT_USER) continue; - var one: OwnView = .{ .g = g, .in = &in, .s = &shell, .sev = &sev }; - r.within(&one, OwnView.run); - client.feed(); + dispatch(g, &in, &sev); + client.feed(g); + if (in.redraw) link.dirty = true; + in.redraw = false; if (link.quit) break; } client.takeSaid(); @@ -1670,7 +1663,7 @@ const StdinFeed = struct { _ = c.SDL_GetWindowSizeInPixels(gp.window, &wpw, &wph); const win_w: f32 = @floatFromInt(@max(wpw, 1)); const win_h: f32 = @floatFromInt(@max(wph, 1)); - handleFinger(&gp.touch, in, finger, win_w, win_h, @floatFromInt(gp.cell_w), @floatFromInt(gp.cell_h), @floatFromInt(gp.tagline_width)); + handleFinger(gp, &gp.touch, in, finger, win_w, win_h, @floatFromInt(gp.cell_w), @floatFromInt(gp.cell_h), @floatFromInt(gp.tagline_width)); }; } continue; @@ -1803,23 +1796,42 @@ fn postKey(in: *Input, key: vaxis.Key, text: []const u8) void { in.post(ev); } +/// The window's input made into events, and where they go: its runner's +/// core (the session's own window) or its link (a replica client). The +/// window reads only its frame and the facts beside it (Gui.facts), which +/// the runner refreshes after each input it applies, as the core is then. const Input = struct { core: *pardes.Pardes, /// The shell whose window this is (views.zig: its view is `gview`). shell: ?*Shell = null, /// A replica client's (`runClient`): its inputs go to its link, never - /// straight to the core, which only reads here. + /// straight to the core. client: ?*Client = null, quit: bool = false, + /// Something the window draws of its own changed (a display's scale, a + /// touchpad's fraction): the runner draws again. + redraw: bool = false, fn post(in: *Input, ev: pardes.Event) void { - if (in.client) |r| return r.post(ev); + // A replica client's: fed after the event (Client.feed). + if (in.client) |cl| return cl.post(ev); + const g = if (in.shell) |s| s.gui else null; // The window's input is its own view's, a replica client's input // the session's last or not. if (in.shell) |s| if (s.core.live != s.gview) { _ = s.windowView(); }; in.core.update(ev); + if (g) |w| pardes.draw.facts(in.core, &w.facts); + } + + /// Pane `id`'s first row shown, after the inputs posted: the session's + /// own window asks (a wheel's rows stop where the pane does); a replica + /// client's speculation may wait on the session, so it never asks. + fn scrollOf(in: *const Input, id: usize) ?i32 { + if (in.client != null) return null; + const pane = in.core.panes[id] orelse return null; + return pane.scroll(); } fn close(in: *Input) void { @@ -1860,9 +1872,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { updateDisplayScale(g.window); // Underlines are drawn into the glyphs a logical pixel thick. resetGlyphAtlas(g); - if (in.client) |r| { - r.link.dirty = true; - } else in.core.needs_frame = true; + in.redraw = true; }, else => {}, } @@ -1923,7 +1933,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { 5 => .forward, else => return, }; - const mc = pointAt(g, in.core, b.x, b.y); + const mc = pointAt(g, b.x, b.y); var ev = pointerMouse(button, if (b.down) .press else .release, mc, pointerMods()); // Let go past the window's edge (SDL follows a held button out // of the window: Wayland's implicit grab, X11's capture). @@ -1951,13 +1961,13 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { } else physical_held) else physical_held; - const mc = pointAt(g, in.core, m.x, m.y); + const mc = pointAt(g, m.x, m.y); in.post(.{ .mouse = pointerMouse(held orelse .none, if (held != null) .drag else .motion, mc, pointerMods()) }); }, c.SDL_EVENT_MOUSE_WHEEL => { const w = sev.wheel; if (w.y == 0 and w.x == 0) return; - const mc = pointAt(g, in.core, w.mouse_x, w.mouse_y); + const mc = pointAt(g, w.mouse_x, w.mouse_y); wheelAt(g, in, .{ .x = w.x, .y = w.y, .integer_y = w.integer_y, .mods = pointerMods() }, mc); }, c.SDL_EVENT_FINGER_DOWN, c.SDL_EVENT_FINGER_MOTION, c.SDL_EVENT_FINGER_UP, c.SDL_EVENT_FINGER_CANCELED => { @@ -1983,7 +1993,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { const win_h: f32 = @floatFromInt(@max(ph, 1)); const fcw: f32 = @floatFromInt(g.cell_w); const fch: f32 = @floatFromInt(g.cell_h); - handleFinger(&g.touch, in, finger, win_w, win_h, fcw, fch, @floatFromInt(g.tagline_width)); + handleFinger(g, &g.touch, in, finger, win_w, win_h, fcw, fch, @floatFromInt(g.tagline_width)); }, // The window's font size; a Linux touchpad's pinch stays unused. c.SDL_EVENT_PINCH_BEGIN, c.SDL_EVENT_PINCH_UPDATE => if (comptime builtin.os.tag == .macos) setFontPx(g, in, Trackpad.pinch(g.px, sev.pinch.scale)), @@ -2028,14 +2038,14 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { for (acts[0..g.deck.feed(pad_input, &acts)]) |act| switch (act) { .move => |mv| { const geometry = windowGeometry(g.window); - const old = mouseCellWithGeometry(g, in.core, g.pad_x, g.pad_y, geometry); + const old = mouseCellWithGeometry(g, g.pad_x, g.pad_y, geometry); const dx = mv.dx * geometry.window_w / geometry.pixel_w; const dy = mv.dy * geometry.window_h / geometry.pixel_h; g.pad_x = std.math.clamp(g.pad_x + dx, 0, geometry.window_w - 1); g.pad_y = std.math.clamp(g.pad_y + dy, 0, geometry.window_h - 1); c.SDL_WarpMouseInWindow(g.window, g.pad_x, g.pad_y); g.pointer_present = true; - const mc = mouseCellWithGeometry(g, in.core, g.pad_x, g.pad_y, geometry); + const mc = mouseCellWithGeometry(g, g.pad_x, g.pad_y, geometry); g.pointer_cell = mc; if (mc.col == old.col and mc.row == old.row) continue; const held = heldPointerButton(g); @@ -2047,7 +2057,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { .execute => .middle, .look => .right, }; - const mc = pointAt(g, in.core, g.pad_x, g.pad_y); + const mc = pointAt(g, g.pad_x, g.pad_y); in.post(.{ .mouse = .{ .button = button, .kind = if (ck.down) .press else .release, @@ -2058,7 +2068,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { } }); }, .wheel => |ticks| { - const mc = pointAt(g, in.core, g.pad_x, g.pad_y); + const mc = pointAt(g, g.pad_x, g.pad_y); var left = ticks; while (left != 0) { left += if (ticks > 0) -1 else 1; @@ -2078,7 +2088,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { .cap_n => .{ .cp = 'N', .text = "N" }, .enter => .{ .cp = pardes.Key.enter }, .tab => .{ .cp = pardes.Key.tab }, - .tty_toggle => .{ .cp = in.core.opts.tty_toggle, .ctrl = true }, + .tty_toggle => .{ .cp = g.tty_toggle, .ctrl = true }, }, }), .rumble => if (g.gamepad) |pad| { @@ -2127,7 +2137,7 @@ fn keyDown(in: *Input, sym: c.SDL_Keycode, mod: c.SDL_Keymod) void { } fn gridCellAtDimensions( - core: *const pardes.Pardes, + g: *const Gui, x: f32, y: f32, body_w: f32, @@ -2138,8 +2148,9 @@ fn gridCellAtDimensions( var point: MouseCell = .{ .col = @intFromFloat(@min(@floor(@max(x, 0) / @max(body_w, 1)), 10_000)), .row = row }; // On the rule over this row, which is where two panes meet if they do. point.rule_above = row > 0 and @max(y, 0) - @as(f32, @floatFromInt(row)) * @max(body_h, 1) < dp(rule_grab_px); - if (onGrid(core, x / @max(body_w, 1), y / @max(body_h, 1))) for (core.surface.tagLayers()) |*layer| { - if (layer.tagHit(x, y, body_w, body_h, tagline_w, @floatFromInt(core.view().row_metrics.tagline_h))) |hit| { + const frame = g.frame orelse return point; + if (onGrid(&g.facts, x / @max(body_w, 1), y / @max(body_h, 1))) for (frame.tagLayers()) |*layer| { + if (layer.tagHit(x, y, body_w, body_h, tagline_w, @floatFromInt(g.facts.row_metrics.tagline_h))) |hit| { point.tag_hit = hit; break; } @@ -2148,14 +2159,15 @@ fn gridCellAtDimensions( } /// Whether a point, in cells, is on the grid. -fn onGrid(core: *const pardes.Pardes, x: f32, y: f32) bool { +fn onGrid(f: *const pardes.Facts, x: f32, y: f32) bool { return std.math.isFinite(x) and std.math.isFinite(y) and x >= 0 and y >= 0 and - x < @as(f32, @floatFromInt(core.view().screen_w)) and y < @as(f32, @floatFromInt(core.view().screen_h)); + x < @as(f32, @floatFromInt(f.screen_w)) and y < @as(f32, @floatFromInt(f.screen_h)); } -fn gridCellAtPixels(g: *const Gui, core: *const pardes.Pardes, x: f32, y: f32) MouseCell { - var point = gridCellAtDimensions(core, x, y, @floatFromInt(g.cell_w), @floatFromInt(g.cell_h), @floatFromInt(g.tagline_width)); - if (onGrid(core, x / @as(f32, @floatFromInt(g.cell_w)), y / @as(f32, @floatFromInt(g.cell_h)))) for (core.surface.bodyLayers()) |*layer| { +fn gridCellAtPixels(g: *const Gui, x: f32, y: f32) MouseCell { + var point = gridCellAtDimensions(g, x, y, @floatFromInt(g.cell_w), @floatFromInt(g.cell_h), @floatFromInt(g.tagline_width)); + const frame = g.frame orelse return point; + if (onGrid(&g.facts, x / @as(f32, @floatFromInt(g.cell_w)), y / @as(f32, @floatFromInt(g.cell_h)))) for (frame.bodyLayers()) |*layer| { if (layer.bodyHit(x, y, @floatFromInt(g.cell_w), @floatFromInt(g.cell_h), @floatFromInt(g.tagline_width), @floatFromInt(g.tagline_height))) |hit| { point.body_hit = hit; break; @@ -2168,23 +2180,21 @@ fn gridCellAtPixels(g: *const Gui, core: *const pardes.Pardes, x: f32, y: f32) M /// part of dispatch after the pointer is placed, so a test can turn it. fn wheelAt(g: *Gui, in: *Input, w: WheelTurn, mc: MouseCell) void { if (w.y != 0 and std.math.isFinite(w.y)) { - const core = in.core; - const hit: ?usize = for (core.panes, 0..) |slot, i| { - if (slot == null) continue; - const r = core.view().rects[i]; + const hit: ?usize = for (0..pardes.MAX_PANES) |i| { + const r = (g.facts.pane(i) orelse continue).rect; if (mc.col >= r.x and mc.col < r.x + r.w and mc.row >= r.y and mc.row < r.y + r.h) break i; } else null; if (g.scroll_pane) |old| if (hit == null or hit.? != old) { resetScroll(g); }; if (hit) |id| { - const pane = core.panes[id].?; - if (pane.addon != null) { + const pane = g.facts.pane(id).?; + if (pane.kind == .addon) { // A kind's (a PDF's strip): the turn as it came, a // touchpad's fraction of a notch too (pa_mouse.amount). resetScroll(g); in.post(.{ .mouse = .{ .button = if (w.y < 0) .wheel_down else .wheel_up, .kind = .press, .col = mc.col, .row = mc.row, .tag_hit = mc.tag_hit, .body_hit = mc.body_hit, .ctrl = w.mods.ctrl, .shift = w.mods.shift, .alt = w.mods.alt, .amount = @abs(w.y) } }); - } else if (!w.mods.shift and pane.isTerminal() and pardes.Term.modes(pane.terminal).wheel) { + } else if (!w.mods.shift and pane.program_wheel) { // The program's (codex, htop, less): every whole turn goes // to it, no glide, for nothing of ours moves. Shift keeps // a terminal's wheel pardes's. @@ -2274,15 +2284,14 @@ fn dispatchTrackpad(g: *Gui, in: *Input, ev: *const c.UITrackpadEvent) void { c.UI_TRACKPAD_HISTORY => { if (ev.a == 0 or !std.math.isFinite(ev.a)) return; const back = ev.a < 0; - const jumps = &in.core.view().jumps; - const can_jump = jumps.n > 0 and (if (back) jumps.cur > 0 else jumps.cur + 1 < jumps.n); + const can_jump = if (back) g.facts.back else g.facts.forward; in.post(.{ .command = if (back) "Back" else "Forward" }); if (comptime builtin.os.tag == .macos) if (can_jump) c.ui_macos_trackpad_haptic(); }, c.UI_TRACKPAD_ROTATE => { - const pane = in.core.panes[in.core.view().active] orelse return; + const pane = g.facts.pane(g.facts.active) orelse return; // Search-step keys never become text in insert/raw mode. - if (pane.body.mode != .normal) return; + if (!pane.normal) return; var ticks = g.trackpad.rotate(ev.a, ev.phase); while (ticks != 0) { in.post(.{ .key = .{ .cp = if (ticks > 0) 'N' else 'n' } }); @@ -2292,13 +2301,13 @@ fn dispatchTrackpad(g: *Gui, in: *Input, ev: *const c.UITrackpadEvent) void { }, c.UI_TRACKPAD_PRESSURE => { const previous = g.trackpad.force(ev.a) orelse return; - const mc = mouseCell(g, in.core, ev.x, ev.y); + const mc = mouseCell(g, ev.x, ev.y); in.post(.{ .mouse = pointerMouse(if (previous == 2) .middle else .left, .release, mc, pointerMods()) }); in.post(.{ .mouse = pointerMouse(.right, .press, mc, pointerMods()) }); in.post(.{ .mouse = pointerMouse(.right, .release, mc, pointerMods()) }); }, c.UI_TRACKPAD_SCROLL => { - const mc = pointAt(g, in.core, ev.x, ev.y); + const mc = pointAt(g, ev.x, ev.y); // AppKit reports points; the grid is measured in backing pixels. const geometry = windowGeometry(g.window); const rows = ev.b * geometry.pixel_h / geometry.window_h / @as(f32, @floatFromInt(g.cell_h)); @@ -2334,22 +2343,22 @@ fn pointerMods() PointerMods { return .{ .ctrl = (m & c.SDL_KMOD_CTRL) != 0, .shift = (m & c.SDL_KMOD_SHIFT) != 0, .alt = (m & c.SDL_KMOD_ALT) != 0, .super = (m & c.SDL_KMOD_GUI) != 0 }; } -fn mouseCellWithGeometry(g: *const Gui, core: *const pardes.Pardes, x: f32, y: f32, geometry: WindowGeometry) MouseCell { +fn mouseCellWithGeometry(g: *const Gui, x: f32, y: f32, geometry: WindowGeometry) MouseCell { const physical = windowPointToPixels(geometry, x, y); - return gridCellAtPixels(g, core, physical.x, physical.y); + return gridCellAtPixels(g, physical.x, physical.y); } -fn mouseCell(g: *const Gui, core: *const pardes.Pardes, x: f32, y: f32) MouseCell { - return mouseCellWithGeometry(g, core, x, y, windowGeometry(g.window)); +fn mouseCell(g: *const Gui, x: f32, y: f32) MouseCell { + return mouseCellWithGeometry(g, x, y, windowGeometry(g.window)); } /// The pointer at window point (x, y), as an event or the gamepad puts it /// there: where the window keeps it, and the cell under it. -fn pointAt(g: *Gui, core: *const pardes.Pardes, x: f32, y: f32) MouseCell { +fn pointAt(g: *Gui, x: f32, y: f32) MouseCell { g.pad_x = x; g.pad_y = y; g.pointer_present = true; - const mc = mouseCell(g, core, x, y); + const mc = mouseCell(g, x, y); g.pointer_cell = mc; return mc; } @@ -2363,7 +2372,7 @@ fn hitTest(_: ?*c.SDL_Window, area: [*c]const c.SDL_Point, data: ?*anyopaque) ca const g: *Gui = @ptrCast(@alignCast(data orelse return c.SDL_HITTEST_NORMAL)); const core = g.hit_core orelse return c.SDL_HITTEST_NORMAL; if (area == null) return c.SDL_HITTEST_NORMAL; - const mc = mouseCell(g, core, @floatFromInt(area.*.x), @floatFromInt(area.*.y)); + const mc = mouseCell(g, @floatFromInt(area.*.x), @floatFromInt(area.*.y)); return if (pardes.tagline.workspaceBlank(core, mc.col, mc.row, mc.tag_hit)) c.SDL_HITTEST_DRAGGABLE else c.SDL_HITTEST_NORMAL; } @@ -2377,7 +2386,7 @@ fn heldPointerButton(g: *const Gui) ?pardes.Mouse.Button { fn refreshPresentedPointer(g: *Gui, in: *Input) void { if (!g.pointer_present) return; - const mc = mouseCell(g, in.core, g.pad_x, g.pad_y); + const mc = mouseCell(g, g.pad_x, g.pad_y); const moved = g.pointer_cell == null or g.pointer_cell.?.col != mc.col or g.pointer_cell.?.row != mc.row; g.pointer_cell = mc; if (!moved) return; @@ -2391,7 +2400,7 @@ fn pollGamepad(g: *Gui, in: *Input) void { const deadzone: f32 = 8000; const ax: f32 = @floatFromInt(c.SDL_GetGamepadAxis(pad, c.SDL_GAMEPAD_AXIS_RIGHTX)); const ay: f32 = @floatFromInt(c.SDL_GetGamepadAxis(pad, c.SDL_GAMEPAD_AXIS_RIGHTY)); - const old = mouseCellWithGeometry(g, in.core, g.pad_x, g.pad_y, geometry); + const old = mouseCellWithGeometry(g, g.pad_x, g.pad_y, geometry); const speed: f32 = @as(f32, @floatFromInt(g.cell_h)) * 0.4; const speed_x = speed * geometry.window_w / geometry.pixel_w; const speed_y = speed * geometry.window_h / geometry.pixel_h; @@ -2402,7 +2411,7 @@ fn pollGamepad(g: *Gui, in: *Input) void { g.pointer_present = true; c.SDL_WarpMouseInWindow(g.window, g.pad_x, g.pad_y); } - const mc = mouseCellWithGeometry(g, in.core, g.pad_x, g.pad_y, geometry); + const mc = mouseCellWithGeometry(g, g.pad_x, g.pad_y, geometry); if (g.pointer_present) { g.pointer_cell = mc; if (mc.col != old.col or mc.row != old.row) { @@ -2858,7 +2867,7 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { // a frame a loop through an edge, else a wake at the next one; none // while the window is minimized or unfocused. A virtual clock never // blinks, so goldens hold still. - const blink = if (s.test_clock != null or minimized or s.surface == null) null else blinkNow(g, s.core.settings.cursor_blink); + const blink = if (s.test_clock != null or minimized or s.surface == null) null else blinkNow(g, g.facts.cursor_blink); const blink_ms: ?c_int = if (blink) |b| (if (b.edge) 1 else if (b.next_ns) |next| @as(c_int, @intCast(@min(std.math.maxInt(c_int), next / std.time.ns_per_ms + 1))) else null) else null; const blinked: c_int = if (blink_ms) |b| (if (waited < 0) b else @min(waited, b)) else waited; // The timedemo's next step is a wake too. @@ -2996,6 +3005,7 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { } s.drainQueue(); if (s.gui) |g| pollGamepad(g, &in); + if (in.redraw) core.needs_frame = true; } /// Detached: no window, asleep until the queue's wake (an SDL user event: @@ -3041,7 +3051,7 @@ fn pollFrame(ctx: ?*anyopaque) void { if (due) _ = s.windowView(); } syncWindowOpacity(g, core); - core.frames.period_ns = refreshNs(g); + frame_probe.?.period_ns = refreshNs(g); syncTaglineFont(g, core); if (core.takeFontRequest()) |path| blk: { const bytes = filesystem.readFile(s.gpa, path) catch { @@ -3068,7 +3078,7 @@ fn pollFrame(ctx: ?*anyopaque) void { if ((g.blink_due or frontendMoving(g)) and !core.needs_frame and s.presented) if (s.surface) |frame| { g.blink_due = false; g.now_ns = s.ownNow(); - s.presented = renderFrame(g, s.gpa, core, frame) catch false; + s.presented = renderFrame(g, s.gpa, frame) catch false; }; } @@ -3110,62 +3120,65 @@ fn demoDue(g: *const Gui) ?c_int { /// through the paths the window's own wheel and keys take, over the /// focused pane's body; its clock starts at the first loop. Its end /// ends the session (PARDES_FRAMES has the timings then). +/// The `.exec` step is the harness's own act on the session (`core`), not +/// the window's input; every other step reads only what the window shows. fn runDemo(g: *Gui, in: *Input, core: *pardes.Pardes) void { - const v = core.view(); const steps = g.demo; var next = g.demo_next orelse return; const now = monoNs(); + const frames = frame_probe.?; if (g.demo_start_ns == 0) { g.demo_start_ns = now; - core.frames.demo_ns = now; - core.frames.demo = g.demo; + frames.demo_ns = now; + frames.demo = g.demo; } defer g.demo_next = next; while (next < steps.len and g.demo_start_ns + @as(u64, steps[next].at_ms) * std.time.ns_per_ms <= now) : (next += 1) { - const r = v.rects[v.active]; + const r = if (g.facts.pane(g.facts.active)) |pane| pane.rect else pardes.layout.Rect{}; if (steps[next].act != .phase) g.input_seen = true; switch (steps[next].act) { .wheel => |notches| { - core.frames.input(now); + frames.input(now); wheelAt(g, in, .{ .y = @floatFromInt(-notches), .integer_y = -notches }, .{ .col = r.x + r.w / 2, .row = r.y + r.h / 2 }); }, .touch => |lines| { - core.frames.input(now); + frames.input(now); wheelAt(g, in, .{ .y = -lines }, .{ .col = r.x + r.w / 2, .row = r.y + r.h / 2 }); }, .key => |key| { - core.frames.input(now); + frames.input(now); in.post(.{ .key = key }); }, .phase => {}, .click => |click| { - core.frames.input(now); - const pane = core.panes[v.active] orelse continue; - const top = core.bodyTop(pane, r); + frames.input(now); + const pane = g.facts.pane(g.facts.active) orelse continue; + const top = r.y + pane.tag_rows; const row: u16 = top + @as(u16, @intFromFloat(click.at * @as(f32, @floatFromInt(r.h -| pane.tag_rows -| 1)))); const col: u16 = if (click.rail) r.x else r.x + config.GUTTER + 4; for ([_]pardes.Mouse.Kind{ .press, .release }) |kind| in.post(.{ .mouse = .{ .button = click.button, .kind = kind, .col = col, .row = row } }); }, .rail_wheel => |notches| { - core.frames.input(now); + frames.input(now); wheelAt(g, in, .{ .y = @floatFromInt(-notches), .integer_y = -notches }, .{ .col = r.x, .row = r.y + r.h / 2 }); }, .paste => |text| { - core.frames.input(now); + frames.input(now); in.post(.{ .paste = text }); }, .exec => |line| { - core.frames.input(now); + frames.input(now); var newest: u32 = 0; for (core.panes) |slot| if (slot) |pane| { newest = @max(newest, pane.serial); }; - _ = pardes.exec.executeFrom(core, v.active, line, false); + _ = pardes.exec.executeFrom(core, core.view().active, line, false); // What it opened is what the next steps scroll. for (core.panes, 0..) |slot, id| if (slot) |pane| if (pane.serial > newest) { - v.active = id; + core.view().active = id; core.needs_frame = true; }; + pardes.draw.facts(core, &g.facts); }, .end => in.close(), } @@ -3265,25 +3278,28 @@ fn syncWindowOpacity(g: *Gui, core: *pardes.Pardes) void { "background transparency requires a native Wayland or alpha-capable SDL window"); } -fn present(ctx: ?*anyopaque, surface: *const pardes.Surface) void { +fn present(ctx: ?*anyopaque, surface: *const pardes.Surface) bool { const s = shellOf(ctx); - const core = s.core; // A replica client draws outside the pump, which marks it there. - if (s.client != null) core.frames.mark_render = pardes.FrameStats.nowNs(); - const g = s.gui orelse return; + if (s.client != null) if (frame_probe) |frames| { + frames.mark_render = pardes.FrameStats.nowNs(); + }; + const g = s.gui orelse return true; frame_started_ns = monoNs(); const frame = surface; s.surface = frame; + g.frame = frame; + g.facts = frame.facts.*; g.frame_arrival_ns = monoNs(); g.now_ns = s.ownNow(); - s.presented = renderFrame(g, s.gpa, core, frame) catch |err| blk: { + s.presented = renderFrame(g, s.gpa, frame) catch |err| blk: { log.err("render: {t}", .{err}); break :blk false; }; // A skipped swapchain image would otherwise hide this input's frame until // the next event. A few retries only: a minimized window never gets one. s.skipped_presents = if (s.presented) 0 else s.skipped_presents +| 1; - if (!s.presented and s.skipped_presents <= 3) core.present_skipped = true; + return s.presented or s.skipped_presents > 3; } /// The gamepad subsystem, started once the first frame is drawn, as the @@ -3670,7 +3686,9 @@ const WheelRun = struct { const r = core.view().rects[core.view().active]; wr.mc = .{ .col = r.x + 10, .row = r.y + r.h / 2 }; core.advance(wr.now_ns); - _ = try core.render(wr.arena.allocator()); + const s = try core.render(wr.arena.allocator()); + wr.g.frame = s; + wr.g.facts = s.facts.*; try wr.frame(gpa, &.{}); return wr; } @@ -3697,6 +3715,8 @@ const WheelRun = struct { if (!wr.core.needs_frame and !frontendMoving(&wr.g)) return; _ = wr.arena.reset(.retain_capacity); const s = try wr.core.render(wr.arena.allocator()); + wr.g.frame = s; + wr.g.facts = s.facts.*; wr.g.now_ns = wr.now_ns; glideFrame(&wr.g, gpa, s); wr.core.needs_frame = false; @@ -3780,17 +3800,19 @@ const settle_land: f32 = 0.02; fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { stepGlide(g, core); + // What the wheel's rows moved, read again (Gui.facts). + pardes.draw.facts(core, &g.facts); var in: Input = .{ .core = core }; _ = scrollRows(g, &in, gpa); + if (in.redraw) core.needs_frame = true; } /// A touchpad's fraction: the picture moved by it, and each whole row it /// crosses posted to `in` (a replica client's go to its link, applied /// after its view is parked again). True when the picture moved. fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool { - const core = in.core; const id = g.scroll_pane orelse return false; - const pane = core.panes[id] orelse { + const pane = g.facts.pane(id) orelse { resetScroll(g); return false; }; @@ -3813,7 +3835,7 @@ fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool { if (g.scroll_lag == 0 and g.scroll_notch == 0 and !g.glide.moving()) resetScroll(g); return false; } - const r = core.view().rects[id]; + const r = pane.rect; if (r.h <= pane.tag_rows) { resetScroll(g); return false; @@ -3824,7 +3846,7 @@ fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool { while (left != 0) { const down = left > 0; left += if (down) -1 else 1; - const was = pane.scroll(); + const was = in.scrollOf(id); in.post(.{ .mouse = .{ .button = if (down) .wheel_down else .wheel_up, @@ -3834,9 +3856,8 @@ fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool { .shift = true, // pardes's own scroll, never a program's wheel }, }); - // A replica client's rows apply after its view is parked again: - // its scroll has not moved yet. - if (in.client == null and pane.scroll() == was) { + // A replica client's rows may wait on the session: it never asks. + if (was != null and in.scrollOf(id) == was) { resetScroll(g); return false; } @@ -3846,14 +3867,14 @@ fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool { // the last one, a fraction of a row off, and the next turn's frame // jumps from there (against the turn when it reverses). const moved = st.rows != 0 or st.lag != g.scroll_lag; - if (moved and in.client == null) core.needs_frame = true; + if (moved and in.client == null) in.redraw = true; g.scroll_lag = st.lag; g.scroll_rect = r; - const body_y = core.bodyTop(pane, r); + const body_y = r.y + pane.tag_rows; g.scroll_body_y = body_y; g.scroll_body_h = r.h -| pane.tag_rows; - if (st.rows != 0) { - const s = &core.surface; + if (st.rows != 0 and g.frame != null) { + const s = g.frame.?; g.scroll_edge_len = 0; if (r.w > config.GUTTER and r.h > pane.tag_rows and r.x + r.w <= s.cols) { const bw = r.w - config.GUTTER; @@ -4143,9 +4164,9 @@ fn imageScissor(g: *const Gui, place: pardes.Placement) c.SDL_Rect { fn renderFrame( g: *Gui, gpa: std.mem.Allocator, - core: *pardes.Pardes, canonical: *const pardes.Surface, ) !bool { + const facts = canonical.facts; // The pictures a pane asks to see as glyph art, drawn into a copy of // the frame (Art.zig); the rest are textures. if (g.art_arena == null) g.art_arena = .init(gpa); @@ -4187,7 +4208,7 @@ fn renderFrame( const chrome = &surface.chrome; // G6: what the scroll just done moved the pane's rows by, measured on // this frame against the last (the glide follows it from there). - for (core.panes, &g.glide.held) |slot, *held| held.* = if (slot) |pane| pane.context_rows else 0; + for (&g.glide.held, 0..) |*held, id| held.* = if (facts.pane(id)) |pane| pane.context_rows else 0; glideFrame(g, gpa, surface); var groups: Groups = .{}; const now = g.now_ns; @@ -4195,7 +4216,7 @@ fn renderFrame( // While the cursor glides or blinks the cells' cursors are not drawn; // the focused one is the overlay's quad. One or the other every frame // (none only at a blink's off half). - const blink_alpha: f32 = if (blinkNow(g, core.settings.cursor_blink)) |b| b.alpha else 1; + const blink_alpha: f32 = if (blinkNow(g, facts.cursor_blink)) |b| b.alpha else 1; // While a glide moves the text, the caret is its quad, drawn from its // own springs, not a cell of the moving rows. const gliding = g.caret.moving(); @@ -4205,10 +4226,12 @@ fn renderFrame( const caret_alpha: f32 = if (gliding) 0.85 + 0.15 * std.math.clamp(1 - g.caret.remaining(now) / 0.5, 0, 1) else 1; g.cursor_quad_alpha = if (quad_mode) caret_alpha * blink_alpha else 0; // The probe's view of this frame's motion (FrameStats.Frame). - core.frames.scroll = g.glide.follow.offset; - core.frames.caret = caretRow(g, surface, now) orelse 0; + if (frame_probe) |frames| { + frames.scroll = g.glide.follow.offset; + frames.caret = caretRow(g, surface, now) orelse 0; + } const cursors_shown = !quad_mode; - var overlay_count = buildOverlay(g, core.settings.pet, core.settings.jump_trail, surface, now, sw, sh); + var overlay_count = buildOverlay(g, facts.pet, facts.jump_trail, surface, now, sw, sh); if (overlay_count != 0 and !g.cells.uploadOverlay(cmd, g.overlay_vertices[0..overlay_count])) overlay_count = 0; if (!prepareNativeImages(g, gpa, cmd, surface, &groups, sw, sh)) { @@ -4222,7 +4245,7 @@ fn renderFrame( const cells: u32 = @as(u32, surface.cols) * surface.rows; try g.cover.resize(gpa, cells); const covered = g.cover.items[0..cells]; - dim.begin(core.settings.inactive_dim, surface.regionList()); + dim.begin(facts.inactive_dim, surface.regionList()); coverFrame(covered, surface.cols, surface.rows, surface.bodyLayers(), surface.tagLayers(), surface.regionList()); try buildDecor(g, gpa, surface, &groups, layout, win_w, win_h, cursors_shown); @@ -4324,7 +4347,7 @@ fn renderFrame( std.debug.assert(cell_next[index] == group.cell_start + group.cell_count); // The body's context rows, which its scroll leaves where they are. const scrolling: ?usize = if (g.glide.follow.offset != 0) g.glide.pane else g.scroll_pane; - const held: u16 = if (scrolling) |id| if (core.panes[id]) |pane| pane.context_rows else 0 else 0; + const held: u16 = if (scrolling) |id| if (facts.pane(id)) |pane| pane.context_rows else 0 else 0; shifted = emitScrollRows(g, instances, cell_total, surface, layout, win_w, win_h, page, held); @memcpy(instances[cell_total + shifted ..][0..decor_len], g.decor.items); g.cells.uploadCells(cmd, cell_total + shifted + decor_len, &g.atlas); @@ -6571,24 +6594,27 @@ test "tagline pointer mapping retains physical grips and carries logical text co const tag_y = r.y; const x = @as(f32, @floatFromInt(r.x + pardes.TAG_TEXT_INSET)) * body_w + 3.5 * tag_w; - const tag = gridCellAtDimensions(core, x, (@as(f32, @floatFromInt(tag_y)) + 0.5) * body_h, body_w, body_h, tag_w); + var g = testGui(10, 20, 8, 12); + g.frame = &core.surface; + g.facts = core.surface.facts.*; + const tag = gridCellAtDimensions(&g, x, (@as(f32, @floatFromInt(tag_y)) + 0.5) * body_h, body_w, body_h, tag_w); try std.testing.expectEqual(pixelCell(x, 10), tag.col); try std.testing.expectEqual(tag_y, tag.row); try std.testing.expectEqual(@as(u16, 3), tag.tag_hit.?.col); try std.testing.expectEqual(pardes.TagKind.pane, tag.tag_hit.?.kind); - const grip = gridCellAtDimensions(core, @as(f32, @floatFromInt(r.x + config.GUTTER)) * body_w - 0.1, (@as(f32, @floatFromInt(tag_y)) + 0.5) * body_h, body_w, body_h, tag_w); + const grip = gridCellAtDimensions(&g, @as(f32, @floatFromInt(r.x + config.GUTTER)) * body_w - 0.1, (@as(f32, @floatFromInt(tag_y)) + 0.5) * body_h, body_w, body_h, tag_w); try std.testing.expect(grip.tag_hit == null); try std.testing.expectEqual(r.x + config.GUTTER - 1, grip.col); const body_y = tag_y + core.panes[core.view().active].?.tag_rows; // a long tag wraps - const body = gridCellAtDimensions(core, x, (@as(f32, @floatFromInt(body_y)) + 0.5) * body_h, body_w, body_h, tag_w); + const body = gridCellAtDimensions(&g, x, (@as(f32, @floatFromInt(body_y)) + 0.5) * body_h, body_w, body_h, tag_w); try std.testing.expectEqual(pixelCell(x, 10), body.col); try std.testing.expectEqual(body_y, body.row); try std.testing.expect(body.tag_hit == null); // The workspace tag's text starts TAG_TEXT_INSET cells in, as a pane's. const x_top = @as(f32, @floatFromInt(pardes.TAG_TEXT_INSET)) * body_w + 3.5 * tag_w; - const topbar = gridCellAtDimensions(core, x_top, 0.5 * body_h, body_w, body_h, tag_w); + const topbar = gridCellAtDimensions(&g, x_top, 0.5 * body_h, body_w, body_h, tag_w); try std.testing.expectEqual(pixelCell(x_top, 10), topbar.col); try std.testing.expectEqual(@as(u16, 3), topbar.tag_hit.?.col); try std.testing.expectEqual(pardes.TagKind.workspace, topbar.tag_hit.?.kind); @@ -6598,11 +6624,12 @@ test "a click at the window's corner lands in the corner cell" { const core = try pardes.Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); defer core.deinit(); var g = testGui(10, 20, 6, 12); + pardes.draw.facts(core, &g.facts); const geometry: WindowGeometry = .{ .window_w = 400, .window_h = 240, .pixel_w = 800, .pixel_h = 480 }; - const last = mouseCellWithGeometry(&g, core, 399.9, 239.9, geometry); + const last = mouseCellWithGeometry(&g, 399.9, 239.9, geometry); try std.testing.expectEqual(@as(u16, 79), last.col); try std.testing.expectEqual(@as(u16, 23), last.row); - const first = mouseCellWithGeometry(&g, core, 0, 0, geometry); + const first = mouseCellWithGeometry(&g, 0, 0, geometry); try std.testing.expectEqual(@as(u16, 0), first.col); try std.testing.expectEqual(@as(u16, 0), first.row); } @@ -6796,6 +6823,7 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a var g = testGui(10, 20, 6, 12); defer g.glide.deinit(gpa); var in: Input = .{ .core = core }; + pardes.draw.facts(core, &g.facts); var sent: std.ArrayList(u8) = .empty; defer sent.deinit(gpa); const Sent = struct { @@ -6813,6 +6841,7 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a const mc: MouseCell = .{ .col = r.x + config.GUTTER + 5, .row = core.bodyTop(pane, r) + 3 }; // What codex 0.159's chat sets on start. core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h\x1b[>7u\x1b[?1004h\x1b[?1049h\x1b[?1007l\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } }); + pardes.draw.facts(core, &g.facts); _ = try Sent.take(core, &sent); // A notch up, then a fast turn of three down: each its report, none // left behind for a glide. @@ -6838,12 +6867,14 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a resetScroll(&g); // Its sign-in screen: mouse off, alternate scroll on, so arrow keys. core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1006l\x1b[?1003l\x1b[?1002l\x1b[?1000l\x1b[?1007h" } }); + pardes.draw.facts(core, &g.facts); _ = try Sent.take(core, &sent); wheelAt(&g, &in, .{ .y = -1, .integer_y = -1 }, mc); try std.testing.expectEqualStrings("\x1b[B", try Sent.take(core, &sent)); // Back on the main screen a shell's wheel is ours: a notch to glide, // nothing to the pty. core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049l" } }); + pardes.draw.facts(core, &g.facts); _ = try Sent.take(core, &sent); wheelAt(&g, &in, .{ .y = 1, .integer_y = 1 }, mc); try std.testing.expectEqualStrings("", try Sent.take(core, &sent)); @@ -8088,13 +8119,16 @@ test "trackpad rotation never types search keys into an insert-mode file or raw var in: Input = .{ .core = core, .client = &client }; var g: Gui = undefined; g.trackpad = .{}; + g.facts = .{}; var ev: c.UITrackpadEvent = std.mem.zeroes(c.UITrackpadEvent); ev.kind = c.UI_TRACKPAD_ROTATE; ev.a = 20; const pane = core.panes[core.view().active].?; pane.body.mode = .insert; + pardes.draw.facts(core, &g.facts); dispatchTrackpad(&g, &in, &ev); pane.body.mode = .tty; + pardes.draw.facts(core, &g.facts); dispatchTrackpad(&g, &in, &ev); try std.testing.expectEqual(@as(usize, 0), client.pending.items.len); ev.kind = c.UI_TRACKPAD_HISTORY; @@ -8158,6 +8192,8 @@ test "detached trackpad scrolling keeps fractions local and queues whole rows fo const id = core.view().active; const r = core.view().rects[id]; var g: Gui = undefined; + g.frame = &core.surface; + g.facts = core.surface.facts.*; g.scroll_pane = id; g.scroll_delta = 0.375; g.scroll_lag = 0; |
