Commit graph

460 commits

Author SHA1 Message Date
Daniel Eklöf
18b702b249
unicode-mode: move state from seat to term
This fixes an issue where entering unicode-mode in one foot client,
also enabled unicode-mode on other foot clients. Both
visually (although glitchy), and in effect.

The reason the state was originally in the seat objects, was to fully
support multi-seat. That is, one seat/keyboard entering unicode-mode
should not affect other seats/keyboards.

The issue with this is that seat objects are Wayland global. Thus, in
server mode, all seat objects are shared between the foot clients.

There is a similarity with IME, which also keeps state in the
seat. There's one big difference, however, and that is IME has Wayland
native enter/leave events, that the compositor emits when windows are
focused/unfocused. These events allow us to reset IME state. For our
own Unicode mode, there is nothing similar.

This patch moves the Unicode state from seats, to the terminal
struct. This does mean that if one seat/keyboard enters Unicode mode,
then *all* seats/keyboards will affect the unicode state. This
potential downside is outweighed by the fact that different foot
clients no longer affect each other.

Closes #1717
2024-05-21 08:36:56 +02:00
Daniel Eklöf
7c20fb247c
term: stash last known DPI, and use after a unmapped/mapped sequence
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.
2024-04-17 09:14:52 +02:00
Daniel Eklöf
7f4328e0b1
term: send SIGHUP before SIGTERM when shutting down
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.
2024-04-05 19:34:17 +02:00
Daniel Eklöf
cb820a498b
sixel: RA region does not affect the text cursor position
The raster attributes is, really, just a way to erase an area. And, if
the sixel is transparent, it's a nop.

The final text cursor position depends, not on our image size (which
is based on RA), but on the final graphical cursor position.

However, we do want to continue using it as a hint of the final image
size, to be able to pre-allocate the backing buffer.

So, here's what we do:

* When trimming trailing transparent rows, only trim the *image*, if
  the graphical cursor is positioned on the last sixel row, *and* the
  sixel is transparent.
* Opaque sixels aren't trimmed at all, since RA in this acts as an
  erase that fills the RA region with the background color.
* The graphical cursor position is always adjusted (i.e. trimmed),
  since it affects the text cursor position.
* The text cursor position is now calculated from the graphical cursor
  position, instead of the image height.
