st/kitty.h
a a4f4f96c62
kitty: draw negative z-index images under the text
Images with a negative z-index are composited between the background
and foreground passes of xdrawline, so that text renders on top of
them with alpha blending, as the protocol requires.
2026-09-06 20:47:48 -05:00

94 lines
3.0 KiB
C

/* kitty.h - kitty terminal graphics protocol for st
*
* See https://sw.kovidgoyal.net/kitty/graphics-protocol/
*/
#ifndef KITTY_H
#define KITTY_H
#if KITTY_GRAPHICS_PATCH
#include <stdint.h>
/* the Unicode placeholder character */
#define KITTY_PLACEHOLDER 0x10EEEE
/* placeholder glyph bits packed into Glyph.kitty */
#define KPH_HAS_ROW (1u << 0)
#define KPH_HAS_COL (1u << 1)
#define KPH_HAS_MSB (1u << 2)
#define KPH_ROW_SHIFT 8
#define KPH_COL_SHIFT 16
#define KPH_MSB_SHIFT 24
/* limits */
#define KITTY_MAX_DIM 16384
#define KITTY_STORAGE_QUOTA (320u * 1024u * 1024u)
#define KITTY_MAX_REL_DEPTH 8
/* a decoded RGBA image (or animation frame) */
typedef struct KittyFrame {
struct KittyFrame *next;
unsigned char *pixels; /* RGBA, width*height*4, may be NULL for lazy frames */
int width, height;
int gap; /* ms until next frame; <0 == gapless */
int transient;
} KittyFrame;
typedef struct KittyImage {
struct KittyImage *next, *prev;
uint32_t id; /* image id (i key) */
uint32_t number; /* image number (I key) */
int width, height; /* dimensions of the root frame */
unsigned char *pixels; /* root frame RGBA data */
size_t datasize;
KittyFrame *frames; /* animation frames, frame 1 == root (pixels) */
int nframes;
int current_frame; /* 1-based */
int anim_state; /* 0 stopped, 2 loading, 3 running */
int loops; /* remaining loops, -1 infinite */
int transient;
uint64_t last_frame_time;/* ms of last frame advance */
unsigned refs; /* number of placements */
} KittyImage;
typedef struct KittyPlacement {
struct KittyPlacement *next, *prev;
KittyImage *image;
uint32_t id; /* placement id (p key) */
int virt; /* U=1 virtual placement (Unicode placeholder) */
/* source rect in image pixels */
int sx, sy, sw, sh;
/* screen position */
int x, y; /* cell coordinates; y is in scrollback space */
int xoff, yoff; /* pixel offset within the first cell */
int cols, rows; /* size on screen in cells */
int z;
int alt; /* belongs to the alternate screen */
/* relative placement */
uint32_t parent_img, parent_plc;
int hoff, voff;
/* scaled pixmap cache */
void *pixmap;
int pm_w, pm_h; /* pixel size the pixmap was rendered at */
int pm_frame; /* frame the pixmap was rendered from */
} KittyPlacement;
/* entry points used by st.c / x.c */
void kitty_apc(const char *buf, size_t len);
void kitty_draw(void);
void kitty_draw_under_cells(int x1, int y, int x2);
int kitty_cell_under(int x, int y);
void kitty_scroll(int top, int bot, int n, int save);
void kitty_deleteplacements(int alt);
void kitty_clearregion(int x1, int y1, int x2, int y2);
void kitty_reset(void);
void kitty_altscreen(int alt);
void kitty_resize(void);
void kitty_trimhistory(int histsize);
int kitty_animating(double *timeout_ms);
int kitty_is_diacritic(Rune u);
int kitty_absorb_diacritic(Glyph *gp, Rune u);
#endif // KITTY_GRAPHICS_PATCH
#endif // KITTY_H