Commit graph

5559 commits

Author SHA1 Message Date
Daniel Eklöf
b8506bbea0
selection: extend: use scrollback relative coordinates
When extending a selection, we determine *how* to extend it (which
endpoint to move, and whether to grow or shrink the selection) by
comparing the extension point with the old start and end coordinates.

For this to work correctly, we need to use scrollback relative
coordinates.

This fixes an issue where extending a very large selection (covering
many pages) sometimes shrunk the selection instead of growing it, or
just misbehaving in general.
2022-07-28 21:06:58 +02:00
Daniel Eklöf
6ebf55572e
selection: foreach_selected_*(): refactor: use grid_row_abs_to_sb() 2022-07-28 21:06:58 +02:00
Daniel Eklöf
a05eaf28bd
selection: selection_on_rows(): use scrollback relative coords
When checking if the current selection intersects with the
region (passed as parameter to the function), use scrollback relative
coordinates.

This fixes an issue where selections crossing the scrollback
wrap-around being misdetected, resulting in either the selection being
canceled while scrolling, even though it wasn’t scrolled out, or the
selection _not_ being canceled, when it _was_ scrolled out.
2022-07-28 21:06:57 +02:00
Daniel Eklöf
632c4839cd
search: find_next(): handle trailing SPACER cells
Make sure to increment match_end_col to account for trailing SPACER
cells after a match.

This fixes an issue where search matches weren’t highlighted correctly
when the match *ends* with a double-width character.
2022-07-28 21:05:06 +02:00
Daniel Eklöf
d79a3b9350
config: add colors.search-box-{no-,}match
Closes #1112
2022-07-28 19:02:56 +02:00
Daniel Eklöf
4873004c37
test: config: test colors.{jump-labels,scrollback-indicator} 2022-07-28 19:02:55 +02:00
Daniel Eklöf
801970aa33
input: kitty: always treat composed characters as ‘printable’
Certain dead key combinations results different escape sequences in
foot, compared to kitty, when the kitty keyboard protocol is used.

        if (composed && is_text)
            key = utf32;
        else {
            key = xkb_keysym_to_utf32(sym_to_use);
            if (key == 0)
                return false;

            /* The *shifted* key. May be the same as the unshifted
             * key - if so, this is filtered out below, when
             * emitting the CSI */
            alternate = xkb_keysym_to_utf32(sym);
        }

If is_text=false, we’ll fall through to the non-composed
logic. is_text is set to true if the character is printable *and*
there aren’t any non-consumed modifiers enabled.

shift+space is one example where shift is *not* consumed (typically -
may be layouts where it is).

