summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/TerminalImages.zig15
-rw-r--r--src/surface.zig6
-rw-r--r--src/tty/tty.zig2
3 files changed, 20 insertions, 3 deletions
diff --git a/src/TerminalImages.zig b/src/TerminalImages.zig
index f3333460..f26b5852 100644
--- a/src/TerminalImages.zig
+++ b/src/TerminalImages.zig
@@ -162,6 +162,14 @@ pub fn draw(
const ch: u32 = @max(1, p.cell_pixels.h);
const pixels = p.native_images and !ti.petscii;
const ctx: Ctx = .{ .ti = ti, .p = p, .s = s, .pane = pane_id, .serial = serial, .tx = tx, .body_y = body_y, .cols = cols, .rows_of = rows_of, .cw = cw, .ch = ch, .pixels = pixels };
+ // Handed on lowest z first (the storage's order is a hash map's), the
+ // order a shell draws them in; equal z keeps the order they came in.
+ const first = s.nimages;
+ defer std.sort.insertion(?pardes.ImagePlace, s.images[first..s.nimages], {}, struct {
+ fn lessThan(_: void, a: ?pardes.ImagePlace, b: ?pardes.ImagePlace) bool {
+ return (if (a) |x| x.z else 0) < (if (b) |y| y.z else 0);
+ }
+ }.lessThan);
// Virtual placements: shown through the placeholder cells, one run of
// them on a row at a time. The placeholders themselves are not text.
@@ -181,7 +189,7 @@ pub fn draw(
const target = storage.placeholderTarget(run.image_id, run.placement_id) orelse continue;
const rp = run.renderPlacement(&target.placement, &img, cw, ch) catch continue;
if (rp.dest_width == 0 or rp.dest_height == 0 or rp.source_width == 0 or rp.source_height == 0) continue;
- ctx.place(img, .{ .x = rp.source_x, .y = rp.source_y, .w = rp.source_width, .h = rp.source_height }, .{
+ ctx.place(img, target.placement.z, .{ .x = rp.source_x, .y = rp.source_y, .w = rp.source_width, .h = rp.source_height }, .{
.x = @as(i64, at.viewport.x) * cw + rp.offset_x,
.y = @as(i64, v) * ch + rp.offset_y,
.w = rp.dest_width,
@@ -223,7 +231,7 @@ pub fn draw(
const sw = if (placed.source_width > 0) @min(placed.source_width, img.width - sx) else img.width - sx;
const sh = if (placed.source_height > 0) @min(placed.source_height, img.height - sy) else img.height - sy;
if (size.width == 0 or size.height == 0 or sw == 0 or sh == 0) continue;
- ctx.place(img, .{ .x = sx, .y = sy, .w = sw, .h = sh }, .{
+ ctx.place(img, placed.z, .{ .x = sx, .y = sy, .w = sw, .h = sh }, .{
.x = (@as(i64, at.screen.x) + dx) * cw + placed.x_offset,
.y = (@as(i64, at.screen.y) - @as(i64, origin.screen.y) + dy) * ch + placed.y_offset,
.w = size.width,
@@ -248,7 +256,7 @@ const Ctx = struct {
/// Draw `src` of `img` over `dst`, one cell row of it at a time: a row
/// is shown, or not, or shown elsewhere, as the body lays it out.
- fn place(ctx: Ctx, img: gfx.Image, src: PixelRect, dst: Rect) void {
+ fn place(ctx: Ctx, img: gfx.Image, z: i32, src: PixelRect, dst: Rect) void {
const cw: i64 = ctx.cw;
const ch: i64 = ctx.ch;
const x0 = @max(dst.x, 0);
@@ -294,6 +302,7 @@ const Ctx = struct {
.rgba = rgba,
.iw = img.width,
.ih = img.height,
+ .z = z,
});
continue;
}
diff --git a/src/surface.zig b/src/surface.zig
index 8ed4074c..aa0068e3 100644
--- a/src/surface.zig
+++ b/src/surface.zig
@@ -257,6 +257,12 @@ pub const ImagePlace = struct {
rgba: []const u8,
iw: usize,
ih: usize,
+ /// A terminal's kitty graphics stacking order (`z=`): the surface lists
+ /// a pane's images lowest first, so a shell drawing them in order puts
+ /// a higher one over a lower; below 0 the program means it under the
+ /// text, which the tty passes on to the outer terminal (the GUI draws
+ /// every image over the cells still). 0 for every other image.
+ z: i32 = 0,
/// Rows [y, y+h) of `rgba` are the only ones that differ from the
/// same pane page at revision `from`: a shell still holding that one may
/// update just these rows instead of taking the whole image again.
diff --git a/src/tty/tty.zig b/src/tty/tty.zig
index 5ad02c28..a358051e 100644
--- a/src/tty/tty.zig
+++ b/src/tty/tty.zig
@@ -847,6 +847,8 @@ fn exactKittyPlacement(
.height = std.math.cast(u16, src_h) orelse return null,
},
.pixel_offset = if (pixel_x != 0 or pixel_y != 0) .{ .x = @intCast(pixel_x), .y = @intCast(pixel_y) } else null,
+ // The outer terminal stacks them, under the text below 0.
+ .z_index = if (place.z != 0) place.z else null,
.size = if (full)
.{ .cols = std.math.cast(u16, cols) orelse return null, .rows = 1 }
else