From 46dd6e6caf7f8d2a1c08b620bcf60cd6835b5803 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 22 Jan 2024 15:51:30 -0800 Subject: [PATCH] kitty graphics: assign automatic placement ID if p==0 Fixes #1356 As stated in the code, the specification itself doesn't explicitly specify this behavior (as far as I can tell), but testing in Kitty results in this working and I believe this is how they do it. --- src/terminal/kitty/graphics_exec.zig | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/terminal/kitty/graphics_exec.zig b/src/terminal/kitty/graphics_exec.zig index 70c63db7e..92efe00de 100644 --- a/src/terminal/kitty/graphics_exec.zig +++ b/src/terminal/kitty/graphics_exec.zig @@ -170,6 +170,16 @@ fn display( .placement_id = d.placement_id, }; + // If the placement has no ID, we assign one. This is not in the spec + // but Kitty appears to support the behavior where specifying multiple + // placements with ID 0 creates new placements rather than replacing + // the existing placement. + if (result.placement_id == 0) { + const storage = &terminal.screen.kitty_images; + result.placement_id = storage.next_id; + storage.next_id +%= 1; + } + // Verify the requested image exists if we have an ID const storage = &terminal.screen.kitty_images; const img_: ?Image = if (d.image_id != 0) @@ -203,7 +213,12 @@ fn display( .rows = d.rows, .z = d.z, }; - storage.addPlacement(alloc, img.id, d.placement_id, p) catch |err| { + storage.addPlacement( + alloc, + img.id, + result.placement_id, + p, + ) catch |err| { encodeError(&result, err); return result; };