diff --git a/include/ghostty/vt.h b/include/ghostty/vt.h index 5dd06521c..649ab1d4d 100644 --- a/include/ghostty/vt.h +++ b/include/ghostty/vt.h @@ -125,6 +125,7 @@ extern "C" { #include #include #include +#include #include #include #include diff --git a/include/ghostty/vt/kitty_graphics.h b/include/ghostty/vt/kitty_graphics.h new file mode 100644 index 000000000..aaacb5330 --- /dev/null +++ b/include/ghostty/vt/kitty_graphics.h @@ -0,0 +1,40 @@ +/** + * @file kitty_graphics.h + * + * Kitty graphics protocol image storage. + */ + +#ifndef GHOSTTY_VT_KITTY_GRAPHICS_H +#define GHOSTTY_VT_KITTY_GRAPHICS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** @defgroup kitty_graphics Kitty Graphics + * + * Opaque handle to the Kitty graphics image storage associated with a + * terminal screen. + * + * @{ + */ + +/** + * 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()). + * + * @ingroup kitty_graphics + */ +typedef struct GhosttyKittyGraphicsImpl* GhosttyKittyGraphics; + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* GHOSTTY_VT_KITTY_GRAPHICS_H */ diff --git a/include/ghostty/vt/terminal.h b/include/ghostty/vt/terminal.h index c243fa25c..ff3f60ae1 100644 --- a/include/ghostty/vt/terminal.h +++ b/include/ghostty/vt/terminal.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -839,6 +840,19 @@ typedef enum { * Output type: bool * */ GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_MEDIUM_SHARED_MEM = 29, + + /** + * The Kitty graphics image storage for the active screen. + * + * Returns a borrowed pointer to the image storage. The pointer is valid + * until the next mutating terminal call (e.g. ghostty_terminal_vt_write() + * or ghostty_terminal_reset()). + * + * Returns GHOSTTY_NO_VALUE when Kitty graphics are disabled at build time. + * + * Output type: GhosttyKittyGraphics * + */ + GHOSTTY_TERMINAL_DATA_KITTY_GRAPHICS = 30, } GhosttyTerminalData; /** diff --git a/src/terminal/c/kitty_graphics.zig b/src/terminal/c/kitty_graphics.zig new file mode 100644 index 000000000..cc0834859 --- /dev/null +++ b/src/terminal/c/kitty_graphics.zig @@ -0,0 +1,8 @@ +const build_options = @import("terminal_options"); +const kitty_gfx = @import("../kitty/graphics_storage.zig"); + +/// C: GhosttyKittyGraphics +pub const KittyGraphics = if (build_options.kitty_graphics) + *kitty_gfx.ImageStorage +else + *anyopaque; diff --git a/src/terminal/c/main.zig b/src/terminal/c/main.zig index 997a8e2c8..ef678e438 100644 --- a/src/terminal/c/main.zig +++ b/src/terminal/c/main.zig @@ -8,6 +8,7 @@ pub const color = @import("color.zig"); pub const focus = @import("focus.zig"); pub const formatter = @import("formatter.zig"); pub const grid_ref = @import("grid_ref.zig"); +pub const kitty_graphics = @import("kitty_graphics.zig"); pub const types = @import("types.zig"); pub const modes = @import("modes.zig"); pub const osc = @import("osc.zig"); @@ -161,6 +162,7 @@ test { _ = cell; _ = color; _ = grid_ref; + _ = kitty_graphics; _ = row; _ = focus; _ = formatter; diff --git a/src/terminal/c/terminal.zig b/src/terminal/c/terminal.zig index a2b0d1092..32bc0311a 100644 --- a/src/terminal/c/terminal.zig +++ b/src/terminal/c/terminal.zig @@ -8,6 +8,7 @@ const Stream = @import("../stream_terminal.zig").Stream; const ScreenSet = @import("../ScreenSet.zig"); const PageList = @import("../PageList.zig"); const kitty = @import("../kitty/key.zig"); +const kitty_gfx_c = @import("kitty_graphics.zig"); const modes = @import("../modes.zig"); const point = @import("../point.zig"); const size = @import("../size.zig"); @@ -515,6 +516,9 @@ pub fn mode_set( return .success; } +/// C: GhosttyKittyGraphics +pub const KittyGraphics = kitty_gfx_c.KittyGraphics; + /// C: GhosttyTerminalScreen pub const TerminalScreen = ScreenSet.Key; @@ -553,6 +557,7 @@ pub const TerminalData = enum(c_int) { kitty_image_medium_file = 27, kitty_image_medium_temp_file = 28, kitty_image_medium_shared_mem = 29, + kitty_graphics = 30, /// Output type expected for querying the data of the given kind. pub fn OutType(comptime self: TerminalData) type { @@ -580,6 +585,7 @@ pub const TerminalData = enum(c_int) { .kitty_image_medium_temp_file, .kitty_image_medium_shared_mem, => bool, + .kitty_graphics => KittyGraphics, }; } }; @@ -664,6 +670,10 @@ fn getTyped( if (comptime !build_options.kitty_graphics) return .no_value; out.* = t.screens.active.kitty_images.image_limits.shared_memory; }, + .kitty_graphics => { + if (comptime !build_options.kitty_graphics) return .no_value; + out.* = &t.screens.active.kitty_images; + }, } return .success;