2024-03-18 17:11:26 +01:00
Daniel Eklöf
cc660bc7c1
sixel: trim trailing, fully transparent sixel rows
See https://github.com/hpjansson/chafa/issues/192
2024-03-18 17:09:20 +01:00
Alyssa Ross
86894a1cd2
Add support for opening an existing PTY
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>
2024-03-14 07:31:03 +01:00
Daniel Eklöf
23908d9277
term_fill(): change ‘character’ parameter from char -> uint8_t 2024-03-07 16:24:33 +01:00
Daniel Eklöf
b3a84ba71b
term: modify term_fill() to optionally reset the SGR attributes 2024-03-07 16:24:33 +01:00
Daniel Eklöf
189cfd717f
term: replace term_put_char() with term_fill() 2024-03-07 16:24:33 +01:00
Daniel Eklöf
ea851962c1
term: add term_put_char()
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
2024-03-07 16:24:32 +01:00
Daniel Eklöf
1568518ab3
sixel: performance improvements
* Store pointer to current pixel (i.e. pixel we're about to write to),
  instead of a row-byte-offset. This way, we don't have to calculate the
  offset into the backing image every time we emit a sixel band.

* Pass data pointer directly to sixel_add_*(), to avoid having to
  calculate an offset into the backing image.

* Special case adding a single 1:1 sixel. This removes a for loop, and
  simplifies state (position) updates. It is likely LTO does this for
  us, but this way, we get it optimized in non-LTO builds as well.
2024-03-06 16:37:54 +01:00
delthas
6c56b04b3f
osc: add support for osc 176 (app ID)
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
2024-02-06 13:50:09 +01:00
Daniel Eklöf
4801d3a305
term: drop term->render.title.is_armed
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.
2024-02-06 13:41:09 +01:00
Daniel Eklöf
7999975016
Don't use fancy Unicode quotes, stick to ASCII 2024-02-06 12:36:45 +01:00
Daniel Eklöf
1c70a84fde
config: add pipe-command-output key-binding 2024-02-06 12:12:57 +01:00
Daniel Eklöf
e9607de5ae
osc: store column of FTCS_COMMAND_{EXECUTED,FINISHED} in row struct 2024-02-06 12:12:57 +01:00
Daniel Eklöf
f8e875a7cd
term: move row->prompt_marker into new struct, row->shell_integration 2024-02-06 12:12:56 +01:00
Leonardo Hernández Hernández
7e3da3007b
wayland: use wl_compositor version 6 when available 2024-01-24 20:00:18 +01:00
Daniel Eklöf
9da7152f83
slave: don't skip setting environment variables when using a custom environment
When launching footclient with -E,--client-environment the environment
variables that should be set by foot, wasn't.

Those variables are:

* TERM
* COLORTERM
* PWD
* SHELL

and all variables defined by the user in the [environment] section in
foot.ini.

In the same way, we did not *unset* TERM_PROGRAM and
TERM_PROGRAM_VERSION.

This patch fixes it by "cloning" the custom environment, making it
mutable, and then adding/removing the variables above from it.

Instead of calling setenv()/unsetenv() directly, we add the wrapper
functions add_to_env() and del_from_env().

When *not* using a custom environment, they simply call
setenv()/unsetenv().

When we *are* using a custom environment, add_to_env() first loops all
existing variables, looking for a match. If a match is found, it's
updated with the new value. If it's not found, a new entry is added.

del_from_env() loops all entries, and removes it when a match is
found. If no match is found, nothing is done.

The mutable environment is allocated on the heap, but never free:d. We
don't need to free it, since it's only allocated after forking, in the
child process.

Closes #1568
2024-01-11 16:37:17 +01:00
Daniel Eklöf
4449177517
term: cache font baseline
No need to redo the calculation for every single cell we render,
every frame...
2023-10-10 14:23:33 +02:00
Daniel Eklöf
4eef001d58
csi: implement DECSET/DECRST/DECRQM 2027 - grapheme cluster processing
This implements private mode 2027 - grapheme cluster processing, as
defined in the "Terminal Unicode Core"[1] specification.

Internally, we just flip the already existing option "grapheme
shaping". Since it's now runtime changeable, we need a copy of it in
the terminal struct, rather than referencing the conf object.

[1]: 13fc5a8993/spec/terminal-unicode-core.tex (L50-L53)
2023-09-25 16:50:44 +02:00
Daniel Eklöf
1719ff93a7
selection: add support for selecting the contents of a quote
This patch changes the default of triple clicking, from selecting the
current logical row, to first trying to select the contents of the
quote under the cursor, and if failing to find a quote, selecting the
current row (like before).

This is implemented by adding a new key binding, 'select-quote'.

It will search for surrounding quote characters, and if one is found
on each side of the cursor, the quote is selected. If not, the entire
row is selected instead.

Subsequent selection operations will behave as if the selection is
either a word selection (a quote was found), or a row selection (no
quote found).

Escaped quote characters are not supported: "foo \" bar" will match
'foo \', and not 'foo " bar'.

Mismatched quotes are not custom handled. They will simply not match.

Nested quotes ("123 'abc def' 456") are supported.

Closes #1364
2023-09-19 16:23:34 +02:00
Daniel Eklöf
86ef638102
term: improve fallback logic when selecting scaling factor while unmapped
The foot window may, for various reasons, become completely
unmapped (that is, being removed from all outputs) at run time.

One example is wlroots based compositors; they unmap all other windows
when an opaque window is fullscreened.

21d99f8dce introduced a regression,
where instead of picking the scaling factor from one of the available
outputs (at random), we started falling back to '1' as soon as we were
unmapped.

This patch restores the original logic, but also improves upon it.

As soon as a scaling factor has been assigned to the window, we store
a copy of it in the term struct ('scale_before_unmap').

When unmapped, we check if it has a valid value (the only time it
doesn't is before the initial map). If so, we use it.

Only if it hasn't been set do we fall back to picking an output at
random, and using its scaling factor.

Closes #1464
2023-08-18 16:48:18 +02:00
Daniel Eklöf
613c61abb4
scaling: always round the scaling factor when converting to int
* In all calls to wl_subsurface_set_position()
* (wp_viewport_set_destination() already does this)
* Whenever we use the scale to calculate margins (search box,
  scrollback indicator etc)
* Since the scaling factor is stored as a float (and not a double),
  use roundf() instead of round()
2023-07-25 16:48:50 +02:00
Daniel Eklöf
a36f67cbe3
render: apply new baseline calculation everywhere
* URL jump labels
* Scrollback position indicator
* Line/box drawings characters

Closes #1430
2023-07-25 15:53:29 +02:00
Daniel Eklöf
21d99f8dce
terminal: break out scaling factor updating, and reduce number of calls to render_resize()
Break out the logic that updates the terminal’s scaling factor value,
from render_resize(), to a new function, term_update_scale(). This
allows us to update the scaling factor without a full grid resize.

We also change how we pick the scaling factor (when fractional scaling
is not in use). Before, we’d use the highest scaling factor from all
monitors we were mapped on. Now, we use the scaling factor from the
monitor we were *last* mapped on.

Then, add a boolean parameter to term_set_fonts(), and when
false, *don’t* call render_resize_force().

Also change term_font_dpi_changed() to only return true if the font
was changed in any way.

Finally, rewrite update_term_for_output_change() to:

* Call term_update_scale() before doing anything else
* Call render_resize{,_force} *last*, and *only* if either the scale
  or the fonts were updated.

This fixes several things:

* A bug where we failed to update the fonts when fractional scaling
  was in use, and we guessed the initial scale/DPI wrong. The bug
  happened because updated the internal "preferred" scale value, and a
  later call to render_resize() updated the terminal’s scale value,
  but since that code path didn’t call term_font_dpi_changed() (and it
  shouldn’t), the fonts weren’t resized properly.

* It ensures we only resize the grid *once* when the scaling factor,
  or DPI is changed. Before this, we’d resize it twice. And this
  happened when e.g. dragging the window between monitors.
2023-07-18 05:48:01 +02:00
Daniel Eklöf
829353a5da
term: font_dpi_changed: scale (and old_scale) are floating point
This should fix an issue where the font size wasn’t updated when
moving the window between outputs whose scaling factors match when
truncated.
2023-07-18 05:48:01 +02:00
Daniel Eklöf
ee794a121e
refactor: track current xcursor using an enum, instead of a char pointer 2023-07-03 14:36:32 +02:00
Daniel Eklöf
49fb0cf359
sixel: re-scale images when the cell dimensions change
Before this patch, when the cell dimensions changed (i.e. when the
font size changes), sixel images were either removed (the new cell
dimensions are smaller than the old), or simply kept at their original
size (new cell dimensions are larger).

With this patch, sixels are instead resized. This means a
sixel *always* occupies the same number of rows and columns,
regardless of how much the font size is changed.

This is done by maintaining two sets of image data and pixman images,
as well as their dimensions. These two sets are the new ‘original’ and
‘scaled’ members of the sixel struct.

The "top-level" pixman image pointer, and the ‘width’ and ‘height’
members either point to the "original", or the "scaled" version.

They are invalidated as soon as the cell dimensions change. They, and
the ‘scaled’ image is updated on-demand (when we need to render a
sixel).

Note that the ‘scaled’ image is always NULL when the current cell
dimensions matches the ones used when emitting the sixel (to save
run-time memory).

Closes #1383
2023-06-30 08:29:35 +02:00
Daniel Eklöf
3555e81fee
sixel: special case parsing of images with an aspect ratio of 1:1
Images with an aspect ratio of 1:1 are by far the most common (though
not the default).

It makes a lot of sense, performance wise, to special case
them.

Specifically, the sixel_add() function benefits greatly from this, as
it is the inner most, most heavily executed function when parsing a
sixel image.

sixel_add_many() also benefits, since allows us to drop a
multiplication. Since sixel_add_many() always called first (no other
call sites call sixel_add() directly), this has a noticeable effect on
performance.

Another thing that helps (though not as much), and not specifically
with AR 1:1 images, is special casing DECGRI a bit.

Up until now, it simply updated the current sixel parameter value. The
problem is that the default parameter value is 0. But, a value of 0
should be treated as 1. By adding a special ‘repeat_count’ variable to
the sixel struct, we can initialize it to ‘1’ when we see DECGRI, and
then simply overwrite it as the parameter value gets updated. This
allows us to drop an if..else when emitting the sixel.
2023-06-29 15:40:00 +02:00
Daniel Eklöf
c1f374cc8d
term: convert ‘scale’ to a float 2023-06-29 15:38:22 +02:00
Daniel Eklöf
774570ec41
sixel: stop cropping images to the last non-transparent row 2023-06-24 07:31:08 +02:00
Daniel Eklöf
d6d143e2a6
sixel: respect sixel aspect ratio
That is, parse P1 when initializing a new sixel, and don’t ignore
pad/pad in the raster attributes command.

The default aspect ratio is 2:1, but most sixels will override it in
the raster attributes command (to 1:1).
2023-06-24 07:31:08 +02:00
Daniel Eklöf
24f12c7b5e
term: add term_cursor_col()
Set cursor column, absolute.

term_cursor_to() needs to reload the current row pointer, and is thus
not very effective when we only need to modify the column.
2023-06-20 14:55:32 +02:00
Daniel Eklöf
d88bea5e22
vt: split up action_param() to three separate functions
We’re already switching on the next VT input byte in the state
machine; no need to if...else if in action_param() too.

That is, split up action_param() into three:

* action_param_new()
* action_param_new_subparam()
* action_param()

This makes the code cleaner, and hopefully slightly faster.

Next, to improve performance further, only check for (sub)parameter
overflow in action_param_new() and action_param_subparam().

Add pointers to the VT struct that points to the currently active
parameter and sub-parameter.

When the number of parameters (or sub-parameters) overflow, warn, and
then point the parameter pointer to a "dummy" value in the VT struct.

This way, we don’t have to check anything in action_param().
2023-06-16 16:26:13 +02:00
Daniel Eklöf
981e4b77cb
term: protect against integer overflow when accumulating scroll damage
When accumulating scroll damage, we check if the last scroll damage’s
scrolling region, and type, matches the new/current scroll damage. If
so, the number of lines in the last scroll damage is increased,
instead of adding a new scroll damage instance to the list.

If the scroll damage list isn’t consumed, this build up of scroll
damage would eventually overflow.

And, even if it didn’t overflow, it could become large enough, that
when later used to calculate e.g. the affected surface area, while
rendering a frame, would cause an overflow there instead.

This patch fixes both issues by:

a) do an overflow check before increasing the line count
b) limit the line count to UINT16_MAX
2023-03-30 16:13:19 +02:00
Daniel Eklöf
296e75f4f5
render: fix glitchy selection while resizing the ‘normal’ screen
The selection coordinates are in absolute row numbers. As such,
selection breaks when interactively resizing the normal grid, since we
then instantiate a temporary grid mapping directly to the current
viewport (for performance reason, to avoid reflowing the entire grid
over and over again).