As a result, pressing ", followed by shift+space with the
international english keyboard layout (where " is a dead key) results
in different sequences in foot and kitty.

This patch fixes this by always treating composed characters as
printable.

Closes #1120
2022-07-28 19:02:25 +02:00
Daniel Eklöf
4abf46955f
keymap: change alt+escape to emit \E\E instead of a CSI 27 sequence
Closes #1105
2022-07-28 19:02:05 +02:00
Daniel Eklöf
24c2d56804
render: it’s unlikely() the current cell is where the cursor is 2022-07-28 18:55:34 +02:00
Daniel Eklöf
87e4004960
csi: clamp color index for ‘CSI 38/48 ; 5 ; idx m’ sequences
Indexed color values are stored in the cell attributes as color
indices (into the 256-color table). However, the index from the CSI
was not validated in any way, meaning you can do something like this:

  echo -e ‘\e[38:5:1024m CRASH \e[m’

and foot will crash on an out-of-bounds access.

Fix by clamping the color index.

Closes #1111
2022-07-22 10:44:33 +02:00
Daniel Eklöf
0c60bb3f29
grid: reflow: require col count > 0 when skipping line truncation
When reflowing the grid, we truncate lines with a hard linebreak after
the last non-empty cell. This way we don’t reflow trailing empty cells
to a new line when resizing the window to a smaller size.

However, “logical” lines (i.e. those without a hard linebreak)
are *not* truncated. This is to ensure we don’t trim empty cells in
the middle of a logical line spanning multiple physical lines.

Since newly allocated rows are initialized with linebreak=false, we
need to ensure _those_ are still truncated - otherwise all that empty
space under the current prompt will be reflowed.

Note that this is a temporary workaround. The correct solution, I
think, is to track whether a line has been printed to or not, and
simply ignore (not reflow) lines that haven’t yet been touched.
2022-06-30 19:47:18 +02:00
Daniel Eklöf
37f094280b
Revert "grid: invert the default value of ‘linebreak’, from false to true"
This reverts commit cdd46cdf85.
2022-06-30 19:37:01 +02:00
Daniel Eklöf
d58290ea12
input: don’t ignore keyboard enter/leave events when there’s no keymap
The compositor _usually_ sends the keymap event *before* the enter
event. But not always.

Not (yet) having a keymap is not a reason to ignore the enter
event (now, on the other hand, getting a key press/release event
without a keymap is a compositor bug).

Closes #1097
2022-06-28 20:57:48 +02:00
Daniel Eklöf
206e9a1050
selection: wl_data_offer_set_action: use enum values instead of magic integers 2022-06-21 19:46:31 +02:00
Daniel Eklöf
6d4d4502e9
selection: reject dnd offers with unsupported mime-types
We were already doing this, implicitly, *if* the offer was for the
main grid.

This patch makes it more clear that we do not accept the offer.
2022-06-20 20:57:26 +02:00
Daniel Eklöf
0d22e9fa01
selection: explicitly reject *all* dnd offers not targeting the grid 2022-06-20 20:57:23 +02:00
Daniel Eklöf
2e4da6fbf6
selection: ignore drag-and-drops with unsupported mime-types
Specifically, make sure we do *not* call wl_data_offer_receive() with
a NULL mime-type, as this causes libwayland to error out, which in
turn causes foot to exit.

Closes #1092
2022-06-20 20:56:11 +02:00
Daniel Eklöf
bfc53d1e71
shm-formats: #ifdef on formats added in 1.20 2022-06-20 19:20:28 +02:00
Daniel Eklöf
fabffd626b
wayland: log human readable SHM format names in debug builds 2022-06-20 18:58:40 +02:00
Daniel Eklöf
8689389523
key-binding: set BIND_ACTION_KEY_COUNT correctly
When the new promp-prev/next bindings were added, we forgot to update
BIND_ACTION_KEY_COUNT to reflect this.
2022-06-17 18:42:42 +02:00
Daniel Eklöf
bdb79e8b9f
osc: add support for OSC 133;A (prompt markers)
This patch adds support for the OSC-133;A sequence, introduced by
FinalTerm and implemented by iTerm2, Kitty and more. See
https://iterm2.com/documentation-one-page.html#documentation-escape-codes.html.

The shell emits the OSC just before printing the prompt. This lets the
terminal know where, in the scrollback, there are prompts.

We implement this using a simple boolean in the row struct ("this row
has a prompt"). The prompt marker must be reflowed along with the text
on window resizes.

In an ideal world, erasing, or overwriting the cell where the OSC was
emitted, would remove the prompt mark. Since we don't store this
information in the cell struct, we can't do that. The best we can do
is reset it in erase_line(). This works well enough in the "normal"
screen, when used with a "normal" shell. It doesn't really work in
fullscreen apps, on the alt screen. But that doesn't matter since we
don't support jumping between prompts on the alt screen anyway.

To be able to jump between prompts, two new key bindings have been
added: prompt-prev and prompt-next, bound to ctrl+shift+z and
ctrl+shift+x respectively.

prompt-prev will jump to the previous, not currently visible, prompt,
by moving the viewport, ensuring the prompt is at the top of the
screen.

prompt-next jumps to the next prompt, visible or not. Again, by moving
the viewport to ensure the prompt is at the top of the screen. If
we're at the bottom of the scrollback, the viewport is instead moved
as far down as possible.

Closes #30
2022-06-16 19:02:10 +02:00
Daniel Eklöf
96f23b4c64
ime: track IME focus independently from keyboard focus
Replace the seat->ime.focused boolean with a terminal instace pointer,
seat->ime_focus.

Set and reset this on ime::enter() and ime::leave() events, and use
this instead of seat->kbd_focus on all other IME events.

This fixes two issues:

a) buggy compositors that sometimes sends an IME enter event without
  first having sent a keyboard enter event.

b) seats may be IME capable while still lacking the keyboard
  capability. Such seats will *always* see IME enter events without a
  corresponding keyboard enter event.
2022-06-15 19:25:33 +02:00
Daniel Eklöf
d852178540
ime: ime_reset_pending_{preedit,commit} is not used outside ime.c 2022-06-15 19:25:32 +02:00
Daniel Eklöf
9dc4f48e7a
vt: tag collision-count check with ‘unlikely’ 2022-06-15 19:25:00 +02:00
Daniel Eklöf
fbcb30bf98
vt: improve key calculation for compose sequences
* Don’t assume 32 bits when rotating the old key. Use the number of
  actual bits available, as determined by CELL_COMB_CHARS_{HI,LO}
* Multiply with magic hash constant

This greatly reduces the number of collisions seen. For example, the
Emoji test file (from the Unicode specification), now has zero
collisions.
2022-06-15 19:25:00 +02:00
Daniel Eklöf
edd68732ad
vt: prevent potential endless loop when finding a slot for a composed character
Composed characters are stored in a tree structure, using a key as
identifier. The key is calculated from the individual characters that
make up the composed character sequence.

Since the address space for keys is limited, collisions may occur. In
this case, we simply increment the key and try again.

It is theoretically possible to saturate the key space, in which case
we’ll get stuck in an endless loop.

Even if the key space isn’t fully saturated, we fairly easy reach a
point where there are so many collisions for each insertion, that
performance drops significantly.

Since key space is limited (it’s not like a hash table that we can
grow), our only option is to limit the number of collisions. If we
can’t find a slot within a hard code amount of collisions, the
character is simply dropped.
2022-06-15 19:25:00 +02:00
Daniel Eklöf
dbe2c0a068
selection: allow HT, VT and FF, disallow NUL in non-bracketed paste mode
This syncs foot with more recent versions of XTerm, where it’s
“disallowedPasteControls” resource has changed its default value to

  BS,DEL,ENQ,EOT,ESC,NULL

Note that we’re already stripping out ENQ,EOT,ESC in all modes.

What does it mean for foot:

* HT, VT and FF are now allowed, regardless of paste mode
* NUL is now stripped in non-bracketed paste mode

Closes #1084
2022-06-15 19:09:40 +02:00
Daniel Eklöf
d3c51b51b7
pgo: slave_spawn(): sync function signature 2022-06-13 16:32:59 +02:00
Daniel Eklöf
8436e6acea
test: config: new test for the new ‘environment’ section 2022-06-13 11:55:24 +02:00
Daniel Eklöf
604a3cdd84
changelog: new ‘environment’ section in foot.ini 2022-06-13 11:55:24 +02:00
Daniel Eklöf
5760bcb3bf
doc: document the new ‘environment’ config section 2022-06-13 11:55:23 +02:00
Daniel Eklöf
755f96321a
config: add a new ‘environment’ section
This section allows the user to define custom environment variables to
be set in the child process:

  [environment]
  name=value
2022-06-13 11:55:23 +02:00
Daniel Eklöf
497c31d9fc
commands: scroll up: simplify viewport clamping logic
When scrolling the viewport up, we need to ensure we don’t go past the
scrollback wrap around.

This was previously done using “custom” logic that tried to calculate
many rows away from the scrollback start the current viewport is.

But this is *exactly* what grid_row_abs_to_sb() does, except it
doesn’t account for uninitialized scrollback.

So, copy the logic from grid_row_abs_to_sb(), but ensure scrollback
start points to valid scrollback data. The maximum number of rows
we’re allowed to scroll is now the same as the current viewport’s
sb-relative coordinate.

Maybe closes #1074
2022-06-13 11:53:37 +02:00
Daniel Eklöf
9567694bab
grid: reflow: don’t trim trailing empty cells from logical lines
When a line in the old grid (the one being reflowed) doesn’t have a
hard linebreak, don’t trim trailing empty cells.

Doing so means we’ll “compress” (remove) empty cells between text
if/when we revert to a larger window size.

The output from neofetch suffers from this; it prints a logo to the
left, and system information to the right. The logo and the system
info column is separated by empty cells (i.e. *not* spaces).

If the window is reduced in size such that the system info is pushed
to a new line, each logo line ends with a number of empty cells. The
next time the window is resized, these empty cells were
ignored (i.e. removed).

That meant that once the window was enlarged again, the system info
column was a) no longer aligned, and b) had been pulled closer to the
logo.

