aboutsummaryrefslogtreecommitdiff
path: root/terminal.c (follow)
Commit message (Collapse)AuthorAgeLines
* terminal: fix selection-override-modifiers=noneCismonX2026-09-02-1/+1
| | | | | | | | | Currently, if config option 'selection-override-modifiers' is set to 'none', the mouse is _always_ grabbed for selection, making mouse tracking mode unusable. A more reasonable behavior is to _never_ override mouse grabbing instead.
* terminal: don't override mouse grab without keymapCismonX2026-08-29-1/+2
| | | | | | | | Without keymap, never grab the mouse for selection when mouse tracking is enabled, since we can't tell whether a mod key is being held. Fixes #2443
* term: don't do a cursor refresh if we're shutting downDaniel Eklöf2026-08-17-1/+1
| | | | | | | | | When running e.g. "foot true", we may reach a state where the window has received the configure event, but we've also already decided to shutdown. In this case, we may not have a grid (render_resize() doesn't do anything when we've started the shutdown routine). Fixes a race that triggers a crash.
* terminal: keep saved SGR attributes per-gridaloires2026-08-15-2/+2
| | | | | | | | | | | | | DECSC/DECRC (ESC7/ESC8), CSI s/u and DECSET/DECRST 1048/1049 all save/restore the SGR attributes through the same, global saved_attrs slot. An application emitting ESC7/ESC8 in the alternate screen to wrap sixel rendering in a save/restore-cursor pair overwrites the slot with its own SGR state. DECRST 1049 then restores those attributes, instead of the ones saved by DECSET 1049. The shell prompt is left with the application's attributes, even though the application reset them (sgr0) before exiting.
* terminal: add visibility reportsTim Culverhouse2026-07-30-0/+9
| | | | | | | | | | | | | Applications cannot infer whether their terminal view is observable from keyboard focus alone, so they may continue expensive rendering while the surface is hidden. Implement private mode 2033 and the one-shot visibility query. Report Wayland xdg_toplevel suspension as not visible and otherwise remain conservative by treating the terminal as potentially visible. Amp-Thread-ID: https://ampcode.com/threads/T-019fb2b7-f245-7124-a69a-1484812532bb Co-authored-by: Amp <amp@ampcode.com>
* term: do not allow codepoint merging into grapheme clusters directly after a cursor moveDaniel Eklöf2026-06-12-1/+12
| | | | | | | That is, only do grapheme clustering when printing codepoints in sequence, without any cursor movements in between. Closes #2383
* term: enqueue data to slave if there are queued paste data buffersDaniel Eklöf2026-03-21-1/+4
| | | | | | | | | | | | | | | | | | | | When writing paste data to the terminal (either interactively, or as an OSC-52 reply), we enqueue other data (key presses, for examples, or query replies) while the paste is happening. The idea is to send the key press _after_ all paste data has been written, to ensure consistency. Unfortunately, we only checked for an on-going paste. I.e. where the paste itself hasn't yet finished. It is also possible the paste itself has finished, but we haven't yet flushed all the paste buffers. That is, if we were able to *receive* paste data faster than the terminal client was able to *consume* it. In this case, we've queued up paste data in the terminal. These are in separate queues, and when emitting e.g. a key press, we didn't check if all _those_ queues had been flushed yet. Closes #2307
* Add support for background blurDaniel Eklöf2026-03-02-0/+8
| | | | | | | | | This patch adds a new config option: colors{,2}.blur=no|yes. When enabled, transparent background are also blurred. Note that this requires the brand new ext-background-effect-v1 protocol, and specifically, that the compositor implements the blur effect.
* Spawning new terminal with --config from parent instanceStéphane Klein2026-03-02-1/+11
| | | | | Reference: https://codeberg.org/dnkl/foot/issues/1622 Signed-off-by: Stéphane Klein <contact@stephane-klein.info>
* config: add [colors-dark] and [colors-light], replacing [colors] and [colors2]Daniel Eklöf2025-12-20-17/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The main reason for having two color sections is to be able to switch between dark and light. Thus, it's better if the section names reflect this, rather than the more generic 'colors' and 'colors2' (which was the dark one and which was the light one, now again?) When the second color section was added, we kept the original name, colors, to make sure we didn't break existing configurations, and third-party themes. However, in the long run, it's probably better to be specific in the section naming, to avoid confusion. So, add 'colors-dark', and 'colors-light'. Keep 'colors' and 'colors2' as aliases for now, but mark them as deprecated. They WILL be removed in a future release. Also rename the option values for initial-color-theme, from 1/2, to dark/light. Keep the old ones for now, marked as deprecated. Update all bundled themes to use the new names. In the light-only themes (i.e. themes that define a single, light, theme), use colors-light, and set initial-color-theme=light. Possible improvements: disable color switching if only one color section has been explicitly configured (todo: figure out how to handle the default color theme values...)
* term: mouse SGR mode: don't emit negative CSI valuesDaniel Eklöf2025-12-13-2/+5
| | | | | | | | | | | | | | | | | | When reporting the column/row pixel value in mouse SGR mode, we emitted negative values when the cursor was being dragged outside the window. Unfortunately, negative values aren't allowed in CSI parameters, as '-' is an intermediate value. It was done this way, to be consistent with XTerm behavior. Allegedly, XTerm has changed its behavior in patch 404. With that in mind, and seeing that foot has never emitted negative values in any other mouse mode, let's stop emitting negative values in SGR mode too. Closes #2226
* term: reverse-scroll: fix crash when viewport ends up outside the (new) scrollbackDaniel Eklöf2025-12-13-1/+17
| | | | | | | | | | | | | | | | | | | | | | If the viewport has been scrolled up, it is possible for a reverse-scroll (rin) to cause the viewport to point to lines outside the scrollback. This is an issue if the scrollback isn't full, since in that case, the viewport will contain NULL lines. This will potentially trigger assertions in a couple of different places. Example backtrace: #2 0x555555cd230c in bug ../../debug.c:44 #3 0x555555ad485e in grid_row_in_view ../../grid.h:83 #4 0x555555b15a89 in grid_render ../../render.c:3465 #5 0x555555b3b0ab in fdm_hook_refresh_pending_terminals ../../render.c:5165 #6 0x555555a74980 in fdm_poll ../../fdm.c:435 #7 0x555555ac2b85 in main ../../main.c:676 Detect when this happens, and force-move the viewport to ensure it is valid. Closes #2232
* render: when double-buffering, pre-apply previous frame's damage earlyDaniel Eklöf2025-10-10-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Foot likes it when compositor releases buffer immediately, as that means we only have to re-render the cells that have changed since the last frame. For various reasons, not all compositors do this. In this case, foot is typically forced to switch between two buffers, i.e. double-buffer. In this case, each frame starts with copying over the damage from the previous frame, to the new frame. Then we start rendering the updated cells. Bringing over the previous frame's damage can be slow, if the changed area was large (e.g. when scrolling one or a few lines, or on full screen updates). It's also done single-threaded. Thus it not only slows down frame rendering, but pauses everything else (i.e. input processing). All in all, it reduces performance and increases input latency. But we don't have to wait until it's time to render a frame to copy over the previous frame's damage. We can do that as soon as the compositor has released the buffer (for the frame _before_ the previous frame). And we can do this in a thread. This frees up foot to continue processing input, and reduces frame rendering time since we can now start rendering the modified cells immediately, without first doing a large memcpy(3). In worst case scenarios (or perhaps we should consider them best case scenarios...), I've seen up to a 10x performance increase in frame rendering times (this obviously does *not* include the time it takes to copy over the previous frame's damage, since that doesn't affect neither input processing nor frame rendering). Implemented by adding a callback mechanism to the shm abstraction layer. Use it for the grid buffers, and kick off a thread that copies the previous frame's damage, and resets the buffers age to 0 (so that foot understands it can start render to it immediately when it later needs to render a frame). Since we have certain way of knowing if a compositor releases buffers immediately or not, use a bit of heuristics; if we see 10 consecutive non-immediate releases (that is, we reset the counter as soon as we do see an immediate release), this new "pre-apply damage" logic is enabled. It can be force-disabled with tweak.pre-apply-damage=no. We also need to take care to wait for the thread before resetting the render's "last_buf" pointer (or we'll SEGFAULT in the thread...). We must also ensure we wait for the thread to finish before we start rendering a new frame. Under normal circumstances, the wait time is always 0, the thread has almost always finished long before we need to render the next frame. But it _can_ happen. Closes #2188
* term: osc8: tag *all* cells in a multi-column character as an URIDaniel Eklöf2025-10-04-3/+5
| | | | | | | | | | | | | When we print a character to the grid, we must also update its OSC-8 state if an OSC-8 URI is currently active. For double-width characters, this was only being done for the first cell. This causes the labels in URL mode to be off, as the link was effectively chopped up into multiple pieces. Closes #2179
* Revert "term: erase: use erase_line() whenever a range corresponds to a full line"Daniel Eklöf2025-10-04-8/+2
| | | | | | This reverts commit 44a674edb86f2f8db3304d76faf567346dcd7d94. It caused a regression with prompt markers, in at least fish+starship.
* term: erase: use erase_line() whenever a range corresponds to a full lineDaniel Eklöf2025-09-25-2/+8
|
* term: no need to pass ptmx as stdout to utempterDaniel Eklöf2025-09-09-2/+2
|
* term: make sure the color table is populated *before* the slave process is spawnedDaniel Eklöf2025-07-22-2/+1
|
* term+input: refactor: move theme switching into term_theme_* functionsDaniel Eklöf2025-06-10-9/+74
|
* cursor-shape: add 'dnd-ask' and 'all-resize'Daniel Eklöf2025-05-22-1/+3
| | | | | | | | | | | | | | | | | | | | These (non-css) cursor shapes were added to the cursor-shape-v1 protocol in wayland-protocols 1.42. We don't need (or use them at all) internally, but add them to the list we use to translate from shape names to shape enums. This allows users to set a custom shape (via OSC-22), while still using server side cursors (i.e. no need to fallback to client-side cursors). If we try to set a shape not implemented by the server, we get a protocol error and foot exits. This is bad. So, make sure we don't do that: 1. First, we need to explicitly bind v2 if implemented by the server 2. Track the bound version number in the wayland struct 3. When matching shape enum, skip shapes not supported in the currently bound version of the cursor-shape protocol
* term: unittest: auto-scroll timer FD is created on-demand nowadaysDaniel Eklöf2025-05-08-4/+2
|
* render: refactor to allow setting only selection bg or fgDaniel Eklöf2025-05-05-2/+0
| | | | | | | | | | | | Before this, we only applied custom selection colors, if *both* the selection bg and fg had been set. Since the options are already split up into two separate options, and since it makes sense to at least be able to keep the foreground colors unchanged (i.e. only setting the selection background), let's allow only having one of the selection colors set. Closes #1846
* config: tweak.surface-bit-depth: add support for 16-bit surfacesDaniel Eklöf2025-05-03-1/+5
| | | | | | | | | This adds supports for 16-bit surfaces, using the new PIXMAN_a16b16g16r16 buffer format. This maps to WL_SHM_FORMAT_ABGR16161616 (little-endian). Use the new 16-bit surfaces by default, when gamma-correct-blending=yes.
* config: tweak.surface-bit-depth now defaults to 'auto'Daniel Eklöf2025-05-01-21/+21
| | | | | | | | | | | When set to 'auto', use 10-bit surfaces if gamma-correct blending is enabled, and 8-bit surfaces otherwise. Note that we may still fallback to 8-bit surfaces (without disabling gamma-correct blending) if the compositor does not support 10-bit surfaces. Closes #2082
* config: add initial-color-theme=1|2Daniel Eklöf2025-04-26-13/+26
| | | | | | | | This option selects which color theme to use by default. I.e. at startup, and after a reset. This is useful with combined theme files, where a single file defines e.g. both a dark and light version of the theme.
* key-bindings: add bindings to switch between color themesDaniel Eklöf2025-04-26-10/+17
| | | | | | * color-theme-switch-1: select the primary color theme * color-theme-switch-2: select the alternative color theme * color-theme-toggle: toggle between the primary and alternative color themes
* config: move cursor.color to colors.cursorDaniel Eklöf2025-04-26-4/+4
|
* Revert "term: append zero-width grapheme breaking characters to previous cell"Daniel Eklöf2025-04-24-1/+1
| | | | This reverts commit 76503fb86a8b8a6b5c3ce1be87c15a55af38508d.
* Revert "term: ignore LTR+RTL markers (U+200E + U+200F)"Daniel Eklöf2025-04-24-8/+0
| | | | This reverts commit 70b324b24c86473a99528feb6f1f91ca70e11a02.
* term: ignore LTR+RTL markers (U+200E + U+200F)Daniel Eklöf2025-04-24-0/+8
| | | | | | | | | Foot doesn't implement RTL, and explicit LTR markers is neither needed, nor used in anyway. In fact, they cause issues with font lookup, as fcft often fails to find the marker codepoint in the primary font, causing a fallback font to be used instead. Closes #2049
* fcft: require fcft >= 3.3.0, add support for new scaling-filtersDaniel Eklöf2025-03-12-0/+1
| | | | | | | | Update tweak.scaling-filter to recognize the new scaling filters added in fcft-3.3.0. Since fcft_set_scaling_filter() is deprecated in 3.3.0, don't use it anymore, and set the scaling filter via fcft_font_options instead.
* grid: change default value of linebreak to trueDaniel Eklöf2025-03-05-1/+1
| | | | | | | | | | | | | | | | | | This way, all lines are treated as having a hard linebreak, until it's cleared when we do an auto-wrap. This change alone causes issues when reflowing text, as now all trailing lines in an otherwise empty window are treated as hard linebreaks, causing the new grid to insert lots of unwanted, empty lines. Fix by doing two things: * *clear* the linebreak flag when we pull in new lines for the new grid. We only want to set it explicitly, when an old row has its linebreak flag set. * Coalesce empty lines with linebreak=true, and only "emit" them as new liens in the new grid if they are followed by non-empty lines.
* term: tweak linebreakingDaniel Eklöf2025-03-05-1/+0
| | | | | | | | | Don't set linebreak on linefeed. Instead, rely on the default value of true, and that it is only cleared when a character is printed while LCF=1. Note that printing to a row that has linebreak cleared, will set the linebreak flag again.
* render: gamma-correct blendingDaniel Eklöf2025-03-05-13/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements gamma-correct blending, which mainly affects font rendering. The implementation requires compile-time availability of the new color-management protocol (available in wayland-protocols >= 1.41), and run-time support for the same in the compositor (specifically, the EXT_LINEAR TF function and sRGB primaries). How it works: all colors are decoded from sRGB to linear (using a lookup table, generated in the exact same way pixman generates it's internal conversion tables) before being used by pixman. The resulting image buffer is thus in decoded/linear format. We use the color-management protocol to inform the compositor of this, by tagging the wayland surfaces with the 'ext_linear' image attribute. Sixes: all colors are sRGB internally, and decoded to linear before being used in any sixels. Thus, the image buffers will contain linear colors. This is important, since otherwise there would be a decode/encode penalty every time a sixel is blended to the grid. Emojis: we require fcft >= 3.2, which adds support for sRGB decoding color glyphs. Meaning, the emoji pixman surfaces can be blended directly to the grid, just like sixels. Gamma-correct blending is enabled by default *when the compositor supports it*. There's a new option to explicitly enable/disable it: gamma-correct-blending=no|yes. If set to 'yes', and the compositor does not implement the required color-management features, warning logs are emitted. There's a loss of precision when storing linear pixels in 8-bit channels. For this reason, this patch also adds supports for 10-bit surfaces. For now, this is disabled by default since such surfaces only have 2 bits for alpha. It can be enabled with tweak.surface-bit-depth=10-bit. Perhaps, in the future, we can enable it by default if: * gamma-correct blending is enabled * the user has not enabled a transparent background
* term: reset the grapheme clustering state on cursor movementsDaniel Eklöf2025-03-04-0/+7
|
* term: set_app_id(): app_id may be NULL, in which case we can't do strlen()Daniel Eklöf2025-02-18-1/+1
| | | | Closes #1963
* term: append zero-width grapheme breaking characters to previous cellDaniel Eklöf2025-02-16-1/+1
| | | | | | | | | | | | | | | | | | When compiled with grapheme clustering support, zero-width characters that also are grapheme breaks, were ignored (not stored in the grid). When utf8proc says the character is a grapheme break, we try to print the character to the current cell. But this is only done when width > 0. As a result, zero width grapheme breaks were simply discarded. This only happens when grapheme clustering is enabled; when disabled, all zero width characters are appended. Fix this by also requiring the width to be non-zero when if we should append the character or not. Closes #1960
* term: print-non-ascii: propagate existing forced-widthDaniel Eklöf2025-02-06-2/+2
| | | | | | | | | | | When appending to an existing composed character, "inherit" its forced width, if set. Also make sure to actually _use_ the forced width, if set, rather than the calculated width. This fixes an issue when appending zero-width codepoints to a forced-width combining character.
* term+vt: refactor: move "utf8" char processing to term_process_and_print_non_ascii()Daniel Eklöf2025-02-06-0/+255
| | | | | | | | | | | This function "prints" any non-ascii character (i.e. any character that ends up in the action_utf8_print() function in vt.c) to the grid. This includes grapheme cluster processing etc. action_utf8_print() now simply calls this function. This allows us to re-use the same functionality from other places (like the text-sizing protocol).
* grid: reflow: handle composed characters longer than 2 cellsDaniel Eklöf2025-02-06-1/+1
| | | | | | | | | | | | | | | | | | | The logic that tries to ensure we don't break a line in the middle of a multi-cell character was flawed when the number of cells were larger than 2. In particular, if the number of cells to copy were limited by the number of cells left on the current (new) line, and were less than the length of the multi-cell character, then we failed to insert the correct number of spacers, and also ended up misplacing the multi-cell character; instead of pushing it to the next line, it was inserted on the current line, even though it doesn't fit. Also change how trailing SPACER cells are rendered (cells that are "fillers" at then end of a line, when a multi-column character was pushed over to the next line): don't copy the previous cell's attributes (which may be wrong anyway), use default attributes instead.
* term: insert-mode: handle combining characters correctlyDaniel Eklöf2025-02-06-3/+4
| | | | | | | | | | | | | | | | | When the client application emits combining characters, for example multi-codepoint emojis, in insert-mode, we ended up pushing partial graphemes to the right, for each codepoint, resulting in too many cells (and with the wrong content) being inserted. The fix is fairly simple; don't "insert" when appending characters to an existing grapheme cluster. This isn't something we can detect easily in print_insert() (it would require us to do grapheme clustering again). Fortunately, we do have the required information in action_utf8_print(). So, pass this information as a boolean to term_print(). Closes #1947
* term: ptmx pause/resume: don't modify the FDM if ptmx has been closedDaniel Eklöf2025-02-05-0/+4
| | | | | This fixes error message spam when resizing a terminal window executed with --hold, and where the client application has terminated.
* Add support for the new Wayland protocol xdg-system-bellDaniel Eklöf2025-01-17-0/+3
| | | | | | | | | | | | | | | | | | | From the release notes: system bell - allowing e.g. terminal emulators to hand off system bell alerts to the compositor for among other things accessibility purposes The new protocol is used when the new config option bell.system=yes (and the compositor implements the protocol, obviously). The system bell is rung independent of whether the foot window has keyboard focus or not (thus relying on compositor configuration to determine whether anything should be done or not in response to the bell). The new option is enabled by default.
* term: cursor_refresh(): don't try to dirty the grid if we don't have oneDaniel Eklöf2025-01-09-0/+3
| | | | | | | | | | | If the compositor sends a keyboard enter event before our window has been mapped, foot crashes; the enter event triggers a cursor refresh (hollow -> non-hollow block cursor), which crashes since we haven't yet allocated a grid. Fix by no-op:ing the refresh if the window hasn't been configured yet. Closes #1910
* terminal: Refresh only overlay when flash expiresAlexander Orzechowski2025-01-09-1/+6
| | | | | | | If we call render_refresh, that will wait for a callback to the main surface. In the case of a flash, the main surface might not get callbacks if the compositor implements fancy culling optimizations like wlroots wlr_scene compositors such as sway version >=1.10.
* term: limit app-id to 2048 charactersDaniel Eklöf2025-01-02-0/+15
| | | | | | | | | | | | Unsure if the protocol imposes a limit (haven't found any documentation), or if the issue is in the libwayland implementation, or wlroots (triggers in at least sway+river). The issue is that setting a too long app-id causes the compositor (river at least) to peg the CPU at 100%, and stop sending e.g. frame callbacks to foot. Closes #1897
* term: set_app_id() + set_window_title(): only allow printable charactersDaniel Eklöf2024-12-17-2/+2
|
* box-drawings: implement octantsDaniel Eklöf2024-12-08-0/+4
|
* term: get_font_dpi(): remove invalid assertionDaniel Eklöf2024-11-24-2/+0
| | | | Closes #1874
* osc: OSC-1 does not set the icon, it sets the icon _label_Daniel Eklöf2024-09-13-30/+6
| | | | | | | | | | In fact, there appears there *is* no escape sequence to set the icon. Keep most of the logic in place, but in practice, we'll always set the icon to the app-id. That is, at startup, we set it to the configured app-id (either from config, or the command line). OSC-176, which sets the app-id, also updates the icon (to the app-id).
* toplevel-icon: implement OSC-1, CSI 20/21/22/23 tDaniel Eklöf2024-09-13-2/+89
| | | | | | | | | | | | | | * The toplevel icon is now set to the app-id, unless "overridden" by OSC-1 or OSC-0. * Implemented OSC-1 * OSC-0 extended to also set the icon * Implemented CSI 20 t - report window icon * Implemented CSI 21 t - report window title * Implemented CSI 22 ; 1 t - push window icon * Implemented CS 23 ; 1 t - pop window icon * Extended CSI 22/23 ; 0 t to also push/pop the icon * Verify app-id set by OSC-176 is valid UTF-8 * Verify icon set by OSC-0/1 is valid UTF-8
* xsnprintf: various improvements related to xvsnprintf() and xsnprintf()Craig Barnes2024-09-13-1/+1
| | | | | | | | | | | | | | | | | | | | | | Summary of changes: * Make xvsnprintf() static * restrict-qualify pointer arguments (as done by the libc equivalents) * Make comments and spec references more thorough * Remove pointless `n <= INT_MAX` assertion (see comment) * Use FATAL_ERROR() instead of xassert() (since the assertion is inside a shared util function but the caller is responsible for ensuring the condition holds true) * Change some callers to use size_t instead of int for the return value (negative returns are impossible and all subsequent uses are size_t) The updated comments and code were taken (and adapted) from: https://gitlab.com/craigbarnes/dte/-/blob/49260bb154bca0434462a41c061e512540ec2e49/src/util/xsnprintf.c#L6-50 This work was entirely authored by me and I hereby license this contribution under the MIT license (stated explicitly, so that there's no ambiguity w.r.t. the original license).
* notifications: BEL and OSC-777 now focuses the window on notification activationDaniel Eklöf2024-09-05-2/+3
| | | | | | | | | | | Or put more propertly; if the notification daemon, and the notification helper used by foot has been configured properly (i.e. they both support XDG activation tokens), notifications generated by BEL and OSC-777 will now raise/focus the window when the default action of the notification is activated - typically by clicking the notification. Closes #1822
* term_set_window_title(): fix bad check for invalid UTF-8Daniel Eklöf2024-08-20-1/+1
| | | | mbsntoc32() returns (size_t)-1 on failure, not (char32_t)-1.
* feature: add resize-keep-grid to allow text reflow on font changesAndrew J. Hesford2024-08-20-1/+5
|
* term: thrd_join() returns thrd_success on success, not 0Daniel Eklöf2024-08-15-1/+1
| | | | Closes #1812
* term: reload_fonts(): don't ignore return value of thrd_join()Daniel Eklöf2024-08-04-2/+4
| | | | | | | | | | This should fix the ‘ret’ may be used uninitialized warning Closes #1789
* xmalloc: remove delim param from xstrjoin() and add separate xstrjoin3()Craig Barnes2024-08-03-4/+4
| | | | | | | | | | | This avoids the need for an unused third argument for most xstrjoin() calls and replaces the cases where it's needed with a more flexible function. Code generation is the same in both cases, when there are 2 string params and a compile-time known delimiter. This commit also converts 4 uses of xasprintf() to use xstrjoin*(). See also: https://godbolt.org/z/xsjrhv9b6
* osc: kitty notifications: cleanup and update to latest version of specDaniel Eklöf2024-08-02-15/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Don't store a list of unfinished notifications. Use a single one. If the notification ID of the 'current' notification doesn't match the previous, unfinished one, the 'current' notification replaces the previous one, instead of updating it. * Update xstrjoin() to take an optional delimiter (for example ','), and use that when joining categories and 'alive IDs'. * Rename ${action-arg} to ${action-argument} * Update handling of the 'n' parameter (symbolic icon name); the spec allows it to be used multiple times, and the terminal is supposed to pick the first one it can resolve. Foot can't resolve icons at all, neither can 'notify-send' or 'fyi' (which is what foot typically executes to display a notification); it's the notification daemon that resolves icons. The spec _could_ be interpreted to mean the terminal should lookup .desktop files, and use the value of the 'Icon' key from the first matching .desktop files. But foot doesn't read .desktop files, and I don't intend to implement XDG directory scanning and parsing of .desktop files just to figure out which icon to use. Instead, use a simple heuristics; use the *shortest* symbolic names. The idea is pretty simple: plain icon names are typically shorter than .desktop file IDs.
* osc: kitty notifications: buttons, icons, app-name, categories etcDaniel Eklöf2024-07-31-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | First, icons have been finalized in the specification. There were only three things we needed to adjust: * symbolic names are base64 encoded * there are a couple of OSC-99 defined symbolic names that need to be translated to the corresponding XDG icon name. * allow in-band icons without a cache ID (that is, allow applications to use p=icon without having to cache the icon first). Second, add support for the following new additions to the protocol: * 'f': custom app-name, overrides the terminal's app-id * 't': categories * 'p=alive': lets applications poll for currently active notifications * 'id' is now 'unset' by default, rather than "0" * 'w': expire time (i.e. notification timeout) * "buttons": aka actions. This lets applications add additional (to the terminal defined "default" action) actions. The 'activated' event has been updated to report which button/action was used to activate the notification. To support button/actions, desktop-notifications.command had to be reworked a bit. There's now a new config option: desktop-notifications.command-action-arg. It has two template arguments ${action-name} and ${action-label}. command-action-arg gets expanded for *each* action. ${action-name} and ${action-label} has been replaced by ${action-arg} in command. This is a somewhat special template, in that it gets replaced by *all* instances of the expanded actions.
* notify: don't close FD 0Daniel Eklöf2024-07-30-0/+4
| | | | | | | | | | | | | | | This fixes a regression where closing a terminal instance, or hard- or soft-resetting a terminal caused FD 0 to be closed. This meant it became re-usable. Usually, by memfd_create() when allocating a new surface buffer. So far nothing _really_ bad has happened. But what if FD 0 is now used by a memfd, and we close _another_ terminal instance? This causes our memfd to be closed. And then, when e.g. trying to scroll the terminal content: fallocate() fails with bad FD.
* notify: separate active notifications from unfinished kitty notificationsDaniel Eklöf2024-07-23-5/+16
| | | | | | | | | | | | | | | | | | | | | This fixes an issue where it wasn't possible to trigger multiple notifications with the same kitty notification ID. This is something that works in kitty, and there's no reason why it shouldn't work. The issue was that we track stdout, and the notification helper's PID in the notification struct. Thus, when a notification is being displayed, we can't re-use the same notification struct instance for another notification. This patch fixes this by adding a new notification list, 'active_notifications'. Whenever we detect that we need to track the helper (notification want's to either focus the window on activation, or send an event to the application), we add a copy of the notification to the 'active' list. The notification can then be removed from the 'kitty' list, allowing kitty notifications to re-use the same ID over and over again, even if old notifications are still being displayed.
* osc: kitty notifications: updated support for iconsDaniel Eklöf2024-07-23-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements the suggested protocol discussed in https://github.com/kovidgoyal/kitty/issues/7657. Icons are handled by loading a cache. Both in-band PNG data, and symbolic names are allowed. Applications use a graphical ID to reference the icon both when loading the cache, and when showing a notification. * 'g' is the graphical ID * 'n' is optional, and assigns a symbolic name to the icon * 'p=icon' - the payload is icon PNG data. It needs to be base64 encoded, but this is *not* implied. I.e. the application *must* use e=1 explicitly. To load an icon (in-band PNG data): printf '\e]99;g=123:p=icon;<base64-encoded-png-data>\e\\' or (symbolic name) printf '\e]99;g=123:n=firefox:p=icon;\e\\' Of course, we can combine the two, assigning *both* a symbolic name, *and* PNG data: printf '\e]99;g=123:n=firefox:p=icon;<base64-encoded-png>\e\\' Then, to use the icon in a notification: printf '\e]99;g=123;this is a notification\e\\' Foot also allows a *symbolic* icon to be defined and used at the same time: printf '\e]99;g=123:n=firefox;this is a notification\e\\' This obviously won't work with PNG data, since it uses the payload portion of the escape sequence.
* osc: kitty notifications: implement focus|reportDaniel Eklöf2024-07-23-13/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds support for window focusing, and sending events back to the client application when a notification is closed. * Refactor notification related configuration options: - add desktop-notifications sub-section - deprecate 'notify' in favor of 'desktop-notifications.command' - deprecate 'notify-focus-inhibit' in favor of 'desktop-notifications.inhibit-when-focused' * Refactor: rename 'struct kitty_notification' to 'struct notification' * Pass a 'struct notification' to notify_notify(), instead of many arguments. * notify_notify() now registers a reaper callback. When the notifier process has terminated, the notification is considered closed, and we either try to focus (activate) the window, or send an event to the client application, depending on the notification setting. * For the window activation, we need an XDG activation token. For now, assume *everything* written on stdout is part of the token. * Refactor: remove much of the warnings from OSC-99; we don't typically log anything when an OSC/CSI has invalid values. * Add icon support to OSC-99. This isn't part of the upstream spec. Foot's implementation: - uses the 'I' parameter - the value is expected to be a symbolic icon name - a quick check for absolute paths is done, and such icon requests are ignored. * Added ${icon} to the 'desktop-notifications.command' template. Uses the icon specified in the notification, or ${app-id} if not set.
* spawn: add optional reaper callback, return pid_tDaniel Eklöf2024-07-23-4/+4
| | | | | This will allow spawn() callers to do things when the spawned process has terminated.
* osc/notify: add support for OSC-99, kitty desktop notificationsDaniel Eklöf2024-07-23-2/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | This adds limited support for OSC-99, kitty desktop notifications[^1]. We support everything defined by the "protocol", except: * 'a': action to perform on notification activation. Since we don't trigger the notification ourselves (over D-Bus), we don't know a) which ID the notification got, or b) when it is clicked. * ... and that's it. Everything else is supported To be explicit, we *do* support: * Chunked notifications (d=0|1), allowing the application to append data to a notification in chunks, before it's finally displayed. * Plain UTF-8, or base64-encoded UTF-8 payload (e=0|1). * Notification identifier (i=xyz). * Payload type (p=title|body). * When to honor the notification (o=always|unfocused|invisible), with the following quirks: - we don't know when the window is invisible, thus it's treated as 'unfocused'. - the foot option 'notify-focus-inhibit' overrides 'always' * Urgency (u=0|1|2) [^1]: https://sw.kovidgoyal.net/kitty/desktop-notifications/
* input: allow mouse selections to start inside the marginsDaniel Eklöf2024-07-19-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this, margins were special cased: * The mouse cursor was always a pointer, and never an I-beam (thus signaling selections cannot be made). * The internal mouse coords where set to -1 when the cursor was inside the margins, causing: - text selections from being made - mouse events being passed to mouse grabbing applications In particular, even with a one-pixel margin, making selections was unnecessarily hard in e.g. fullscreen mode, where you'd expect to be able to throw the cursor into the corner of the screen and then start a selection. With this patch, the cursor is treated as if it was in the first/last column/row, when inside the margin(s). An unintended side-effect of this, initially, was that auto-scrolling selections where way too easy to trigger, since part of its logic is checking if the cursor is inside the margins. That problem has been reduced by two things: * auto-scrolling does not occur unless a selection has been started. That is, just holding down the mouse in the margins and moving up/down doesn't cause scrolling. You have to first select at least one cell in the visible viewport. * A selection isn't fully started (i.e. a cell is actually selected) unless the cursor is inside the actual grid, and *not* in the margins. What does the last point mean? We now allow a selection to be _started_ when clicking in the margin. What this means internally is we set a start coordinate for a selection, but *not* and end coordinate. At this point, we don't have an actual selection. Nothing is selected, and no cells are highlighted, graphically. This happens when we set an end coordinate. Without the last bullet point, that would happen as soon as the cursor was _moved_, even if still inside the margins. Now, we require the cursor to leave the margins and touch an actual cell before we set an end coordinate. Closes #1702
* csi: in-band window resize notifications, private mode 2048Daniel Eklöf2024-07-19-0/+35
| | | | | | | | | | | | | This implements https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83, in-band window resize notifications. When user enables private mode 2048 (in-band resize notifications), *always* send current size, even if the mode is already active. This ensures applications can rely on getting a reply from the terminal.
* input: don't map wheel events to BTN_{BACK,FORWARD}Daniel Eklöf2024-07-13-10/+16
| | | | | | | | | | | | | | | | | | | | BTN_BACK and BTN_FORWARD are separate buttons. The scroll wheel don't have any button mappings in libinput/wayland, so make up our own defines. This allows us to map them in mouse bindings. Also expose BTN_WHEEL_{LEFT,RIGHT}. These were already defined, and used, internally, to handle wheel tilt events. With this, they can also be used in mouse bindings. Finally, fix encoding used for BTN_{BACK,FORWARD} when sending mouse button events to the client application. Before this, they were mapped to buttons 4/5. But, button 4/5 are for the scroll wheel, and as mentioned above, BTN_{BACK,FORWARD} are not the same as scroll wheel "buttons". Closes #1763
* osc: extend damage-cells-by-color to default fg/bg as wellDaniel Eklöf2024-07-03-0/+90
| | | | | | | | | | | | | | | When changing part of the color palette, through either OSC-4, or OSC-10 and OSC-11 (and the corresponding reset OSCs: 104, 110 and 111), only dirty affected cells. We've always done this, but only for OSC-4. This patch breaks out that logic, and extends it to handle default fg/bg too. It also fixes a bug where cells with colored underlines were not dirtied if the underline was the only part of the cell that was affected by a OSC-4 change.
* csi: implement XTPUSHCOLORS+XTPOPCOLORS+XTREPORTCOLORSDaniel Eklöf2024-07-03-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The documentation of these sequences are vague and lacking, as is often the case with XTerm invented control sequences. I've tried to replicate what XTerm does (as of xterm-392). The stack represents *stashed/stored* palettes. The currently active palette is *not* stored on the stack. The stack is dynamically allocated, and starts out with zero elements. Now, XTerm has a somewhat weird definition of "pushing" and "popping" in this context, and the documentation is somewhat misleading. What a push does is this: it stores the current palette to the stack at the specified slot. If the specified slot number (Pm) is 0, the slot used is the current slot index incremented by 1. The "current" slot index is then set to the specified slot (which is current slot + 1 if Pm == 0). Thus, "push" (i.e. when Pm == 0 is used) means store to the "next" slot. This is true even if the current slot index points into the middle of stack. Pop works in a similar way. The palette is restored from the specified slot index. If the specified slot number is 0, we use the current slot index. The "current" slot index is then set to the specified slot - 1 (current slot - 1 if Pm == 0). XTREPORTCOLORS return the current slot index, and the number of palettes stored on the stack, on the format CSI ? <slot index> ; <palette count> # Q When XTPUSHCOLORS grows the stack with more than one element (i.e. via a 'CSI N # P' sequence), make sure *all* new slots are initialized (to the current color palette). This avoids uninitialized slots, that could then be popped with XTPOPCOLORS. Closes #856
* osc: merge OSC 10/11/12/17/19 handlingDaniel Eklöf2024-07-03-6/+4
| | | | | | | | | | 10/11/17/19 were already merged, so this patch just stops special casing 12 (cursor color). In preparation for XTPUSHCOLORS/XTPOPCOLORS, the cursor colors are moved from their own struct, into the 'colors' struct. Also fix a bug where OSC 17/19 queries returned OSC-11 data.
* Rename various uses of "curly" in the source code with "underline"Craig Barnes2024-07-01-12/+12
| | | | | Since "curly" could make it seem as if all underline styles are curled (to people unfamiliar with the codebase), whereas in reality only 1 is.
* term: performance: use a bitfield to track which ascii printer to useDaniel Eklöf2024-06-26-8/+15
| | | | | | | | | | | The things affecting which ASCII printer we use have grown... Instead of checking everything inside term_update_ascii_printer(), use a bitfield. Anything affecting the printer used, must now set a bit in this bitfield. This makes term_update_ascii_printer() much faster, since all it needs to do is check if the bitfield is zero or not.
* term: term_fill(): only set OSC-8 + styled hyperlinks when use_sgr_attrs is setDaniel Eklöf2024-06-26-3/+4
|
* terminal: term_fill(): fix osc8 erase bug + handle styled underlinesDaniel Eklöf2024-06-26-2/+16
| | | | | | | | Only clear OSC-8 hyperlinks at the target columns if we don't have an active OSC-8 URI. This corresponds to normal VT attributes; the currently active attributes are set, and all others are cleared. Handle styled underlines in the same way
* csi: wip: styled underlinesDaniel Eklöf2024-06-26-3/+19
| | | | | | | | | | | | | This is work in progress, and fairly untested. This adds initial tracking of styled underlines. Setting attributes seems to work (both color and underline style). Grid reflow has *not* been tested. When rendering, style is currently ignored (all styles are rendered as a plain, legacy underline). Color however, *is* applied.
* render: use single-pixel buffers for overlays, when possibleDaniel Eklöf2024-05-22-1/+3
| | | | | | | | | | | | | | | | | | | The unicode-mode, and flash overlays are single color buffers. This means we can use the single-pixel buffer protocol. It's undefined whether the compositor will release the buffer or not; to make things easier, simply destroy the buffer as soon as we've committed it. Note that since compositors don't necessarily release single-pixel buffers, we can't plug them into our own buffer interface. This means we can't use buffer pointers to check if we can re-use the previous buffer (i.e. we can skip comitting a new buffer), or if we have to create a new one. It's _almost_ enough to just check if the last overlay style is the same as the current one. Except that that doesn't take window resizes into account...
* config: add cursor.blink-rate optionDaniel Eklöf2024-05-20-5/+9
| | | | | | The default is 500ms, which corresponds to the old, hardcoded default. Closes #1707
* term: default to DPI 96, if the monitor's DPI is 0Daniel Eklöf2024-04-20-4/+7
| | | | | This can happen in virtualized environments, or when running a nested Wayland session.
* term: stash last known DPI, and use after a unmapped/mapped sequenceDaniel Eklöf2024-04-17-3/+21
| | | | | | | | | | | | | | | | | | A compositor may unmap, and then remap the window, for example when the window is minimized, or if the user switches workspace. With DPI aware rendering, we *need* to know on which output we're mapped, in order to use the correct DPI. This means the first frame we render, before being mapped, always guesses the DPI. In an unmap/map sequence, guessing the wrong DPI means the window will flicker. Fix by stashing the last used DPI value, and use that instead of guessing. This means the *only* time we _actually_ guess the DPI, is the very first frame, when starting up foot.
* term: don't print outside grid when printing multi-column charactersDaniel Eklöf2024-04-15-1/+4
| | | | | | | | | | When auto-wrap is disabled, a multi-column character may be printed on a line that doesn't fit the entire character. That is, the "spacers" we print, as place holders in the columns after the first one, may reach outside the grid. We did (try to) check for this, but the check was off by one. Meaning, we could, in some cases, print outside the grid.
* wayland: remove has_wl_compositor_v6Daniel Eklöf2024-04-12-1/+1
| | | | | | | | | We deviate slightly from the specification, in that we don't assume a preferred buffer scale of 1. Instead, we "guess" the scale *until we receive a surface_preferred_buffer_scale event. Because of this, we don't need the has_wl_compositor_v6 member, as it's enough to check if we have a non-zero 'preferred buffer scale'.
* term: send SIGHUP before SIGTERM when shutting downDaniel Eklöf2024-04-05-13/+57
| | | | | | | | If we're the ones initiating shutdown, start by sending SIGHUP. Only if the client application does not terminate, send SIGTERM (and if it still refuses to terminate, send SIGKILL). Also reduce the timeout between the signals from 60s to 30s.
* term: don't shutdown terminal when PTY is closed, unless --pty was usedDaniel Eklöf2024-04-05-1/+13
| | | | | | | | | | | | | | | | | Unless --pty has been used, we do *not* want to shutdown the terminal when the PTY is closed by the client application; we want to wait for the client application to actually terminate. This was the behavior before the --pty patch. This was changed in the --pty patch, since then, we don't *have* a client application. That is, foot has not forked+exec:ed anything. The only way to trigger a shutdown (from the client side) is to close the PTY. This patch restores the old behavior, when --pty is *not* used. Closes #1666
* wayland: only use the surface preferred scale if set by the compositorDaniel Eklöf2024-04-05-1/+1
| | | | | | | | Before this patch, we would, in some cases, fallback to the surface preferred (not fractional) scaling, even though the compositor hadn't actually published a preferred buffer scale; the presence of a v6 compositor interface doesn't mean we've actually received a preferred scale yet.
* xmalloc: add xmemdup() and use to replace some uses of xmalloc+memcpyCraig Barnes2024-03-17-4/+1
|
* Add support for opening an existing PTYAlyssa Ross2024-03-14-27/+40
| | | | | | | | | | | | | | | | | Virtual machine monitor programs (e.g. QEMU, Cloud Hypervisor) expose guest consoles as PTYs. With this patch, foot can access these guest consoles. Usually, the program used for accessing these PTYs is screen, but screen is barely developed, doesn't support resizing, and has a bunch of other unrelated stuff going on. It would be nice to have a terminal emulator that properly supported opening an existing PTY. The VMM controls the master end of the PTY, so to the other end (in this case foot), it just behaves like any application running in a directly-opened PTY, and all that's needed is to change foot's code to support opening an existing PTY rather than creating one. Co-authored-by: tanto <tanto@ccc.ac>
* term_fill(): no need to set attrs.clean = 0Daniel Eklöf2024-03-07-2/+0
| | | | The VT state’s attribute is always 0
* term_fill(): change ‘character’ parameter from char -> uint8_tDaniel Eklöf2024-03-07-1/+1
|
* term_fill(): make sure the filled cells have their ‘clean’ bit resetDaniel Eklöf2024-03-07-1/+3
|
* term: modify term_fill() to optionally reset the SGR attributesDaniel Eklöf2024-03-07-2/+7
|
* term: replace term_put_char() with term_fill()Daniel Eklöf2024-03-07-13/+19
|
* term: codespell: limitiations -> limitationsDaniel Eklöf2024-03-07-1/+1
|
* put_char fixupDaniel Eklöf2024-03-07-0/+1
|
* term: print: spacers may be printed all the way up to the last columnDaniel Eklöf2024-03-07-1/+1
|
* term: add term_put_char()Daniel Eklöf2024-03-07-0/+36
| | | | | | | | This function prints a single, non-double width, character to the grid. It handles OSC-8 hyperlinks, but does not: * update the cursor location * erase sixels
* term: erase-scrollback: handle non-existing scrollback historyDaniel Eklöf2024-02-15-0/+11
| | | | | | | | | | | | If scrollback.lines == 0, and the window size (number of rows) is a power of two, all rows are always visible. I.e. there is no scrollback history. This threw off the scrollback erase logic, causing visible rows to be erased, and set to NULL. This triggered a crash when trying to update the view. Closes #1610
* osc: add support for osc 176 (app ID)delthas2024-02-06-1/+60
| | | | | | | | | | This adds support for a new OSC escape sequence: OSC 176, that lets terminal programs tell the terminal the name of the app that is running. foot then sets the app ID of the toplevel to that ID, which lets the compositor know which app is running, and typically sets the appropriate icon, window grouping, ... See: https://gist.github.com/delthas/d451e2cc1573bb2364839849c7117239
* term: drop term->render.title.is_armedDaniel Eklöf2024-02-06-2/+0
| | | | | | | | | | | | | | | | | This boolean isn't needed. The idea was probably to not re-program the timer unnecessarily, or even to prevent it from being moved forward in time indefinitely. However, the logic has (probably) gone through some changes, that now makes it irrelevant. The timer isn't moved forward indefinitely; it is always set to 8ms from the last title update. The closer we get to that point in time, the smaller the timeout we set. Now, is_armed _did_ prevent the timer from being re-programmed. But that tiny performance tweak isn't really necessary, as the title should, in normal cases, not be set that often anyway.