Reduce the allowance for cropping glyphs wider than their cell, rather
than rescaling them, to 2/10 of the cell width, since cropping removes
ink, and test that cropped glyphs fill their cell.
FreeType: Move combining marks with their base glyph when it is rescaled
and moved into its cell, so that they stay in place relative to it.
CoreText: Rescale glyphs individually, as with FreeType, so that a
combining mark wider than the cell does not cause its base glyph to be
shrunk. Measure the width of glyphs in whole pixels, as rasterized, as
with FreeType, so that both renderers make the same decision. Never crop
colored glyphs, as with FreeType.
concat_cells: Produce RGBA bytes for 8 bit sprites, as for 32 bit ones,
and handle empty cells.
As with the CoreText renderer, a glyph that is rescaled to fit its cell is
moved so that its ink starts at the left edge of the cell, so that marks that
hang to the left of it, as in polytonic Greek capitals, are no longer cut off.
Port the overhang allowance from the FreeType renderer: a glyph wider than
its single cell by at most 2/9 of the cell width, with a minimum of 2px, is
cropped rather than rescaled. Previously any glyph whose right edge was more
than 1px past the cell was rescaled, shrinking glyphs such as the d with
caron of Cascadia Code and the texture healing alternates of Monaspace.
Widths are measured per glyph, as with FreeType, so that combining marks do
not cause their base glyph to be shrunk.
The left overhang of a glyph is now taken into account, and a glyph that is
rescaled is moved so that its ink starts at the left edge of the cell, so
that marks that hang to the left of it, as in polytonic Greek capitals, are
no longer cut off. Glyphs that extend past the right edge of the cell are
moved left as far as their left bearing allows, as with FreeType.
Also fix the tests for this to run on macOS: face_from_path() ignored the
font size on macOS and the tests treated pixels with only color bits set as
ink.
Fix concat_cells() for 32 bit sprites, broken since the SIMD compositing
change, which treated the 0xRRGGBBAA sprite pixels as RGBA bytes, producing
an opaque white image.
A glyph whose bitmap is wider than its cell is rendered again at a
smaller font size so that it fits, unless it is wider by no more than
two pixels, in which case it is cropped. That allowance is absolute, so
it covers less of the cell as the cell grows, and fonts with glyphs
that overhang their advance by design end up on the wrong side of it:
the texture healing alternates of Monaspace and 0xProto, or the d with
caron of Cascadia Code. Such a glyph is drawn visibly smaller than its
neighbors, at one font size and not at the next.
Make the allowance proportional to the cell width: 2/9 of the cell,
which is the 2px the rule was originally tuned for at the 9px cell of a
typical monospace font at 11pt and 96 dpi, with a minimum of 2px for
smaller cells. That keeps the widest Monaspace alternate, 14% wider
than its cell, at full size. A glyph that overhangs by more, such as a
Greek capital whose breathing mark and accent hang well outside the
cell, is still rescaled, since cropping would remove the marks.
Closes#10879
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#10869Closes#10870
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
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.
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.
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
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.
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.
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.
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.
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
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
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
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.
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.
While rendering is paused, output can change the live scroll position,
pixel scroll offset, scrollback size and active screen. Image layers,
cursor visibility and the scrollbar used those live values while the
text was drawn from the frozen snapshot, so they drifted from it.
Capture the scrollback size and active screen at pause time and add
rendered_scrolled_by, rendered_history_count and rendered_on_main_screen
macros alongside rendered_pixel_scroll_offset_y. Move image layer
updates and scrollbar visibility and geometry into screen.c so the
renderer and the tests share the same code.
Closes#10847
Test that multicell chars not cut by the erase survive it: a wide char at
the top of the screen and a scaled char in the live prompt running from the
scrollback onto the screen. Check the full text after cutting large chars,
make the fragment check verify the parts above and below each multicell
cell, and run the standalone checks in subtests so that one failure no
longer hides the checks after it.
When the first lines of the live prompt were in the scrollback, an unsigned
wrap made erase_last_command delete most of the screen and the newest
scrollback lines, including the live prompt. Delete the erased lines from
the middle of the scrollback instead, with a new historybuf_delete_lines()
that removes multicell chars cut by the deletion, and also remove such
fragments from the screen. Clear selections and the wrap flag of the line
above the erased lines on every path.
Also keep the last visited prompt on the same content when lines are
inserted or deleted (CSI L/M), forget it on a hard reset, and only fill from
the scrollback when unscrolling (CSI + T) if the scroll region starts at the
top of the screen, instead of overwriting the top line of the screen.
Store the last visited prompt as one row relative to the top of the live
screen (negative rows are in the scrollback) plus the viewport row it was
visited at, and derive the scroll offset when it is used. Previously it was
stored as a (viewport y, scrolled_by) pair that every code path moving lines
had to keep consistent by hand, which broke after erasing a command left
less scrollback than the saved offset, and when scrolling regions with
margins or reverse indexing.
Choose the tab to focus using only the windows that were actually saved,
moving the choice into a pure function so it can be tested without
constructing a TabManager. Test the first OS window logic with simple fake
tab managers instead of patching TabManager internals. Merge the changelog
entries and mention restore after logout.
TabManager.serialize_state_as_session wrote focus_tab as the index of the
active tab among all the tabs of the OS window, but loading a session
counts only the tabs it creates. With --match the tabs of other sessions
are not saved, so a session with such tabs before its active tab came back
on the wrong tab, or on its last tab once the index was clamped.
Write the index among the saved tabs. When the active tab is not saved, as
when it belongs to another session, write the saved tab with the most
recently focused saved window. That is the tab kitty focuses when switching
to the session while it is open, as window_for_session_name picks the
session's most recently focused window, so the session comes back as it was
last seen. Leaving focus_tab out instead would focus whichever saved tab
has the last focus command, usually the last one, which is arbitrary.
Boss.serialize_state_as_session passed is_first to the first OS window it
serialized, which is any but the focused one when there are several. With
--match that OS window can have no matching windows and write nothing, and
the next one then started the file with new_os_window, so loading the
session opened it in a new OS window instead of the current one. Whether
it did depended on which OS window had focus when saving.
Pass is_first to the first OS window that writes anything.
ColorProfile.as_dict() used the key cursor_text instead of the kitty.conf
name cursor_text_color, so get-colors listed the window override under a
different name than the configured value, which then shadowed it.
The bootstrap script extracted the tarball with umask 000, so tar
created any directories not present in the tarball, such as ~/.terminfo
and the ssh kitten data directory, with mode 0777. Since tar is run with
-p, the permissions of entries in the tarball are already restored
exactly, so the umask override is unnecessary. Remove it so that
directories not in the tarball respect the user's umask, matching the
behavior of bootstrap.py.
Fixes#10834Closes#10835
Check for conversion errors per option so a failed conversion returns
immediately instead of storing the error sentinel and continuing. Document
why macos_titlebar_color stays signed. Make the test meaningful on 64-bit
platforms by asserting negative values are rejected for the unsigned
options, and restore options afterwards.
RGB encodings can use the high bit of a 32-bit long. Decode the Wayland titlebar and scrollbar colors as unsigned values at runtime, matching their config converters. Keep the signed macOS titlebar sentinels.
Expect OverflowError for dimensions that exceed sys.maxsize, since
PyArg_ParseTuple rejects them before the PNG buffer validation runs.
Continue to expect ValueError for invalid dimensions and buffer lengths
that reach the validation code.
Export NULL_COLOR_VALUE using PyLong_FromUnsignedLong instead of
PyModule_AddIntMacro, which converts it to a signed long. On 32-bit
platforms this turns 0xffffffff into -1 and causes the generated Go
uint32 constant to overflow, preventing kitten from building.
Add a regression check for the exported value.
bash is compiled with the paths to its system wide profile and bashrc
(SYS_PROFILE and SYS_BASHRC) and there is no way to query bash for them.
Previously kitty guessed locations in /etc, which fails on distros that
keep these files elsewhere, such as hermetic /usr distros like Clear Linux
(/usr/share/defaults/etc) or Nix (/etc/bashrc).
Now find the paths by scanning the bash executable for them, both in kitty
and in kitten run-shell (so it works on remote hosts via the ssh kitten).
The result is cached per executable in kitty. If the scan fails, or the
locations are explicitly specified via the environment, the previous
behavior is used.
Fixes#10819
Add the command-start, command-finish, alternate-screen-enter and
alternate-screen-exit events, which fire for changes in the active window,
and the active_window_command_running, active_window_alternate_screen,
active_window_command_state_age and active_window_alternate_screen_age
fields to KittyCustomShaderData, so shaders can show effects while
commands run and hide them in full screen programs.
Previously the cursor was always drawn after the pre-edit text, as the
cursor position sent by the input method was ignored, so one could not see
which character was being edited when moving inside the pre-edit text, as
with Chewing. Pass the pre-edit cursor from IBus, Wayland text-input and
macOS to kitty, in code points, and place the cursor there. On Wayland, do
not drop pre-edit updates that only move the cursor.
Also use the pre-edit cells rather than the original line under them to
size and color the cursor, so that it covers wide pre-edit characters.
The IME candidate window remains anchored at the start of the pre-edit text.
Fixes#10807
Requests on a registered stream skip authentication, so restrict that to
genuine continuations of the authorized request that opened the stream:
- A continuation may differ from the opening request only in its data,
so it can no longer, for example, supply a different cmdline to run.
- Streams are bound to the socket peer or window that opened them, and
only requests from that origin can continue or cancel them.
- Streams are aborted, discarding any buffered data, when the peer
disconnects, the window is closed or the request is cancelled, so
abandoned streams no longer stay authorized.
Cancellations of async requests are allowed without authentication, and
requests on a registered stream are allowed without authentication too.
handle_cmd() registered the stream before returning for a cancellation, so
an unauthenticated cancellation could register a stream id that a later
request then used to skip authentication. Register the stream only after
cancellations have returned.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The child was reaped by the first waitpid() but since WIFEXITED was false the
loop continued and the next waitpid() raised ChildProcessError, hiding the
actual reason for the failure. Now report the signal and screen contents.
Store per color scheme auto theme state in a typed dataclass instead of
string built attribute names. Track which theme files were seen during
the directory scan rather than checking for existence afterwards, so a
file deleted mid-scan cannot invalidate unscanned themes. Reset
applied_theme when the applied theme file is deleted.
Always re-read theme files on config reload and apply the theme for the
current system color scheme. Previously, once the applied theme was
invalidated, reloads stopped refreshing theme files, so re-creating the
file had no effect until the next system color scheme change. This also
means theme files created after startup are now applied on reload.