Fix by stashing the actual selection coordinates, and ajusting the
"active" ones to the temporary grid.
2023-03-27 16:53:41 +02:00
Daniel Eklöf
0ac0d0647a
interactive resize: improve user experience
Re-initialize the temporary ‘normal’ grid instance each time we
receive a configure event while doing an interactive resize.

This way, window content will not be "erased" when the window is first
made smaller, then larger again.

And, if the viewport is up in the scrollback history, increasing the
window size will reveal more of the scrollback, instead of just being
black.

The last issue is the cursor; it’s currently not "stuck" where it
should be. Instead, it follows the window around. This is due to two
things:

1) the temporary grid we create is large enough to contain the current
   viewport, but not more than that. That means we can’t "scroll up", to
   hide the cursor.

2) grid_resize_without_reflow() doesn’t know anything about
   "interactive resizing". As such, it will ensure the cursor is bound
   to the new grid dimensions.

I don’t yet have a solution for this. This patch implements a
workaround to at least reduce the impact, by simply hiding the cursor
while we’re doing an interactive resize.
2022-10-17 18:49:57 +02:00
Daniel Eklöf
298f210ed9
render: rename term->render.resizing -> term->interactive_resizing
But also, more importantly, logical fixes:

* Stash the number of new scrollback lines the stashed ‘normal’ grid
  should be resized *to*.

