From e65ada6bfab3e3851281be253b5e8187b652b66b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 12:35:31 -0300 Subject: the Pet back, the window's alone: src/gui/pet.zig and the window's pet overlay return as they were (the workspace tag's blank end, the tag's colours, now read from the Surface's chrome, its walk and hop on the window's own clock, SDL_GetTicks), and Pet is a plain setting now, a choice of off, cat or frog the window reads (config.Runtime.pet, a byte with no state behind it, dumped and replicated as any setting, in /ctl and DumpConfig as `Pet `, and as `# Pet unsupported` where no window draws it, so an init file shared with a terminal loads there clean); its behaviour test and the appearance gallery's pets return Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/gui/gui.zig | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 4 deletions(-) (limited to 'src/gui/gui.zig') diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 4f82d246..e5ca645d 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -13,6 +13,7 @@ const look = @import("../look.zig"); const message = pardes.Messages.Message; const file_watch = @import("../file_watch.zig"); const deck = @import("deck.zig"); +const pet = @import("pet.zig"); const fonts = @import("../fonts.zig"); // the fallback faces const selection_pipe = @import("../selection_pipe.zig"); const c_heap = @import("c_heap"); @@ -239,9 +240,9 @@ const LoadedFallback = struct { const max_touch_points: usize = 16; const touch_scroll_tick: f32 = 0.02; -// The triangle overlay holds only the cursor's glide quad: the chrome is -// decor. -const max_overlay_vertices: usize = 6; +// The triangle overlay holds only the pet and the cursor's glide quad: the +// chrome is decor. +const max_overlay_vertices: usize = pet.max_vertices + 6; const font_px_step: f32 = 2.0; const font_px_min: f32 = 8.0; @@ -991,6 +992,8 @@ const Gui = struct { words: Words = .{}, touch: Touch = .{}, + /// The workspace tag's pet (Pet), on the window's own clock. + pet_state: pet.State = .{}, live_ctrl: bool = false, live_alt: bool = false, @@ -5418,7 +5421,7 @@ fn renderFrame( if (!pdf_focus) core.frames.scroll = g.glide.follow.offset; core.frames.caret = caretRow(g, surface) orelse 0; const cursors_shown = !quad_mode; - var overlay_count = buildOverlay(g, surface, sw, sh); + var overlay_count = buildOverlay(g, core.settings.pet, surface, sw, sh); if (overlay_count != 0 and !uploadOverlayGpu(g, cmd, overlay_count)) overlay_count = 0; if (!prepareNativeImages(g, gpa, cmd, surface, &groups, sw, sh)) { @@ -8056,16 +8059,96 @@ fn cursorDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, /// The triangle overlay: the cursor's glide, over everything. fn buildOverlay( g: *Gui, + which: pardes.config.Runtime.Pet, surface: *const pardes.Surface, sw: u32, sh: u32, ) u32 { if (g.overlay_vertices.len == 0 or sw == 0 or sh == 0) return 0; var builder = OverlayBuilder{ .vertices = g.overlay_vertices, .win_w = @floatFromInt(sw), .win_h = @floatFromInt(sh) }; + appendWorkspacePet(g, which, surface, &builder); appendCursorGlide(g, surface, &builder); return @intCast(builder.len); } +/// The workspace tag's pet (the Pet setting, gui/pet.zig): in the blank +/// end of the grid's first row, past the tag's text, in the tag's colours, +/// on the window's own clock. Nothing of it reaches the core. +fn appendWorkspacePet(g: *Gui, which: pardes.config.Runtime.Pet, surface: *const pardes.Surface, builder: *OverlayBuilder) void { + const kind: pet.Kind = @fromBackingInt(@backingInt(which)); + if (kind == .off or surface.rows == 0 or surface.cols == 0) { + g.pet_state = .{}; + return; + } + var occupied: usize = 0; + for (surface.cells[0..surface.cols], 0..) |*cell, i| { + if (cellCodepoint(cell) != ' ') occupied = i + 1; + } + const band_top: f32 = @floatFromInt(taglineBandOffset(0, builder.win_h, g.cell_h, g.tagline_height)); + const region = if (occupied >= surface.cols) null else pet.lane( + occupied, + @floatFromInt(g.tagline_width), + builder.win_w, + band_top, + @floatFromInt(g.tagline_height), + ); + // ponytail: it moves when the window draws; a wake of its own for an + // idle window if a still pet ever matters. + const pose = g.pet_state.sample(kind, c.SDL_GetTicks(), region) orelse return; + const ink = overlayRgb(surface.chrome.tag_fg); + const eye = overlayRgb(surface.chrome.tag_bg); + // Behind the cursor: the overlay is over the cells, so the pixels a + // cursor covers are left out. + var boxes: [max_cursors]CursorBox = undefined; + const cursors = boxes[0..cursorBoxes(g, surface, fixedCellLayout(g), builder.win_h, &boxes)]; + for (0..pet.height) |y| for (0..pet.width) |x| { + const color = pet.pixel(kind, pose, x, y); + if (color == 0) continue; + const x0 = pose.x + @as(f32, @floatFromInt(x)) * pose.scale; + const y0 = pose.y + @as(f32, @floatFromInt(y)) * pose.scale; + const covered = for (cursors) |box| { + if (x0 < box.x1 and x0 + pose.scale > box.x0 and y0 < box.y1 and y0 + pose.scale > box.y0) break true; + } else false; + if (covered) continue; + builder.addRect(x0, y0, x0 + pose.scale, y0 + pose.scale, if (color == 2) eye else ink); + }; +} + +test "a pet stays past the workspace tag's text, and off it is gone" { + std.testing.refAllDecls(pet); + var cells: [80]pardes.Cell = @splat(.{}); + const surface: pardes.Surface = .{ .cols = 80, .rows = 1, .cells = &cells }; + for ("Workspace Commands", 0..) |ch, i| { + cells[i].text[0] = ch; + cells[i].len = 1; + cells[i].default = false; + } + var g = testGui(10, 20, 8, 16); + var vertices: [pet.max_vertices]OverlayVertex = undefined; + var builder: OverlayBuilder = .{ .vertices = &vertices, .win_w = 800, .win_h = 480 }; + appendWorkspacePet(&g, .cat, &surface, &builder); + try std.testing.expect(builder.len > 0); + for (vertices[0..builder.len]) |v| { + const x = (v.x + 1) * 400; + const y = (1 - v.y) * 240; + try std.testing.expect(x >= 20 * 8 - 0.01); + try std.testing.expect(y >= 0 and y < 20); + } + builder.len = 0; + appendWorkspacePet(&g, .off, &surface, &builder); + try std.testing.expectEqual(@as(usize, 0), builder.len); + try std.testing.expectEqual(@as(?u64, null), g.pet_state.tick); +} + +fn overlayRgb(rgb: [3]u8) OverlayColor { + return .{ + .r = @as(f32, @floatFromInt(rgb[0])) / 255.0, + .g = @as(f32, @floatFromInt(rgb[1])) / 255.0, + .b = @as(f32, @floatFromInt(rgb[2])) / 255.0, + .a = 1, + }; +} + /// G3: the focused cursor while it glides or blinks, its quad from the core /// (Chrome.cursor_quad, grid cells) in its cursor colour; a little less than /// solid, so the glyphs it passes over stay legible. @@ -8171,6 +8254,16 @@ const OverlayBuilder = struct { b.addVertex(x2, y2, color); } + fn addRect(b: *OverlayBuilder, x0_in: f32, y0_in: f32, x1_in: f32, y1_in: f32, color: OverlayColor) void { + if (b.len + 6 > b.vertices.len) return; + const x0 = std.math.clamp(@min(x0_in, x1_in), 0.0, b.win_w); + const x1 = std.math.clamp(@max(x0_in, x1_in), 0.0, b.win_w); + const y0 = std.math.clamp(@min(y0_in, y1_in), 0.0, b.win_h); + const y1 = std.math.clamp(@max(y0_in, y1_in), 0.0, b.win_h); + if (x1 <= x0 or y1 <= y0) return; + b.addTri(x0, y0, x1, y0, x1, y1, color); + b.addTri(x0, y0, x1, y1, x0, y1, color); + } }; fn envU16(env: *std.process.Environ.Map, name: []const u8) ?u16 { -- cgit v1.3