Commit graph

1895 commits

Author SHA1 Message Date
Kovid Goyal
a481180d48
Add a mode to report scroll events to programs in full detail
Mode 5523, while mouse tracking is on, makes kitty report each scroll event
as a single CSI > ... M escape code instead of as button 4-7 presses. It
carries integer deltas in v120 units or pixels, with fractions carried
over, the user's scroll multiplier as a hint, the kind of device, the
gesture phase, and flags for momentum and inverted (natural) scrolling,
and the full set of modifiers. Only the sign of the multipliers is applied.

To support this GLFW scroll events now carry the source device, the
gesture phase and whether the direction is inverted, on Wayland, X11 and
macOS. The momentum scroller now forwards the gesture end before starting
momentum and no longer reports a cancel for momentum that never began.
2026-11-16 13:43:41 +05:30
Kovid Goyal
161fc04a66
Ignore the paused rendering snapshot when rendering is not paused
The snapshot of the screen taken for a synchronized update is kept after
the update ends, so its cells prevented the style table from being
emptied on hard resets and clearing of the scrollback, and kept their
styles alive through garbage collection. It is unused when rendering is
not paused and is overwritten entirely when rendering is next paused, so
only consider it while rendering is paused.

Also detect use of the formatting of stale line copies when comparing
lines and in test_shape() and test_render_line().
2026-11-16 13:43:41 +05:30
Kovid Goyal
13c7980ab4
Speed up processing of text that scrolls the screen
Lines scrolled onto the screen no longer have their render data cleared,
instead they are marked dirty so that rendering recomputes it, except when
there is a marker, as marks are render data used without rendering. This
reduces the memory written to clear a line by 40%.

The ASCII fast path in draw_text no longer checks for multicell cells in
a line that was just cleared by a line feed scrolling the screen, until
something that can create multicell cells happens.

Together these make the ascii benchmark ~14% and the scrollback and
render benchmarks ~8% and ~14% faster. Also update the throughput
numbers in the performance docs, using the median of several runs.
2026-11-16 13:43:41 +05:30
Kovid Goyal
c2567d63d3
Only empty the style table on hard resets and clearing the scrollback
Emptying it whenever the whole screen was erased meant that full screen
programs, which erase the screen on every redraw, had all their styles
interned again and the style texture uploaded again every frame. Also do
not empty tables with few styles, as they are not worth it. Empty it when
the scrollback is cleared by the clear_terminal action as well.

Improves the truecolor text and half blocks benchmarks by 50% and 33%.
2026-11-16 13:43:40 +05:30
Kovid Goyal
7c549dc83a
Double the maximum number of cell styles
Remove the temp_flag bit from CPUCell, which was used only to mark the
cells whose text is extracted for a selection, and use a temporary bitmap
for that instead. The freed bit is used for the style index, doubling
the maximum number of styles to 262144.
2026-11-16 13:43:40 +05:30
Kovid Goyal
0726ec71b1
Detect use of the formatting of stale line copies
Copies of lines made with LineBuf.create_line_copy() are not remapped
when the style table of their screen is garbage collected, so their
style indices become invalid. Record the generation of the style table
in copies and raise ValueError when the formatting of a copy made
before a collection is used. Copying a whole line into a copy makes
its formatting valid again.
2026-11-16 13:43:40 +05:30
Kovid Goyal
08333a778a
Empty the style table when no cell uses a style
On a hard reset or when erasing the whole display, if the scrollback is
empty and no cell on any screen buffer has a style, empty the style
table, freeing the memory used by styles from, for example, a burst of
output with many colors. Checking is cheap as only the screen buffers
need to be scanned.
2026-11-16 13:43:40 +05:30
Kovid Goyal
bd353afb9c
Intern cell styles and store only CPUCells in the scrollback
The formatting of cells (colors and SGR attributes) is now interned per
screen in a StyleTable and cells store a 17 bit index into it in the
previously unused bits of CPUCell. Render data (sprite and mark) is kept
in a separate RenderCell array for screen lines and in a small render
cache for history lines being displayed, so the scrollback stores only
CPUCells, 12 bytes per cell instead of 32. GPUCell is now only the upload
format, built from the CPUCell, its style and its RenderCell.

When the table fills up, it is compacted at the start of drawing text,
reducing the color precision of cells in the scrollback if needed, cells
on screen always keep their exact styles. The map from styles to indices
is a verstable set of indices with a small cache of recent styles in
front of it.

