![]() |
libghostty
|
API for the images that programs send with the Kitty graphics protocol.
The terminal keeps every image a program sends, and every placement of an image on screen, in an image storage. Each screen (main and alternate) has its own. GhosttyKittyGraphics is a handle to the storage of the active screen. Use it to:
This API doesn't tell you where to draw images. The render state does that. See "Drawing Images" below.
Kitty graphics are off until you give the terminal a storage limit with GHOSTTY_TERMINAL_OPT_KITTY_IMAGE_STORAGE_LIMIT. To accept PNG images, also install a PNG decoder with ghostty_sys_set() and GHOSTTY_SYS_OPT_DECODE_PNG, as in this example:
Get the storage handle with ghostty_terminal_get() and GHOSTTY_TERMINAL_DATA_KITTY_GRAPHICS. The handle is borrowed from the terminal. It stays valid until the next call that changes the terminal, such as ghostty_terminal_vt_write() or ghostty_terminal_reset(), so get it again after each of those.
Use the render state's image list to find what to draw. It lists every Kitty image on screen, however the program placed it:
Each entry already has its position, size, source rectangle, layer and z-index worked out, so one drawing routine handles all of them. See "Images" in the Render State documentation for the details.
The storage only provides the pixels. Each entry in the list has an image ID. Look it up with ghostty_kitty_graphics_image(), then read the image's size, pixel format and pixels with ghostty_kitty_graphics_image_get(). The pixels are always decoded and uncompressed, so you can upload them as they are:
Don't also draw images from this API's placement iterator. The render state's list already includes those placements, so they would be drawn twice. See "Inspecting the Storage" below for what the iterator is for.
Most frames don't change any image, so a renderer can skip most of its image work. Two values tell you what to redo:
Use the image generation as part of your texture cache key. Don't rely on the image's size or data length instead: a program can send new pixels with the same size under the same ID.
Here is a frame loop that reads the list only when it changed:
The storage also has a generation of its own, GHOSTTY_KITTY_GRAPHICS_DATA_GENERATION. It changes whenever a program sends, places or deletes an image, but not when images only move on screen. It can't tell you when to read the render state's list again. It is useful for work that only depends on what the storage holds, such as freeing textures of images that were deleted.
The two storage generations are never reused, not even across the main and alternate screens, terminal resets, or different terminals. That makes either one safe to use as a cache key on its own. The render state's placements generation is different: only compare it with the last value you read from the same render state.
The Kitty graphics protocol lets programs send images with several frames and ask the terminal to play them, much like an animated GIF. The terminal stores every frame, but it does not keep its own timer. Your application drives playback by calling ghostty_kitty_graphics_animation_tick().
Each call shows whichever frame is due at the time you pass in. When an image moves to a new frame, two things change:
If you already cache textures by image generation (see "Knowing What Changed" above), new frames appear without any extra work.
The tick also tells you when the next frame is due. Use that time to schedule a single redraw instead of calling the tick in a loop:
You never need to watch for animations starting. A program starts or resumes playback by writing a command to the terminal, and that write already gives you a reason to redraw. The tick on that redraw picks up the animation. A terminal with no playing animations costs nothing extra.
Here is a helper that follows these steps. A renderer calls it once per frame and uses the result to schedule the next redraw:
The example below plays a two-frame animation with that helper. It uses a pretend clock so that it runs instantly:
A program can place an image with text instead of at a cell. It creates a virtual placement, which has no position of its own, and prints placeholder characters (U+10EEEE) where the image should appear. The image then moves with those characters, like text. Programs such as tmux use this so that images scroll, move and disappear along with the text around them.
Only the cells know where these images are, so the storage can't tell you. The render state finds the placeholder cells and lists each part of the image like any other entry, so you draw them the same way as every other image. See "Kitty Graphics Placeholders" in the Render State documentation.
A GhosttyKittyGraphicsPlacementIterator lists every placement in the storage, including placements that are off screen and virtual placements. Use it for tools such as debuggers or tests that need to see what the storage holds. A renderer doesn't need it.
These functions work out the geometry of the iterator's current placement from the storage:
They only know about placements at a cell, and placements relative to one. They can't find virtual placements, or placements relative to a virtual placement, because those depend on the cells. The render state gives the same values for every entry in its list, so prefer it whenever you are drawing.
All handles borrowed from the terminal (GhosttyKittyGraphics, GhosttyKittyGraphicsImage) become invalid after any call that changes the terminal. The placement iterator belongs to you and must be freed, but the values it returns are only valid until the terminal changes.
The following example creates a terminal, places one image at a cell and another with placeholder cells, lists both from the render state, and reads each image's pixels from the storage:
Typedefs | |
| typedef struct GhosttyKittyGraphicsImpl * | GhosttyKittyGraphics |
| typedef const struct GhosttyKittyGraphicsImageImpl * | GhosttyKittyGraphicsImage |
| typedef struct GhosttyKittyGraphicsPlacementIteratorImpl * | GhosttyKittyGraphicsPlacementIterator |
Data Structures | |
| struct | GhosttyKittyGraphicsPlacementRenderInfo |
| typedef struct GhosttyKittyGraphicsImpl* GhosttyKittyGraphics |
Opaque handle to a Kitty graphics image storage.
Obtained via ghostty_terminal_get() with GHOSTTY_TERMINAL_DATA_KITTY_GRAPHICS. The pointer is borrowed from the terminal and remains valid until the next mutating terminal call (e.g. ghostty_terminal_vt_write() or ghostty_terminal_reset()).
| typedef const struct GhosttyKittyGraphicsImageImpl* GhosttyKittyGraphicsImage |
Opaque handle to a Kitty graphics image.
Obtained via ghostty_kitty_graphics_image() with an image ID. The pointer is borrowed from the storage and remains valid until the next mutating terminal call.
| typedef struct GhosttyKittyGraphicsPlacementIteratorImpl* GhosttyKittyGraphicsPlacementIterator |
Queryable data kinds for ghostty_kitty_graphics_get().
| Enumerator | |
|---|---|
| GHOSTTY_KITTY_GRAPHICS_DATA_INVALID | Invalid / sentinel value. |
| GHOSTTY_KITTY_GRAPHICS_DATA_PLACEMENT_ITERATOR | Populate a pre-allocated placement iterator with placement data from the storage. Iterator data is only valid as long as the underlying terminal is not mutated. Output type: GhosttyKittyGraphicsPlacementIterator * |
| GHOSTTY_KITTY_GRAPHICS_DATA_GENERATION | A value that changes whenever a program sends, replaces, places or deletes an image. It is 0 if nothing has changed the storage yet, which means the storage is empty. If the value matches the last one you read, the storage holds the same images and placements as before. The placements may still have moved on screen, because scrolling and resizing move them without changing the storage. So this value can't tell you when to read the render state's image list again. For that, use GHOSTTY_RENDER_STATE_DATA_IMAGE_PLACEMENTS_GENERATION. See "Knowing What Changed" in the Kitty Graphics documentation. A value is never reused, not even by another screen, after a reset, or by another terminal. You can use it as a cache key on its own. Output type: uint64_t * |
Definition at line 238 of file kitty_graphics.h.
Queryable data kinds for ghostty_kitty_graphics_image_get().
| Enumerator | |
|---|---|
| GHOSTTY_KITTY_IMAGE_DATA_INVALID | Invalid / sentinel value. |
| GHOSTTY_KITTY_IMAGE_DATA_ID | The image ID. Output type: uint32_t * |
| GHOSTTY_KITTY_IMAGE_DATA_NUMBER | The image number. Output type: uint32_t * |
| GHOSTTY_KITTY_IMAGE_DATA_WIDTH | Image width in pixels. Output type: uint32_t * |
| GHOSTTY_KITTY_IMAGE_DATA_HEIGHT | Image height in pixels. Output type: uint32_t * |
| GHOSTTY_KITTY_IMAGE_DATA_FORMAT | Pixel format of the image. Never GHOSTTY_KITTY_IMAGE_FORMAT_PNG; PNG payloads are decoded to RGBA before storage. Output type: GhosttyKittyImageFormat * |
| GHOSTTY_KITTY_IMAGE_DATA_COMPRESSION | Compression of the image. Always GHOSTTY_KITTY_IMAGE_COMPRESSION_NONE; compressed payloads are inflated before storage. Output type: GhosttyKittyImageCompression * |
| GHOSTTY_KITTY_IMAGE_DATA_DATA_PTR | Borrowed pointer to the raw pixel data. Valid as long as the underlying terminal is not mutated. Returns GHOSTTY_NO_VALUE when the image metadata is resident but its pixel payload is pending. The data is always fully decoded, uncompressed pixels in the format reported by GHOSTTY_KITTY_IMAGE_DATA_FORMAT: zlib payloads are inflated and PNG payloads are decoded to RGBA at transmission time, before the image is stored. Consumers can upload this directly to the GPU without any decode step. For an animated image (Kitty graphics animation, actions a=f/a=a) this is the pixel data of the current animation frame. The image's GHOSTTY_KITTY_IMAGE_DATA_GENERATION changes whenever the current frame changes, so generation-keyed caches remain coherent. Output type: const uint8_t ** |
| GHOSTTY_KITTY_IMAGE_DATA_DATA_LEN | Length of the raw pixel data in bytes. Always equal to width * height * bytes-per-pixel for the reported format. For a pending image, this is the expected length reserved against the storage limit even though DATA_PTR is not available yet. Output type: size_t * |
| GHOSTTY_KITTY_IMAGE_DATA_GENERATION | A value that changes whenever this image's pixels may have changed: when a program sends the image or replaces it, and when an animation moves to a new frame. Use it as part of your texture cache key. If it matches the texture you have, you don't need to read the pixels again. The render state reports the same value for each of its entries as GHOSTTY_RENDER_STATE_IMAGE_DATA_IMAGE_GENERATION. Don't use the image's size or data length to detect changes instead. A program can send new pixels of the same size under the same ID. A value is never reused, not even by another image, another screen, or another terminal. It is never 0 for a stored image, so you can use 0 to mean "no texture yet". One case doesn't change this value. When a program finishes sending an image whose pixels were still on the way, the image keeps its value, and GHOSTTY_KITTY_IMAGE_DATA_DATA_PTR starts returning the pixels. GHOSTTY_KITTY_GRAPHICS_DATA_GENERATION changes when that happens, so read DATA_PTR again then. Output type: uint64_t * |
Definition at line 462 of file kitty_graphics.h.
Queryable data kinds for ghostty_kitty_graphics_placement_get().
| Enumerator | |
|---|---|
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_INVALID | Invalid / sentinel value. |
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IMAGE_ID | The image ID this placement belongs to. Output type: uint32_t * |
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_PLACEMENT_ID | The placement ID. Output type: uint32_t * |
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IS_VIRTUAL | Whether this is a virtual placement, which a program shows with Unicode placeholder cells. A virtual placement appears wherever its placeholder cells are, so the storage has no position for it. The render state's image list positions it from its cells like any other placement, so a renderer doesn't need to check this. See "Unicode Placeholders" in the Kitty Graphics documentation. Output type: bool * |
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_X_OFFSET | Pixel offset from the left edge of the cell. Output type: uint32_t * |
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Y_OFFSET | Pixel offset from the top edge of the cell. Output type: uint32_t * |
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_X | Source rectangle x origin in pixels. Output type: uint32_t * |
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_Y | Source rectangle y origin in pixels. Output type: uint32_t * |
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_WIDTH | Source rectangle width in pixels (0 = full image width). Output type: uint32_t * |
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_HEIGHT | Source rectangle height in pixels (0 = full image height). Output type: uint32_t * |
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_COLUMNS | Number of columns this placement occupies. Output type: uint32_t * |
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_ROWS | Number of rows this placement occupies. Output type: uint32_t * |
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Z | Z-index for this placement. Output type: int32_t * |
Definition at line 278 of file kitty_graphics.h.
Settable options for ghostty_kitty_graphics_placement_iterator_set().
| Enumerator | |
|---|---|
| GHOSTTY_KITTY_GRAPHICS_PLACEMENT_ITERATOR_OPTION_LAYER | Only return placements in one layer. See GhosttyKittyPlacementLayer. Input type: GhosttyKittyPlacementLayer * |
Definition at line 410 of file kitty_graphics.h.
Compression of a Kitty graphics image.
Note that stored images are always decompressed: GHOSTTY_KITTY_IMAGE_COMPRESSION_ZLIB_DEFLATE payloads are inflated before storage, so ghostty_kitty_graphics_image_get() always reports GHOSTTY_KITTY_IMAGE_COMPRESSION_NONE. Consumers never need to inflate image data themselves.
Definition at line 451 of file kitty_graphics.h.
Pixel format of a Kitty graphics image.
Note that stored images are always fully decoded: GHOSTTY_KITTY_IMAGE_FORMAT_PNG is never returned by ghostty_kitty_graphics_image_get() because PNG payloads are decoded to GHOSTTY_KITTY_IMAGE_FORMAT_RGBA before storage. The PNG value exists only for protocol-level completeness.
Definition at line 431 of file kitty_graphics.h.
A layer to limit the storage placement iterator to, set with GHOSTTY_KITTY_GRAPHICS_PLACEMENT_ITERATOR_OPTION_LAYER.
The Kitty graphics protocol picks a placement's layer from its z-index, as each value below describes. This filter is only for the storage iterator. To draw, use the layer the render state gives each entry (GHOSTTY_RENDER_STATE_IMAGE_DATA_LAYER). It follows the same rules, and it also covers virtual placements, which are always drawn below the text.
Definition at line 389 of file kitty_graphics.h.
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_animation_tick | ( | GhosttyKittyGraphics | graphics, |
| uint64_t | now_ms, | ||
| uint64_t * | next_ms ) |
Advance playing animations and get the time of the next frame.
Every playing animation moves to the frame that is due at now_ms. An animation moves forward at most one frame per call. If calls arrive late, playback slows down rather than skipping frames.
Images that moved to a new frame get a new GHOSTTY_KITTY_IMAGE_DATA_GENERATION, and their GHOSTTY_KITTY_IMAGE_DATA_DATA_PTR returns the new frame's pixels.
Time is measured in milliseconds on a clock you choose, such as the time since your application started. The clock must only move forward, and you must keep using the same clock with the same starting point for as long as the terminal exists. The time written to next_ms uses the same clock.
This call changes the image storage. Like ghostty_terminal_vt_write(), it invalidates any GhosttyKittyGraphicsImage handles and image data pointers you are holding, so look images up again afterwards. The GhosttyKittyGraphics handle itself stays valid.
Call this once each time you prepare a frame to draw, not in a loop. The "Animation" section of Kitty Graphics explains how to schedule redraws with the returned time and includes an example.
| graphics | The kitty graphics handle | |
| now_ms | The current time in milliseconds | |
| [out] | next_ms | Set to the time the next frame is due, in milliseconds on the same clock as now_ms. Only written when the function returns GHOSTTY_SUCCESS. |
References ghostty_kitty_graphics_animation_tick().
Referenced by ghostty_kitty_graphics_animation_tick().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_get | ( | GhosttyKittyGraphics | graphics, |
| GhosttyKittyGraphicsData | data, | ||
| void * | out ) |
Get data from a kitty graphics storage instance.
The output pointer must be of the appropriate type for the requested data kind.
Returns GHOSTTY_NO_VALUE when Kitty graphics are disabled at build time.
| graphics | The kitty graphics handle | |
| data | The type of data to extract | |
| [out] | out | Pointer to store the extracted data |
References ghostty_kitty_graphics_get().
Referenced by ghostty_kitty_graphics_get().
| GHOSTTY_API GhosttyKittyGraphicsImage ghostty_kitty_graphics_image | ( | GhosttyKittyGraphics | graphics, |
| uint32_t | image_id ) |
Look up a Kitty graphics image by its image ID.
Returns NULL if no image with the given ID exists or if Kitty graphics are disabled at build time.
| graphics | The kitty graphics handle |
| image_id | The image ID to look up |
References ghostty_kitty_graphics_image().
Referenced by ghostty_kitty_graphics_image().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_image_get | ( | GhosttyKittyGraphicsImage | image, |
| GhosttyKittyGraphicsImageData | data, | ||
| void * | out ) |
Get data from a Kitty graphics image.
The output pointer must be of the appropriate type for the requested data kind.
| image | The image handle (NULL returns GHOSTTY_INVALID_VALUE) | |
| data | The data kind to query | |
| [out] | out | Pointer to receive the queried value |
References ghostty_kitty_graphics_image_get().
Referenced by ghostty_kitty_graphics_image_get().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_image_get_multi | ( | GhosttyKittyGraphicsImage | image, |
| size_t | count, | ||
| const GhosttyKittyGraphicsImageData * | keys, | ||
| void ** | values, | ||
| size_t * | out_written ) |
Get multiple data fields from a Kitty graphics image in a single call.
This is an optimization over calling ghostty_kitty_graphics_image_get() repeatedly, particularly useful in environments with high per-call overhead such as FFI or Cgo.
Each element in the keys array specifies a data kind, and the corresponding element in the values array receives the result. The type of each values[i] pointer must match the output type documented for keys[i].
Processing stops at the first error; on success out_written is set to count, on error it is set to the index of the failing key (i.e. the number of values successfully written).
| image | The image handle (NULL returns GHOSTTY_INVALID_VALUE) | |
| count | Number of key/value pairs | |
| keys | Array of data kinds to query | |
| values | Array of output pointers (types must match each key's documented output type) | |
| [out] | out_written | On return, receives the number of values successfully written (may be NULL) |
References ghostty_kitty_graphics_image_get_multi().
Referenced by ghostty_kitty_graphics_image_get_multi().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_get | ( | GhosttyKittyGraphicsPlacementIterator | iterator, |
| GhosttyKittyGraphicsPlacementData | data, | ||
| void * | out ) |
Get data from the current placement in a placement iterator.
Call ghostty_kitty_graphics_placement_next() at least once before calling this function.
| iterator | The iterator handle (NULL returns GHOSTTY_INVALID_VALUE) | |
| data | The data kind to query | |
| [out] | out | Pointer to receive the queried value |
References ghostty_kitty_graphics_placement_get().
Referenced by ghostty_kitty_graphics_placement_get().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_get_multi | ( | GhosttyKittyGraphicsPlacementIterator | iterator, |
| size_t | count, | ||
| const GhosttyKittyGraphicsPlacementData * | keys, | ||
| void ** | values, | ||
| size_t * | out_written ) |
Get multiple data fields from the current placement in a single call.
This is an optimization over calling ghostty_kitty_graphics_placement_get() repeatedly, particularly useful in environments with high per-call overhead such as FFI or Cgo.
Each element in the keys array specifies a data kind, and the corresponding element in the values array receives the result. The type of each values[i] pointer must match the output type documented for keys[i].
Processing stops at the first error; on success out_written is set to count, on error it is set to the index of the failing key (i.e. the number of values successfully written).
| iterator | The iterator handle (NULL returns GHOSTTY_INVALID_VALUE) | |
| count | Number of key/value pairs | |
| keys | Array of data kinds to query | |
| values | Array of output pointers (types must match each key's documented output type) | |
| [out] | out_written | On return, receives the number of values successfully written (may be NULL) |
References ghostty_kitty_graphics_placement_get_multi().
Referenced by ghostty_kitty_graphics_placement_get_multi().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_grid_size | ( | GhosttyKittyGraphicsPlacementIterator | iterator, |
| GhosttyKittyGraphicsImage | image, | ||
| GhosttyTerminal | terminal, | ||
| uint32_t * | out_cols, | ||
| uint32_t * | out_rows ) |
Compute the grid cell size of the current placement.
Returns the number of columns and rows that the placement occupies in the terminal grid. If the placement specifies explicit columns and rows, those are returned directly; otherwise they are calculated from the pixel size and cell dimensions.
| iterator | The placement iterator positioned on a placement | |
| image | The image handle for this placement's image | |
| terminal | The terminal handle | |
| [out] | out_cols | On success, receives the number of columns |
| [out] | out_rows | On success, receives the number of rows |
References ghostty_kitty_graphics_placement_grid_size().
Referenced by ghostty_kitty_graphics_placement_grid_size().
| GHOSTTY_API void ghostty_kitty_graphics_placement_iterator_free | ( | GhosttyKittyGraphicsPlacementIterator | iterator | ) |
Free a placement iterator.
| iterator | The iterator handle to free (may be NULL) |
References ghostty_kitty_graphics_placement_iterator_free().
Referenced by ghostty_kitty_graphics_placement_iterator_free().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_iterator_new | ( | const GhosttyAllocator * | allocator, |
| GhosttyKittyGraphicsPlacementIterator * | out_iterator ) |
Create a new placement iterator instance.
All fields except the allocator are left undefined until populated via ghostty_kitty_graphics_get() with GHOSTTY_KITTY_GRAPHICS_DATA_PLACEMENT_ITERATOR.
| allocator | Pointer to allocator, or NULL to use the default allocator | |
| [out] | out_iterator | On success, receives the created iterator handle |
References ghostty_kitty_graphics_placement_iterator_new().
Referenced by ghostty_kitty_graphics_placement_iterator_new().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_iterator_set | ( | GhosttyKittyGraphicsPlacementIterator | iterator, |
| GhosttyKittyGraphicsPlacementIteratorOption | option, | ||
| const void * | value ) |
Set an option on a placement iterator.
Use GHOSTTY_KITTY_GRAPHICS_PLACEMENT_ITERATOR_OPTION_LAYER with a GhosttyKittyPlacementLayer value to filter placements by z-layer. The filter is applied during iteration: ghostty_kitty_graphics_placement_next() will skip placements that do not match the configured layer.
The default layer is GHOSTTY_KITTY_PLACEMENT_LAYER_ALL (no filtering).
| iterator | The iterator handle (NULL returns GHOSTTY_INVALID_VALUE) |
| option | The option to set |
| value | Pointer to the value (type depends on option; NULL returns GHOSTTY_INVALID_VALUE) |
References ghostty_kitty_graphics_placement_iterator_set().
Referenced by ghostty_kitty_graphics_placement_iterator_set().
| GHOSTTY_API bool ghostty_kitty_graphics_placement_next | ( | GhosttyKittyGraphicsPlacementIterator | iterator | ) |
Advance the placement iterator to the next placement.
If a layer filter has been set via ghostty_kitty_graphics_placement_iterator_set(), only placements matching that layer are returned.
| iterator | The iterator handle (may be NULL) |
References ghostty_kitty_graphics_placement_next().
Referenced by ghostty_kitty_graphics_placement_next().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_pixel_size | ( | GhosttyKittyGraphicsPlacementIterator | iterator, |
| GhosttyKittyGraphicsImage | image, | ||
| GhosttyTerminal | terminal, | ||
| uint32_t * | out_width, | ||
| uint32_t * | out_height ) |
Compute the rendered pixel size of the current placement.
Takes into account the placement's source rectangle, specified columns/rows, and aspect ratio to calculate the final rendered pixel dimensions.
| iterator | The placement iterator positioned on a placement | |
| image | The image handle for this placement's image | |
| terminal | The terminal handle | |
| [out] | out_width | On success, receives the width in pixels |
| [out] | out_height | On success, receives the height in pixels |
References ghostty_kitty_graphics_placement_pixel_size().
Referenced by ghostty_kitty_graphics_placement_pixel_size().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_rect | ( | GhosttyKittyGraphicsPlacementIterator | iterator, |
| GhosttyKittyGraphicsImage | image, | ||
| GhosttyTerminal | terminal, | ||
| GhosttySelection * | out_selection ) |
Compute the grid rectangle occupied by the current placement.
Uses the placement's pin, the image dimensions, and the terminal's cell/pixel geometry to calculate the bounding rectangle. Virtual placements (unicode placeholders) return GHOSTTY_NO_VALUE.
| terminal | The terminal handle | |
| image | The image handle for this placement's image | |
| iterator | The placement iterator positioned on a placement | |
| [out] | out_selection | On success, receives the bounding rectangle as a selection with rectangle=true |
References ghostty_kitty_graphics_placement_rect().
Referenced by ghostty_kitty_graphics_placement_rect().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_render_info | ( | GhosttyKittyGraphicsPlacementIterator | iterator, |
| GhosttyKittyGraphicsImage | image, | ||
| GhosttyTerminal | terminal, | ||
| GhosttyKittyGraphicsPlacementRenderInfo * | out_info ) |
Get all of the geometry of the current placement in one call.
This fills in a GhosttyKittyGraphicsPlacementRenderInfo with the pixel size, grid size, viewport position and source rectangle. Set its size with GHOSTTY_INIT_SIZED first.
This is for inspecting the storage. To draw, use the render state's image list instead. It gives the same values for every image on screen, including virtual placements and placements relative to them. If you draw from both, images are drawn twice. See "Drawing Images" in the Kitty Graphics documentation.
The call succeeds even when the placement isn't in the viewport. Check viewport_visible before using viewport_col and viewport_row.
| iterator | The placement iterator, moved to a placement | |
| image | The image of this placement | |
| terminal | The terminal the storage belongs to | |
| [out] | out_info | Receives the geometry |
References ghostty_kitty_graphics_placement_render_info().
Referenced by ghostty_kitty_graphics_placement_render_info().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_source_rect | ( | GhosttyKittyGraphicsPlacementIterator | iterator, |
| GhosttyKittyGraphicsImage | image, | ||
| uint32_t * | out_x, | ||
| uint32_t * | out_y, | ||
| uint32_t * | out_width, | ||
| uint32_t * | out_height ) |
Get the resolved source rectangle for the current placement.
Applies kitty protocol semantics: a width or height of 0 in the placement means "use the full image dimension", and the resulting rectangle is clamped to the actual image bounds. The returned values are in pixels and are ready to use for texture sampling.
| iterator | The placement iterator positioned on a placement | |
| image | The image handle for this placement's image | |
| [out] | out_x | Source rect x origin in pixels |
| [out] | out_y | Source rect y origin in pixels |
| [out] | out_width | Source rect width in pixels |
| [out] | out_height | Source rect height in pixels |
References ghostty_kitty_graphics_placement_source_rect().
Referenced by ghostty_kitty_graphics_placement_source_rect().
| GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_viewport_pos | ( | GhosttyKittyGraphicsPlacementIterator | iterator, |
| GhosttyKittyGraphicsImage | image, | ||
| GhosttyTerminal | terminal, | ||
| int32_t * | out_col, | ||
| int32_t * | out_row ) |
Get the top-left cell of the current placement, relative to the viewport.
This is for inspecting the storage. To draw, use the render state's image list instead. It positions every image on screen, including virtual placements and placements relative to them, and covers overscan rows. If you draw from both, images are drawn twice. See "Drawing Images" in the Kitty Graphics documentation.
The row is negative when the top of the placement scrolled above the viewport. For example, an image 4 rows tall that scrolled up by 2 rows has a row of -2. Its top 2 rows are above the viewport and its bottom 2 rows are still visible.
| iterator | The placement iterator, moved to a placement | |
| image | The image of this placement | |
| terminal | The terminal the storage belongs to | |
| [out] | out_col | On success, receives the column |
| [out] | out_row | On success, receives the row, which can be negative |
References ghostty_kitty_graphics_placement_viewport_pos().
Referenced by ghostty_kitty_graphics_placement_viewport_pos().