This patch doesn’t special case trailing empty cells when the line
being reflowed doesn’t have a hard linebreak. This means e.g. ‘ls’
output is unaffected.

Closes #1055
2022-06-11 12:02:20 +02:00
Daniel Eklöf
cdd46cdf85
grid: invert the default value of ‘linebreak’, from false to true 2022-06-11 12:02:20 +02:00
Daniel Eklöf
377997be9d
Merge branch 'tokyonight' 2022-06-01 20:01:51 +02:00
Lorenz
e521fe5394
Add 'themes/tokyonight-storm' 2022-06-01 20:01:30 +02:00
Lorenz
b4443c7daa
Add 'themes/tokyonight-night' 2022-06-01 20:01:30 +02:00
Lorenz
45b6d91eef
Add 'themes/tokyonight-day' 2022-06-01 20:01:23 +02:00
Stefan Prosiegel
8d03652a18
themes: add catppuccin 2022-05-25 17:05:36 +02:00
Daniel Eklöf
bc7214cd88
config: use $HOME instead of getpwuid() to retrieve users’s home dir
When searching for foot.ini, use $HOME instead of getpwuid() to
retrieve the user’s home directory.
2022-05-25 17:02:41 +02:00
Daniel Eklöf
7e8b5f9610
main: minor rewording of non-UTF8 locale warnings and errors 2022-05-14 09:14:57 +02:00
Daniel Eklöf
15d45d5704
meson: -Dsystemd-units-dir installs even if systemd is not found
If -Dsystemd-units-dir is explicitly set, then install the systemd
service files regardless of whether systemd is available or not.
2022-05-12 13:46:06 +02:00
Daniel Eklöf
62fe452cc2
meson: add -Dsystemd-units-dir=<path> meson command line option
This allows package maintainers to override the location to which our
systemd service files are installed.