benchmark.py throughput: ascii +48%, unicode +29%, csi +10%, truecolor
text -22%, truecolor half blocks -9%.
2026-11-16 13:43:40 +05:30
Kovid Goyal
02f0f6ec00
Only test abstract UNIX sockets on Linux
Abstract sockets are a Linux-only feature, binding to one on macOS fails
with ENOENT.
2026-11-16 13:43:40 +05:30
Kovid Goyal
909e3d6359
Use an accurate title for the overlay showing startup errors
Errors during startup that are not caused by invalid config lines, such
as failing to listen on the remote control socket, were shown under the
title "Errors parsing configuration" with the heading "In final effective
configuration". The title now reflects whether the errors are config
parse errors, startup errors or both.
2026-11-16 13:43:39 +05:30
Kovid Goyal
b4d3876fc2
Remove stale UNIX sockets when listening for remote control
If the socket file for --listen-on was left behind by a kitty instance
that was killed, binding to it failed, so remote control was disabled
and an error was shown over the program. Now, if no process is listening
on the socket, it is removed and binding is retried. A socket that a
process is listening on and files that are not sockets are never
removed, and the error shown includes the reason for the failure.
2026-11-16 13:43:39 +05:30
Kovid Goyal
8efb82b5b8
Replace sync_to_monitor and repaint_delay with render_interval
The new render_interval option either syncs redraws to the monitor
(the default), optionally with a minimum interval between frames, or
redraws on a schedule with a minimum interval between frames. The
interval is now enforced per OS window, including when output is being
parsed, which the old repaint_delay was not.

On X11, render frames are now provided by the Present extension, with
libxcb-present loaded at runtime. Frames are requested lazily on X11,
since a pending NotifyMSC request delays buffer presentation by the GPU
driver under Xwayland. Xwayland completing requests early and failing to
report vertical blanks for long periods are handled. Without Present,
kitty falls back to blocking buffer swaps as before.

Render frames now only wake up the main loop when something is waiting
for them, so animations such as the eased cursor blink are no longer
sampled at the monitor refresh rate. On Wayland, frame callbacks are
also used when not syncing to the monitor, to stop rendering hidden
windows.

The removed options are converted to render_interval if it is not
specified anywhere, including in other config files and overrides,
otherwise they are ignored with a warning.

Also fix gen config failing on options whose type is a builtin.
2026-11-16 13:43:39 +05:30
Kovid Goyal
7326d3075a
Speed up drawing of cells with many combining chars
- Add runs of plain combining chars to a cell with a single lookup in
  the text cache, rather than one for each char, which also added the
  intermediate texts of the cell to the cache.

- Also collect garbage in the text cache when starting a new line, not
  just when starting to draw text, as a single draw can add a great many
  entries, making the cache slower to use the larger it grows.

- Size the hash map of the text cache for the expected number of entries
  after garbage collection, to avoid repeatedly rehashing it as it grows.

This makes the unique multi-codepoint cells benchmark ~80% faster.

The differential test of batched drawing now compares cells by content,
since cells with multiple codepoints store indices into the text cache,
which change as intermediate texts are no longer added to it.
2026-11-16 13:43:39 +05:30
Kovid Goyal
b815054414
Much faster SIMD UTF-8 decoding of valid UTF-8
Decode 64 byte blocks of valid UTF-8 containing no ESC using the
approach of simdutf: blocks are validated with the lookup tables of
Keiser and Lemire and converted twelve bytes at a time using shuffles
looked up from a mask of the bytes that end code points, with fast
paths for runs of ASCII, two byte and three byte sequences. Anything
else, ESC, invalid UTF-8 and the end of the input, is decoded as
before.

The shuffle tables are generated by gen/utf8_decode_tables.py.

This decodes the text of the unicode benchmark 2.6 times faster, faster
than simdutf's own conversion with error checking, and speeds up the
unicode benchmark by ~8%.

The new AVX2 decoder is faster than the AVX-512 one, so remove the
AVX-512 decoder and use the AVX2 one on CPUs with AVX-512 as well.

Also add a test comparing the SIMD decoders with the scalar one on long
inputs, which exercise the decoding of blocks, as the existing tests use
short inputs.
2026-11-16 13:43:39 +05:30
Kovid Goyal
61c953491e
Use a compact per char draw info table in the batched draw path
Decoding the packed bitfields of CharProps took about half the
instructions of the batched non-ASCII draw loop. Precompute, for each
distinct CharProps value, the number of cells a char occupies and its
grapheme segmentation property, and use that in the loop instead.

