diff options
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/gui.zig | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 5b80b342..125f53cf 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -1475,6 +1475,10 @@ const Gui = struct { /// owns the wheel (terminal.ownsWheel). program_wheel: f32 = 0, glide: Glide = .{}, + /// PARDES_FRAMES_DEMO: the scroll timedemo's next step and when it + /// started (FrameStats.demo); null when none runs. + demo_next: ?usize = null, + demo_start_ns: u64 = 0, /// G9 and G11: the selection's and the hovered word's glow blocks as /// last drawn, for their fade-in. sel_glow: SelGlow = .{}, @@ -2156,6 +2160,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, attach: ?[]const u .capture_series = test_mode and env.get("PARDES_TEST_SERIES") != null, .capture_dir = capture_dir orelse "", .soft_present = soft_present, + .demo_next = if (env.get("PARDES_FRAMES_DEMO") != null) 0 else null, .surface_opacity = surface_opacity, .soft_renderer = soft_renderer, }; @@ -4074,7 +4079,9 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { // blinks, so goldens hold still. const blink = if (s.test_clock != null or minimized) null else blinkNow(g, if (s.surface) |frame| &frame.chrome else null); 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 ms: c_int = if (blink_ms) |b| (if (waited < 0) b else @min(waited, b)) else waited; + 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. + const ms: c_int = if (demoDue(g)) |due| (if (blinked < 0) due else @min(blinked, due)) else blinked; // The wait is the 9P connections' turn with the core. pardes.turn.rest(); const got = c.SDL_WaitEventTimeout(&sev, ms); @@ -4116,6 +4123,7 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { } if (motion) |*m| dispatch(g, &in, m); } + runDemo(g, &in, core); } if (s.test_mode) { const r = s.feed.pump(s.gpa, &in, s.gui) catch { @@ -4144,6 +4152,7 @@ fn pollFrame(ctx: ?*anyopaque) void { return; }; syncWindowOpacity(g, core); + core.frames.period_ns = refreshNs(g); syncTaglineFont(g, core); syncLigatures(g, core); if (core.takeFontRequest()) |path| blk: { @@ -4193,6 +4202,34 @@ fn pollFrame(ctx: ?*anyopaque) void { /// Frames drawn for a blink alone, with no core render (tests, tracing). var blink_redraws: u64 = 0; +/// How long until the timedemo's next step, ms; null when none runs. +fn demoDue(g: *const Gui) ?c_int { + const next = g.demo_next orelse return null; + if (g.demo_start_ns == 0 or next >= pardes.FrameStats.demo.len) return 0; + const at = g.demo_start_ns + @as(u64, pardes.FrameStats.demo[next].at_ms) * std.time.ns_per_ms; + return @intCast(@min(std.math.maxInt(c_int), (at -| monoNs()) / std.time.ns_per_ms)); +} + +/// PARDES_FRAMES_DEMO: the steps of FrameStats.demo whose time has come, +/// 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). +fn runDemo(g: *Gui, in: *Input, core: *pardes.Pardes) void { + const steps = pardes.FrameStats.demo; + var next = g.demo_next orelse return; + const now = monoNs(); + if (g.demo_start_ns == 0) g.demo_start_ns = now; + 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 = core.rects[core.active]; + switch (steps[next].act) { + .wheel => |notches| wheelAt(g, in, .{ .y = @floatFromInt(-notches), .integer_y = -notches }, .{ .col = r.x + r.w / 2, .row = r.y + r.h / 2 }), + .key => |key| in.post(.{ .key = key }), + .end => in.close(), + } + } +} + /// The blink now, from the frame's time since input and how long ago it /// arrived; null where nothing blinks (off, idle, an unfocused window). fn blinkNow(g: *const Gui, chrome: ?*const pardes.Chrome) ?pardes.animation.Blink { @@ -5932,6 +5969,11 @@ fn renderFrame( const blink_alpha: f32 = if (blinkNow(g, chrome)) |b| b.alpha else 1; const quad_mode = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or blink_alpha < 1); g.cursor_quad_alpha = if (quad_mode) chrome.cursor_alpha * blink_alpha else 0; + // The probe's view of this frame's motion (FrameStats.Frame). + if (core) |p| { + const probe = &@constCast(p).frames; + probe.scroll = g.glide.offset; + } const cursors_shown = groups.tracks == 0 and !quad_mode; var overlay_count = buildOverlay(g, core, surface, sw, sh, debug_on); if (overlay_count != 0 and !uploadOverlayGpu(g, cmd, overlay_count)) |