It’s value is an *absolute* path, and *not* relative ${prefix}.

The default is ${systemduserunitdir}.
2022-05-12 13:45:53 +02:00
Daniel Eklöf
56e5855fff
doc: benchmarks: update with desktop results for 1.12.1 (r9) 2022-05-12 13:10:24 +02:00
Daniel Eklöf
834beb966e
doc: benchmarks: update with laptop results for 1.12.1 (r9) 2022-05-12 11:53:08 +02:00
Daniel Eklöf
200c5cbc79
wayland: throttle xdg activation token requests for window urgency
When XDG activation support was added to URL mode, we introduced a
regression, where it is possible to flood the Wayland socket with XDG
activation token requests.

Start foot with “foot -o bell.urgency=yes”, then run:

  while true; do echo -en ‘\a’; done

Finally, switch keyboard focus to another window. Foot crashes.

Throttle the token requests by limiting the number of outstanding
urgency token requests to 1.

Closes #1065
2022-05-11 21:17:52 +02:00
Daniel Eklöf
fc67bff9c0
terminal: move viewport when part of it is scrolled out
If the viewport is at the top of the scrollback, and a program is
scrolling (e.g. by emitting newlines), the viewport needs to be
moved. Otherwise, the top of the viewport will show the *bottom* of
the scrollback (i.e. the newly emitted lines), and the bottom of the
viewport shows the top of the scrollback.

How do we detect if the viewport needs to be moved?

We convert its absolute row number to a scrollback relative row. This
number is also the maximum number of rows we can scroll without the
viewport being scrolled out.

In other words, if the number of rows to scroll is larger than the
viewports scrollback relative row number, the viewport needs to
moved.

How much do we need to move it? The difference between the number of
rows to scroll, and the viewports scrollback relative row number.

Example:

if the viewport is at the very top of the scrollback, its scrollback
relative row number is 0. In this case, it needs to be moved the same
number of rows as is being scrolled.
2022-05-11 17:58:18 +02:00
Lorenz
3431619d07 Themes: Add 'Monokai Pro' theme
Signed-off-by: Lorenz <lorenz@noreply.codeberg.org>
2022-05-09 06:16:05 +02:00
Daniel Eklöf
f14fc120ad
pgo: add xdg_activation_token parameter to spawn() stub 2022-05-06 10:39:49 +02:00