On macOS, kitty now tries to render using Metal, falling back to OpenGL,
see the gpu_driver option. The driver has not yet been compiled or run
on macOS, it was written on Linux and only syntax checked against stub
headers.
Shader targets of the form msl-NN (for MSL N.N) compile each program to
a single MSL source file containing the entry points for all stages,
compiled by the driver at runtime, for the built-in and custom shaders.
slangc ignores [[vk::binding]] for Metal, so the program metadata keeps
the kitty binding slots and passes the argument table indices assigned
by slangc as native names. The push constant block, emitted as an
ordinary constant buffer, is recognized by the name of its type. As
Metal has y=1 at the top in NDC, the generated code is fixed up to
negate the y coordinate of the position output by vertex entry points.
Layouts that would differ because bool is a single byte in MSL are
rejected. The MSL is validated with the Metal compiler when available.
The MSL shaders are temporarily built on all platforms, for development.
The driver follows the design of the Vulkan driver: command buffers with
serials and at most three in flight, copy on write of buffer storage the
GPU may still use, private textures uploaded with blits from staging
memory, pipeline variants created when first used and a CAMetalLayer
per window. Vertex inputs whose offset or stride is not a multiple of
four bytes, as Metal requires, are repacked into a cached copy.
Add vulkan-headers to the Linux dependencies, and fail freezing on Linux
if either the OpenGL or the Vulkan GPU driver, or the built-in shaders
for its shader target, are missing. Document vulkan-headers as a build
dependency.
On Linux and BSD, kitty now renders using Vulkan 1.3, falling back to
OpenGL if Vulkan is not available, see the gpu_driver option. The driver
is built when the Vulkan headers are present, libvulkan is loaded at
runtime.
The driver implements the immediate mode GPU API on top of a small ring
of command buffers, submitted when windows are presented or when the CPU
needs results, such as when reading back pixels. It uses dynamic
rendering, synchronization2, push descriptors for textures and uniform
buffers and push constants for the uniform parameters of pipelines.
Buffers are host visible and written only by the CPU, with copy on write
of storage still in use by the GPU, which preserves the OpenGL semantics
the rest of kitty relies on without the CPU ever waiting for the GPU.
Pipelines have variants for each render target format, blend mode and
set of vertex input formats, created when first used. Vertex strides are
dynamic state.
Rendering is pixel identical to OpenGL in the screenshot comparisons,
with the validation layers reporting no errors.
Integer textures are now declared in the shaders with their actual
number of channels, as Vulkan requires the format of the image in the
SPIR-V to match the texture. Drivers that cannot determine the size of
uniform blocks, such as Vulkan without SPIR-V reflection, can now report
it as zero.
Shader targets of the form spirv-NN (for SPIR-V N.N) compile each
program to a single SPIR-V module containing the entry points for all
stages, along with the same backend neutral program metadata as for
GLSL. The compiled modules are validated with spirv-val, when it is
available. Custom shaders are compiled at runtime for SPIR-V targets as
well, and the tests compile and validate all bundled custom shaders for
SPIR-V in addition to the target of the loaded driver.
The program metadata now includes the names of the entry points, which
are passed to drivers in GPUShaderSource, since a module can contain
the entry points of several stages. compile_program() accepts binary
shaders as bytes.
This replaces the unused, untargeted .spv files that were built before.
Pixel coordinates of viewports, scissor rectangles and read back pixels
now have their origin at the top left of the render target, rows are
read back top to bottom, NDC y=-1 is the top of the viewport and render
targets have their top row at texture coordinate t=0, the same as
uploaded images. Vulkan and Metal drivers can then render with no flips
at all.
The OpenGL driver is now the special case. Framebuffer objects already
behave this way, so it converts only when rendering to a window: vertex
shaders negate gl_Position.y via a kitty_flip_y uniform that the GLSL
fixup adds, viewport and scissor y coordinates are converted, rows of
read back pixels are reversed and copying to a texture uses a flipping
blit.
kitty's code gets simpler: viewports and scissor rectangles no longer
need the framebuffer height, screenshots no longer need their rows
flipped and textures produced by rendering are sampled the same way as
uploaded ones. The rounded rect shader no longer uses SV_Position, whose
origin differs between backends.
User facing custom shader UV coordinates are unchanged, still with
their origin at the bottom left.
Rendering is pixel identical to before.
The gpu_driver option is an ordered list of the GPU drivers to try,
defaulting to metal, vulkan, opengl. Drivers that are not part of the
build are skipped.
Add connect() to the GPU driver API. It is called once the windowing
system has been initialized, with the connection to the display, so
that drivers can check that they are able to render to windows on it,
before any windows are created. The driver is now loaded after
glfwInit() for this reason. If a driver cannot connect, the next one is
tried. If the driver fails to choose a visual or create a surface for
the first window, before any GPU resources exist, kitty switches to the
next usable driver and creates the window again.
--debug-rendering reports the driver used and why others were rejected.
Declare the uniform parameters of every program as a single Params
struct, shared by all stages of the program, in a push constant block,
instead of as uniform parameters of the entry points. Slang lays out
the uniform parameters of each entry point starting at offset zero, so
the vertex and fragment parameters overlap, which Vulkan does not allow
in push constants. A single block shared by all stages is also what
Metal wants, and it is still emitted as loose uniforms for OpenGL.
The build now fails if a program has entry point uniform parameters or
more than 128 bytes of them, the push constant size guaranteed by Vulkan.
Since a program now has at most one block of uniform parameters, drop
the stage from GPUParamBlock, bump the GPU API version, and simplify
the lookup of parameters by name in kitty, as each name is now present
in only one parameter block.
The small, frequently changing parameters of a pipeline, the uniform
parameters of each entry point and uniform blocks whose contents are
constant for the lifetime of a pipeline (currently only the gamma LUT),
are now parameter blocks whose layout comes from the shader reflection
data. kitty writes their contents into memory it owns and passes changed
blocks to the driver with set_params() just before drawing, instead of
setting individual uniforms by location.
This is the only way parameters are set, so the GL specific
pipeline_uniform_slot() and set_uniform_*() functions are gone from the
driver API. Drivers are free to implement parameter blocks as they see
fit: the OpenGL driver uses loose uniforms, uploading only the fields that
changed, Vulkan would use push constants and Metal set*Bytes().
Pipeline creation, including all parsing of the program metadata, now
lives in kitty/gpu.c.
Every texture and uniform block in kitty's shaders now declares its
binding slot with [[vk::binding(N)]], from a single documented table,
SHADER_BINDING_SLOTS, which the shader build verifies. Slots are unique
across shaders and kinds of resource, as Vulkan requires, and so that
resources bound once and used by many programs, such as the sprite
textures, are never displaced by another program's bindings.
The slots are passed to the C code in the program metadata, which no
longer hard codes texture units or uniform buffer binding points, and no
longer sets sampler uniforms or calls glUniformBlockBinding() equivalents.
Instead the driver receives the slots when a pipeline is created. The
OpenGL driver applies them to the linked program since OpenGL 3 has no
layout(binding) qualifiers; targets where the slots are part of the
compiled code can ignore them.
Each GPU driver now declares the shader target it consumes (glsl-140 for
the OpenGL driver), a fixed property available as soon as the driver is
loaded. setup.py compiles the built-in shaders for the targets of the
drivers it builds, into a directory per target, and custom shaders are
compiled at runtime for the target of the loaded driver. The GLSL_VERSION
constant is no longer exported to Python.
The program metadata passed to the C code is now generated from the
reflection data produced by slangc and is backend neutral: vertex input
locations, uniform names, uniform block sizes and array layouts, all
identified by their names in the Slang source. Block sizes are verified
against the driver. The only target specific part is a map from Slang
names to the identifiers in the compiled code, which the OpenGL driver
needs to look up parameters by name and which is passed to the driver
when creating a pipeline. The driver no longer needs to be queried for
uniform array layouts.
The debug config output now uses the name reported by the driver.
glfw is now a windowing only library. It no longer creates OpenGL
contexts and contains no GLX, EGL, NSGL or OSMesa code. Instead it
exposes native window handles, and the GPU driver creates surfaces that
render into them, owning everything needed to render and present, such
as OpenGL contexts or, in future, Vulkan swapchains.
The GPU driver API (now version 2) gains surfaces: creation from native
X11, Wayland and Cocoa windows, making current, resizing, presenting,
swap interval, handling native view changes and recreation (macOS) and
choosing the X11 visual before window creation. The OpenGL driver
implements them with GLX on X11, EGL on Wayland and NSGL on macOS, all
ported from glfw, loading every library at runtime.
glfw gains a GLFW_X11_VISUAL_ID window hint, a native surface changed
callback (used on macOS where the NSOpenGLContext must be updated) and
glfwWindowContentsPresented(), which on Wayland commits surface state
after a frame is presented. The OpenGL context API, hints and the
share parameter of glfwCreateWindow() are removed.
The macOS (NSGL) code is untested as it could not be built.
All OpenGL calls now live in gpu/opengl, which is built as kitty/opengl.so,
next to the glfw backends. glfw_init() is passed the path to the driver and
loads it. The driver is initialized once the first OpenGL context is
current. fast_data_types no longer links against libGL.
kitty/gpu.c contains the driver loader and the higher level helpers
(programs and their metadata, vertex array objects, viewport stack) that
were previously in kitty/gl.c, implemented on top of the driver API.
shaders.c and the rest of kitty use only the driver API.
Also remove the unused GL_* constants and the unused bind_program,
create_vao, etc. functions exported to Python.
gpu/api.h defines the interface between kitty and dynamically loaded GPU
drivers. It uses only standard C types, with opaque 64 bit handles for all
resources, so that it can be implemented with OpenGL, Vulkan or Metal.
A new panel created via single instance now runs in the working
directory of the invocation, rather than that of the first instance, as
commands run in existing panels and other single instance commands
already do. The environment of the invocation is cleaned up with
process_env() as for other single instance commands, so that variables
such as XDG_ACTIVATION_TOKEN and VTE_VERSION are not passed to the
commands.
Commands sent to an already running panel or quick access terminal, both
in existing panels and in newly created ones, are now user launches
passed to the launch wrapper. They have no source window, since they are
not run from any window in the panel. A new panel without a command runs
the shell instead of the run-shell kitten, so the wrapper sees the actual
shell, as for a panel started without single instance.
Closes#10900
The layout did not reserve space for the border of a single window, so
the border overlapped the margin and, when the margin was narrower than
the border, extended past the edges of the OS window. The negative
coordinates were then parsed as unsigned, which with rounded borders made
the whole window be covered by the corner fill, hiding its contents.
Reserve the border in layout_single_window_group whenever a full border
is drawn around the window, including when a visible dock causes borders
to be drawn, account for it in the initial OS window size in cells, and
parse border rects as signed integers, clipping them to the OS window.
Fixes#10899
The HarfBuzz font was created before the named instance or axis
coordinates were applied to the FreeType face and was only resynced if
the face had a transform matrix. So shaping used the default variation
coordinates, which broke fonts that substitute glyphs based on axis
values via GSUB FeatureVariations, such as the cursive (CRSV) axis of
Annotation Mono.
Adds a test using a small subset of Annotation Mono (SIL OFL 1.1).
Fixes#10897
The fix for CVE-2026-54056 only made remote regular file creation
exclusive. A remote source could still send a symlink and then a
directory with the same name, as names were only de-duplicated on
case insensitive filesystems. CreateDirAt() would then follow the
symlink and the directory's children would be written outside the
staging directory.
Always de-duplicate names, create remote directories exclusively and
never follow symlinks when opening a newly created directory.
Port the CSI tokenizer and SGR grouping logic from vt-parser.c and
cursor.c so that empty parameters terminated by a semicolon are treated
as zero everywhere, not only in extended colors. This fixes stale
attributes being re-applied on wrapped lines for codes such as ;m, ;31m
and 4:;31m. Also match kitty for codes with invalid characters or
private/intermediate bytes (ignored entirely), misplaced sub-parameters,
mixed colon/semicolon colors, out of range color indices, SGR 21 and
clamped underline styles.
Closes#10895
A semicolon commits an empty CSI field as zero. Skip empty fields at a colon or the CSI terminator so that incomplete extended colors keep the current color when wrapping text.
Animations are only scanned in the windows of the active tab, so if the
previously active tab had no animations, scanning stopped and was never
restarted when switching back. Request a rescan when the active tab
changes.
Fixes#10894
On macOS the default shell is run via /usr/bin/login and the run-shell
kitten, with the user wrapper placed inside login, so the expected argv
differs from Linux.
- Treat trailing empty SGR color parameters as zero, matching the terminal
- Ignore the color space id in colon form RGB colors (38:2:id:r:g:b)
- Fix bright colors (90-97, 100-107, 38;5;8-15) being re-emitted off by one
- Handle parse errors explicitly and simplify color target selection
- Add tests for SGR state parsing
A user launch wrapper can start a persistent helper before the command. Use a lone, unmatched child for the current lookup and cache the child only once its command line matches the launch arguments.
A wrapper that runs the command as a child, rather than exec-ing it, can
run other children before, after or alongside it, such as a script that
runs some setup commands first. Re-check that the cached child of a
wrapper is still its live child, so that root_pid does not get stuck on
an exited helper, or on the command after it exits while the wrapper
keeps running. When a wrapper has several children, prefer the one
running the wrapped command, and only cache the choice if it is certain.
Match wrappers specified by name when their argv[0] is the path they
were found at, as is the case when run by the hold kitten, and wrappers
specified by path only by that exact path.
Compare the wrapper argv and the script arguments with empty arguments
dropped, as cmdline_of_pid() does on Linux, in one place, so that
binary wrappers with empty arguments are also matched.
Add tests for wrappers that run other commands, that exec after being
seen, with prefix and empty arguments, run via the hold kitten, and for
matches_cmdline() and runs_command().
The dialog was drawn by writing newlines and relying on the terminal to
wrap long lines, recording clickable ranges assuming nothing scrolled or
wrapped. When the content was taller than the window, the screen
scrolled and every clickable range was off by the scroll amount.
Now the full layout is computed up front, with clickable ranges relative
to it, and rows are drawn with absolute cursor positioning and line
wrapping disabled, so the terminal never scrolls or wraps. The boxed
choice layout is used only if it fits entirely, otherwise the compact
one is used, and if even that does not fit, the content is bottom
aligned so the choices remain visible. Choices too wide for the screen
are truncated with an ellipsis.
Also fix:
- The hidden text placeholder not being clickable when it wraps over
multiple lines, its clickable range going stale after a resize, and
its range including one cell too many.
- Compact choice ranges being computed by iterating over a map, putting
them in random order when several choices share a line.
- An empty box row or compact row being output when the first choice is
wider than the screen.
- truncate_at_space using a cell width as a byte offset, splitting
multi-byte characters, and looping forever when a character is wider
than the available width.
Closes#10883
Drop the redundant v2 prefix from the disk cache key, as the key format
already changed when the inode was added.
Render the file the cache key was computed from, so that retargeting a
symlink while rendering, even if it is restored before AddPath() checks
the key again, cannot store the preview of one file under the key of
another. Renderers that need the selected path, custom preview commands
and calibre, opt out via NeedsSelectedPath(). The selected path is also
used when the target has a different extension, as renderers may detect
the format from it.
Recheck the path key before updating the cache. Include the inode so a replacement with the same size and modification time gets a different key. Version the key to invalidate previously cached previews.
Retry once when a changed path still resolves to a regular file.