summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.zig19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 82866a30..f36de939 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -1512,6 +1512,8 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options) !void {
defer for (&ptys) |*slot| if (slot.*) |pt| {
_ = libc.close(pt.fd);
};
+ // the core's one way to ask about those ptys, pulled at the Exec that cares
+ core.tty_query = .{ .ctx = &ptys, .taken = &ttyTakenAt };
var lsp_workers: LspWorkers = .{};
var queue: Queue = .{
.gpa = gpa,
@@ -2062,6 +2064,7 @@ fn runGrid(init: std.process.Init, opts_in: pardes.Options) !void {
defer for (&ptys) |*slot| if (slot.*) |pt| {
_ = libc.close(pt.fd);
};
+ core.tty_query = .{ .ctx = &ptys, .taken = &ttyTakenAt };
var lsp_workers: LspWorkers = .{};
var queue: Queue = .{
.gpa = gpa,
@@ -2908,7 +2911,8 @@ fn drainEffects(
}
const pt = forkShell(core.shellBin(), cwd_z, core.screen_h, core.screen_w);
ptys[sp.pane] = pt;
- // report the pane's starting directory back to the core (tags)
+ // report the pane's starting directory back to the core (tags); the
+ // slot needs no occupancy reset, nothing about it is remembered
var lbuf: [1024]u8 = undefined;
if (look.shellCwd(pt.pid, &lbuf)) |wd| core.setCwd(sp.pane, wd);
if (threads_ok) spawnReader(gpa, pt, sp.pane, gens[sp.pane], queue);
@@ -3014,6 +3018,9 @@ fn forkShell(bin: []const u8, cwd: ?[*:0]const u8, rows: u16, cols: u16) Pty {
return .{ .fd = master, .pid = pid };
}
+/// Live cwd for tags/look: a cheap per-pane process lookup, polled every frame
+/// because a tagline draws it. Whether a pane's tty still belongs to the prompt
+/// pardes forked is deliberately NOT polled with it — see `ttyTakenAt`.
fn pollCwds(core: *pardes.Pardes, ptys: *[pardes.MAX_PANES]?Pty) void {
for (ptys, 0..) |slot, id| if (slot) |pt| {
var lbuf: [1024]u8 = undefined;
@@ -3021,6 +3028,16 @@ fn pollCwds(core: *pardes.Pardes, ptys: *[pardes.MAX_PANES]?Pty) void {
};
}
+/// The core's `tty_query`: is a program (vim, a pager, an agent) holding this
+/// pane's tty instead of the shell we forked? Asked by the core only where it is
+/// about to type a command line, which is why the /proc walk behind it is not in
+/// pollCwds above: nothing draws this answer, and an Exec is a rare frame.
+fn ttyTakenAt(ctx: ?*anyopaque, pane: usize) bool {
+ const table: *const [pardes.MAX_PANES]?Pty = @ptrCast(@alignCast(ctx orelse return false));
+ const pt = table[pane] orelse return false;
+ return look.ttyTaken(pt.pid, pt.fd);
+}
+
/// web: no ptys, no fs — panes replay from the embedded dump. Only the
/// clipboard and open_link effects have a browser meaning.
fn drainEffectsWeb(core: *pardes.Pardes, gpa: std.mem.Allocator, g: *Gui) void {