diff options
Diffstat (limited to 'src/layout.zig')
| -rw-r--r-- | src/layout.zig | 118 |
1 files changed, 117 insertions, 1 deletions
diff --git a/src/layout.zig b/src/layout.zig index 1d93c993..fca4c846 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -855,6 +855,122 @@ fn blankRows(p: *const Pardes, id: usize) u16 { return rows -| @as(u16, @intCast(@min(used, rows))); } +/// 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. + _ = firstColumn(p); + const asked = if (p.exec_column != null) null else origin; + compute(p); + const before = v.rects; + const before_min = minima(p); + switch (kind) { + // New: the bottom half of the last pane in its own column + // (look.c:921-923, et->col). + .scratch => 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 => acmePlace(p, p.exec_column orelse v.ncol - 1, null, id), + .errors => acmePlace(p, v.ncol - 1, null, id), + // makenewwindow(nil) for 9P's new (acme.c:877), else (t). + .fs => acmePlace(p, acmeColumn(p, from), null, id), + .shell, .doc => 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 (!placedRoomy(p, id, &before)) if (findPane(p, id)) |f| { + removePane(p, id); + for (v.cols[f.col].panes[0..p.view().cols[f.col].n]) |k| v.rects[k] = before[k]; + snapColWeights(p, f.col); + if (!splitTallest(p, f.col, id) or !placedRoomy(p, id, &before)) { + if (findPane(p, id) != null) { + removePane(p, id); + for (v.cols[f.col].panes[0..p.view().cols[f.col].n]) |k| v.rects[k] = before[k]; + 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 (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]; + snapColWeights(p, c); + if (v.cols[c].n == 0) { + insert(p, c, 0, id); + break; + } + if (splitTallest(p, c, id) and placedRoomy(p, id, &before)) break; + if (findPane(p, id) != null) removePane(p, id); + } else { + 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 { + 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); + restoreMinimaFrom(p, &settled, &before_min); + if (kind == .command) return; + tagline.exitHeader(p); + v.active = id; + if (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 (activeColumn(p)) |c| return c; + if (findPane(p, p.view().active)) |f| return f.col; + return columnOf(p, from); +} + +fn columnOf(p: *Pardes, id: usize) usize { + return if (findPane(p, id)) |f| f.col else p.view().ncol - 1; +} + /// Whether column `col` has the width and the weight to halve for a new /// column beside it. pub fn canSplitCol(p: *Pardes, col: usize) bool { @@ -977,7 +1093,7 @@ pub fn splitBelow(p: *Pardes, src_id: usize, nw: *Pane) void { const cur: u16 = if (!src.isTerminal()) body / 2 else panes.terminal.gridCursor(src).y + 1; // cap keep so a content-full source still leaves the new pane a tag + // a few body rows (an Alt-n from a full shell was born 0 rows tall) - // ...and the source min_body_rows of its own (exec.placeNew), when it + // ...and the source min_body_rows of its own (placeNew), when it // has them: a boot layout splits before any row is laid out. const least = @min(min_body_rows, body); const keep = std.math.clamp(cur, least, @max(least, body -| (BOX_H + 3))); |