There’s also a couple of performance changes here:

* When doing a delayed reflow (tiocswinsz timer), call
  sixel_reflow_grid(term, &term->normal) - there’s no need to reflow
  sixels in the ‘alt’ screen.

* When doing a delayed reflow, free all scroll damage. It’s not
  needed, since we’re damaging the entire window anyway.

* Use minimum size for the temporary ‘normal’ grid (that contains the
  current viewport). We just need it to be large enough to fit the
  current viewport, and be a valid grid row count (power of 2). This
  just so happens to be the current ‘alt’ grid’s row count...
2022-10-10 17:19:18 +02:00
Daniel Eklöf
c5c97c2fd4
term_ptmx_{pause,resume}: return success/fail 2022-10-10 17:19:18 +02:00
Daniel Eklöf
f4f1989b6e
render: resize: ignore ptmx read events during interactive resize 2022-10-10 17:19:18 +02:00
Daniel Eklöf
8179d73daa
render: delay reflow for ‘resize-delay-ms’ milliseconds
Reflowing a large scrollback is *slow*. During an interactive resize,
it can easily take long enough that the compositor fills the Wayland
socket with configure events. Eventually, the socket becomes full and
the compositor terminates the connection, causing foot to exit.

This patch is work-in-progress, and the first step towards alleviating
this.

