summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/typ/builtins-gui.json1
-rw-r--r--docs/typ/builtins-tui.json1
-rw-r--r--docs/typ/reference.typ1
-rw-r--r--src/builtins.zig2
-rw-r--r--src/config.zig18
-rw-r--r--src/gui/gui.zig136
6 files changed, 153 insertions, 6 deletions
diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json
index 1c435a63..08aaa7e1 100644
--- a/docs/typ/builtins-gui.json
+++ b/docs/typ/builtins-gui.json
@@ -45,6 +45,7 @@
{"name": "GripWidth", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "The grip and scrollbar width, as a percent of the theme's rail."},
{"name": "Help", "leader": "SPC ?", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Open the help: every key and every builtin."},
{"name": "Hover", "leader": "SPC l k", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Ask the language server about the symbol under the cursor."},
+ {"name": "InactiveDim", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "Fade the unfocused panes' text by a percentage, 0 through 100, 0 off."},
{"name": "Incl", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "acme's Incl, for the session: `Incl dir ...` adds directories a look at a name found nowhere else is tried in (`stdio.h`, `<foo.h>`), bare lists them, `Incl -` empties the list."},
{"name": "Index", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Run the file's language indexer at its project root, writing the index.scip the language words ask first."},
{"name": "Joincol", "leader": "SPC c j", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Fold the active pane's column into the one on its right, keeping its panes."},
diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json
index 4bb2837b..4cdfe219 100644
--- a/docs/typ/builtins-tui.json
+++ b/docs/typ/builtins-tui.json
@@ -41,6 +41,7 @@
{"name": "Grep", "leader": "SPC f g", "also": ["topbar"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Find's sibling: Find matches file NAMES under this pane's directory, Grep matches the LINES of those files, on the disk engine's worker."},
{"name": "Help", "leader": "SPC ?", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Open the help: every key and every builtin."},
{"name": "Hover", "leader": "SPC l k", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Ask the language server about the symbol under the cursor."},
+ {"name": "InactiveDim", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "Fade the unfocused panes' text by a percentage, 0 through 100, 0 off."},
{"name": "Incl", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "acme's Incl, for the session: `Incl dir ...` adds directories a look at a name found nowhere else is tried in (`stdio.h`, `<foo.h>`), bare lists them, `Incl -` empties the list."},
{"name": "Index", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Run the file's language indexer at its project root, writing the index.scip the language words ask first."},
{"name": "Joincol", "leader": "SPC c j", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Fold the active pane's column into the one on its right, keeping its panes."},
diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ
index 85f093a9..6f093df3 100644
--- a/docs/typ/reference.typ
+++ b/docs/typ/reference.typ
@@ -463,6 +463,7 @@ Source analysis is cached for 64 files and 64 MiB.
*Effects.* #word("Motion") `off|crisp|smooth|bouncy|playful` (default `smooth`),
#word("JumpTrail") (off: a jump of the cursor leaves a short trail that fades, in a truecolor terminal and the window),
+#word("InactiveDim") `<0-100>` (0: the window fades the unfocused panes' text by that percent, never below its contrast floor),
#word("CursorBlink"), #word("GripWidth") `<50-300>`, the GUI's. No effect
may lower the contrast of text, the selection or a focus indicator.
diff --git a/src/builtins.zig b/src/builtins.zig
index c6c4327b..bb3a167b 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -244,7 +244,7 @@ pub const registry = struct {
// a switch flips bare, a choice steps, and DumpDir and Shell bare
// are the default
.toggle, .dump_dir, .choice, .motion, .shell => false,
- .theme, .font, .tagline_size, .window_opacity, .window_blur, .message_ms, .grip_width => true,
+ .theme, .font, .tagline_size, .window_opacity, .window_blur, .message_ms, .inactive_dim, .grip_width => true,
// bare, it says the current value (exec.applySettingBuiltin)
.tab, .callstack_depth, .search_rows => false,
};
diff --git a/src/config.zig b/src/config.zig
index 46a5f7c3..dbe4e9b7 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -171,6 +171,7 @@ pub const leader_path = paths: {
table.set(.ProgramEsc, null);
table.set(.Motion, null);
if (builtins.capabilities.lift) table.set(.GripWidth, null);
+ table.set(.InactiveDim, null);
if (builtins.capabilities.lift) table.set(.Pet, null);
if (builtins.TreeContext.enabled) table.set(.TreeContext, null);
table.set(.ThemeFile, null);
@@ -707,6 +708,11 @@ pub const Runtime = struct {
/// A font's programming ligatures (`->`, `!=`) draw across their cells.
/// Only a shell that shapes text has the setting (`Capabilities.ligatures`).
ligatures: bool = true,
+ /// How far the unfocused panes' text fades toward its ground, a percent
+ /// (0 off), kept above the pair's own contrast or 4.5, whichever is
+ /// lower: a setting alone, which the window draws (gui.zig's Dim) and a
+ /// terminal keeps.
+ inactive_dim: u8 = 0,
/// The grip's button and the scrollbar under it, one width, as a percent
/// of the theme's `rail_px` (acme's 12px Scrollwid at a 17px tagline):
/// a pixel shell's (docs/typ/themes.typ).
@@ -890,6 +896,8 @@ pub const Runtime = struct {
dump_dir,
/// A motion flavour.
motion,
+ /// A percentage, 0 through 100.
+ inactive_dim,
grip_width,
tab,
callstack_depth,
@@ -947,6 +955,7 @@ pub const Runtime = struct {
.{ .word = "ProgramEsc", .action = .{ .toggle = .program_esc }, .doc = "In a raw terminal, Esc goes to the program and Shift-Esc backs out, on; off (the default) swaps them." },
.{ .word = "Motion", .action = .motion, .doc = "How animations move: off, crisp, smooth, bouncy or playful." },
.{ .word = "GripWidth", .action = .grip_width, .doc = "The grip and scrollbar width, as a percent of the theme's rail." },
+ .{ .word = "InactiveDim", .action = .inactive_dim, .doc = "Fade the unfocused panes' text by a percentage, 0 through 100, 0 off." },
.{ .word = "Pet", .action = .{ .choice = .pet }, .doc = "The window's companion in the workspace tag's blank space: off, cat or frog." },
.{ .word = "MessageLinger", .action = .{ .message_ms = .linger }, .doc = "How long, in milliseconds, a message stays after what dismisses it." },
.{ .word = "MessageFall", .action = .{ .message_ms = .fall }, .doc = "How long, in milliseconds, a message takes to fall into its row." },
@@ -1050,6 +1059,7 @@ pub const Runtime = struct {
},
},
.motion => state.motion = stepped(animation.Motion.Flavour, state.motion, argument) orelse return false,
+ .inactive_dim => state.inactive_dim = number(u8, argument, " \t\r\n%", 0, 100) orelse return false,
.grip_width => state.grip_width = number(u16, argument, " \t\r\n%", 50, 300) orelse return false,
.callstack_depth => state.callstack_depth = number(u8, argument, " \t\r\n", 1, @import("lsp/lsp.zig").callstack_max_depth) orelse return false,
.tab => state.tab = number(u16, argument, " \t\r\n", 1, 16) orelse return false,
@@ -1084,7 +1094,7 @@ pub const Runtime = struct {
/// words (`choices`), else its range or the kind of thing it takes.
pub fn takes(action: Action) ?[]const u8 {
return choices(action) orelse switch (action) {
- .window_opacity, .window_blur => "0-100 (a percentage)",
+ .inactive_dim, .window_opacity, .window_blur => "0-100 (a percentage)",
.grip_width => "50-300 (a percentage)",
.tab => "1-16 (cells)",
.callstack_depth => "1-64 (levels)",
@@ -1178,7 +1188,7 @@ pub const Runtime = struct {
else
try out.print("{s} {s}\n", .{ setting.word, context.theme_name }),
// A number in a field named as its action.
- inline .window_opacity, .window_blur, .callstack_depth, .tab, .search_rows, .grip_width => |_, tag| try out.print("{s} {d}\n", .{ setting.word, @field(state, @tagName(tag)) }),
+ inline .window_opacity, .window_blur, .inactive_dim, .callstack_depth, .tab, .search_rows, .grip_width => |_, tag| try out.print("{s} {d}\n", .{ setting.word, @field(state, @tagName(tag)) }),
.dump_dir => {
const dir = if (state.dump_dir.len > 0) state.dump_dir.get() else context.default_dump_dir;
if (dir.len > 0) try out.print("{s} {s}\n", .{ setting.word, dir }) else try out.print("# {s} (none)\n", .{setting.word});
@@ -1386,8 +1396,8 @@ pub const Runtime = struct {
.{ "MessageLinger", "1500" }, .{ "MessageFall", "1500" }, .{ "MessageDissolve", "1500" },
.{ "DumpDir", "~/dumps" }, .{ "TermImages", "petscii" }, .{ "JumpScope", "all" },
.{ "SearchPlace", "column" }, .{ "SearchPane", "new" }, .{ "Motion", "playful" },
- .{ "GripWidth", "200" }, .{ "CallstackDepth", "16" }, .{ "Tab", "8" },
- .{ "SearchRows", "12" },
+ .{ "GripWidth", "200" }, .{ "InactiveDim", "35" }, .{ "CallstackDepth", "16" },
+ .{ "Tab", "8" }, .{ "SearchRows", "12" },
};
for (values) |v| try std.testing.expect(apply(&state, find(v[0]).?, v[1]));
try std.testing.expect(state.font.requested_name.set("Wanted Mono"));
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index c2a4cb4e..01a58eae 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -1310,7 +1310,9 @@ const Cover = packed struct(u16) {
pane_grip: bool = false,
/// In a grip's first row, where its button is.
grip_top: bool = false,
- _: u4 = 0,
+ /// In an unfocused pane's tag or body rows while InactiveDim fades them.
+ dim: bool = false,
+ _: u3 = 0,
};
/// Marks the grid cells a body or tag layer covers, which the layers paint
@@ -1341,6 +1343,10 @@ fn coverFrame(cover: []Cover, cols: u16, rows: u16, body_layers: []const pardes.
for (regions) |region| {
if (region.kind == .column_grip) bar = region.rect;
}
+ // InactiveDim: an unfocused pane's tag and body rows (Dim.begin).
+ if (dim.amount > 0) for (regions) |region| {
+ if ((region.kind == .tag or region.kind == .body) and dim.of(region.owner)) mark.rect(cover, cols, rows, region.rect, "dim", true);
+ };
for (regions) |region| switch (region.kind) {
.grip, .column_grip => {
mark.rect(cover, cols, rows, region.rect, "grip", true);
@@ -5440,6 +5446,7 @@ fn renderFrame(
const cells: u32 = @as(u32, surface.cols) * surface.rows;
try g.cover.resize(gpa, cells);
const covered = g.cover.items[0..cells];
+ dim.begin(core.settings.inactive_dim, surface.regionList());
coverFrame(covered, surface.cols, surface.rows, surface.bodyLayers(), surface.tagLayers(), surface.regionList());
try buildDecor(g, gpa, surface, &groups, layout, win_w, win_h, cursors_shown);
@@ -5828,6 +5835,7 @@ fn emitTagLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const p
// A window is rarely a whole number of cells wide: a band that ends at
// the last column runs on through the leftover pixels to the edge.
const band_right = if (win_w - right < bw) @max(right, win_w) else right;
+ const faded = (layer.kind == .pane or layer.kind == .notice) and dim.of(layer.id);
// A row to each line, each a grid row with the tagline's glyphs.
for (0..layer.rows) |index| {
const y = layer.viewport.y + @as(u16, @intCast(index));
@@ -5841,6 +5849,7 @@ fn emitTagLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const p
const cursor = if (layer.cursor) |cu| show_cursor and !cu.bar and cu.x == col and cu.y == index else false;
emitInstance(g, instances, next.*, @intCast(col), y, .{ .w = tw, .h = bh, .x_off = left, .y_off = slide }, win_w, win_h, .tagline, cells, col, line_cursor, cursor, page);
clipInstance(&instances[next.*], .{ -1e9, if (slide != 0) top else -1e9, right, 1e9 }, win_w, win_h);
+ if (faded and !cursor) dim.fade(&instances[next.*]);
next.* += 1;
}
}
@@ -5862,6 +5871,7 @@ fn emitBodyLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const
const left = @as(f32, @floatFromInt(layer.viewport.x)) * bw;
const right = left + @as(f32, @floatFromInt(layer.viewport.w)) * bw;
const bottom = @as(f32, @floatFromInt(layer.viewport.y + layer.viewport.h)) * bh;
+ const faded = dim.of(layer.id);
for (0..layer.rows) |index| {
const row: u16 = @intCast(index);
const top = layer.rowTop(row, bh, th);
@@ -5885,6 +5895,7 @@ fn emitBodyLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const
const glyph_top = top - (if (header) @as(f32, @floatFromInt(taglineBandOffset(0, win_h, g.cell_h, g.tagline_height))) else 0);
emitInstance(g, instances, next.*, 0, 0, .{ .w = width, .h = height, .x_off = left + @as(f32, @floatFromInt(col)) * width, .y_off = glyph_top }, win_w, win_h, role, line, col, line_cursor, cursor, page);
clipInstance(&instances[next.*], .{ -1e9, -1e9, right, bottom }, win_w, win_h);
+ if (faded and !cursor) dim.fade(&instances[next.*]);
next.* += 1;
}
if (layer.hasContextBorderAfter(row)) {
@@ -6077,10 +6088,12 @@ fn emitSurfaceCell(
instances[next.*].x0 += @as(f32, @floatFromInt(inset)) / win_w * 2;
instances[next.*].u0 += @as(f32, @floatFromInt(inset)) / atlas_w;
}
+ if (here.dim and !is_cursor) dim.fade(&instances[next.*]);
next.* += 1;
return;
}
emitInstance(g, instances, next.*, col, row, body_layout, win_w, win_h, role, line, at, cursor, is_cursor, page);
+ if (line_cover[at].dim and !is_cursor) dim.fade(&instances[next.*]);
next.* += 1;
}
@@ -7642,6 +7655,127 @@ fn updateDisplayScale(window: *c.SDL_Window) void {
display_scale = std.math.clamp(display_scale, 1, 4);
}
+/// InactiveDim: the unfocused panes' text faded toward its ground by the
+/// setting's percent, never below the pair's own contrast or 4.5, whichever
+/// is lower. The window's alone, from the regions' focus: renderFrame
+/// begins it each frame. ponytail: one window per process, as display_scale.
+var dim: Dim = .{};
+
+const Dim = struct {
+ amount: f32 = 0,
+ /// The pane with the keyboard, from its regions.
+ focused: u16 = pardes.Region.none,
+ /// The few ink and paper pairs a frame has, each faded once.
+ keys: [32]?[6]u8 = @splat(null),
+ values: [32][3]u8 = undefined,
+
+ fn begin(d: *Dim, percent: u8, regions: []const pardes.Region) void {
+ d.* = .{ .amount = @as(f32, @floatFromInt(@min(percent, 100))) / 100 };
+ for (regions) |region| if (region.active and (region.kind == .grip or region.kind == .tag or region.kind == .body)) {
+ d.focused = region.owner;
+ break;
+ };
+ if (d.focused == pardes.Region.none) d.amount = 0;
+ }
+
+ /// Whether pane `owner`'s text fades this frame.
+ fn of(d: *const Dim, owner: u16) bool {
+ return d.amount > 0 and owner != d.focused;
+ }
+
+ /// A cell instance's ink faded toward its ground.
+ fn fade(d: *Dim, instance: *CellInstance) void {
+ const ink = d.faded(byteRgb(.{ instance.fr, instance.fg, instance.fb }), byteRgb(.{ instance.br, instance.bg, instance.bb }));
+ instance.fr = @as(f32, @floatFromInt(ink[0])) / 255.0;
+ instance.fg = @as(f32, @floatFromInt(ink[1])) / 255.0;
+ instance.fb = @as(f32, @floatFromInt(ink[2])) / 255.0;
+ }
+
+ fn faded(d: *Dim, ink: [3]u8, paper: [3]u8) [3]u8 {
+ const key = ink ++ paper;
+ const slot = (@as(usize, ink[0]) *% 31 +% @as(usize, ink[1]) *% 7 +% ink[2] +% @as(usize, paper[0]) *% 13 +% @as(usize, paper[1]) *% 3 +% paper[2]) % d.keys.len;
+ if (d.keys[slot]) |held| if (std.mem.eql(u8, &held, &key)) return d.values[slot];
+ // Contrast falls as the ink nears its paper: the most of `amount`
+ // that keeps the pair at its own contrast or 4.5, whichever is lower.
+ const floor = @min(pardes.colors.contrast(ink, paper), 4.5);
+ var t = d.amount;
+ if (pardes.colors.contrast(blendLinear(ink, paper, t), paper) < floor) {
+ var lo: f32 = 0;
+ var hi: f32 = t;
+ for (0..8) |_| {
+ const mid = (lo + hi) / 2;
+ if (pardes.colors.contrast(blendLinear(ink, paper, mid), paper) >= floor) lo = mid else hi = mid;
+ }
+ t = lo;
+ }
+ d.keys[slot] = key;
+ d.values[slot] = blendLinear(ink, paper, t);
+ return d.values[slot];
+ }
+
+ fn byteRgb(rgb: [3]f32) [3]u8 {
+ var out: [3]u8 = undefined;
+ for (&out, rgb) |*o, v| o.* = @intFromFloat(@round(std.math.clamp(v, 0, 1) * 255));
+ return out;
+ }
+};
+
+/// `t` of the way from one colour to the other in linear light, so a
+/// coloured ink does not muddy on its way to the paper.
+fn blendLinear(from: [3]u8, to: [3]u8, t: f32) [3]u8 {
+ var out: [3]u8 = undefined;
+ for (&out, from, to) |*o, a, b| {
+ const l = pardes.colors.to_linear[a] * (1 - t) + pardes.colors.to_linear[b] * t;
+ o.* = encoded[@intFromFloat(@round(std.math.clamp(l, 0, 1) * (encoded.len - 1)))];
+ }
+ return out;
+}
+
+/// Linear light back to an sRGB channel, in 4096 steps.
+const encoded: [4096]u8 = blk: {
+ @setEvalBranchQuota(1_000_000);
+ var table: [4096]u8 = undefined;
+ for (&table, 0..) |*out, i| {
+ const l = @as(f64, @floatFromInt(i)) / 4095;
+ const v = if (l <= 0.0031308) l * 12.92 else 1.055 * std.math.pow(f64, l, 1.0 / 2.4) - 0.055;
+ out.* = @intFromFloat(@round(v * 255));
+ }
+ break :blk table;
+};
+
+test "InactiveDim fades the unfocused panes' rows alone, never below the text's floor" {
+ const gpa = std.testing.allocator;
+ const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
+ defer core.deinit();
+ _ = try core.newShell(1, "");
+ try std.testing.expect(pardes.layout.splitColumn(core, 0, 1, false));
+ core.sync();
+ const s = try core.render(core.scratch.allocator());
+ defer dim = .{};
+ dim.begin(60, s.regionList());
+ try std.testing.expect(dim.focused != pardes.Region.none);
+ var cover: [80 * 24]Cover = undefined;
+ coverFrame(&cover, 80, 24, &.{}, &.{}, s.regionList());
+ var seen: [2]bool = .{ false, false };
+ for (s.regionList()) |region| if (region.kind == .body or region.kind == .tag) {
+ const unfocused = region.owner != dim.focused;
+ try std.testing.expectEqual(unfocused, cover[@as(usize, region.rect.y) * 80 + region.rect.x].dim);
+ seen[@intFromBool(unfocused)] = true;
+ } else if (region.kind == .grip) try std.testing.expect(!cover[@as(usize, region.rect.y) * 80 + region.rect.x].dim);
+ try std.testing.expect(seen[0] and seen[1]);
+ // Toward the ground, a pair already near its floor no further.
+ var instance: CellInstance = std.mem.zeroes(CellInstance);
+ instance.fr = 0.9;
+ instance.fg = 0.9;
+ instance.fb = 0.9;
+ dim.fade(&instance);
+ try std.testing.expect(instance.fr < 0.9 and instance.fr > 0);
+ try std.testing.expect(pardes.colors.contrast(Dim.byteRgb(.{ instance.fr, instance.fg, instance.fb }), .{ 0, 0, 0 }) >= 4.5 - 1e-3);
+ // Off, nothing fades.
+ dim.begin(0, s.regionList());
+ try std.testing.expect(!dim.of(0) and !dim.of(1));
+}
+
/// A logical pixel size in the display's pixels: rounded, at least one.
fn dp(logical: f32) f32 {
return @max(1, @round(logical * display_scale));