From 29e6f988ee392f5a7d7a7f1b007f3a33c2c43041 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:54:02 -0300 Subject: gui: dead declarations and one-line helpers go: setenv, Msg, MessageBatch, the topbarPaneBorderPixels alias, blink_redraws (counted, never read), wakeSdl (sdlWake again), anchorInset, bodyLayerAt, addChecker, guiFontName, handleFinger's forward to handlePairFinger, and a test of std.AutoHashMap Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/gui/gui.zig | 64 +++++++++------------------------------------------------ 1 file changed, 10 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/gui/gui.zig b/src/gui/gui.zig index e3014c6a..61bd61f0 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -31,7 +31,6 @@ const tracy = @import("../tracy.zig"); pub const c = @import("gui_c"); // SDL3 and font.h, translated by build.zig const host_io = @import("../host_io.zig"); -extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int; const TIOCSWINSZ: c_int = @bitCast(@as(u32, if (@hasDecl(posix.T, "IOCSWINSZ")) posix.T.IOCSWINSZ else 0x80087467)); const log = std.log.scoped(.gui); @@ -440,17 +439,6 @@ test "tagline percentage changes measured band height without body metrics" { try std.testing.expect(full.height <= @as(u32, @intCast(cell_h))); } -test "glyph atlas cache separates body and tagline roles" { - var glyphs = std.AutoHashMap(GlyphKey, Slot).init(std.testing.allocator); - defer glyphs.deinit(); - try glyphs.put(.{ .face = 0, .glyph = 36, .role = .body }, .{ .u = 0, .v = 0 }); - try glyphs.put(.{ .face = 0, .glyph = 36, .role = .tagline }, .{ .u = 10, .v = 0 }); - try glyphs.put(.{ .face = 0, .glyph = 36, .role = .body, .decoration = .{ .bold = true } }, .{ .u = 20, .v = 0 }); - try std.testing.expectEqual(@as(usize, 3), glyphs.count()); - try std.testing.expectEqual(@as(u32, 0), glyphs.get(.{ .face = 0, .glyph = 36, .role = .body }).?.u); - try std.testing.expectEqual(@as(u32, 10), glyphs.get(.{ .face = 0, .glyph = 36, .role = .tagline }).?.u); -} - test "installed Nerd Symbols fallback covers Yazi directory icons" { try std.testing.expectEqualStrings("SymbolsNerdFont-Regular", fonts.fallback_names[2]); @@ -810,10 +798,6 @@ fn takeScrollTicks(accum: *f32) i32 { fn handleFinger(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); - return handlePairFinger(t, in, f, win_w, win_h, cell_w, cell_h, tagline_w); -} - -fn handlePairFinger(t: *Touch, in: *Input, f: Finger, win_w: f32, win_h: f32, cell_w: f32, cell_h: f32, tagline_w: f32) void { switch (f.kind) { .down => { t.updatePoint(f); @@ -867,14 +851,13 @@ const RetiredShell = struct { pid: libc.pid_t = 0, kill_at: i64 = 0 }; const Queue = host_io.Inbox; -/// Wakes a blocking SDL_WaitEventTimeout after a push from another thread. +/// Wakes a blocking SDL_WaitEventTimeout from another thread: a push to +/// the queue, a link's message, a post chain's compile done (ShaderBuild). fn sdlWake(_: ?*anyopaque) void { var sev = std.mem.zeroes(c.SDL_Event); sev.type = c.SDL_EVENT_USER; _ = c.SDL_PushEvent(&sev); } -const Msg = Queue.Msg; -const MessageBatch = Queue.Batch; const PipeTasks = selection_pipe.Tasks; const output_capacity = Queue.output_capacity; @@ -1600,18 +1583,14 @@ fn setGuiFontName(g: *Gui, fallback: []const u8) void { g.font_name_len = @intCast(len); } -fn guiFontName(g: *const Gui) []const u8 { - return g.font_name[0..g.font_name_len]; -} - fn observeGuiFont(g: *const Gui, core: *pardes.Pardes) void { const size: u16 = @intFromFloat(@round(g.px * 100.0)); - _ = core.observeFont(guiFontName(g), size, .pixels); + _ = core.observeFont(g.font_name[0..g.font_name_len], size, .pixels); } fn acknowledgeGuiFont(g: *const Gui, core: *pardes.Pardes) void { const size: u16 = @intFromFloat(@round(g.px * 100.0)); - _ = core.acknowledgeFont(guiFontName(g), size, .pixels); + _ = core.acknowledgeFont(g.font_name[0..g.font_name_len], size, .pixels); } fn loadFallbackFonts(g: *Gui, gpa: std.mem.Allocator) void { @@ -3812,7 +3791,7 @@ const Shell = struct { gens: *[pardes.MAX_PANES]u32, queue: *Queue, /// What drainQueue takes each wakeup, kept rather than rebuilt. - batch: MessageBatch = .{}, + batch: Queue.Batch = .{}, pipe_tasks: *PipeTasks, inotify_fd: c_int, watches: *file_watch.Table, @@ -4335,12 +4314,6 @@ const Shell = struct { } }; -/// A post chain compile is done (ShaderBuild.zig): the loop's SDL wait ends. -fn wakeSdl(_: ?*anyopaque) void { - var event = std.mem.zeroes(c.SDL_Event); - event.type = c.SDL_EVENT_USER; - _ = c.SDL_PushEvent(&event); -} fn wakeFs(ctx: ?*anyopaque) void { const q: *Queue = @ptrCast(@alignCast(ctx.?)); @@ -4600,7 +4573,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); - _ = s.shaders.sync(s.gpa, s.io, core, s.inotify_fd, s.watches, .{ .call = wakeSdl }); + _ = s.shaders.sync(s.gpa, s.io, core, s.inotify_fd, s.watches, .{ .call = sdlWake }); { var passes: [Post.max]ShaderBuild.Pass = undefined; g.post.sync(s.gpa, g.device, g.swapchain_format, s.shaders.view(&core.settings.post, &passes), s.shaders.revision, core); @@ -4614,14 +4587,10 @@ fn pollFrame(ctx: ?*anyopaque) void { // A blink edge: the last frame again, the cursor's alpha moved on. if (g.blink_due and !core.needs_frame and s.presented) if (s.surface) |frame| { g.blink_due = false; - blink_redraws += 1; s.presented = renderFrame(g, s.gpa, core, frame) catch false; }; } -/// Frames drawn for a blink alone, with no core render (tests, tracing). -var blink_redraws: u64 = 0; - /// PARDES_FRAMES_CAPTURE's directory, and how many frames it has. var frame_capture_dir: ?[]const u8 = null; var frame_capture_count: u32 = 0; @@ -6577,7 +6546,7 @@ fn renderFrame( col, line_cursor, false, - cursors_shown and at == cursor_idx and !cursor_bar and bodyLayerAt(surface, col, row) == null, + cursors_shown and at == cursor_idx and !cursor_bar and bodyLayerIn(surface.bodyLayers(), col, row) == null, page, ); if (data_diff) emitSurfaceCell( @@ -6850,7 +6819,6 @@ const ResolvedCell = struct { clear_bg: bool = false, }; -const topbarPaneBorderPixels = pardes.topbarPaneBorderPixels; const taglineBandOffset = pardes.taglineBandOffset; test "tagline bands center in their cells and Tagbottom faces the window edge" { @@ -7075,10 +7043,6 @@ fn clipInstanceTop(instance: *CellInstance, top: f32, win_h: f32) void { instance.y0 = @max(instance.y1, limit); } -fn bodyLayerAt(surface: *const pardes.Surface, col: u16, row: u16) ?*const pardes.Layer { - return bodyLayerIn(surface.bodyLayers(), col, row); -} - fn bodyLayerIn(layers: []const pardes.Layer, col: u16, row: u16) ?*const pardes.Layer { for (layers) |*layer| { const r = layer.viewport; @@ -7163,10 +7127,6 @@ fn gripCellChanged(surface: *const pardes.Surface, covered: []const Cover, previ return false; } -fn anchorInset(g: *const Gui, row: u16, win_h: f32) u32 { - return taglineBandOffset(row, win_h, g.cell_h, g.tagline_height); -} - /// acme's Scrollwid column at a pane's or column's left edge, in window /// pixels: where its button sits over its scrollbar, one width for both /// (`rail_px` at acme's 17px font, scaled with the tagline, and always @@ -7283,7 +7243,7 @@ fn emitSurfaceCell( // An anchor starts at its column's rule: its left edge is inset by // its top margin so the band frames it on the left as above and // below, and its mark moves right by half that to stay centered. - const inset: u32 = if (line_cover[at - offset].anchor) anchorInset(g, row, win_h) else 0; + const inset: u32 = if (line_cover[at - offset].anchor) taglineBandOffset(row, win_h, g.cell_h, g.tagline_height) else 0; // A grip is acme's button: its fill is this cell's ground, cut to // the button (and a dirty one's inset a pixel inside its ring, so // the ring reads round it), its glyph centered in it. @@ -8946,10 +8906,6 @@ fn addDecor(g: *Gui, gpa: std.mem.Allocator, x0_in: f32, y0_in: f32, x1_in: f32, /// A checker (decor.frag.glsl): squares of `px` window pixels in `a` and /// `b` from the quad's corner (lapis's scroll track); `stripes`, bands of /// `px` across it instead (lapis's focused title bar), `a` first. -fn addChecker(g: *Gui, gpa: std.mem.Allocator, x0: f32, y0: f32, x1: f32, y1: f32, a: [3]u8, b: [3]u8, px: f32, track: ?pardes.animation.Track, win_w: f32, win_h: f32) !void { - return addPattern(g, gpa, x0, y0, x1, y1, a, b, px, false, track, win_w, win_h); -} - fn addPattern(g: *Gui, gpa: std.mem.Allocator, x0: f32, y0: f32, x1: f32, y1: f32, a: [3]u8, b: [3]u8, px: f32, stripes: bool, track: ?pardes.animation.Track, win_w: f32, win_h: f32) !void { const first = g.decor.items.len; try addDecor(g, gpa, x0, y0, x1, y1, a, 1, track, win_w, win_h); @@ -9471,7 +9427,7 @@ fn paneDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ti const column = scrollColumn(g, chrome, rail.rect.x, layout); try addDecor(g, gpa, x0, y0, x0 + layout.w, y1, page, 1, track, win_w, win_h); if (chrome.decor_checker) |gold| - try addChecker(g, gpa, column[0], y0, column[1], y1, chrome.scroll_track, gold, dp(@floatFromInt(@max(1, chrome.decor_checker_px))), track, win_w, win_h) + try addPattern(g, gpa, column[0], y0, column[1], y1, chrome.scroll_track, gold, dp(@floatFromInt(@max(1, chrome.decor_checker_px))), false, track, win_w, win_h) else try addDecor(g, gpa, column[0], y0, column[1], y1, chrome.scroll_track, 1, track, win_w, win_h); if (rail.thumb_h != 0 and rail.thumb_span > 0) { @@ -10551,7 +10507,7 @@ fn cursorBoxes(g: *const Gui, surface: *const pardes.Surface, layout: CellLayout const page = chrome.page orelse bg_default; var n: usize = 0; if (surface.cursor) |cursor| { - if (cursor.x < surface.cols and cursor.y < surface.rows and bodyLayerAt(surface, cursor.x, cursor.y) == null and tagLayerIn(surface.tagLayers(), cursor.x, cursor.y) == null) { + if (cursor.x < surface.cols and cursor.y < surface.rows and bodyLayerIn(surface.bodyLayers(), cursor.x, cursor.y) == null and tagLayerIn(surface.tagLayers(), cursor.x, cursor.y) == null) { const cell = &surface.cells[@as(usize, cursor.y) * surface.cols + cursor.x]; const role = cellFontRole(cell); const width: f32 = if (role == .tagline) @floatFromInt(g.tagline_width) else layout.w; -- cgit v1.3