It delays the reflow by:

* Snapshotting (copying) the original grid when an interactive resize
  is started.
* While resizing, we apply a simple truncation resize of the
  grid (like we handle the alt screen).
* When the resize is done, or paused for ‘resize-delay-ms’, the grid
  is reflowed.

TODO: we *must* not allow any changes to the temporary (truncated)
grid during the resize. Any changes to the grid would be lost when the
final reflow is applied. That is, we must completely pause the ptmx
pipe while a resize is in progress.

Future improvements:

The initial copy can be slow. We should be able to avoid it by
rewriting the reflow algorithm to not free anything. This is
complicated by the fact that some resources (e.g. sixel images) are
currently *moved* to the new grid. They’d instead have to be copied.
2022-10-10 17:19:17 +02:00
Daniel Eklöf
e249b52abd
render: apply a dimmed overlay while in Unicode input mode 2022-08-08 16:31:28 +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
9907d7bbe9
search: don't modify search.start coord *before* finding next match
The match logic uses the last start coordinate to determine which end
points in the selection to update. This sometimes fails when the start
coordinate has been changed by e.g. a key binding - the new start
coordinate is incorrectly matched against the old-but-modified start
coordinate, causing foot to e.g. *not* upate the selection start
coordinate.

Example:

  $ echo 'test\n\test\ntest'

Then do a scrollback search for 'test. The first match is found
correctly (the last 'test'), but searching for the previous match
(ctrl+r) does not select the middle 'test'.

Fix by passing the search direction to search_find_next(), and have
_it_ calculate the coordinate to start search. There are three possibilities:

* forward
* backward
* "backward", but at the same position

The first two are used when searching for next/prev match with ctrl+s
and ctrl+r. The last one is used when the search criteria is
updated. In this case, we don't want to move to the previous match,
*unless* the current match no longer matches.
2022-04-21 18:54:27 +02:00
Daniel Eklöf
24ee3dcc10
wayland: refactor: remove ‘struct config’ pointer from wayland struct
The global config doesn’t necessarily reflect the correct
configuration to use - we should *always* use the current terminal
instance’s conf pointer.

* Move selection override modifier mask to the key_binding_set struct
* Always warn if XDG activation is unavailable, not just if
  bell.urgent is set (we no longer have access to this information)
* Pass ‘bool presentation_timings’ as a parameter to wayl_init()
* Remove ‘presentation_timings’ member from the ‘terminal’ struct

Closes #932
2022-04-17 16:34:04 +02:00
Daniel Eklöf
90a2ca966f
key-binding: new API, for handling sets of key bindings
Up until now, our Wayland seats have been tracking key bindings. This
makes sense, since the seat’s keymap determines how the key bindings
are resolved.

