From 8903d352237919455996831047017ae57f2a83ef Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 05:42:57 -0300 Subject: layout: exec.placeNew moves into layout.zig as layout.placeNew, with NewPane, the type only it switches on, and acmeColumn and columnOf, which only it calls, before canSplitCol, since 29 of its 41 references are layout's own (acmePlace, takeRoom, splitTallest, placedRoomy); callers name layout, and Dir, mini and Store, which imported exec for it alone, import layout instead Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/exec.zig | 130 ++++------------------------------------------------------- 1 file changed, 7 insertions(+), 123 deletions(-) (limited to 'src/exec.zig') diff --git a/src/exec.zig b/src/exec.zig index 93f524cf..d0bee0e9 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -403,7 +403,7 @@ pub fn spawnTty(p: *Pardes, from: usize) ?*Pane { }; nt.greet = true; nt.body.mode = .tty; - placeNew(p, from, from, free, .shell); + layout.placeNew(p, from, from, free, .shell); if (refusedPlacement(p, free)) { p.reportError(from, "Term", error.NoPaneRoom); return null; @@ -411,13 +411,13 @@ pub fn spawnTty(p: *Pardes, from: usize) ?*Pane { return nt; } -/// A pane placeNew found no room for: taken back now, before anything is +/// A pane layout.placeNew found no room for: taken back now, before anything is /// logged of it or answered with its serial (it was never announced), so /// no `new`/`del` pair and no serial a script was told of is left behind. fn refusedPlacement(p: *Pardes, id: usize) bool { if (!p.unplaced.isSet(id)) return false; p.unplaced.unset(id); - // It held no weight (placeNew put every pane's rows back as they + // It held no weight (layout.placeNew put every pane's rows back as they // were): nothing else moves, a pane dragged short included. p.removePane(id, null) catch |err| p.reportError(id, "open", err); return true; @@ -717,7 +717,7 @@ pub fn executeFrom(p: *Pardes, id: usize, txt: []const u8, from_body: bool) ?usi /// Runs `line` in a command pane for `from`'s directory: `from` itself if /// it is one whose command is done, else the directory's command pane that -/// is done, else a new one, placed as placeNew places a command pane. +/// is done, else a new one, placed as layout.placeNew places a command pane. /// A pane reused keeps what it showed: the new command runs below a line /// naming it, as acme appends to +Errors and never clears it (util.c:213). fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { @@ -739,7 +739,7 @@ fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { // Not one whose pty a job it left behind still prints to: reusing it // would hang that job up. // From a column's tag, only a finished pane in that column is reused, - // as the new one goes in that column (placeNew). + // as the new one goes in that column (layout.placeNew). // Nor one leased: an open that was answered its serial and is still // open reads that pane's output, which another client's command must // not replace; a new pane runs it instead. @@ -784,7 +784,7 @@ fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { }; pane.command_from = winid(p, src); echoCommand(p, pane, line); - placeNew(p, from, from, free, .command); + layout.placeNew(p, from, from, free, .command); if (refusedPlacement(p, free)) { p.reportError(from, "exec", error.NoPaneRoom); return null; @@ -1092,122 +1092,6 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] look.cancelLookHover(p); } -/// What a new pane is, and who asked: each rule places them differently. -/// `scratch` is New's, `fs` 9P's pane/new, `errors` a +Errors pane. -pub const NewPane = enum { scratch, fs, shell, doc, command, errors }; - -/// Put new pane `id` in the layout: every new pane comes through here, as -/// acme's makenewwindow places it, and every one but a command pane takes -/// the keyboard. `from` is the pane that asked, `origin` the text it asked -/// from: null when a column tag, the workspace tag or 9P asked (acme's -/// t->w == nil). -pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPane) void { - const v = p.view(); - // No column left (the last one Delcol'd): a pane made from the workspace - // tag opens one to go in. - _ = layout.firstColumn(p); - const asked = if (p.exec_column != null) null else origin; - layout.compute(p); - const before = v.rects; - const before_min = layout.minima(p); - switch (kind) { - // New: the bottom half of the last pane in its own column - // (look.c:921-923, et->col). - .scratch => layout.acmePlace(p, p.exec_column orelse columnOf(p, from), null, id), - // +Errors, a command's output: the last column (util.c:94-98); a - // command run from a column's tag, that column. - .command => layout.acmePlace(p, p.exec_column orelse v.ncol - 1, null, id), - .errors => layout.acmePlace(p, v.ncol - 1, null, id), - // makenewwindow(nil) for 9P's new (acme.c:877), else (t). - .fs => layout.acmePlace(p, acmeColumn(p, from), null, id), - .shell, .doc => layout.acmePlace(p, acmeColumn(p, from), asked, id), - } - // No pane is made shorter than its tag and two rows: where the place - // chosen has not the room, the column's tallest pane gives it, and - // where none can, the pane is refused, and closed at the step's end - // (Pardes.unplaced) once whatever made it is done with it. - if (!layout.placedRoomy(p, id, &before)) if (layout.findPane(p, id)) |f| { - layout.removePane(p, id); - for (v.cols[f.col].panes[0..p.view().cols[f.col].n]) |k| v.rects[k] = before[k]; - layout.snapColWeights(p, f.col); - if (!layout.splitTallest(p, f.col, id) or !layout.placedRoomy(p, id, &before)) { - if (layout.findPane(p, id) != null) { - layout.removePane(p, id); - for (v.cols[f.col].panes[0..p.view().cols[f.col].n]) |k| v.rects[k] = before[k]; - layout.snapColWeights(p, f.col); - } - // No pane to halve, but the column has the rows for the new - // one's minimum above the others': it takes them from those with - // the most to spare (a pane dragged short keeps its own), so - // what is refused is only what the documented arithmetic cannot - // hold. - // +Errors and 9P's pane/new go wherever there is room, last - // column first, as acme takes rows from a window that has them - // before saying there are none; with none, +Errors's maker says - // the text some other way (appendErrors), and pane/new is - // refused. - if (layout.takeRoom(p, f.col, id)) {} else if (kind == .errors or kind == .fs) { - var c = v.ncol; - while (c > 0) { - c -= 1; - if (c == f.col) continue; - for (v.cols[c].panes[0..p.view().cols[c].n]) |k| v.rects[k] = before[k]; - layout.snapColWeights(p, c); - if (v.cols[c].n == 0) { - layout.insert(p, c, 0, id); - break; - } - if (layout.splitTallest(p, c, id) and layout.placedRoomy(p, id, &before)) break; - if (layout.findPane(p, id) != null) layout.removePane(p, id); - } else { - layout.insert(p, f.col, v.cols[f.col].n, id); - p.unplaced.set(id); - // Refused holding no weight: its column's rows come - // back as they were. - p.panes[id].?.vweight = 0; - // No pane anywhere can give it rows: pane/new is refused. - if (kind == .fs) p.reportError(from, "placement", error.NoPaneRoom); - return; - } - } else { - layout.insert(p, f.col, v.cols[f.col].n, id); - // Refused, it closes at the step's end holding no weight, so - // its column's rows come back as they were, none rounded off. - p.panes[id].?.vweight = 0; - p.unplaced.set(id); - p.reportError(from, "placement", error.NoPaneRoom); - return; - } - } - }; - // Placed: no pane the rows' rounding took under its minimum stays - // there. Only those: a pane dragged short before keeps its rows, and - // the others keep theirs, as acme's coladd moves only the window it - // splits (cols.c:41-108). The new pane had nothing to keep: it is - // lifted to its minimum too. - var settled = before; - settled[id].h = std.math.maxInt(u16); - layout.restoreMinimaFrom(p, &settled, &before_min); - if (kind == .command) return; - tagline.exitHeader(p); - v.active = id; - if (layout.findPane(p, id)) |f| p.setActiveColumn(f.col); -} - -/// acme's makenewwindow column (util.c:456-467): the column a command came -/// from (its tag's), else the active column, else the keyboard's pane's, -/// else the asking pane's. -fn acmeColumn(p: *Pardes, from: usize) usize { - if (p.exec_column) |c| return c; - if (layout.activeColumn(p)) |c| return c; - if (layout.findPane(p, p.view().active)) |f| return f.col; - return columnOf(p, from); -} - -fn columnOf(p: *Pardes, id: usize) usize { - return if (layout.findPane(p, id)) |f| f.col else p.view().ncol - 1; -} - // ---- the words addons bring (Kind.Registry's) ---- /// A line whose first word is an addon's: run, and true; false for one @@ -1237,7 +1121,7 @@ pub fn runWord(p: *Pardes, id: usize, w: *const pardes.Kind.Word, line: []const p.unplaced.set(free); return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: {s}", .{ name, made.addon.?.refused.slice() }) catch name); } - return placeNew(p, id, id, free, .doc); + return layout.placeNew(p, id, id, free, .doc); } const kind = p.kinds.kinds[w.kind].nameOf(); const here = if (p.panes[id]) |pane| if (pane.addon) |s| s.live and s.is(kind) else false else false; -- cgit v1.3