From 4c134eaa5c7f84eba7091c9ccef86567f1434d49 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 7 Nov 2026 19:45:54 -0300 Subject: gui: a kind's pane (an image, a PDF) is watched again and shows its file as it is now: Kind.open and a restored kind's pane emit its watch, which kinds #14 dropped with pdf_view, and a reload counts into its pictures' keys, since its kind numbers them afresh from each open and a window keeps a texture by key; the T1 session watches files as a host does (Session.filesChanged) and two behaviour cases pin it Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Kind.zig | 14 +++++++++++++- src/dump.zig | 5 ++++- src/pardes.zig | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Kind.zig b/src/Kind.zig index 27cd1a6d..bdbfeb2e 100644 --- a/src/Kind.zig +++ b/src/Kind.zig @@ -134,7 +134,7 @@ pub const Slot = struct { // jobs' inputs, its file's hash, a placeholder's record, the place // its kind says), and what a frame makes (the thumb, the pointer, // whether one was drawn: a view's, never a step's). - .local = .{ "ops", "st", "gpa", "arena", "opened", "jobs", "tokens", "record", "where_text", "thumb_at", "thumb_span", "pointer", "painted", "over", "shadow", "used" }, + .local = .{ "ops", "st", "gpa", "arena", "opened", "reloads", "jobs", "tokens", "record", "where_text", "thumb_at", "thumb_span", "pointer", "painted", "over", "shadow", "used" }, }; /// Its kind's code here; null in a placeholder (`live` false: its kind /// not in the registry, its record kept for the day it comes) or a @@ -150,6 +150,10 @@ pub const Slot = struct { /// The hash of the file's bytes it was opened from, 0 for none (a /// record's): whether the file a watch arms on is still those. opened: u64 = 0, + /// Times its file changed under it (fileChanged): its pictures' keys + /// carry it, since its kind numbers them afresh from each open, and a + /// frontend keeps what it uploaded by key. + reloads: u32 = 0, /// Its kind's generation when it was opened (Entry.gen). gen: u32 = 0, path: []u8 = &.{}, @@ -248,6 +252,9 @@ pub fn open(p: *Pardes, id: usize, k: u8, path: ?[]const u8, bytes: ?[]const u8) const pane = try p.newDocPane(id); pane.addon = s; _ = reopen(p, id, s, bytes); + // Its file watched, as a text's is: changed on disk, it opens again + // from it (fileChanged); retirePane lets the watch go. + if (s.path.len > 0 and @import("fs.zig").localPath(s.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); return pane; } @@ -346,6 +353,7 @@ pub fn fileChanged(p: *Pardes, id: usize, _: []const u8) bool { if (checked) s.used.clearRetainingCapacity(); if (s.record) |r| s.gpa.free(r); s.record = record; + s.reloads +%= 1; return reopen(p, id, s, bytes orelse ""); } @@ -445,6 +453,10 @@ pub fn paint(p: *const Pardes, slot: *Slot, id: usize, arena: std.mem.Allocator, continue; } frame.buf[frame.n] = pl; + if (slot.reloads != 0) { + frame.buf[frame.n].key = std.hash.Wyhash.hash(slot.reloads, std.mem.asBytes(&pl.key)); + if (pl.from != 0) frame.buf[frame.n].from = std.hash.Wyhash.hash(slot.reloads, std.mem.asBytes(&pl.from)); + } frame.n += 1; } slot.thumb_at = std.math.clamp(out.at, 0, 1); diff --git a/src/dump.zig b/src/dump.zig index 8aa4aa16..9849c8e4 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -596,7 +596,10 @@ fn reviveSession(p: *Pardes, previous: ?*Pardes, resumed: bool) !void { /// kind's pane opened again (a PDF a build before the pdf addon dumped, as /// the addon's). fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool) void { - if (pane.addon) |slot| return reviveSlot(p, id, slot); + if (pane.addon) |slot| { + if (slot.path.len > 0 and filesystem.localPath(slot.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + return reviveSlot(p, id, slot); + } if (pane.terminal != null) { // A command pane comes back finished, showing what it said: its // command is not run again. A host that runs shells starts one diff --git a/src/pardes.zig b/src/pardes.zig index ecbc0633..2fa1d390 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -84,6 +84,7 @@ pub const Addon = @import("Addon.zig"); pub const dump = @import("dump.zig"); pub const lsp = @import("lsp/lsp.zig"); pub const host_io = @import("host_io.zig"); +pub const file_watch = @import("file_watch.zig"); pub const Host = host_io.Host; pub const frameMark = tracy.frameMark; -- cgit v1.3