However, tying bindings to the seat/keymap alone isn’t enough, since
we also depend on the current configuration (i.e. user settings) when
resolving a key binding.

This means configurations that doesn’t match the wayland object’s
configuration, currently don’t resolve key bindings correctly. This
applies to footclients where the user has overridden key bindings on
the command line (e.g. --override key-bindings.foo=bar).

Thus, to correctly resolve key bindings, each set of key bindings must
be tied *both* to a seat/keymap, *and* a configuration.

This patch introduces a key-binding manager, with an API to
add/remove/lookup, and load/unload keymaps from sets of key bindings.

In the API, sets are tied to a seat and terminal instance, since this
makes the most sense (we need to instantiate, or incref a set whenever
a new terminal instance is created). Internally, the set is tied to a
seat and the terminal’s configuration.

Sets are *added* when a new seat is added, and when a new terminal
instance is created. Since there can only be one instance of each
seat, sets are always removed when a seat is removed.

Terminals on the other hand can re-use the same configuration (and
typically do). Thus, sets ref-count the configuration. In other words,
when instantiating a new terminal, we may not have to instantiate a
new set of key bindings, but can often be incref:ed instead.

Whenever the keymap changes on a seat, all key bindings sets
associated with that seat reloads (re-resolves) their key bindings.

Closes #931
2022-04-17 15:39:51 +02:00
Daniel Eklöf
501a9fbb5e
url-mode: add a key binding that enables “persistent” URL mode
This is an alternative to ‘show-urls-launch’, where we stay in URL
mode after activating an URL.

Closes #964
2022-04-17 11:24:27 +02:00
Daniel Eklöf
bd089c845f
search: break out “find next match” logic to a new function 2022-04-16 20:13:22 +02:00
Daniel Eklöf
78fcdc5787
render: implement ‘flash’ and search mode’s ‘dimming’ with a sub-surface
Search mode and ‘flash’ (OSC-555) both achieves similar visual
effects: flash tints the entire window yellow, and search mode dims
it (except the search match).

But, they do so in completely different ways. Search mode is detected
in render_cell(), and the colors are then dimmed there.

Flash is implemented by blending a yellow, semi-transparent color on
top of the rendered grid.

This patch replaces those two implementations with a single one. We
add a new sub-surface, called the ‘overlay’. In normal mode, it’s
unmapped.

When either search mode, or flash, is enabled, we enable it, and
fill it with a semi-transparent color. Yellow for ‘flash’, and
“black” (i.e. no color) for search mode.

The compositor then blends it with the grid. Hopefully on the GPU,
meaning it’ll be faster than if we blend in software.

There are more performance benefits however. By using a separate
surface, we can do much better damage tracking.

The normal grid rendering code no longer have to care about neither
search mode, nor flash. Thus, we get rid of a couple of ‘if’
statements in render_cell(), which is nice. But more importantly, we
can drop full grid repaints in a couple of circumstances:

* Entering/exiting search mode
* Every frame while flash is active

Now, when rendering the search mode overlay, we do want to do some
damage tracking, also of the overlay.

This, since search mode doesn’t dim the *entire* window. The search
match is *not* dimmed. This is implemented by punching a hole in the
overlay sub-surface. That is, we make part of it *fully*
transparent. The basic idea is to set a clip region that excludes the
search match, and then dim the rest of the overlay.

It’s slightly more complicated than that however, if we want to reuse
the last frame’s overlay buffer (i.e we don’t want to re-render
the *entire* overlay every frame).

In short, we need to:

* Clear (punch hole) in areas that are part of this frame’s search
  match, but not the last frame’s (since those parts are _already_
  cleared).
* Dim the areas that were part of the last frame’s search match, but
  aren’t anymore (the rest of the overlay should already be dimmed).

To do this, we save the last frame’s “holes” (as a pixman
region). Then, when rendering the next frame, we first calculate the
new frame’s “holes” region.

The region to clear is “this frame’s holes minus last frame’s holes”
The region to dim is “last frame’s holes minus this frames holes”.

Finally, we compute the bounding box of all modified cells by taking
the union of the two diff regions mentioned above. This allows us to
limit the buffer damage sent to the compositor.
2022-04-16 18:31:02 +02:00