This speeds up the unicode benchmark by ~8%.

Also add test cases for a batched run that stops at an existing
multicell char after an unpaired regional indicator, which the random
test cases did not cover.
2026-11-16 13:43:39 +05:30
Kovid Goyal
832216f752
Speed up parsing of CSI codes and erasing of lines
- Check for multicell chars in the erased range before looking for them
  cell by cell, with a branch free check that reads only the word of each
  cell containing the multicell flag. The common case is a line with no
  multicell chars.

- Add a fast path that parses CSI codes of the common form, an optional
  private marker, numeric params separated by ; or : and the final byte,
  in a single pass, falling back to the generic CSI parser for anything
  else.

- Do not call the UTF-8 decoder for no text when an escape code directly
  follows another one, and start parsing CSI codes right after ESC [
  rather than in the next iteration of the parse loop.

This speeds up the CSI benchmark by 25% to 30% and the truecolor
benchmarks by ~10%.

A differential test compares the fast path and the generic CSI parser on
random input, and a new test covers erasing parts of multicell chars,
which no existing test did.
2026-11-16 13:43:39 +05:30
Kovid Goyal
51b1495103
Add a batched draw path for runs of non-ASCII text
Draw runs of non-ASCII chars that each start a new cell of width one or
two in a tight loop, with the run invariant checks done once and state
kept in locals, falling back to the scalar path for anything that needs
special handling: combining chars, zero width chars, the image
placeholder, existing multicell cells, wrapping, insert mode and charset
translation.

Cells are written as 64 bit values built in registers, since assembling
them as structs makes compilers go through the stack with partial stores
that stall on store forwarding. The grapheme segmentation step is cached
as it depends only on the state and the segmentation property of the
char, which repeat in a run of text, breaking the chain of dependent
table lookups between consecutive chars.

This speeds up the unicode benchmark by ~30%, drawing CJK text by ~70%.

A differential test compares the batched and scalar paths on random
operations.
2026-11-16 13:43:39 +05:30
Kovid Goyal
c5a9253568
macOS: minor fixes to the new C based font selection code 2026-11-16 13:43:38 +05:30
Kovid Goyal
1005ae5c7d
Prepare the builtin NERD font in the font selection thread
Loading the builtin NERD font, which includes a fontconfig match for its
hinting settings, was done on the main thread when the results of font
selection were first used. Do the slow parts of it in the font selection
thread instead. On Linux the PostScript name is read from the name table
of the font file and the fontconfig match is done in the thread, and the
FreeType face, which is only used for fallback, is created when first
needed. On macOS the font descriptor is created in the thread.

This saves ~0.6ms on the main thread during startup on Linux.
2026-11-16 13:43:38 +05:30
Kovid Goyal
e1a00bfeed
Select fonts in C, in a thread, during startup
Font selection was done in Python on the main thread, taking ~15ms at
startup on Linux and much more on macOS, where all installed fonts were
listed from CoreText and converted to Python, taking ~165ms.

Port the selection algorithm to pure C in font-select.c, with platform
backends in fontconfig.c and core_text.m, so that it can run in a thread
started by set_font_family(). The results are used when the first font
group is created, typically when the first OS Window is created. The
data for variable fonts is read from the font tables by C code that does
not use Python or FreeType.

The fontconfig backend lists all monospace fonts once and filters them
in C, as listing fonts is dominated by scanning all fonts. The CoreText
backend queries only the needed font families and PostScript names
instead of all installed fonts.

On Linux, the selected fonts are identical to those selected by the
previous Python implementation for ~1400 font specifications, including
variable fonts. The CoreText backend has not yet been compiled or tested.
2026-11-16 13:43:38 +05:30
Kovid Goyal
ae01a551f8
Do not import the launch module when there are no watchers
Creating the first window imported kitty.launch, which is slow to
import, just to find out there are no watchers to load. This delayed
the launch of the first child by a few ms.
2026-11-16 13:43:38 +05:30
Kovid Goyal
b910e78498
Bump generated MSL version to that used on macOS 14 2026-11-16 13:43:37 +05:30
Kovid Goyal
0343d05250
Add software rendering as a fallback GPU driver
On Linux and BSD, kitty now falls back to rendering on the CPU with the
Mesa lavapipe (Vulkan) or llvmpipe (OpenGL) software renderers when no
usable GPU is found, such as in virtual machines or with broken GPU
drivers. This is the new software value of the gpu_driver option, last
in the default list.

Drivers are now told which kind of renderer they may use. The software
candidates use only software renderers: Vulkan selects CPU devices and
OpenGL sets LIBGL_ALWAYS_SOFTWARE and __GLX_VENDOR_LIBRARY_NAME while
the renderer is chosen, restoring them afterwards so they are not passed
on to child programs. The other candidates reject software renderers,
unless they are last, so that a working GPU, even one usable only by a
later driver, is always preferred to the CPU. Previously, on systems
with a GPU usable only with OpenGL, kitty would use lavapipe. Drivers
report whether they render in software in their capabilities.

Failing to initialize the GPU driver for the first window is no longer
fatal: the window is recreated with the next driver, as is already done
for failures creating surfaces. OpenGL can only detect that it is using
llvmpipe once a context is current.

When software rendering is used, a message saying so is shown at the
top of every OS window for five seconds after it is first rendered.
2026-11-16 13:43:37 +05:30
Kovid Goyal
a6768a955c
Add a Metal GPU driver and an MSL shader target
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.
2026-11-16 13:43:37 +05:30
Kovid Goyal
4860f6b1a7
Add a Vulkan GPU driver
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.
2026-11-16 13:43:37 +05:30
Kovid Goyal
b2ecebf4c6
Add a SPIR-V shader target for the built-in and custom shaders
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.
2026-11-16 13:43:37 +05:30
Kovid Goyal
512b8d568a
Use the coordinate conventions of Vulkan and Metal for the GPU API
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.
2026-11-16 13:43:37 +05:30
Kovid Goyal
26fa27171a
Add a gpu_driver option to choose between GPU drivers with fallback
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.
2026-11-16 13:43:37 +05:30
Kovid Goyal
7904b536e8
Pass the uniform parameters of shaders in a single push constant block
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.
2026-11-16 13:43:36 +05:30
Kovid Goyal
a0d7bf110d
Make shader targets driver defined and program metadata reflection based
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.
2026-11-16 13:43:36 +05:30
Kovid Goyal
a3ef223193
Add a build check for the OpenGL GPU driver 2026-11-16 13:43:36 +05:30
Kovid Goyal
b692122f22
Allow selecting text drawn in the tab bar outside the tabs
Dragging the mouse over text drawn in the tab bar outside the tabs, such
as text a custom tab_bar.py draws below the tabs of a vertical tab bar,
selects it, and releasing the button copies it like a window selection
(primary selection, then copy_on_select). Clicks and double clicks on
empty space and presses on tabs behave as before.

Based on the draft in #10870, with these additions:

- Movement within drag_threshold selects nothing, so a slightly jittery
  double click on text still opens a new tab.
- A selection whose release was lost does not keep capturing the
  mouse: it is cancelled by a press outside the tab bar (which then goes
  to its normal target), by motion with no button held, by any press in
  the tab bar, and by the OS window losing focus.
- The pointer shape is reset after the press or release that starts or
  ends a selection, instead of being left as the drag shape.

Fixes #10869
Closes #10870
2026-11-15 09:32:37 +05:30
Kovid Goyal
87d06354dd
Custom shaders: Fix focus driven groups ending in the wrong state after hide/unhide
Shader animation events are accumulated per OS window and only consumed
when the window is next rendered. A focus-out followed by a focus-in with
no rendered frame in between, as happens when the window is hidden and
shown again, or a brief focus steal within one repaint interval, left both
bits pending. The state machine then treated them as simultaneous, so the
focus-out hard stop prevented os-window-focus-in groups from starting and
groups started by focus-out were turned on while focused.

Now a focus change replaces any pending opposite focus change, so only the
final focus state is reported. Genuinely simultaneous events, such as a
click that moves focus away, still give focus-out priority.

Closes #10871
2026-11-15 08:39:25 +05:30
Kovid Goyal
64a02b4061
Fix cursor underflow when VS15 narrows a wide char on the previous soft wrapped line
The VS15 branch of draw_combining_char unconditionally moved the cursor
back by the width removed from the char. When the char was on the
previous line (cursor at x=0 after a soft wrap) this wrapped cursor->x to
UINT_MAX leading to out of bounds reads and writes. Only move the cursor
when it is on the same line as the char. Also preserve the soft wrap
marker in the cells cleared by halve_multicell_width.
2026-11-15 08:16:13 +05:30
Kovid Goyal
f8556bbf8d
Fix #10858 2026-11-14 08:16:53 +05:30
Kovid Goyal
c4dd943f72
Only render regular files as window logos/background images and time out image conversion
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
A program running in the terminal could use edit-in-kitty to set --logo=/dev/zero
which would cause the image converter to read an infinite stream, blocking the
kitty main loop and consuming unbounded memory.
2026-11-13 21:51:03 +05:30
Kovid Goyal
11cbfdce23
Allow resizing docks
Docks can now be resized in whole cells by dragging their inner border,
with the resize_window action and with kitten @ resize-window, where
wider or taller always means bigger whatever the edge of the dock. A
dock keeps at least one cell and grows only into the content it is
docked to, so the docks inside it are never shrunk. OS window docks do
not shrink the tab docks of any tab, and when dragged, the other tabs
are re-laid out once, at the end of the drag. Percentage sizes stay
percentages. The new size is stored in the DockSpec, so it is reported
by kitten @ ls and saved in sessions. Resetting window sizes does not
change docks, as they are not part of the layout.

Previously the inner border of a dock showed a resize pointer but
dragging it did nothing, or in the Tall layout moved a layout divider.

Fixes #10857
2026-11-13 19:44:03 +05:30
Kovid Goyal
760caa1f6a
Handle ConEmu OSC 9;9 cwd reporting and ignore other ConEmu OSC 9 sub-commands
OSC 9;9;path is now treated as a report of the current working directory,
like OSC 7, instead of popping up a desktop notification. Other ConEmu
numeric OSC 9 sub-commands (1-12) are ignored rather than shown as
notifications.
2026-11-13 19:44:02 +05:30
Kovid Goyal
dfed4dc311
Fix multiline chars being torn by resize and ED 22
Removing multicell chars cleared only their text and the is_multicell flag,
leaving their other multicell fields. Code that did not check is_multicell
then mistook the removed cells for parts of multicell chars, so chars were
placed after unrelated rows and rewrap copied unrelated lines below such a
cell as the lower rows of a multiline char, tearing chars. Now all the
multicell fields are cleared and rewrap checks is_multicell.

The marker that preserves a blank cursor line during a resize was assumed
to be at the start of the line, but rewrap can place it after the lower
rows of multiline chars from the lines above, so removing it changed the
char at the start of the line instead, tearing multiline chars there. Now
the marker is removed where it is, just before the cursor.

When moving the screen into the scrollback for ED 22, the number of lines
to move was computed from the visual lines, which are lines from the
scrollback when it is scrolled. So too many lines were moved, adding blank
lines to the scrollback, or too few, tearing multiline chars. Now the lines
of the screen are used.
2026-11-13 19:43:59 +05:30
Kovid Goyal
0f19d55463
Fix infinite loops when making space for chars next to multiline chars
When looking for space free of the lower rows of multiline chars, with the
cursor on the last line below the bottom margin, a linefeed does not move
the cursor, so move_cursor_past_multicell() looped forever. Now it makes
space at the end of the line in that case.

move_cursor_past_multicell() also removed only the multicell char under the
cursor, not other chars in the cells the char being drawn would occupy. So
a wide char, for example one widened by VS16 at the end of a line, could
overwrite the first cells of a multiline char, leaving fragments of it.
Inserting chars before such a fragment looped forever, as the end of the
fragment was computed from its width ignoring its scale, so the loop went
backwards. Now all multicell chars in those cells are removed, and the end
of a char is computed from its scale and width and is always after the
current cell.

Also a char widened at the end of the line that was moved to cells
overlapping its original cell had its second cell cleared.
2026-11-13 19:43:52 +05:30
Kovid Goyal
cfd2b23dca
Fix out of bounds accesses with partially scrolled off multiline chars
Scrolling down (CSI T) could cut off the lower rows of a scale > 1 text
sizing character at the bottom of the screen. Adding a combining char to
it then wrote past the end of the line buffer in add_combining_char and
rewrapping on resize read past the end of the line buffer in
copy_multiline_extra_lines.

Multiline chars that are cut off at the edge of the screen or of the
history buffer, by scrolling or by inserting lines, are partially
scrolled off and are rendered as such, so they are kept. Code walking the rows of a multiline char now only visits
the adjacent rows that actually continue the char, rather than trusting
the y and scale of a cell, so it stays in bounds and does not modify
unrelated cells for partial or torn chars.

Chars that would be torn, i.e. left with rows from unrelated lines
adjacent to their remaining part, are removed. This happens when
scrolling with margins, when a partial char is moved away from the edge
of the screen by scrolling or deleting lines, when inserting lines pushes
the lower rows of a char straddling the bottom margin out of the scroll
region, and when a partial char
cut off at the bottom is no longer at the bottom after a resize. Rewrap
drops partial chars, as it already did for chars with missing top rows,
placing cursors that were on them where the char would have been.

The checks for torn chars are skipped unless a multiline char has been
drawn in the screen, and chars cut off at the bottom of the screen,
which can only be created by scrolling down or inserting lines, are
tracked so that
linefeeds do not need to scan for them.

A hard reset now clears the alternate screen as well, so that the flag
tracking whether multiline chars have been used can be reset.

Also fix the lower rows of multiline chars being lost on rewrap when the
lines after the char were continuations that fit on its first row.
2026-11-13 10:43:13 +05:30
Kovid Goyal
bdd1e84346
Allow docking windows to the OS window with launch --type=os-window-dock
An OS window dock is shown in every tab of its OS window, below the tab
bar and outside the docks of the tab, and lives as long as the OS window.
It is a single window running a single program, which is kept in the
active tab: it is moved to the new active tab on every tab switch, by a
new C function that moves the window between tabs of an OS window
without recreating its GPU resources. Every tab reserves the space for
the OS window docks, so switching tabs does not resize any windows.

The docks are not closed with tabs and do not keep a tab open, stay in
their OS window when the tab containing them is moved to another OS
window, and are closed when the last other window in the OS window is
closed. They are listed as part of the active tab, and the dock entry of
every docked group in the output of kitten @ ls now has a scope of
window, tab or os-window. They are saved in sessions, once per OS window.

Fixes #10854
2026-11-12 12:47:48 +05:30
Kovid Goyal
65da47b611
More detail for on_quit events and a new on_cwd change event 2026-11-12 11:29:08 +05:30
Kovid Goyal
cb66ed55ca
Fix watcher calls being silently dropped during bursts of window changes
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
Every on_resize and on_focus_change took its own 0s timer, so creating many
windows from a single callback filled the fixed size glfw timer table and
add_timer() returned 0, silently dropping the watcher calls. Now watcher
calls are queued and delivered in order behind a single pending timer, and
only when the window actually has a watcher for the event. Calls made during
delivery go to the next batch, preserving the recursion guard the timer
exists for.

Also fix add_timer() leaking a reference to the callback when the timer
could not be added.

Fixes #10853
2026-11-12 09:03:33 +05:30
Kovid Goyal
b261b08b7a
Keep the session of tabs and windows moved to another tab or OS window
A tab moved to another OS Window keeps its session, and new tabs and OS
Windows created for moved tabs and windows belong to the session of what
was moved. A window keeps its own session, which may be none, wherever it
is moved, so --add-to-session=! is respected; a window of no session
belongs to the session of the tab it is in.

Add Window.effective_session_name for the "window session, else its tab's
session" rule that was duplicated in five places, and use it in launch as
well, so --add-to-session=. and --cwd=current agree with
new_window_with_cwd. OS Windows created by launch --type=os-window or for
moved tabs and windows now also record their session.

Closes #10851
2026-11-12 08:51:54 +05:30
Kovid Goyal
a0ac36784f
Cleanup previous PR 2026-11-12 08:49:43 +05:30
Zhizhen He
c5e6bdf1fe
Preserve session files when save_as_session --match has no windows to save
Report an error before writing if a filtered session serializes to
nothing. This keeps an existing session file intact and avoids
creating an empty one at a new path.
2026-11-12 09:33:49 +08:00
Kovid Goyal
14f82c6fcb
Test that scroll_to_prompt with an offset records the target prompt
With a scroll offset the top of the viewport is in the output of the
command above the target. Check that last_visited_cmd_output and
scroll_to_prompt 0 use the prompt that was jumped to, for every offset
and when jumping forward.
2026-11-11 20:18:59 +05:30
Zhizhen He
96ddbed7f6 Clamp scroll_to_prompt offsets to available scrollback
Keep the viewport within the history buffer and remember the matched prompt when it is visible so last-visited output follows the jump.
2026-11-11 21:18:20 +08:00
Kovid Goyal
bb237bf137
fix failing test
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
2026-11-11 14:15:05 +05:30