diff --git a/src/terminal/kitty/graphics_exec.zig b/src/terminal/kitty/graphics_exec.zig index e7fcac5f5..005ee39a5 100644 --- a/src/terminal/kitty/graphics_exec.zig +++ b/src/terminal/kitty/graphics_exec.zig @@ -108,6 +108,9 @@ fn transmit( }; img.deinit(alloc); + // After the image is added, set the ID in case it changed + result.id = img.id; + return result; } @@ -182,8 +185,15 @@ fn loadAndAddImage( var img = try Image.load(alloc, cmd); errdefer img.deinit(alloc); + // If the image has no ID, we assign one + const storage = &terminal.screen.kitty_images; + if (img.id == 0) { + img.id = storage.next_id; + storage.next_id +%= 1; + } + // Store our image - try terminal.screen.kitty_images.addImage(alloc, img); + try storage.addImage(alloc, img); return img; } diff --git a/src/terminal/kitty/graphics_storage.zig b/src/terminal/kitty/graphics_storage.zig index 6ea9fed19..a59303238 100644 --- a/src/terminal/kitty/graphics_storage.zig +++ b/src/terminal/kitty/graphics_storage.zig @@ -16,6 +16,10 @@ pub const ImageStorage = struct { const ImageMap = std.AutoHashMapUnmanaged(u32, Image); const PlacementMap = std.AutoHashMapUnmanaged(PlacementKey, Placement); + /// This is the next automatically assigned ID. We start mid-way + /// through the u32 range to avoid collisions with buggy programs. + next_id: u32 = 2147483647, + /// The set of images that are currently known. images: ImageMap = .{},