mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 16:26:08 +03:00
terminal/kitty-gfx: assign an internal image id
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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 = .{},
|
||||
|
||||
|
Reference in New Issue
Block a user