diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Core.zig | 62 | ||||
| -rw-r--r-- | src/Finder.zig | 26 | ||||
| -rw-r--r-- | src/Handover.zig | 40 | ||||
| -rw-r--r-- | src/Query.zig | 4 | ||||
| -rw-r--r-- | src/builtins.zig | 4 | ||||
| -rw-r--r-- | src/draw.zig | 10 | ||||
| -rw-r--r-- | src/dump.zig | 6 | ||||
| -rw-r--r-- | src/exec.zig | 12 | ||||
| -rw-r--r-- | src/gui/gui.zig | 2 | ||||
| -rw-r--r-- | src/keys.zig | 2 | ||||
| -rw-r--r-- | src/layout.zig | 354 | ||||
| -rw-r--r-- | src/mouse.zig | 74 | ||||
| -rw-r--r-- | src/ninep/cols.zig | 22 | ||||
| -rw-r--r-- | src/ninep/ctl.zig | 6 | ||||
| -rw-r--r-- | src/ninep/tree.zig | 8 | ||||
| -rw-r--r-- | src/panes.zig | 18 | ||||
| -rw-r--r-- | src/views.zig | 15 |
17 files changed, 323 insertions, 342 deletions
diff --git a/src/Core.zig b/src/Core.zig index fa39f884..8d88fcbd 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -105,16 +105,12 @@ reserved_slots: [MAX_PANES]bool = @splat(false), retired_panes: RetiredPanes = .{}, // layout: columns own x by weight; panes own y by vweight within a column. ncol: usize = 0, -col_weight: [MAX_COLS]u64 = @splat(column_weight_unit), -// Zeroed, not undefined: a digest takes the whole of it, a release -// build's heap leaves its unused slots whatever was there before, and -// two replicas must agree on them (src/replica.zig). -col_panes: [MAX_COLS][MAX_PANES]usize = @splat(@splat(0)), -col_n: [MAX_COLS]usize = @splat(0), +cols: [MAX_COLS]Column = @splat(.{}), /// Each column's tag and the workspace's: Texts like a pane's tag, with -/// no prefix, showing a default until someone edits them. +/// no prefix, showing a default until someone edits them. Not the +/// Column's: a view opened takes the live one's columns (views.open) but +/// tags of its own. col_tags: [MAX_COLS]Text = @splat(.{ .what = .column }), -col_serial: [MAX_COLS]u32 = @splat(0), next_column_serial: u32 = 1, /// The finder column, where query panes stack with SearchPlace column /// (Finder.zig). @@ -609,11 +605,11 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes { _ = try p.newShell(2, ""); for (p.panes[0..3]) |slot| slot.?.greet = true; p.ncol = 2; - p.col_n[0] = 2; - p.col_panes[0][0] = 0; - p.col_panes[0][1] = 1; - p.col_n[1] = 1; - p.col_panes[1][0] = 2; + p.cols[0].n = 2; + p.cols[0].panes[0] = 0; + p.cols[0].panes[1] = 1; + p.cols[1].n = 1; + p.cols[1].panes[0] = 2; }, .shell => { _ = try p.newShell(0, ""); @@ -646,8 +642,8 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes { /// The layout every single-pane boot starts from. fn oneColumn(p: *Pardes) void { p.ncol = 1; - p.col_n[0] = 1; - p.col_panes[0][0] = 0; + p.cols[0].n = 1; + p.cols[0].panes[0] = 0; } /// The recent list's own allocator: it is kept best effort (a file not @@ -2089,6 +2085,20 @@ pub const PendingWrite = struct { bytes: []u8, off: usize = 0 }; /// The session layouts `init` can put on screen. One name each, so choosing /// between them reads as a choice instead of a chain of ifs over four options. +/// A column (acme's Column, cols.c): its panes top to bottom, its share of +/// the width and its serial. Its tag is the session's `col_tags`, and its +/// place on screen (`col_x`, `col_w`) is worked out each sync, as a pane's +/// rect is. +pub const Column = struct { + // Zeroed, not undefined: a digest takes the whole of it, a release + // build's heap leaves its unused slots whatever was there before, and + // two replicas must agree on them (src/replica.zig). + panes: [MAX_PANES]usize = @splat(0), + n: usize = 0, + weight: u64 = column_weight_unit, + serial: u32 = 0, +}; + pub const Boot = enum { /// the document named on the command line, or the pane explaining why not document, @@ -3564,13 +3574,13 @@ test "column tag first-cell execution keeps New local to the clicked column" { layout.newScratchIn(p, 0, layout.activeColumn(p).?); p.sync(); for (0..2) |column| { - p.active = p.col_panes[1 - column][0]; + p.active = p.cols[1 - column].panes[0]; p.presented(); - const before = p.col_n; + const before = p.cols; p.update(.{ .mouse = .{ .button = .middle, .kind = .press, .col = p.col_x[column] + TAG_TEXT_INSET, .row = TOPBAR_H } }); p.update(.{ .mouse = .{ .button = .middle, .kind = .release, .col = p.col_x[column] + TAG_TEXT_INSET, .row = TOPBAR_H } }); - try std.testing.expectEqual(before[column] + 1, p.col_n[column]); - try std.testing.expectEqual(before[1 - column], p.col_n[1 - column]); + try std.testing.expectEqual(before[column].n + 1, p.cols[column].n); + try std.testing.expectEqual(before[1 - column].n, p.cols[1 - column].n); try std.testing.expectEqual(column, layout.findPane(p, p.active).?.col); } try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content); @@ -3653,8 +3663,8 @@ test "argv naming nothing boots an errors pane rather than failing the launch" { // One pane, filling the window, and it is an OUTPUT pane rather than the // shell a bare `pardes` boots: the answer is the whole screen. try std.testing.expectEqual(@as(u8, 1), p.ncol); - try std.testing.expectEqual(@as(usize, 1), p.col_n[0]); - try std.testing.expectEqual(@as(usize, 0), p.col_panes[0][0]); + try std.testing.expectEqual(@as(usize, 1), p.cols[0].n); + try std.testing.expectEqual(@as(usize, 0), p.cols[0].panes[0]); try std.testing.expectEqual(@as(usize, 0), p.active); for (p.panes[1..]) |slot| try std.testing.expect(slot == null); const pane = p.panes[0].?; @@ -3752,22 +3762,22 @@ test "the bare tty startup opens a text pane under the shell, unfocused" { // One column, shell on top in raw mode, an empty text pane under it. try std.testing.expectEqual(@as(usize, 1), p.ncol); - try std.testing.expectEqual(@as(usize, 2), p.col_n[0]); - const shell = p.panes[p.col_panes[0][0]].?; - const scratch = p.panes[p.col_panes[0][1]].?; + try std.testing.expectEqual(@as(usize, 2), p.cols[0].n); + const shell = p.panes[p.cols[0].panes[0]].?; + const scratch = p.panes[p.cols[0].panes[1]].?; try std.testing.expect(shell.isTerminal()); try std.testing.expectEqual(Text.Mode.tty, shell.body.mode); try std.testing.expect(!scratch.isTerminal()); try std.testing.expectEqualStrings("", scratch.file.?.content); // ...and the shell keeps the keyboard. - try std.testing.expectEqual(p.col_panes[0][0], p.active); + try std.testing.expectEqual(p.cols[0].panes[0], p.active); // Unnamed, it is the bare shell every test asks for. const plain = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer plain.deinit(); try std.testing.expectEqual(Boot.tty_shell, plain.boot); - try std.testing.expectEqual(@as(usize, 1), plain.col_n[0]); + try std.testing.expectEqual(@as(usize, 1), plain.cols[0].n); } test "tty output follows only from the bottom" { diff --git a/src/Finder.zig b/src/Finder.zig index 3744e5d1..1e8fa022 100644 --- a/src/Finder.zig +++ b/src/Finder.zig @@ -58,8 +58,8 @@ pub fn place(f: *Finder, p: *Pardes, id: usize) bool { fold(p, c, id); // The oldest goes once there are too many: the bottom one, as the top // is always the newest. - while (p.col_n[c] > max_results) { - const oldest = p.col_panes[c][p.col_n[c] - 1]; + while (p.cols[c].n > max_results) { + const oldest = p.cols[c].panes[p.cols[c].n - 1]; p.removePane(oldest, null) catch break; } return true; @@ -75,13 +75,11 @@ fn open(f: *Finder, p: *Pardes) ?usize { const before_min = layout.minima(p); const before = p.rects; const c = p.ncol; - p.col_n[c] = 0; - // Not used for its width (layout.compute), only kept positive for the - // code that halves and joins weights. - p.col_weight[c] = layout.column_weight_unit; + // Its weight, the default, is not used for its width (layout.compute), + // only kept positive for the code that halves and joins weights. + p.cols[c] = .{}; p.col_tags[c] = .{ .what = .column, .gpa = p.gpa }; p.col_tags[c].own = p.gpa.dupe(u8, tag_text) catch null; - p.col_serial[c] = 0; p.ncol += 1; f.serial = layout.columnSerial(p, c); // Where nothing holds every minimum there is no finder, as Newcol is @@ -99,7 +97,7 @@ fn open(f: *Finder, p: *Pardes) ?usize { /// to it, its +Preview) to its tag. fn fold(p: *Pardes, c: usize, top: usize) void { layout.compute(p); - for (p.col_panes[c][0..p.col_n[c]]) |k| { + for (p.cols[c].panes[0..p.cols[c].n]) |k| { const pane = p.panes[k] orelse continue; if (k == top or layout.groupRoot(p, k) == top) { pane.collapsed = false; @@ -124,7 +122,7 @@ pub fn raise(f: *Finder, p: *Pardes, id: usize) void { const end = layout.groupEnd(p, c, at.idx); var moved: [pardes.MAX_PANES]usize = undefined; const n = end - at.idx; - @memcpy(moved[0..n], p.col_panes[c][at.idx..end]); + @memcpy(moved[0..n], p.cols[c].panes[at.idx..end]); for (moved[0..n]) |k| layout.removePane(p, k); for (moved[0..n], 0..) |k, i| layout.insert(p, c, i, k); } @@ -154,7 +152,7 @@ pub fn away(f: *Finder, p: *Pardes, from: usize, kind: pardes.exec.NewPane) ?usi /// The finder column has lost its last pane: it goes, and every other /// column is as wide as before it came. pub fn emptied(f: *Finder, p: *Pardes, c: usize) bool { - if (f.column(p) != c or p.col_n[c] != 0) return false; + if (f.column(p) != c or p.cols[c].n != 0) return false; layout.dropColumn(p, c); f.serial = 0; return true; @@ -173,13 +171,13 @@ pub fn dragWidth(f: *Finder, p: *Pardes, other: usize, finder_w: u64) void { var rest_weight: u128 = 0; var rest_cells: u64 = 0; for (0..p.ncol) |k| if (k != fc and k != other) { - rest_weight += p.col_weight[k]; + rest_weight += p.cols[k].weight; rest_cells += p.col_w[k]; }; if (rest_cells > 0) { const other_cells = combined - fw; const w = @as(u128, other_cells) * rest_weight / rest_cells; - p.col_weight[other] = @intCast(std.math.clamp(w, 1, layout.max_column_weight)); + p.cols[other].weight = @intCast(std.math.clamp(w, 1, layout.max_column_weight)); } layout.compute(p); } @@ -203,7 +201,7 @@ test "SearchPlace column: query panes stack in a finder column at the right edge typeKeys(p, "/"); const fc = p.finder.column(p).?; try std.testing.expectEqual(@as(usize, 1), fc); - const first = p.col_panes[fc][0]; + const first = p.cols[fc].panes[0]; try std.testing.expect(p.panes[first].?.query != null); // the first search narrows the column once; its panes keep their rows try std.testing.expect(p.col_w[0] < width_before); @@ -218,7 +216,7 @@ test "SearchPlace column: query panes stack in a finder column at the right edge // a second search, from the other pane: on top, the first folded p.active = other; typeKeys(p, "/"); - const second = p.col_panes[fc][0]; + const second = p.cols[fc].panes[0]; try std.testing.expect(second != first); try std.testing.expect(p.panes[first].?.collapsed); layout.compute(p); diff --git a/src/Handover.zig b/src/Handover.zig index 2233d228..2d47bb4e 100644 --- a/src/Handover.zig +++ b/src/Handover.zig @@ -94,14 +94,14 @@ pub fn begin(h: *Handover, p: *Pardes, carried: Kind, at: usize) void { .pane => { const f = layout.findPane(p, at) orelse return; const end = if (layout.ownerOf(p, at) == null) layout.groupEnd(p, f.col, f.idx) else f.idx + 1; - for (p.col_panes[f.col][f.idx..end]) |id| { + for (p.cols[f.col].panes[f.idx..end]) |id| { ids[n] = id; n += 1; } }, .column => { - if (at >= p.ncol or p.col_n[at] == 0) return; - for (p.col_panes[at][0..p.col_n[at]]) |id| { + if (at >= p.ncol or p.cols[at].n == 0) return; + for (p.cols[at].panes[0..p.cols[at].n]) |id| { ids[n] = id; n += 1; } @@ -172,7 +172,7 @@ pub fn finish(h: *Handover, p: *Pardes, seq: u32, to: []const u8, failure: ?[]co }; } if (h.carried == .column) if (layout.columnBySerial(p, h.column_serial)) |c| { - if (p.col_n[c] == 0 and p.ncol > 1) layout.dropColumn(p, c); + if (p.cols[c].n == 0 and p.ncol > 1) layout.dropColumn(p, c); }; layout.compute(p); p.setMessage(p.active, if (kept == 0) @@ -293,18 +293,18 @@ pub fn adopt(p: *Pardes, bytes: []const u8) !usize { p.sync(); return slots[0]; } - for (0..p.ncol) |c| for (p.col_panes[c][0..p.col_n[c]]) |id| { + for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n]) |id| { heights[id] = p.rects[id].h; }; // The group under the pointer (a pane with what is attached to it): the // new panes go under all of it, out of its owner's rows. - var after: usize = p.col_n[tc]; + var after: usize = p.cols[tc].n; var root: ?usize = null; var k: usize = 0; - while (k < p.col_n[tc]) { + while (k < p.cols[tc].n) { const end = layout.groupEnd(p, tc, k); - const first = p.col_panes[tc][k]; - const last = p.col_panes[tc][end - 1]; + const first = p.cols[tc].panes[k]; + const last = p.cols[tc].panes[end - 1]; root = first; after = end; if (y < p.rects[last].y + p.rects[last].h) break; @@ -520,8 +520,8 @@ test "a grip let go past the window's edge dumps its pane alone, and closes it o const p = try twoPanes(std.testing.allocator); defer p.deinit(); const f = layout.findPane(p, 0).?; - try std.testing.expect(p.col_n[f.col] == 2); - const other = p.col_panes[f.col][1 - f.idx]; + try std.testing.expect(p.cols[f.col].n == 2); + const other = p.cols[f.col].panes[1 - f.idx]; const before = p.rects[other]; releaseOutside(p, 0); // Dumped and asked for; nothing moved yet. @@ -552,7 +552,7 @@ test "a grip let go past the window's edge dumps its pane alone, and closes it o // (Store.zig): Panes does not offer it back here. try std.testing.expect(p.store.closedBySerial(serial) == null); p.sync(); - try std.testing.expectEqual(@as(usize, 1), p.col_n[layout.findPane(p, other).?.col]); + try std.testing.expectEqual(@as(usize, 1), p.cols[layout.findPane(p, other).?.col].n); } test "a pane edited while it is on its way to another window stays here too" { @@ -569,7 +569,7 @@ test "a terminal's grip let go past the edge stays: its shell is this window's" const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30, .shells = 3 }); defer p.deinit(); p.update(.{ .resize = .{ .cols = 100, .rows = 30 } }); - const id = p.col_panes[1][0]; + const id = p.cols[1].panes[0]; try std.testing.expect(p.panes[id].?.isTerminal()); releaseOutside(p, id); try std.testing.expect(!p.handover.flying); @@ -587,8 +587,8 @@ test "a pane let go over another window goes under the pane the pointer is over, to.sync(); const before = to.rects; const c = layout.findPane(to, 0).?.col; - const upper = to.col_panes[c][0]; - const lower = to.col_panes[c][1]; + const upper = to.cols[c].panes[0]; + const lower = to.cols[c].panes[1]; // The pointer over the upper pane, six rows into it. to.pointer_inside = true; to.hover_col = to.rects[upper].x + 5; @@ -598,9 +598,9 @@ test "a pane let go over another window goes under the pane the pointer is over, const pane = to.panes[id].?; try std.testing.expectEqualStrings("unsaved alpha\nbeta\n", pane.file.?.content); try std.testing.expect(tagline.dirty(pane)); - try std.testing.expectEqual(upper, to.col_panes[c][0]); - try std.testing.expectEqual(id, to.col_panes[c][1]); - try std.testing.expectEqual(lower, to.col_panes[c][2]); + try std.testing.expectEqual(upper, to.cols[c].panes[0]); + try std.testing.expectEqual(id, to.cols[c].panes[1]); + try std.testing.expectEqual(lower, to.cols[c].panes[2]); // The pane under the pointer keeps its top and gives its rows below // the pointer; the new one is just there; every other pane is where it was. try std.testing.expectEqual(before[upper].y, to.rects[upper].y); @@ -639,12 +639,12 @@ test "a column let go over another window goes beside the column the pointer is to.sync(); try std.testing.expectEqual(ncol + 1, to.ncol); try std.testing.expectEqual(ncol, layout.findPane(to, id).?.col); - try std.testing.expectEqual(@as(usize, 2), to.col_n[ncol]); + try std.testing.expectEqual(@as(usize, 2), to.cols[ncol].n); for (0..ncol - 1) |k| { try std.testing.expectEqual(widths[k], to.col_w[k]); try std.testing.expectEqual(xs[k], to.col_x[k]); } // The finish here: both panes and their column gone from the window. from.update(.{ .handed = .{ .seq = from.handover.seq, .to = "pardes/2" } }); - try std.testing.expect(from.ncol == 1 or from.col_n[c] == 0 or layout.findPane(from, 0) == null); + try std.testing.expect(from.ncol == 1 or from.cols[c].n == 0 or layout.findPane(from, 0) == null); } diff --git a/src/Query.zig b/src/Query.zig index 3337a575..7347b21c 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -2175,7 +2175,7 @@ test "a / query: keystroke by keystroke, the owner shows the set, rows from its defer p.deinit(); const pane = try p.setTestFile("alpha one\nbeta\nalphabet\ngamma alpha\nalpha two\ndelta\n"); p.newScratchBelow(0); - const below = p.col_panes[0][1]; + const below = p.cols[0].panes[1]; p.active = 0; layout.compute(p); const before = p.rects; @@ -2340,7 +2340,7 @@ test "Find: names fuzzy per keystroke, the group born with its +Preview, nothing defer p.deinit(); _ = try testFileIn(p, &tmp, "x.txt", "x\n"); p.newScratchBelow(0); - const other = p.col_panes[0][1]; + const other = p.cols[0].panes[1]; try std.testing.expect(layout.splitColumn(p, other, other, false)); p.active = 0; layout.compute(p); diff --git a/src/builtins.zig b/src/builtins.zig index 8a2c2f5f..a12ddebe 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1762,9 +1762,9 @@ pub const Down = struct { // Onto the top pane of the column the header stands over. const col = c.p.header_column orelse if (column) |at| at.col else return; // An empty column's tag has nothing below it. - if (col < c.p.ncol and c.p.col_n[col] == 0) return; + if (col < c.p.ncol and c.p.cols[col].n == 0) return; tagline.exitHeader(c.p); - if (col < c.p.ncol) c.p.active = c.p.col_panes[col][0]; + if (col < c.p.ncol) c.p.active = c.p.cols[col].panes[0]; return; } _ = layout.focusDir(c.p, c.id, .down); diff --git a/src/draw.zig b/src/draw.zig index 136c57a8..e8276904 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -110,13 +110,13 @@ pub fn place(p: *Pardes, s: *Surface) void { if (p.col_w[c] == 0) continue; const active = if (layout.findPane(p, p.active)) |found| found.col == c else false; const inset = @min(TAG_TEXT_INSET, p.col_w[c]); - s.addRegion(.{ .kind = .column_grip, .owner = @intCast(c), .serial = p.col_serial[c], .active = active, .rect = .{ .x = p.col_x[c], .y = p.topBarHeight(), .w = @min(config.GUTTER, p.col_w[c]), .h = column_rows } }); - s.addRegion(.{ .kind = .column_tag, .owner = @intCast(c), .serial = p.col_serial[c], .active = active, .rect = .{ .x = p.col_x[c] + inset, .y = p.topBarHeight(), .w = p.col_w[c] - inset, .h = column_rows } }); + s.addRegion(.{ .kind = .column_grip, .owner = @intCast(c), .serial = p.cols[c].serial, .active = active, .rect = .{ .x = p.col_x[c], .y = p.topBarHeight(), .w = @min(config.GUTTER, p.col_w[c]), .h = column_rows } }); + s.addRegion(.{ .kind = .column_tag, .owner = @intCast(c), .serial = p.cols[c].serial, .active = active, .rect = .{ .x = p.col_x[c] + inset, .y = p.topBarHeight(), .w = p.col_w[c] - inset, .h = column_rows } }); }; const active_col = if (layout.findPane(p, p.active)) |found| found.col else null; for (0..p.ncol) |c| { if (p.col_w[c] == 0) continue; - s.addRegion(.{ .kind = .column, .owner = @intCast(c), .serial = p.col_serial[c], .active = active_col == c, .rect = .{ .x = p.col_x[c], .y = p.topBarHeight(), .w = p.col_w[c], .h = s.rows -| p.topBarHeight() } }); + s.addRegion(.{ .kind = .column, .owner = @intCast(c), .serial = p.cols[c].serial, .active = active_col == c, .rect = .{ .x = p.col_x[c], .y = p.topBarHeight(), .w = p.col_w[c], .h = s.rows -| p.topBarHeight() } }); } if (p.settings.workspace_tag) s.addRegion(.{ .kind = .workspace_tag, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = p.topBarHeight() } }); @@ -221,7 +221,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { // Separators have their own role; a scrollbar need not frame the page. const whole = s.regions[0].rect; s.fill(whole.x, whole.y, whole.w, whole.h, .{ .bg = .{ .rgb = chrome.border } }); - for (0..p.ncol) |c| if (p.col_n[c] == 0) s.fill(p.col_x[c], p.topBarHeight() + layout.columnBarHeight(p), p.col_w[c], s.rows -| (p.topBarHeight() + layout.columnBarHeight(p)), .{ .bg = .{ .rgb = chrome.empty_col } }); + for (0..p.ncol) |c| if (p.cols[c].n == 0) s.fill(p.col_x[c], p.topBarHeight() + layout.columnBarHeight(p), p.col_w[c], s.rows -| (p.topBarHeight() + layout.columnBarHeight(p)), .{ .bg = .{ .rgb = chrome.empty_col } }); for (&p.panes, 0..) |*slot, id| { const pane = slot.* orelse continue; @@ -587,7 +587,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v if (layer.cells.len != count) layer.cells = try p.gpa.realloc(layer.cells, count); layer.kind = kind; layer.id = id; - layer.serial = if (kind == .column) p.col_serial[id] else 0; + layer.serial = if (kind == .column) p.cols[id].serial else 0; layer.viewport = viewport; layer.cols = columns; layer.rows = viewport.h; diff --git a/src/dump.zig b/src/dump.zig index facd9b9a..55be8d58 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -432,11 +432,11 @@ fn ensureKind(p: *Pardes, pane: *pardes.panes.Pane) !void { fn dropMissing(p: *Pardes) void { for (0..p.ncol) |c| { var n: usize = 0; - for (p.col_panes[c][0..p.col_n[c]]) |id| if (id < MAX_PANES and p.panes[id] != null) { - p.col_panes[c][n] = id; + for (p.cols[c].panes[0..p.cols[c].n]) |id| if (id < MAX_PANES and p.panes[id] != null) { + p.cols[c].panes[n] = id; n += 1; }; - p.col_n[c] = n; + p.cols[c].n = n; } if (p.active >= MAX_PANES or p.panes[p.active] == null) p.active = for (p.panes, 0..) |slot, i| { if (slot != null) break i; diff --git a/src/exec.zig b/src/exec.zig index 11d003b5..63bb4c1c 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -1134,12 +1134,12 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan // (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 (p.col_panes[f.col][0..p.col_n[f.col]]) |k| p.rects[k] = before[k]; + for (p.cols[f.col].panes[0..p.cols[f.col].n]) |k| p.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 (p.col_panes[f.col][0..p.col_n[f.col]]) |k| p.rects[k] = before[k]; + for (p.cols[f.col].panes[0..p.cols[f.col].n]) |k| p.rects[k] = before[k]; layout.snapColWeights(p, f.col); } // No pane to halve, but the column has the rows for the new @@ -1157,16 +1157,16 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan while (c > 0) { c -= 1; if (c == f.col or c == finder_column) continue; - for (p.col_panes[c][0..p.col_n[c]]) |k| p.rects[k] = before[k]; + for (p.cols[c].panes[0..p.cols[c].n]) |k| p.rects[k] = before[k]; layout.snapColWeights(p, c); - if (p.col_n[c] == 0) { + if (p.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, p.col_n[f.col], id); + layout.insert(p, f.col, p.cols[f.col].n, id); p.unplaced.set(id); // Refused holding no weight: its column's rows come // back as they were. @@ -1176,7 +1176,7 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan return; } } else { - layout.insert(p, f.col, p.col_n[f.col], id); + layout.insert(p, f.col, p.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; diff --git a/src/gui/gui.zig b/src/gui/gui.zig index c148c3fc..cf35a5fa 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -8019,7 +8019,7 @@ test "an empty column is ruled on both sides, as between two filled ones" { pardes.layout.newColumn(core, 0); core.sync(); try std.testing.expectEqual(@as(usize, 3), core.ncol); - try std.testing.expectEqual(@as(usize, 0), core.col_n[1]); + try std.testing.expectEqual(@as(usize, 0), core.cols[1].n); const s = try core.render(core.scratch.allocator()); var g = testGui(10, 20, 6, 12); defer g.decor.deinit(gpa); diff --git a/src/keys.zig b/src/keys.zig index 9910e2f6..60e6fa0f 100644 --- a/src/keys.zig +++ b/src/keys.zig @@ -271,7 +271,7 @@ pub fn handleKey(p: *Pardes, key: Key) void { if (hit(key, config.pane_to_new_column)) { tagline.exitHeader(p); const f = layout.findPane(p, p.active).?; - if (p.ncol < MAX_COLS and p.col_n[f.col] > 1) { + if (p.ncol < MAX_COLS and p.cols[f.col].n > 1) { _ = layout.splitColumn(p, p.active, p.active, false); } return; diff --git a/src/layout.zig b/src/layout.zig index bcee3fba..aec8587c 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -81,7 +81,7 @@ pub const window_labels = "asfgqwertyuiopzxvbnm"; /// The letter window mode shows on pane `id`. pub fn windowLabel(p: *const Pardes, id: usize) ?u8 { var n: usize = 0; - for (0..p.ncol) |c| for (p.col_panes[c][0..p.col_n[c]]) |pane| { + for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n]) |pane| { if (n == window_labels.len) return null; if (pane == id) return window_labels[n]; n += 1; @@ -140,17 +140,17 @@ pub fn windowKey(p: *Pardes, key: pardes.Key) void { /// Column `c`'s serial, handed out the first time it is asked for. pub fn columnSerial(p: *Pardes, c: usize) u32 { - if (p.col_serial[c] == 0) { - p.col_serial[c] = p.next_column_serial; + if (p.cols[c].serial == 0) { + p.cols[c].serial = p.next_column_serial; p.next_column_serial +%= 1; if (p.next_column_serial == 0) p.next_column_serial = 1; } - return p.col_serial[c]; + return p.cols[c].serial; } pub fn columnBySerial(p: *const Pardes, serial: u32) ?usize { if (serial == 0) return null; - for (0..p.ncol) |column| if (p.col_serial[column] == serial) return column; + for (0..p.ncol) |column| if (p.cols[column].serial == serial) return column; return null; } @@ -190,36 +190,27 @@ pub fn setColumnPairWidth(p: *Pardes, left: usize, left_width: u64) void { // Too narrow for both to keep MINW: any split would squeeze one away. if (combined < 2 * @as(u64, config.MINW)) return; const width = std.math.clamp(left_width, config.MINW, @max(@as(u64, config.MINW), combined -| config.MINW)); - const pair = p.col_weight[left] + p.col_weight[left + 1]; + const pair = p.cols[left].weight + p.cols[left + 1].weight; if (pair <= 1 or combined == 0) return; const numerator = @as(u128, pair) * width + combined / 2; const share = std.math.clamp(@as(u64, @intCast(numerator / combined)), 1, pair - 1); - p.col_weight[left] = share; - p.col_weight[left + 1] = pair - share; + p.cols[left].weight = share; + p.cols[left + 1].weight = pair - share; } pub fn reorderColumn(p: *Pardes, from: usize, to: usize) void { if (from >= p.ncol or to >= p.ncol or from == to) return; - const ids = p.col_panes[from]; - const count = p.col_n[from]; - const weight = p.col_weight[from]; + const moved = p.cols[from]; const tag = p.col_tags[from]; - const serial = p.col_serial[from]; var at = from; while (at != to) { const next = if (at < to) at + 1 else at - 1; - p.col_panes[at] = p.col_panes[next]; - p.col_n[at] = p.col_n[next]; - p.col_weight[at] = p.col_weight[next]; + p.cols[at] = p.cols[next]; p.col_tags[at] = p.col_tags[next]; - p.col_serial[at] = p.col_serial[next]; at = next; } - p.col_panes[to] = ids; - p.col_n[to] = count; - p.col_weight[to] = weight; + p.cols[to] = moved; p.col_tags[to] = tag; - p.col_serial[to] = serial; if (p.header_column) |column| { if (column == from) p.header_column = to else if (from < to and column > from and column <= to) { p.header_column = column - 1; @@ -264,9 +255,9 @@ pub fn movePlacement(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) ?MovePlaceme const span_end = if (ownerOf(p, id) == null) groupEnd(p, src.col, src.idx) else src.idx + 1; const own_root = groupRoot(p, id); const tc = targetColumn(p, cur_x); - if (tc == src.col and p.col_n[src.col] == span_end - src.idx) return null; + if (tc == src.col and p.cols[src.col].n == span_end - src.idx) return null; var span_h: u16 = 0; - for (p.col_panes[src.col][src.idx..span_end]) |k| span_h +|= p.rects[k].h; + for (p.cols[src.col].panes[src.idx..span_end]) |k| span_h +|= p.rects[k].h; if (tc == src.col) { const top = p.rects[id].y; // Dropped on itself it stays, unless dragged down from its top with @@ -278,28 +269,28 @@ pub fn movePlacement(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) ?MovePlaceme // Every pane's rows as laid out; only the placed panes' are read. var heights: [MAX_PANES]u16 = undefined; for (&heights, p.rects) |*h, r| h.* = r.h; - if (p.col_n[src.col] > span_end - src.idx) { - const sib = if (src.idx > 0) p.col_panes[src.col][src.idx - 1] else p.col_panes[src.col][span_end]; + if (p.cols[src.col].n > span_end - src.idx) { + const sib = if (src.idx > 0) p.cols[src.col].panes[src.idx - 1] else p.cols[src.col].panes[span_end]; heights[sib] +|= span_h; } var y: u16 = p.topBarHeight() + columnBarHeight(p); - if (p.col_n[tc] == 0) return .{ .preview_col = tc, .above_id = null, .row = y, .above_y = y, .above_h = 0 }; + if (p.cols[tc].n == 0) return .{ .preview_col = tc, .above_id = null, .row = y, .above_y = y, .above_h = 0 }; var last: ?MovePlacement = null; var k: usize = 0; - while (k < p.col_n[tc]) { + while (k < p.cols[tc].n) { if (tc == src.col and k >= src.idx and k < span_end) { k += 1; continue; } // Its own group's panes are places of their own: that is how an // attachment's grip resizes it against its owner. - const unit_end = if (groupRoot(p, p.col_panes[tc][k]) == own_root) k + 1 else groupEnd(p, tc, k); + const unit_end = if (groupRoot(p, p.cols[tc].panes[k]) == own_root) k + 1 else groupEnd(p, tc, k); var h: u16 = 0; for (k..unit_end) |j| { if (tc == src.col and j >= src.idx and j < span_end) continue; - h +|= heights[p.col_panes[tc][j]]; + h +|= heights[p.cols[tc].panes[j]]; } - const above = p.col_panes[tc][unit_end - 1]; + const above = p.cols[tc].panes[unit_end - 1]; k = unit_end; const row = splitRowFor(y, h, cur_y, if (tc == src.col) BOX_H else null) orelse { y +|= h; @@ -329,15 +320,15 @@ pub fn movePane(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) void { const span_end = if (owner == null) groupEnd(p, src.col, src.idx) else src.idx + 1; const count = span_end - src.idx; var moved: [MAX_PANES]usize = undefined; - @memcpy(moved[0..count], p.col_panes[src.col][src.idx..span_end]); - const source_multi = p.col_n[src.col] > count; + @memcpy(moved[0..count], p.cols[src.col].panes[src.idx..span_end]); + const source_multi = p.cols[src.col].n > count; var heights: [MAX_PANES]u16 = undefined; for (&heights, p.rects) |*h, r| h.* = r.h; var span_h: u16 = 0; for (moved[0..count]) |m| span_h +|= heights[m]; for (moved[0..count]) |m| removePane(p, m); if (source_multi) { - const sib = if (src.idx > 0) p.col_panes[src.col][src.idx - 1] else p.col_panes[src.col][src.idx]; + const sib = if (src.idx > 0) p.cols[src.col].panes[src.idx - 1] else p.cols[src.col].panes[src.idx]; heights[sib] +|= span_h; } const above = placement.above_id orelse { @@ -378,8 +369,8 @@ pub fn movePane(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) void { pub fn setColumnWeights(p: *Pardes, col: usize, heights: *const [MAX_PANES]u16) void { if (col >= p.ncol) return; - for (0..p.col_n[col]) |k| { - const pid = p.col_panes[col][k]; + for (0..p.cols[col].n) |k| { + const pid = p.cols[col].panes[k]; if (p.panes[pid]) |pane| if (!pane.collapsed) { pane.vweight = @floatFromInt(@max(1, heights[pid])); }; @@ -392,9 +383,9 @@ pub fn givePaneRows(p: *Pardes, id: usize, wanted: u16, context: usize) void { const at = findPane(p, id) orelse return; compute(p); var heights: [MAX_PANES]u16 = @splat(0); - for (p.col_panes[at.col][0..p.col_n[at.col]]) |other| heights[other] = p.rects[other].h; + for (p.cols[at.col].panes[0..p.cols[at.col].n]) |other| heights[other] = p.rects[other].h; var missing = wanted -| heights[id]; - for (p.col_panes[at.col][0..p.col_n[at.col]]) |other| { + for (p.cols[at.col].panes[0..p.cols[at.col].n]) |other| { if (other == id or p.panes[other].?.collapsed) continue; const body_rows: u16 = if (other == context) 6 else 3; const minimum = @max(minRows(p, other), p.panes[other].?.tag_rows + body_rows); @@ -409,17 +400,17 @@ pub fn givePaneRows(p: *Pardes, id: usize, wanted: u16, context: usize) void { } pub fn applyRowSplit(p: *Pardes, cc: usize, k: usize, cur_y: u16) void { - if (k + 1 >= p.col_n[cc]) return; - const a = p.panes[p.col_panes[cc][k]] orelse return; - const b = p.panes[p.col_panes[cc][k + 1]] orelse return; - const ra = p.rects[p.col_panes[cc][k]]; - const rb = p.rects[p.col_panes[cc][k + 1]]; + if (k + 1 >= p.cols[cc].n) return; + const a = p.panes[p.cols[cc].panes[k]] orelse return; + const b = p.panes[p.cols[cc].panes[k + 1]] orelse return; + const ra = p.rects[p.cols[cc].panes[k]]; + const rb = p.rects[p.cols[cc].panes[k + 1]]; const combined: f32 = @floatFromInt(ra.h + rb.h); var nt: f32 = @floatFromInt(if (p.settings.tag_bottom) cur_y -| ra.y else (cur_y + 1) -| ra.y); // A terminal keeps its tag and two body rows (floorRows); a text pane // gives up all but its tag, as acme's do. - const lo: f32 = @floatFromInt(@max(BOX_H, floorRows(p, p.col_panes[cc][k]))); - const hi = combined - @as(f32, @floatFromInt(@max(BOX_H, floorRows(p, p.col_panes[cc][k + 1])))); + const lo: f32 = @floatFromInt(@max(BOX_H, floorRows(p, p.cols[cc].panes[k]))); + const hi = combined - @as(f32, @floatFromInt(@max(BOX_H, floorRows(p, p.cols[cc].panes[k + 1])))); nt = std.math.clamp(nt, @min(lo, @max(@as(f32, BOX_H), hi)), @max(@as(f32, BOX_H), hi)); if (combined <= 0) return; // Dragging a folded tag open is an explicit resize, so switch this pair @@ -439,18 +430,18 @@ pub fn applyRowSplit(p: *Pardes, cc: usize, k: usize, cur_y: u16) void { pub fn findPane(p: *const Pardes, id: usize) ?struct { col: usize, idx: usize } { for (0..p.ncol) |c| { - for (0..p.col_n[c]) |k| { - if (p.col_panes[c][k] == id) return .{ .col = c, .idx = k }; + for (0..p.cols[c].n) |k| { + if (p.cols[c].panes[k] == id) return .{ .col = c, .idx = k }; } } return null; } pub fn insert(p: *Pardes, c: usize, idx: usize, id: usize) void { - var k = p.col_n[c]; - while (k > idx) : (k -= 1) p.col_panes[c][k] = p.col_panes[c][k - 1]; - p.col_panes[c][idx] = id; - p.col_n[c] += 1; + var k = p.cols[c].n; + while (k > idx) : (k -= 1) p.cols[c].panes[k] = p.cols[c].panes[k - 1]; + p.cols[c].panes[idx] = id; + p.cols[c].n += 1; } /// Take a pane out of its column. The column stays, empty if this was its @@ -460,8 +451,8 @@ pub fn removePane(p: *Pardes, id: usize) void { const f = findPane(p, id) orelse return; const c = f.col; var k = f.idx; - while (k + 1 < p.col_n[c]) : (k += 1) p.col_panes[c][k] = p.col_panes[c][k + 1]; - p.col_n[c] -= 1; + while (k + 1 < p.cols[c].n) : (k += 1) p.cols[c].panes[k] = p.cols[c].panes[k + 1]; + p.cols[c].n -= 1; } /// Close column `c` once its panes are gone, its width to the one left of @@ -474,26 +465,23 @@ pub fn dropColumn(p: *Pardes, c: usize) void { /// dropColumn with no `delcol`, for a column never announced. pub fn dropColumnUnannounced(p: *Pardes, c: usize) void { - std.debug.assert(p.col_n[c] == 0); + std.debug.assert(p.cols[c].n == 0); tagline.exitHeader(p); // The finder's width was its share, no weight: nobody gets one, so the // others are as wide as before it came. A column whose weight would go // to the finder gives it to the column on the finder's other side. const finder = p.finder.column(p); const heir: ?usize = if (p.ncol <= 1 or finder == c) null else if (c > 0 and finder != c - 1) c - 1 else if (c + 1 < p.ncol and finder != c + 1) c + 1 else if (c > 1) c - 2 else if (c + 2 < p.ncol) c + 2 else null; - if (heir) |h| p.col_weight[h] +|= p.col_weight[c]; + if (heir) |h| p.cols[h].weight +|= p.cols[c].weight; p.col_tags[c].deinit(p.gpa); var j = c; while (j + 1 < p.ncol) : (j += 1) { - p.col_panes[j] = p.col_panes[j + 1]; - p.col_n[j] = p.col_n[j + 1]; - p.col_weight[j] = p.col_weight[j + 1]; + p.cols[j] = p.cols[j + 1]; p.col_tags[j] = p.col_tags[j + 1]; - p.col_serial[j] = p.col_serial[j + 1]; } p.ncol -= 1; p.col_tags[p.ncol] = .{ .what = .column, .gpa = p.gpa }; - p.col_serial[p.ncol] = 0; + p.cols[p.ncol].serial = 0; } /// `newcol <serial>` or `delcol <serial>` in the log: the column's serial, @@ -517,28 +505,22 @@ pub fn joinCol(p: *Pardes, c: usize) void { pub fn joinFits(p: *Pardes, c: usize) bool { if (c + 1 >= p.ncol) return true; const dst = c + 1; - const n = p.col_n[c]; - const had = p.col_n[dst]; - const weights = .{ p.col_weight[c], p.col_weight[dst] }; - const panes_c = p.col_panes[c]; + const kept = .{ p.cols[c], p.cols[dst] }; joinPanes(p, c, dst); const fits = minimaFit(p); - p.col_n[dst] = had; - p.col_n[c] = n; - p.col_panes[c] = panes_c; - p.col_weight[c] = weights[0]; - p.col_weight[dst] = weights[1]; + p.cols[c] = kept[0]; + p.cols[dst] = kept[1]; compute(p); return fits; } fn joinPanes(p: *Pardes, c: usize, dst: usize) void { - for (0..p.col_n[c]) |k| p.col_panes[dst][p.col_n[dst] + k] = p.col_panes[c][k]; - p.col_n[dst] += p.col_n[c]; - p.col_n[c] = 0; + for (0..p.cols[c].n) |k| p.cols[dst].panes[p.cols[dst].n + k] = p.cols[c].panes[k]; + p.cols[dst].n += p.cols[c].n; + p.cols[c].n = 0; // The width goes right, where the panes went. - p.col_weight[dst] +|= p.col_weight[c]; - p.col_weight[c] = 0; + p.cols[dst].weight +|= p.cols[c].weight; + p.cols[c].weight = 0; } /// Put new pane `id` in column `c` as acme's makenewwindow does @@ -550,7 +532,7 @@ fn joinPanes(p: *Pardes, c: usize, dst: usize) void { /// that is in the column and not much smaller. pub fn acmePlace(p: *Pardes, c: usize, origin: ?usize, id: usize) void { compute(p); - const n = p.col_n[c]; + const n = p.cols[c].n; if (n == 0) { insert(p, c, 0, id); p.panes[id].?.vweight = 1; @@ -558,7 +540,7 @@ pub fn acmePlace(p: *Pardes, c: usize, origin: ?usize, id: usize) void { } var big: ?usize = null; var empty: ?usize = null; - for (p.col_panes[c][0..n]) |k| { + for (p.cols[c].panes[0..n]) |k| { const pane = p.panes[k] orelse continue; // An attachment is its owner's: never halved for another pane. if (pane.collapsed or ownerOf(p, k) != null) continue; @@ -574,7 +556,7 @@ pub fn acmePlace(p: *Pardes, c: usize, origin: ?usize, id: usize) void { const y: u16 = y: { const o = origin orelse { var last = v0; - for (p.col_panes[c][0..n]) |k| if (!p.panes[k].?.collapsed and ownerOf(p, k) == null) { + for (p.cols[c].panes[0..n]) |k| if (!p.panes[k].?.collapsed and ownerOf(p, k) == null) { last = k; }; break :y bodyFrom(p, last) + bodyRows(p, last) / 2; @@ -610,9 +592,9 @@ pub fn minimaFit(p: *Pardes) bool { compute(p); const avail = p.screen_h -| (p.topBarHeight() + columnBarHeight(p)); for (0..p.ncol) |c| { - if (p.col_n[c] < 2) continue; + if (p.cols[c].n < 2) continue; var need: u32 = 0; - for (p.col_panes[c][0..p.col_n[c]]) |k| { + for (p.cols[c].panes[0..p.cols[c].n]) |k| { const pane = p.panes[k] orelse continue; need += if (pane.collapsed) BOX_H else minRows(p, k); } @@ -625,8 +607,8 @@ pub fn minimaFit(p: *Pardes) bool { /// alone in its column always does). pub fn columnAtMinimums(p: *Pardes, c: usize) bool { compute(p); - if (p.col_n[c] < 2) return true; - for (p.col_panes[c][0..p.col_n[c]]) |k| { + if (p.cols[c].n < 2) return true; + for (p.cols[c].panes[0..p.cols[c].n]) |k| { const pane = p.panes[k] orelse continue; if (!pane.collapsed and p.rects[k].h < minRows(p, k)) return false; } @@ -638,12 +620,12 @@ pub fn columnAtMinimums(p: *Pardes, c: usize) bool { /// column has not the rows for all of them (or holds a folded pane). pub fn shareColumn(p: *Pardes, c: usize) bool { compute(p); - const n = p.col_n[c]; + const n = p.cols[c].n; if (n == 0) return false; const avail = p.screen_h -| (p.topBarHeight() + columnBarHeight(p)); var mins: [MAX_PANES]u16 = undefined; var need: u32 = 0; - for (p.col_panes[c][0..n], 0..) |k, i| { + for (p.cols[c].panes[0..n], 0..) |k, i| { const pane = p.panes[k] orelse return false; if (pane.collapsed) return false; p.rects[k].w = p.col_w[c]; @@ -662,7 +644,7 @@ pub fn shareColumn(p: *Pardes, c: usize) bool { }; hs[low] += 1; } - for (p.col_panes[c][0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(hs[i]); + for (p.cols[c].panes[0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(hs[i]); compute(p); return true; } @@ -672,7 +654,7 @@ pub fn shareColumn(p: *Pardes, c: usize) bool { pub fn minima(p: *Pardes) [MAX_PANES]u16 { compute(p); var mins: [MAX_PANES]u16 = @splat(0); - for (0..p.ncol) |c| for (p.col_panes[c][0..p.col_n[c]]) |k| { + for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n]) |k| { mins[k] = minRows(p, k); }; return mins; @@ -687,12 +669,12 @@ pub fn minima(p: *Pardes) [MAX_PANES]u16 { pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min: ?*const [MAX_PANES]u16) void { compute(p); for (0..p.ncol) |c| { - const n = p.col_n[c]; + const n = p.cols[c].n; if (n < 2) continue; var hs: [MAX_PANES]u16 = undefined; var mins: [MAX_PANES]u16 = undefined; var short = false; - for (p.col_panes[c][0..n], 0..) |k, i| { + for (p.cols[c].panes[0..n], 0..) |k, i| { const pane = p.panes[k] orelse return; if (pane.collapsed) break; hs[i] = p.rects[k].h; @@ -700,7 +682,7 @@ pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min: if (hs[i] < mins[i] and before[k].h >= if (before_min) |bm| bm[k] else mins[i]) short = true; } else { if (!short) continue; - for (p.col_panes[c][0..n], 0..) |k, i| { + for (p.cols[c].panes[0..n], 0..) |k, i| { if (hs[i] >= mins[i] or before[k].h < if (before_min) |bm| bm[k] else mins[i]) continue; while (hs[i] < mins[i]) { var giver: ?usize = null; @@ -714,7 +696,7 @@ pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min: hs[i] += 1; } } - for (p.col_panes[c][0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i])); + for (p.cols[c].panes[0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i])); } } compute(p); @@ -731,8 +713,8 @@ pub fn keepColumn(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_m restoreMinimaFrom(p, before, before_min); for (0..p.ncol) |k| { compute(p); - if (p.col_n[k] < 2) continue; - const squeezed = for (p.col_panes[k][0..p.col_n[k]]) |id| { + if (p.cols[k].n < 2) continue; + const squeezed = for (p.cols[k].panes[0..p.cols[k].n]) |id| { const pane = p.panes[id] orelse continue; if (!pane.collapsed and p.rects[id].h < minRows(p, id) and before[id].h >= before_min[id]) break true; } else false; @@ -750,13 +732,13 @@ pub fn keepColumn(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_m /// False, changing nothing, when the column has not the rows. pub fn takeRoom(p: *Pardes, c: usize, id: usize) bool { compute(p); - const n = p.col_n[c]; + const n = p.cols[c].n; p.rects[id].w = p.col_w[c]; var need = minRows(p, id); var hs: [MAX_PANES]u16 = undefined; var mins: [MAX_PANES]u16 = undefined; var spare: u32 = 0; - for (p.col_panes[c][0..n], 0..) |k, i| { + for (p.cols[c].panes[0..n], 0..) |k, i| { const pane = p.panes[k] orelse return false; if (pane.collapsed) return false; hs[i] = p.rects[k].h; @@ -771,7 +753,7 @@ pub fn takeRoom(p: *Pardes, c: usize, id: usize) bool { }; hs[giver] -= 1; } - for (p.col_panes[c][0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i])); + for (p.cols[c].panes[0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i])); insert(p, c, n, id); p.panes[id].?.vweight = @floatFromInt(minRows(p, id)); compute(p); @@ -785,8 +767,8 @@ pub fn takeRoom(p: *Pardes, c: usize, id: usize) bool { pub fn placedRoomy(p: *Pardes, id: usize, before: *const [MAX_PANES]Rect) bool { compute(p); const f = findPane(p, id) orelse return true; - if (p.col_n[f.col] == 1) return true; - for (p.col_panes[f.col][0..p.col_n[f.col]]) |k| { + if (p.cols[f.col].n == 1) return true; + for (p.cols[f.col].panes[0..p.cols[f.col].n]) |k| { const pane = p.panes[k] orelse continue; if (pane.collapsed) continue; if (k != id and p.rects[k].h >= before[k].h) continue; @@ -801,7 +783,7 @@ pub fn placedRoomy(p: *Pardes, id: usize, before: *const [MAX_PANES]Rect) bool { pub fn splitTallest(p: *Pardes, c: usize, id: usize) bool { compute(p); var tall: ?usize = null; - for (p.col_panes[c][0..p.col_n[c]]) |k| { + for (p.cols[c].panes[0..p.cols[c].n]) |k| { if (k == id or p.panes[k].?.collapsed or ownerOf(p, k) != null) continue; if (tall == null or p.rects[k].h > p.rects[tall.?].h) tall = k; } @@ -811,7 +793,7 @@ pub fn splitTallest(p: *Pardes, c: usize, id: usize) bool { p.rects[id].w = p.col_w[c]; if (h < minRows(p, v) + minRows(p, id)) return false; snapColWeights(p, c); - insert(p, c, p.col_n[c], id); + insert(p, c, p.cols[c].n, id); const given = std.math.clamp(h / 2, minRows(p, id), h - minRows(p, v)); p.panes[v].?.vweight = @floatFromInt(h - given); p.panes[id].?.vweight = @floatFromInt(given); @@ -824,10 +806,10 @@ pub fn splitTallest(p: *Pardes, c: usize, id: usize) bool { /// `y` in a group: the new pane goes under all of it, its rows from the /// group's owner, so nothing lands between a pane and its results. fn splitAt(p: *Pardes, c: usize, id: usize, y: u16) void { - const n = p.col_n[c]; + const n = p.cols[c].n; var k: usize = 0; - while (k + 1 < n and y >= p.rects[p.col_panes[c][k]].y + p.rects[p.col_panes[c][k]].h) k += 1; - const v = groupRoot(p, p.col_panes[c][k]); + while (k + 1 < n and y >= p.rects[p.cols[c].panes[k]].y + p.rects[p.cols[c].panes[k]].h) k += 1; + const v = groupRoot(p, p.cols[c].panes[k]); const r = p.rects[v]; snapColWeights(p, c); insert(p, c, groupEnd(p, c, k), id); @@ -880,9 +862,9 @@ pub fn canSplitCol(p: *Pardes, col: usize) bool { compute(p); if (p.col_w[col] < config.MINW * 2) return false; - const weight = p.col_weight[col]; + const weight = p.cols[col].weight; if (weight >= 2 and weight % 2 == 0) return true; - for (0..p.ncol) |column| if (p.col_weight[column] > std.math.maxInt(u64) / 2) + for (0..p.ncol) |column| if (p.cols[column].weight > std.math.maxInt(u64) / 2) return false; return weight > 0; } @@ -893,10 +875,8 @@ pub fn canSplitCol(p: *Pardes, col: usize) bool { /// its first one, empty; null when it has columns. pub fn firstColumn(p: *Pardes) ?usize { if (p.ncol != 0) return null; - p.col_weight[0] = 2; + p.cols[0] = .{ .weight = 2 }; p.col_tags[0] = .{ .what = .column, .gpa = p.gpa }; - p.col_serial[0] = 0; - p.col_n[0] = 0; p.ncol = 1; noteColumn(p, "newcol", columnSerial(p, 0)); return 0; @@ -912,27 +892,22 @@ pub fn insertColumn(p: *Pardes, col: usize, before: bool) ?usize { /// yet be taken back (Newcol's trial), which then leaves no trace. pub fn insertColumnUnannounced(p: *Pardes, col: usize, before: bool) ?usize { if (!canSplitCol(p, col)) return null; - var old_weight = p.col_weight[col]; + var old_weight = p.cols[col].weight; if (old_weight < 2 or old_weight % 2 != 0) { old_weight *= 2; - for (0..p.ncol) |column| p.col_weight[column] *= 2; + for (0..p.ncol) |column| p.cols[column].weight *= 2; } const source_weight = old_weight / 2; - p.col_weight[col] = source_weight; + p.cols[col].weight = source_weight; const c = col + @intFromBool(!before); tagline.exitHeader(p); var j = p.ncol; while (j > c) : (j -= 1) { - p.col_panes[j] = p.col_panes[j - 1]; - p.col_n[j] = p.col_n[j - 1]; - p.col_weight[j] = p.col_weight[j - 1]; + p.cols[j] = p.cols[j - 1]; p.col_tags[j] = p.col_tags[j - 1]; - p.col_serial[j] = p.col_serial[j - 1]; } - p.col_weight[c] = old_weight - source_weight; + p.cols[c] = .{ .weight = old_weight - source_weight }; p.col_tags[c] = .{ .what = .column, .gpa = p.gpa }; - p.col_serial[c] = 0; - p.col_n[c] = 0; p.ncol += 1; return c; } @@ -945,7 +920,7 @@ pub fn splitColumn(p: *Pardes, source_id: usize, id: usize, before: bool) bool { const source = findPane(p, source_id) orelse return false; if (!canSplitCol(p, source.col)) return false; if (id == source_id) { - if (p.col_n[source.col] <= 1) return false; + if (p.cols[source.col].n <= 1) return false; _ = absorbVWeight(p, id, null); removePane(p, id); } else if (findPane(p, id) != null) return false; @@ -955,8 +930,8 @@ pub fn splitColumn(p: *Pardes, source_id: usize, id: usize, before: bool) bool { } pub fn snapColWeights(p: *Pardes, c: usize) void { - for (0..p.col_n[c]) |k| { - const pid = p.col_panes[c][k]; + for (0..p.cols[c].n) |k| { + const pid = p.cols[c].panes[k]; if (p.panes[pid]) |pp| if (!pp.collapsed) { pp.vweight = @floatFromInt(@max(1, p.rects[pid].h)); }; @@ -970,15 +945,15 @@ pub fn snapColWeights(p: *Pardes, c: usize) void { /// (the pane below for the top one); the pane that got them is returned. pub fn absorbVWeight(p: *Pardes, id: usize, to: ?usize) ?usize { const f = findPane(p, id) orelse return null; - if (p.col_n[f.col] <= 1) return null; + if (p.cols[f.col].n <= 1) return null; // A refused pane held no weight: the rows the others' rounding lent it // go back to them as they were, nobody's weight snapped. if (p.panes[id]) |pane| if (!pane.collapsed and pane.vweight == 0) return null; snapColWeights(p, f.col); - var sib = to orelse if (f.idx > 0) p.col_panes[f.col][f.idx - 1] else p.col_panes[f.col][f.idx + 1]; + var sib = to orelse if (f.idx > 0) p.cols[f.col].panes[f.idx - 1] else p.cols[f.col].panes[f.idx + 1]; var k = f.idx; while (to == null and k > 0) : (k -= 1) { - sib = p.col_panes[f.col][k - 1]; + sib = p.cols[f.col].panes[k - 1]; // nor to a pane attached to another: rows go to owners if (p.panes[sib]) |pp| if (if (pp.file) |ff| panes.Output.fileTraits(ff.output).doc else true) if (ownerOf(p, sib) == null) break; } @@ -1055,9 +1030,9 @@ fn descends(p: *const Pardes, id: usize, root: usize) bool { /// One past the last pane of the group that pane `idx` of column `c` is /// in: `idx + 1` for a pane with nothing attached. pub fn groupEnd(p: *const Pardes, c: usize, idx: usize) usize { - const root = groupRoot(p, p.col_panes[c][idx]); + const root = groupRoot(p, p.cols[c].panes[idx]); var k = idx + 1; - while (k < p.col_n[c] and descends(p, p.col_panes[c][k], root) and p.col_panes[c][k] != root) k += 1; + while (k < p.cols[c].n and descends(p, p.cols[c].panes[k], root) and p.cols[c].panes[k] != root) k += 1; return k; } @@ -1068,10 +1043,10 @@ pub fn groupEnd(p: *const Pardes, c: usize, idx: usize) usize { /// it stands. Nothing moves. Top to bottom, so a nested attachment is /// judged after the one it hangs from. pub fn keepGroups(p: *Pardes) void { - for (0..p.ncol) |c| for (p.col_panes[c][0..p.col_n[c]], 0..) |id, k| { + for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n], 0..) |id, k| { const pane = p.panes[id] orelse continue; if (pane.attached_to == null) continue; - const kept = if (ownerOf(p, id)) |owner| k > 0 and descends(p, p.col_panes[c][k - 1], owner) else false; + const kept = if (ownerOf(p, id)) |owner| k > 0 and descends(p, p.cols[c].panes[k - 1], owner) else false; if (kept) continue; pane.attached_to = null; }; @@ -1144,12 +1119,12 @@ pub fn giveBack(p: *Pardes, id: usize, gainer: usize, below: bool, rows: u16) bo /// ponytail: unfolding opens every attachment, one folded alone before /// included; remembering which were is a bit a pane. fn collapseGroup(p: *Pardes, c: usize, start: usize, end: usize) void { - const root = p.panes[p.col_panes[c][start]].?; + const root = p.panes[p.cols[c].panes[start]].?; const folding = !root.collapsed; snapColWeights(p, c); const neighbor = expandedNeighbor(p, c, start, .above) orelse expandedNeighbor(p, c, end - 1, .below); var spare: u16 = if (neighbor) |other| p.rects[other].h -| BOX_H else 0; - for (p.col_panes[c][start..end]) |k| { + for (p.cols[c].panes[start..end]) |k| { const pane = p.panes[k] orelse continue; if (folding) { if (pane.collapsed) continue; @@ -1217,9 +1192,9 @@ pub fn toggleCollapse(p: *Pardes, id: usize) void { /// would spread over the whole column instead. pub fn expandedNeighbor(p: *const Pardes, col: usize, index: usize, side: enum { above, below }) ?usize { var k = index; - while (if (side == .above) k > 0 else k + 1 < p.col_n[col]) { + while (if (side == .above) k > 0 else k + 1 < p.cols[col].n) { k = if (side == .above) k - 1 else k + 1; - const id = p.col_panes[col][k]; + const id = p.cols[col].panes[k]; if (p.panes[id]) |pane| if (!pane.collapsed) return id; } return null; @@ -1230,7 +1205,7 @@ fn computeCollapsedColumn(p: *Pardes, c: usize, x: u16, width: u16, folded: usiz const available = p.screen_h -| y; var expanded_left: usize = 0; var weight: f32 = 0; - for (p.col_panes[c][0..p.col_n[c]]) |id| if (p.panes[id]) |pane| { + for (p.cols[c].panes[0..p.cols[c].n]) |id| if (p.panes[id]) |pane| { if (!pane.collapsed) { expanded_left += 1; weight += pane.vweight; @@ -1239,7 +1214,7 @@ fn computeCollapsedColumn(p: *Pardes, c: usize, x: u16, width: u16, folded: usiz const expanded_height = available -| @as(u16, @intCast(folded)); var budget = expanded_height; var folded_left = folded; - for (p.col_panes[c][0..p.col_n[c]]) |id| { + for (p.cols[c].panes[0..p.cols[c].n]) |id| { const pane = p.panes[id] orelse continue; const room = p.screen_h -| y; const height: u16 = if (pane.collapsed) blk: { @@ -1272,7 +1247,7 @@ pub fn compute(p: *Pardes) void { var wsum: u128 = 0; var last_plain: usize = p.ncol; for (0..p.ncol) |c| if (finder != c) { - wsum += p.col_weight[c]; + wsum += p.cols[c].weight; last_plain = c; }; if (wsum == 0) wsum = 1; @@ -1286,7 +1261,7 @@ pub fn compute(p: *Pardes) void { offset = finder_w; break :end x + finder_w; } else end: { - prefix += p.col_weight[c]; + prefix += p.cols[c].weight; break :end if (c == last_plain) offset + rest else offset + columnBoundary(rest, prefix, wsum); }; const cw = end -| x; @@ -1294,7 +1269,7 @@ pub fn compute(p: *Pardes) void { p.col_w[c] = cw; var folded: usize = 0; - for (p.col_panes[c][0..p.col_n[c]]) |id| if (p.panes[id]) |pane| { + for (p.cols[c].panes[0..p.cols[c].n]) |id| if (p.panes[id]) |pane| { if (pane.collapsed) folded += 1; }; if (folded > 0) { @@ -1303,8 +1278,8 @@ pub fn compute(p: *Pardes) void { } var vsum: f32 = 0; - for (0..p.col_n[c]) |k| { - if (p.panes[p.col_panes[c][k]]) |pane| vsum += pane.vweight; + for (0..p.cols[c].n) |k| { + if (p.panes[p.cols[c].panes[k]]) |pane| vsum += pane.vweight; } if (vsum <= 0) vsum = 1; @@ -1312,9 +1287,9 @@ pub fn compute(p: *Pardes) void { const top = y; const avail_h = p.screen_h -| y; var hs: [MAX_PANES]u16 = undefined; - const n = p.col_n[c]; + const n = p.cols[c].n; for (0..n) |k| { - const id = p.col_panes[c][k]; + const id = p.cols[c].panes[k]; const pane = p.panes[id] orelse { hs[k] = 0; continue; @@ -1328,7 +1303,7 @@ pub fn compute(p: *Pardes) void { keepTerminalFloors(p, c, hs[0..n]); y = top; for (0..n) |k| { - const id = p.col_panes[c][k]; + const id = p.cols[c].panes[k]; if (p.panes[id] == null) continue; p.rects[id] = .{ .x = x, .y = y, .w = cw, .h = hs[k] }; y +|= hs[k]; @@ -1350,13 +1325,13 @@ fn floorRows(p: *Pardes, id: usize) u16 { // ponytail: a row per step, O(panes x rows); a column holds few of both. fn keepTerminalFloors(p: *Pardes, c: usize, hs: []u16) void { for (hs, 0..) |*h, k| { - const floor = floorRows(p, p.col_panes[c][k]); + const floor = floorRows(p, p.cols[c].panes[k]); while (h.* < floor) { var giver: ?usize = null; var spare: u16 = 0; for (hs, 0..) |other, j| { if (j == k) continue; - const extra = other -| floorRows(p, p.col_panes[c][j]); + const extra = other -| floorRows(p, p.cols[c].panes[j]); if (extra > spare) { spare = extra; giver = j; @@ -1475,7 +1450,7 @@ test "collapse expansion is limited to space available in one neighbor" { // Text panes: a terminal would keep its tag and two rows (floorRows). for (1..4) |id| { p.newScratchBelow(0); - try std.testing.expectEqual(id, p.col_panes[0][id]); + try std.testing.expectEqual(id, p.cols[0].panes[id]); } compute(p); toggleCollapse(p, 2); @@ -1523,7 +1498,7 @@ test "collapse survives tiny resizes and TagBottom" { p.screen_h = @intCast(height); compute(p); var used: u16 = 0; - for (p.col_panes[0][0..p.col_n[0]]) |id| { + for (p.cols[0].panes[0..p.cols[0].n]) |id| { const rect = p.rects[id]; try std.testing.expect(rect.h <= p.screen_h -| rect.y); used += rect.h; @@ -1577,31 +1552,31 @@ test "column reorder moves only crossed state and preserves weights" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 173, .rows = 20 }); defer p.deinit(); p.ncol = 4; - p.col_n = @splat(0); for (0..4) |c| { - p.col_weight[c] = c * 13 + 7; - p.col_serial[c] = @intCast(c + 10); - p.col_panes[c][0] = c; + p.cols[c].n = 0; + p.cols[c].weight = c * 13 + 7; + p.cols[c].serial = @intCast(c + 10); + p.cols[c].panes[0] = c; p.col_tags[c].cur_col = @intCast(c + 20); } compute(p); - const original_weights = p.col_weight; + const original_weights = weightsOf(p); const outer_x = p.col_x[0]; const outer_w = p.col_w[0]; p.header_focus = true; p.header_column = 1; p.header_scroll = 9; reorderColumn(p, 1, 3); - try std.testing.expectEqual(original_weights[1], p.col_weight[3]); - try std.testing.expectEqual(original_weights[2], p.col_weight[1]); - try std.testing.expectEqual(@as(u32, 11), p.col_serial[3]); + try std.testing.expectEqual(original_weights[1], p.cols[3].weight); + try std.testing.expectEqual(original_weights[2], p.cols[1].weight); + try std.testing.expectEqual(@as(u32, 11), p.cols[3].serial); try std.testing.expectEqual(@as(?usize, 3), p.header_column); try std.testing.expectEqual(@as(i32, 21), tagline.focusedHeader(p).?.cur_col); try std.testing.expectEqual(@as(usize, 9), p.header_scroll); try std.testing.expectEqual(outer_x, p.col_x[0]); try std.testing.expectEqual(outer_w, p.col_w[0]); reorderColumn(p, 3, 1); - try std.testing.expectEqualSlices(u64, original_weights[0..4], p.col_weight[0..4]); + try std.testing.expectEqualSlices(u64, original_weights[0..4], weightsOf(p)[0..4]); try std.testing.expectEqual(@as(i32, 21), p.col_tags[1].cur_col); } @@ -1619,9 +1594,9 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, _ = try p.setTestFile("alpha one\nbeta\nalphabet\ngamma\nalpha two\ndelta\nepsilon\nzeta\n"); p.newScratchBelow(0); p.newScratchBelow(0); - const other_col = p.col_panes[0][2]; + const other_col = p.cols[0].panes[2]; try std.testing.expect(splitColumn(p, other_col, other_col, false)); - const below = p.col_panes[0][1]; + const below = p.cols[0].panes[1]; p.active = 0; compute(p); const before = p.rects; @@ -1631,7 +1606,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, const s = try testAttachment(p); try std.testing.expect(attachFrom(p, 0, s, 9, 0)); try std.testing.expectEqual(@as(?usize, 0), ownerOf(p, s)); - try std.testing.expectEqual(s, p.col_panes[0][1]); + try std.testing.expectEqual(s, p.cols[0].panes[1]); for (unrelated) |k| try std.testing.expectEqualDeep(before[k], p.rects[k]); try std.testing.expectEqual(before[0].h, p.rects[0].h + p.rects[s].h); try std.testing.expectEqual(before[0].y, p.rects[0].y); @@ -1639,7 +1614,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, // A second level (a preview under a query pane): out of the first's rows. const pv = try testAttachment(p); try std.testing.expect(attachFrom(p, s, pv, 4, s)); - try std.testing.expectEqual(pv, p.col_panes[0][2]); + try std.testing.expectEqual(pv, p.cols[0].panes[2]); try std.testing.expectEqual(@as(usize, 0), groupRoot(p, pv)); try std.testing.expectEqual(@as(usize, 3), groupEnd(p, 0, 0)); for (unrelated) |k| try std.testing.expectEqualDeep(before[k], p.rects[k]); @@ -1658,8 +1633,8 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, exec.runBuiltin(p, .New, 0, "", null); exec.runBuiltin(p, .New, s, "", null); var at = findPane(p, 0).?; - try std.testing.expectEqual(s, p.col_panes[at.col][at.idx + 1]); - try std.testing.expectEqual(pv, p.col_panes[at.col][at.idx + 2]); + try std.testing.expectEqual(s, p.cols[at.col].panes[at.idx + 1]); + try std.testing.expectEqual(pv, p.cols[at.col].panes[at.idx + 2]); // The seam between owner and attachment is the user's: the pair alone. compute(p); @@ -1667,7 +1642,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, applyRowSplit(p, at.col, at.idx, p.rects[s].y - 3); compute(p); try std.testing.expectEqual(pre_drag[0].h + pre_drag[s].h, p.rects[0].h + p.rects[s].h); - for (p.col_panes[at.col][0..p.col_n[at.col]]) |k| if (k != 0 and k != s) try std.testing.expectEqualDeep(pre_drag[k], p.rects[k]); + for (p.cols[at.col].panes[0..p.cols[at.col].n]) |k| if (k != 0 and k != s) try std.testing.expectEqualDeep(pre_drag[k], p.rects[k]); // Collapse folds the group and unfolds it. compute(p); @@ -1682,8 +1657,8 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, movePane(p, 0, p.col_x[1] + 4, p.rects[other_col].y + p.rects[other_col].h / 2); at = findPane(p, 0).?; try std.testing.expectEqual(@as(usize, 1), at.col); - try std.testing.expectEqual(s, p.col_panes[1][at.idx + 1]); - try std.testing.expectEqual(pv, p.col_panes[1][at.idx + 2]); + try std.testing.expectEqual(s, p.cols[1].panes[at.idx + 1]); + try std.testing.expectEqual(pv, p.cols[1].panes[at.idx + 2]); try std.testing.expectEqual(@as(?usize, 0), ownerOf(p, s)); // Del of the preview gives its rows to its owner, the query pane. @@ -1699,7 +1674,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, try std.testing.expect(p.panes[s] == null); compute(p); try std.testing.expectEqual(pair[0].h + pair[s].h, p.rects[0].h); - for (p.col_panes[1][0..p.col_n[1]]) |k| if (k != 0) try std.testing.expectEqualDeep(pair[k], p.rects[k]); + for (p.cols[1].panes[0..p.cols[1].n]) |k| if (k != 0) try std.testing.expectEqualDeep(pair[k], p.rects[k]); // Del of the owner closes what is attached to it. const again = try testAttachment(p); @@ -1824,9 +1799,9 @@ pub fn removeColumn(p: *Pardes, col: usize) !void { const beside = if (had_focus) besideColumn(p, col, if (p.header_focus) null else p.rects[p.active]) else null; var ids: [MAX_PANES]usize = undefined; var parents: [MAX_PANES]*Pane = undefined; - const count = p.col_n[col]; + const count = p.cols[col].n; for (0..count) |i| { - ids[i] = p.col_panes[col][i]; + ids[i] = p.cols[col].panes[i]; parents[i] = p.panes[ids[i]].?; } try panes.detachCwds(p, parents[0..count]); @@ -1851,7 +1826,7 @@ pub fn besideColumn(p: *const Pardes, col: usize, r: ?Rect) ?usize { const next = if (col > 0) col - 1 else col + 1; const mid = if (r) |at| at.y + at.h / 2 else p.screen_h / 2; var pick: ?usize = null; - for (p.col_panes[next][0..p.col_n[next]]) |k| { + for (p.cols[next].panes[0..p.cols[next].n]) |k| { if (p.panes[k] == null) continue; pick = k; if (p.rects[k].y +| p.rects[k].h > mid) break; @@ -1901,7 +1876,7 @@ pub fn reprojectTagHit(p: *const Pardes, tag_hit: TagHit) ?TagHit { const pane = p.panes[tag_hit.id] orelse return null; if (pane.serial != tag_hit.serial) return null; } - if (tag_hit.kind == .column and (tag_hit.id >= p.ncol or p.col_serial[tag_hit.id] != tag_hit.serial)) return null; + if (tag_hit.kind == .column and (tag_hit.id >= p.ncol or p.cols[tag_hit.id].serial != tag_hit.serial)) return null; return Layer.tagAgain(tag_hit); } @@ -1943,7 +1918,7 @@ test "a new column takes width only from the column that created it" { const coarse = try Pardes.init(std.testing.allocator, .{ .cols = 22, .rows = 10 }); defer coarse.deinit(); - coarse.col_weight[0] = 3; + coarse.cols[0].weight = 3; _ = try coarse.newShell(1, ""); try std.testing.expect(splitColumn(coarse, 0, 1, false)); coarse.sync(); @@ -1956,18 +1931,14 @@ test "a new column takes width only from the column that created it" { try std.testing.expect(splitColumn(extreme, 0, 1, false)); _ = try extreme.newShell(2, ""); insert(extreme, 0, 1, 2); - extreme.col_weight[0] = std.math.maxInt(u64) / 2 + 2; // odd and cannot double - extreme.col_weight[1] = 1; + extreme.cols[0].weight = std.math.maxInt(u64) / 2 + 2; // odd and cannot double + extreme.cols[1].weight = 1; compute(extreme); - const panes_before = extreme.col_panes; - const counts_before = extreme.col_n; - const weights_before = extreme.col_weight; + const cols_before = extreme.cols; const source_vweight = extreme.panes[0].?.vweight; const sibling_vweight = extreme.panes[2].?.vweight; try std.testing.expect(!splitColumn(extreme, 0, 0, false)); - try std.testing.expectEqual(panes_before, extreme.col_panes); - try std.testing.expectEqual(counts_before, extreme.col_n); - try std.testing.expectEqual(weights_before, extreme.col_weight); + try std.testing.expectEqual(cols_before, extreme.cols); try std.testing.expectEqual(source_vweight, extreme.panes[0].?.vweight); try std.testing.expectEqual(sibling_vweight, extreme.panes[2].?.vweight); } @@ -1981,8 +1952,8 @@ test "Newcol refuses an unsplittable restored weight before spawning" { try std.testing.expect(splitColumn(p, id - 1, id, false)); } const restored_cap = std.math.maxInt(u64) / 6; - for (0..4) |column| p.col_weight[column] = restored_cap; - p.col_weight[3] -= 1; + for (0..4) |column| p.cols[column].weight = restored_cap; + p.cols[3].weight -= 1; for ([_]usize{ 3, 2, 1 }) |id| { const pane = p.panes[id].?; try panes.deinitPane(p, pane); @@ -1992,8 +1963,8 @@ test "Newcol refuses an unsplittable restored weight before spawning" { } while (p.nextEffect()) |_| {} - try std.testing.expect(p.col_weight[0] > std.math.maxInt(u64) / 2); - try std.testing.expect(p.col_weight[0] % 2 == 1); + try std.testing.expect(p.cols[0].weight > std.math.maxInt(u64) / 2); + try std.testing.expect(p.cols[0].weight % 2 == 1); try std.testing.expect(!canSplitCol(p, findPane(p, 0).?.col)); const panes_before = p.panes; const serial_before = p.next_serial; @@ -2012,10 +1983,10 @@ test "repeated non-dyadic column splits preserve every unrelated boundary" { p.sync(); const handle = p.col_x[0] + p.col_w[0] - 1; - const untouched = p.col_weight; + const untouched = weightsOf(p); p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } }); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = TOPBAR_H + 1 } }); - try std.testing.expectEqual(untouched, p.col_weight); + try std.testing.expectEqual(untouched, weightsOf(p)); p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } }); p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 417, .row = TOPBAR_H + 1 } }); @@ -2043,22 +2014,22 @@ test "dragging a column's only pane to another leaves that column in place, empt newScratchIn(p, 0, activeColumn(p).?); const moved = p.active; p.sync(); - const weights = p.col_weight; - const tag_serial = p.col_serial[1]; + const weights = weightsOf(p); + const tag_serial = p.cols[1].serial; movePane(p, moved, p.col_x[0] + 4, p.rects[0].y + p.rects[0].h / 2); p.sync(); // acme's coldragwin: colclose then coladd (cols.c:516-517); the column // left behind keeps its place, width and tag. try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqual(@as(usize, 0), p.col_n[1]); - try std.testing.expectEqual(tag_serial, p.col_serial[1]); - try std.testing.expectEqualDeep(weights, p.col_weight); - try std.testing.expectEqual(@as(usize, 2), p.col_n[0]); + try std.testing.expectEqual(@as(usize, 0), p.cols[1].n); + try std.testing.expectEqual(tag_serial, p.cols[1].serial); + try std.testing.expectEqualDeep(weights, weightsOf(p)); + try std.testing.expectEqual(@as(usize, 2), p.cols[0].n); // ...and a pane dragged into the empty column takes it whole. movePane(p, moved, p.col_x[1] + 4, p.screen_h / 2); p.sync(); - try std.testing.expectEqualSlices(usize, &.{moved}, p.col_panes[1][0..p.col_n[1]]); - try std.testing.expectEqual(@as(usize, 1), p.col_n[0]); + try std.testing.expectEqualSlices(usize, &.{moved}, p.cols[1].panes[0..p.cols[1].n]); + try std.testing.expectEqual(@as(usize, 1), p.cols[0].n); } test "tiny screens keep pane space before adding a column tag" { @@ -2068,3 +2039,10 @@ test "tiny screens keep pane space before adding a column tag" { try std.testing.expectEqual(TOPBAR_H, p.rects[0].y); _ = try p.render(p.scratch.allocator()); } + +/// Each column's weight, as a test compares them. +fn weightsOf(p: *const Pardes) [MAX_COLS]u64 { + var out: [MAX_COLS]u64 = undefined; + for (&out, p.cols) |*w, c| w.* = c.weight; + return out; +} diff --git a/src/mouse.zig b/src/mouse.zig index 5c3821e7..43d66e0b 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -162,14 +162,14 @@ fn clampBorderRow(ay: u16, ah: u16, bh: u16, mrow: u16, tag_bottom: bool) u16 { } fn seamRowOf(p: *const Pardes, c: usize, k: usize) u16 { - const r = p.rects[p.col_panes[c][k]]; + const r = p.rects[p.cols[c].panes[k]]; return if (p.settings.tag_bottom) r.y +| r.h else r.y + r.h -| 1; } fn cornerFixture(gpa: std.mem.Allocator) !*Pardes { const p = try Pardes.init(gpa, .{ .cols = 100, .rows = 30, .shells = 3 }); p.update(.{ .resize = .{ .cols = 100, .rows = 30 } }); - p.active = p.col_panes[1][0]; + p.active = p.cols[1].panes[0]; p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell below it, same column p.sync(); return p; @@ -189,8 +189,8 @@ test "a pane's last row of text is no resize handle; the rule over the next pane test "a pane's grip dragged up or down its own column moves its top, down to the floor of the pane above" { const p = try cornerFixture(std.testing.allocator); defer p.deinit(); - const upper = p.col_panes[1][0]; - const lower = p.col_panes[1][1]; + const upper = p.cols[1].panes[0]; + const lower = p.cols[1].panes[1]; const grip_x = p.rects[lower].x; // Up, past the pane above's first row: a text pane keeps its tag, a // terminal its tag and two rows (layout.floorRows). @@ -202,7 +202,7 @@ test "a pane's grip dragged up or down its own column moves its top, down to the p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = grip_x, .row = top } }); p.sync(); try std.testing.expectEqual(floor, p.rects[upper].h); - try std.testing.expectEqual(lower, p.col_panes[1][1]); + try std.testing.expectEqual(lower, p.cols[1].panes[1]); // Down, inside itself: its top follows, the pane above taking the rows. const to = p.rects[lower].y + 6; p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = grip_x, .row = p.rects[lower].y } }); @@ -246,7 +246,7 @@ pub fn chromeTarget(p: *const Pardes, col: u16, row: u16) ?ChromeTarget { } for (0..p.ncol) |column| { if (col < p.col_x[column] or col >= p.col_x[column] + p.col_w[column]) continue; - for (0..p.col_n[column] -| 1) |index| { + for (0..p.cols[column].n -| 1) |index| { const seam = seamRowOf(p, column, index); if (@max(row, seam) - @min(row, seam) == slack) return .{ .col = col, .row = seam }; } @@ -263,8 +263,8 @@ test "a press near chrome takes it: the tag rows, a column's handle or a seam on const handle = p.col_x[0] + p.col_w[0] - 1; const seam = seamRowOf(p, 0, 0); const mid = p.col_x[0] + p.col_w[0] / 2; - const top = p.rects[p.col_panes[0][0]].y; - const low = p.rects[p.col_panes[1][1]]; + const top = p.rects[p.cols[0].panes[0]].y; + const low = p.rects[p.cols[1].panes[1]]; const body = low.y + low.h / 2; try std.testing.expectEqual(ChromeTarget{ .col = 5, .row = 0 }, chromeTarget(p, 5, 0).?); try std.testing.expectEqual(ChromeTarget{ .col = handle, .row = body }, chromeTarget(p, handle, body).?); @@ -597,7 +597,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { if (mcol < p.col_x[column] or mcol >= p.col_x[column] + @min(config.GUTTER, p.col_w[column])) continue; if (m.button == config.select_button) { p.header_drag = false; - p.drag = .{ .column_move = .{ .serial = p.col_serial[column], .cur_x = mcol, .grab = mcol - p.col_x[column] } }; + p.drag = .{ .column_move = .{ .serial = p.cols[column].serial, .cur_x = mcol, .grab = mcol - p.col_x[column] } }; } return; } @@ -632,7 +632,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { column = c; x = p.col_x[c] + TAG_TEXT_INSET; if (layout.findPane(p, p.active)) |active_col| { - if (active_col.col != c and p.col_n[c] > 0) p.active = p.col_panes[c][0]; + if (active_col.col != c and p.cols[c].n > 0) p.active = p.cols[c].panes[0]; } break; }; @@ -653,7 +653,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { // Held, as a pane tag's sweep is: it runs when the button // comes up (headerSweepRun). p.header_sweep = .{ - .serial = if (column) |c| p.col_serial[c] else null, + .serial = if (column) |c| p.cols[c].serial else null, .button = m.button, .anchor = point.at, .cur = point.at, @@ -888,7 +888,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { /// row `mrow`. Out-of-range columns simply have no seam. fn seamIdxAt(p: *const Pardes, c: usize, mrow: u16) ?usize { if (c >= p.ncol) return null; - for (0..p.col_n[c] -| 1) |k| if (mrow == seamRowOf(p, c, k)) return k; + for (0..p.cols[c].n -| 1) |k| if (mrow == seamRowOf(p, c, k)) return k; return null; } @@ -900,9 +900,9 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo clampBorderCol(p.col_x[c], p.col_w[c], p.col_w[c + 1], mcol) else mcol; - if (d.corner) |k| if (k.idx + 1 < p.col_n[k.col]) { - const a = p.rects[p.col_panes[k.col][k.idx]]; - const b = p.rects[p.col_panes[k.col][k.idx + 1]]; + if (d.corner) |k| if (k.idx + 1 < p.cols[k.col].n) { + const a = p.rects[p.cols[k.col].panes[k.idx]]; + const b = p.rects[p.cols[k.col].panes[k.idx + 1]]; d.cur_y = clampBorderRow(a.y, a.h, b.h, mrow, p.settings.tag_bottom); } else { d.cur_y = mrow; @@ -911,9 +911,9 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo .border_h => |*d| { const cc = d.col; const k = d.top_idx; - if (k + 1 < p.col_n[cc]) { - const a = p.rects[p.col_panes[cc][k]]; - const b = p.rects[p.col_panes[cc][k + 1]]; + if (k + 1 < p.cols[cc].n) { + const a = p.rects[p.cols[cc].panes[k]]; + const b = p.rects[p.cols[cc].panes[k + 1]]; // Held by the rule over the lower pane: the seam is the row above. const seam = if (p.settings.tag_bottom) mrow else mrow -| 1; d.cur_y = clampBorderRow(a.y, a.h, b.h, seam, p.settings.tag_bottom); @@ -1573,15 +1573,15 @@ test "a corner drag's two axes clamp independently" { test "a v-handle press at the RIGHT column's seam drags both boundaries" { const p = try cornerFixture(std.testing.allocator); defer p.deinit(); - try std.testing.expectEqual(@as(usize, 2), p.col_n[1]); + try std.testing.expectEqual(@as(usize, 2), p.cols[1].n); const handle = p.col_x[0] + p.col_w[0] - 1; const right_seam = nudgeRightSeam(p, 3); try std.testing.expect(right_seam != seamRowOf(p, 0, 0)); - const w0 = p.col_weight[0]; - const v_left = p.panes[p.col_panes[0][0]].?.vweight; - const v_right = p.panes[p.col_panes[1][0]].?.vweight; + const w0 = p.cols[0].weight; + const v_left = p.panes[p.cols[0].panes[0]].?.vweight; + const v_right = p.panes[p.cols[1].panes[0]].?.vweight; p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = right_seam } }); try std.testing.expect(p.drag == .border_v); @@ -1595,9 +1595,9 @@ test "a v-handle press at the RIGHT column's seam drags both boundaries" { // both halves committed: the column pair widened, and the RIGHT column's // pane pair reweighted — while the left column's panes stayed put - try std.testing.expect(p.col_weight[0] > w0); - try std.testing.expect(p.panes[p.col_panes[1][0]].?.vweight != v_right); - try std.testing.expectEqual(v_left, p.panes[p.col_panes[0][0]].?.vweight); + try std.testing.expect(p.cols[0].weight > w0); + try std.testing.expect(p.panes[p.cols[1].panes[0]].?.vweight != v_right); + try std.testing.expectEqual(v_left, p.panes[p.cols[0].panes[0]].?.vweight); } test "a tie row still moves the LEFT column's pane pair only" { @@ -1611,8 +1611,8 @@ test "a tie row still moves the LEFT column's pane pair only" { try std.testing.expectEqual(left_seam, seamRowOf(p, 1, 0)); const handle = p.col_x[0] + p.col_w[0] - 1; - const v_left = p.panes[p.col_panes[0][0]].?.vweight; - const v_right = p.panes[p.col_panes[1][0]].?.vweight; + const v_left = p.panes[p.cols[0].panes[0]].?.vweight; + const v_right = p.panes[p.cols[1].panes[0]].?.vweight; p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = left_seam } }); const corner = p.drag.border_v.corner orelse return error.NoCorner; @@ -1621,8 +1621,8 @@ test "a tie row still moves the LEFT column's pane pair only" { p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle, .row = left_seam - 4 } }); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = left_seam - 4 } }); p.sync(); - try std.testing.expect(p.panes[p.col_panes[0][0]].?.vweight != v_left); - try std.testing.expectEqual(v_right, p.panes[p.col_panes[1][0]].?.vweight); + try std.testing.expect(p.panes[p.cols[0].panes[0]].?.vweight != v_left); + try std.testing.expectEqual(v_right, p.panes[p.cols[1].panes[0]].?.vweight); } test "a v-handle press at nobody's seam is still a plain edge drag" { @@ -1635,9 +1635,9 @@ test "a v-handle press at nobody's seam is still a plain edge drag" { var row: u16 = TOPBAR_H + 1; while (row == left_seam or row == right_seam) row += 1; - const w0 = p.col_weight[0]; - const v_left = p.panes[p.col_panes[0][0]].?.vweight; - const v_right = p.panes[p.col_panes[1][0]].?.vweight; + const w0 = p.cols[0].weight; + const v_left = p.panes[p.cols[0].panes[0]].?.vweight; + const v_right = p.panes[p.cols[1].panes[0]].?.vweight; p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = row } }); try std.testing.expect(p.drag == .border_v); try std.testing.expect(p.drag.border_v.corner == null); @@ -1645,9 +1645,9 @@ test "a v-handle press at nobody's seam is still a plain edge drag" { p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle + 8, .row = row + 5 } }); p.sync(); // exactly ONE boundary moved - try std.testing.expect(p.col_weight[0] > w0); - try std.testing.expectEqual(v_left, p.panes[p.col_panes[0][0]].?.vweight); - try std.testing.expectEqual(v_right, p.panes[p.col_panes[1][0]].?.vweight); + try std.testing.expect(p.cols[0].weight > w0); + try std.testing.expectEqual(v_left, p.panes[p.cols[0].panes[0]].?.vweight); + try std.testing.expectEqual(v_right, p.panes[p.cols[1].panes[0]].?.vweight); } test "a RIGHT-column corner's two axes clamp independently" { @@ -1666,8 +1666,8 @@ test "a RIGHT-column corner's two axes clamp independently" { // and the mirror: below the bottom at mid-width. y parks, x tracks again p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle, .row = 999 } }); try std.testing.expectEqual(handle, p.drag.border_v.cur_x); - const a = p.rects[p.col_panes[1][0]]; - const b = p.rects[p.col_panes[1][1]]; + const a = p.rects[p.cols[1].panes[0]]; + const b = p.rects[p.cols[1].panes[1]]; try std.testing.expectEqual(clampBorderRow(a.y, a.h, b.h, 999, p.settings.tag_bottom), p.drag.border_v.cur_y); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = 999 } }); } diff --git a/src/ninep/cols.zig b/src/ninep/cols.zig index 60071bd0..3a7f0dbb 100644 --- a/src/ninep/cols.zig +++ b/src/ninep/cols.zig @@ -36,9 +36,9 @@ pub fn writeLayout(p: *Pardes, w: *std.Io.Writer) !void { for (0..p.ncol) |c| { try w.print("{d} {d} {d} {d} {s} {s}", .{ layout.columnSerial(p, c), c, p.col_x[c], p.col_w[c], - if (active == c) "current" else "notcurrent", if (p.col_n[c] == 0) "empty" else "full", + if (active == c) "current" else "notcurrent", if (p.cols[c].n == 0) "empty" else "full", }); - for (p.col_panes[c][0..p.col_n[c]]) |id| if (p.panes[id]) |pane| try w.print(" {d}", .{pane.serial}); + for (p.cols[c].panes[0..p.cols[c].n]) |id| if (p.panes[id]) |pane| try w.print(" {d}", .{pane.serial}); try w.writeByte('\n'); } if (layout.activeColumn(p) orelse active) |c| try w.print("active {d}\n", .{layout.columnSerial(p, c)}) else try w.writeAll("active -\n"); @@ -238,9 +238,9 @@ test "Joincol is refused when the joined column cannot give each pane its tag an _ = th.wr(p, focus, try std.fmt.bufPrint(&digits, "{d}\n", .{b})); _ = try th.newPane(p); try testing.expectEqual(@as(usize, 2), p.ncol); - try testing.expect(p.col_n[0] >= 2 and p.col_n[1] >= 2); + try testing.expect(p.cols[0].n >= 2 and p.cols[1].n >= 2); // Focus in the left column: joined, four panes want 12 rows of 10. - const left = p.panes[p.col_panes[0][0]].?.serial; + const left = p.panes[p.cols[0].panes[0]].?.serial; _ = th.wr(p, focus, try std.fmt.bufPrint(&digits, "{d}\n", .{left})); const r = th.wr(p, ctl, "Joincol\n"); try testing.expectEqual(tree.Status.err, r.reply.status); @@ -311,12 +311,12 @@ test "a Newcol refused because the tags would not fit logs its err alone and spe const made = try th.newPane(p); const pane = p.panes[p.paneBySerial(made).?].?; const col = layout.findPane(p, p.paneBySerial(made).?).?.col; - for (p.col_panes[col][0..p.col_n[col]]) |k| { + for (p.cols[col].panes[0..p.cols[col].n]) |k| { const each = p.panes[k].?; if (each.tag.own) |old| p.gpa.free(old); each.tag.own = try p.gpa.dupe(u8, std.mem.asBytes(&@as([60][5]u8, @splat("word ".*)))); } - try testing.expect(p.col_n[col] >= 2); + try testing.expect(p.cols[col].n >= 2); p.sync(); const ctl = @backingInt(tree.TopFile.ctl); const focus = @backingInt(tree.TopFile.focus); @@ -450,7 +450,7 @@ test "New and Term run at /tagexec and a column's exec, with no pane at all too" // Every pane gone: the workspace tag makes one all the same. for ([_][]const u8{ "New\n", "Term\n" }) |line| { while (p.ncol > 0) { - const first = p.panes[p.col_panes[0][0]].?.serial; + const first = p.panes[p.cols[0].panes[0]].?.serial; _ = th.wr(p, tree.Node.of(first, .ctl), "delete\n"); if (panes.anyPane(p) == null) break; } @@ -495,7 +495,7 @@ test "every pane word a tag no pane owns does not hold is refused there, Edit in pub fn remove(p: *Pardes, req: Req, serial: u32, file: tree.ColFile) Reply { if (file != .dir) return Reply.fail(req.tag, E.PERM); const col = layout.columnBySerial(p, serial) orelse return Reply.fail(req.tag, E.NOENT); - if (p.col_n[col] > 0) return tree.failText(req.tag, E.NOTEMPTY, "column not empty: close its panes, or write Delcol to its ctl"); + if (p.cols[col].n > 0) return tree.failText(req.tag, E.NOTEMPTY, "column not empty: close its panes, or write Delcol to its ctl"); layout.removeColumn(p, col) catch return Reply.fail(req.tag, E.IO); return .{ .tag = req.tag }; } @@ -617,7 +617,7 @@ test "a column's ctl and exec act on it as its tag would, and rmdir closes it on const empty = layout.columnSerial(p, 1); // New on the empty column's ctl fills it, wherever the keyboard is. try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(empty, .ctl), "New\n").reply.status); - try testing.expectEqual(@as(usize, 1), p.col_n[1]); + try testing.expectEqual(@as(usize, 1), p.cols[1].n); try testing.expectEqual(E.INVAL, th.wr(p, Node.ofCol(empty, .ctl), "Exit\n").errno()); var rec: [64]u8 = undefined; try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err - col/{d}/ctl: unknown control message \"Exit\"", .{empty}))); @@ -662,7 +662,7 @@ test "tagexec runs a word as a click in the workspace tag; exec files read back // A column's exec makes a pane there and reads it back. const right = layout.columnSerial(p, 1); try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(right, .exec), "New\n").reply.status); - const made = p.panes[p.col_panes[1][0]].?.serial; + const made = p.panes[p.cols[1].panes[0]].?.serial; var want: [16]u8 = undefined; try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), th.rd(p, Node.ofCol(right, .exec), 0, 64).bytes); try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), th.rd(p, tagexec, 0, 64).bytes); @@ -716,7 +716,7 @@ test "a column's ctl refuses an unknown word and an argument as the other ctls d const extra = th.wr(p, ctl_node, "New extra\n"); try testing.expectEqual(E.INVAL, extra.errno()); try testing.expect(std.mem.startsWith(u8, extra.reply.ename, "wrong #args")); - try testing.expectEqual(@as(usize, 1), p.col_n[0]); + try testing.expectEqual(@as(usize, 1), p.cols[0].n); // A pane's bare answer and a winsize of no size say what they take. try testing.expectEqualStrings("answer takes a choice or -", th.wr(p, Node.of(p.panes[0].?.serial, .ctl), "answer\n").reply.ename); } diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 2151126d..dc95e0ec 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2388,11 +2388,11 @@ test "a column takes panes until their documented minimums fill it, not until no const avail = p.screen_h - (p.topBarHeight() + layout.columnBarHeight(p)); for (0..p.ncol) |c| { var need: u32 = 0; - for (p.col_panes[c][0..p.col_n[c]]) |k| need += layout.minRows(p, k); + for (p.cols[c].panes[0..p.cols[c].n]) |k| need += layout.minRows(p, k); // Refused only when one more pane's tag and two rows would not fit. - if (p.col_n[c] > 1) try testing.expect(avail - need < 3); + if (p.cols[c].n > 1) try testing.expect(avail - need < 3); // Every pane keeps its minimum. - for (p.col_panes[c][0..p.col_n[c]]) |k| try testing.expect(p.rects[k].h >= layout.minRows(p, k)); + for (p.cols[c].panes[0..p.cols[c].n]) |k| try testing.expect(p.rects[k].h >= layout.minRows(p, k)); } } diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index 8c0743bd..08db0d75 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -1832,7 +1832,7 @@ test "random placements, refused or not, leave no pane under its tag and two row } for (0..p.ncol) |c| if (!layout.columnAtMinimums(p, c)) { std.debug.print("seed {d} rows {d} step {d} action {d}: column {d} under its minimums\n", .{ seed, rows, step, action, c }); - for (p.col_panes[c][0..p.col_n[c]]) |id| std.debug.print(" pane {d} h {d} min {d}\n", .{ id, p.rects[id].h, layout.minRows(p, id) }); + for (p.cols[c].panes[0..p.cols[c].n]) |id| std.debug.print(" pane {d} h {d} min {d}\n", .{ id, p.rects[id].h, layout.minRows(p, id) }); return error.TestUnexpectedResult; }; } @@ -2052,8 +2052,8 @@ test "no placement leaves a pane shorter than its tag and two rows; a full colum var count: usize = 0; for (p.panes) |slot| count += @intFromBool(slot != null); try testing.expectEqual(made, count); // the refused one is gone - for (0..p.ncol) |c| for (p.col_panes[c][0..p.col_n[c]]) |k| { - if (p.col_n[c] > 1 and !p.panes[k].?.collapsed) + for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n]) |k| { + if (p.cols[c].n > 1 and !p.panes[k].?.collapsed) try testing.expect(p.rects[k].h >= p.panes[k].?.tag_rows + pardes.layout.min_body_rows); }; } @@ -2102,6 +2102,6 @@ test "a pane made from pane/new goes last in its column, even when the last pane for (0..3) |_| { const made = call(p, .{ .tag = 1, .op = .open, .node = @backingInt(TopFile.new) }).reply.handle; p.sync(); - try testing.expectEqual(made, p.panes[p.col_panes[0][p.col_n[0] - 1]].?.serial); + try testing.expectEqual(made, p.panes[p.cols[0].panes[p.cols[0].n - 1]].?.serial); } } diff --git a/src/panes.zig b/src/panes.zig index 94c9615f..4f7ca0e7 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -1025,7 +1025,7 @@ pub fn removePane(p: *Pardes, id: usize, to: ?usize) error{OutOfMemory}!void { // An attachment's rows go back to its owner and nobody else. const owner = layout.ownerOf(p, id); const place = layout.findPane(p, id); - const emptied = if (place) |f| (if (p.col_n[f.col] == 1) f.col else null) else null; + const emptied = if (place) |f| (if (p.cols[f.col].n == 1) f.col else null) else null; // What it was and where, for Panes to bring back (Store.zig). const kept = p.store.keep(p, id); errdefer if (kept) |k| k.free(p.recentGpa()); @@ -1054,8 +1054,8 @@ pub fn removePane(p: *Pardes, id: usize, to: ?usize) error{OutOfMemory}!void { /// the jumplist, and alternating with it is exactly what Last is for. pub fn neighbourPane(p: *Pardes, from: usize) ?usize { if (layout.findPane(p, from)) |at| { - const n = p.col_n[at.col]; - if (n > 1) return p.col_panes[at.col][(at.idx + 1) % n]; + const n = p.cols[at.col].n; + if (n > 1) return p.cols[at.col].panes[(at.idx + 1) % n]; } for (p.panes, 0..) |slot, id| { if (slot != null and id != from) return id; @@ -1213,8 +1213,7 @@ test "owned cwd close copies are transactional across inherited chains" { while (p.nextEffect()) |_| {} p.parkPendingWrite(0, "queued"); const pending = p.pending_write[0].?.bytes; - const columns = p.col_panes; - const counts = p.col_n; + const columns = p.cols; const active = p.active; const live_bytes = allocator.allocated_bytes - allocator.freed_bytes; allocator.fail_index = allocator.alloc_index + failed_copy; @@ -1223,8 +1222,7 @@ test "owned cwd close copies are transactional across inherited chains" { try std.testing.expectEqual(parent, first.cwd.inherited); try std.testing.expectEqual(parent, second.cwd.inherited); try std.testing.expectEqual(first, grandchild.cwd.inherited); - try std.testing.expectEqualDeep(columns, p.col_panes); - try std.testing.expectEqualDeep(counts, p.col_n); + try std.testing.expectEqualDeep(columns, p.cols); try std.testing.expectEqual(active, p.active); try std.testing.expectEqual(@as(usize, 0), p.effects_len); try std.testing.expectEqual(pending.ptr, p.pending_write[0].?.bytes.ptr); @@ -1257,13 +1255,11 @@ test "owned cwd column close allocates every copy before removing any pane" { second_child.cwd = .{ .inherited = p.panes[1].? }; while (p.nextEffect()) |_| {} const before = p.panes; - const columns = p.col_panes; - const counts = p.col_n; + const columns = p.cols; allocator.fail_index = allocator.alloc_index + 1; try std.testing.expectError(error.OutOfMemory, layout.removeColumn(p, 0)); for (before, p.panes) |old, current| try std.testing.expectEqual(old, current); - try std.testing.expectEqualDeep(columns, p.col_panes); - try std.testing.expectEqualDeep(counts, p.col_n); + try std.testing.expectEqualDeep(columns, p.cols); try std.testing.expectEqual(@as(usize, 0), p.effects_len); try std.testing.expect(first_child.cwd == .inherited and second_child.cwd == .inherited); allocator.fail_index = std.math.maxInt(usize); diff --git a/src/views.zig b/src/views.zig index f54e9eb2..46959783 100644 --- a/src/views.zig +++ b/src/views.zig @@ -33,8 +33,7 @@ pub const max = 4; /// what drawing it keeps (its frame and its timings). pub const fields = [_][:0]const u8{ "screen_w", "screen_h", "cell_pixels", "row_metrics", - "ncol", "col_weight", "col_panes", "col_n", - "col_tags", "col_serial", "finder", "rects", + "ncol", "cols", "col_tags", "finder", "rects", "col_x", "col_w", "active", "jumps", "njumps", "jcur", "jump_force", "active_column", @@ -367,17 +366,17 @@ fn unpark(p: *Pardes, k: u8) void { // now) leave its layout, and its keyboard leaves them. for (0..p.ncol) |c| { var n: usize = 0; - for (p.col_panes[c][0..p.col_n[c]]) |id| { + for (p.cols[c].panes[0..p.cols[c].n]) |id| { const pane = p.panes[id] orelse continue; if (pane.serial != slot.serials[id]) continue; - p.col_panes[c][n] = id; + p.cols[c].panes[n] = id; n += 1; } - p.col_n[c] = n; + p.cols[c].n = n; } if (layout.findPane(p, p.active) == null) { - for (0..p.ncol) |c| if (p.col_n[c] > 0) { - p.active = p.col_panes[c][0]; + for (0..p.ncol) |c| if (p.cols[c].n > 0) { + p.active = p.cols[c].panes[0]; break; }; } @@ -450,7 +449,7 @@ pub fn open(p: *Pardes) ?u8 { /// How a view is laid out and focused: what a new one takes of the live /// one (`open`), and what one going leaves the view that stays (`closeKeeping`). -const laid_out = .{ "ncol", "col_weight", "col_panes", "col_n", "col_serial", "finder", "active", "active_column", "jumps", "njumps", "jcur" }; +const laid_out = .{ "ncol", "cols", "finder", "active", "active_column", "jumps", "njumps", "jcur" }; const sized = .{ "screen_w", "screen_h", "cell_pixels", "row_metrics" }; /// View `k` gone, and the view that stays live laid out as `k` was: its |
