Commit graph

510 commits

Author SHA1 Message Date
Daniel Eklöf
0be55ef74c
term: erase_cell_range(): check if row->extra != NULL 2021-11-21 18:09:27 +01:00
Daniel Eklöf
53fc1a1cb1
term: tail-call optimize calls to grid_row_uri_range_erase() 2021-11-21 18:09:27 +01:00
Daniel Eklöf
09a331857a
term: call grid_row_uri_range_erase() when printing cells 2021-11-21 18:09:26 +01:00
Daniel Eklöf
1a0de0017f
grid: add grid_row_uri_range_erase()
This function handles erasing of an URI range. That is, a range of the
row is being either erased, or overwritten (from the URI perspective,
these two are the same thing).

We handle both partial overwrites (split up, or truncate URI), as well
as complete overwrites (remove URI).
2021-11-21 18:09:26 +01:00
Daniel Eklöf
d46af6bd7a
term: track cell color source
Each cell now tracks it’s current color source:

* default fg/bg
* base16 fg/bg (maps to *both* the regular and bright colors)
* base256 fg/bg
* RGB

Note that we don’t have enough bits to separate the regular from the
bright colors. These _shouldn’t_ be the same, so we ought to be
fine...
2021-11-20 16:46:38 +01:00
Daniel Eklöf
c01904a2c7
config: add [colors].dim0-7
This allows you to configure custom colors to be used when colors are
being dimmed (`\E[2m`).

It is implemented by color matching (just like
bold-text-in-bright=palette-based); the color-to-be-dimmed is matched
against the current color palette.

If it matches one of the regular colors (colors 0-7), the
corresponding “dim” color will be used.

If it matches one of the bright colors (colors 8-15), the
corresponding “regular” color will be used (but *only* if the “dim”
color has been set).

Otherwise, the color is dimmed by reducing its luminance.

The default behavior, i.e. when dim0-7 hasn’t been configured, is to
dim by reducing luminance for *all* colors. I.e. we don’t do any color
matching at all. In particular, this means that dimming a bright color
will *not* result in the corresponding “regular” color.

Closes #776
2021-11-13 17:39:08 +01:00
Daniel Eklöf
d29c3cf7b7
config: add {str,value}_to_uint{16,32}()
This allows us to pass the final pointer directly to the conversion
functions, as well as allowing us to print outside-range errors.
2021-11-13 11:04:29 +01:00
Ronan Pigott
99d5bf64bc foot/client: implement xdga client activation
This is an application of the xdg activation protocol that will allow
compositors to associate new foot toplevels with the command that
launched them.

footclient receives an activation token from the launcher which the
compositor can use to track application startup. It passes the token
to the foot server, which then activates the new window with the token
to complete the startup sequence.
2021-10-31 18:52:29 -07:00
Daniel Eklöf
db2529159c
term: bell: simplify if-statement - we don’t need two nested levels 2021-10-22 20:04:23 +02:00
Daniel Eklöf
2fbc336eb9
term: ignore window title updates if title is un-changed 2021-10-22 18:01:53 +02:00
Mitja Horvat
729f7466ae notify: add the notify-focus-inhibit config option
foot doesn't show desktop notifications (via OSC777) if the current
terminal has keyboard focus.

This is probably a sane default, but there are use cases where showing
a notification regardless of the focus status may be desired. For
example, a completion notification of a long running task inside a
non-focused tmux window.

This PR adds the notify-focus-inhibit option which can be used to
disable inhibition of notifications when the window has focus.

The default value is `yes`, which retains the old behavior.
2021-10-06 23:33:17 +02:00
Daniel Eklöf
fb77637eb9
term: only scale using DPI if *all* monitors have a scaling factor or one
With dpi-aware=auto (the default), scale fonts using DPI *only*
if *all* available monitors have a scaling factor of one.

The idea is this: if a user, with multiple monitors, have enabled
scaling on *at least* one monitor, he/she has most likely done so to
match the size of his/hers other monitors.

For example, if the user has one monitor with a scaling factor of one,
and another one with a scaling factor of two, he/she expects things to
be twice as large on the second monitor.

If we (foot) scale using DPI on the first monitor, and using the
scaling factor on the second monitor, foot will *not* look twice as
big on the second monitor (this was the old behavior of
dpi-aware=auto).

Part of #714
2021-09-24 22:07:47 +02:00
Daniel Eklöf
37b15adcd8
term: turn ‘box-drawings’ array into three dynamically allocated arrays
The box_drawings array is now quite large, and uses up ~4K
when *empty*.

This patch splits it up into three separate, dynamically allocated
arrays; one for the traditional box+line drawing and block elements
glyphs, one for braille, and one for the legacy computing symbols.

When we need to render a glyph, the *entire* array (that it belongs
to) is allocated.

I.e this is one step closer to a dynamic glyph cache (like the one
fcft uses), but doesn’t go all the way.

This is especially nice for people with
‘box-drawings-uses-font-glyphs=yes’; for them, the custom glyphs now
uses 3*8 bytes (for the three array pointers), instead of 4K.
2021-09-14 09:50:49 +02:00
Daniel Eklöf
d126662560
term: reduce scope of variable 2021-09-05 12:39:25 +02:00
Daniel Eklöf
bb948d03e1
terminal: prefer the advance width of ‘M’ over that of a space
This makes some non-monospaced fonts more readable, allowing users to
read errors and warnings printed in the window.

Furthermore, fcft-3.0 will remove the space_advance member, so once we
upgrade, we’ll have to rasterize a glyph ourselves anyway.
2021-08-31 19:56:59 +02:00
Daniel Eklöf
b4402a6aa5
term: check visual-focus, not kbd-focus when enabling/disabling cursor blink
term_cursor_blink_update() is called when the visual focus changes
state (i.e. when our top-level surface is activated de-activated).

Checking keyboard focus worked on Sway, but on e.g. GNOME, the order
in which keyboard focus and visual focus are updated is different, and
we ended up either making the cursor invisible, or visible, but not
blinking, when changing focus back to the window.

Closes #686
2021-08-17 18:31:42 +02:00
Daniel Eklöf
f6f8f2b35e
pt-or-px: heed the dpi-aware setting
Before this patch, pt-or-px values, like letter-spacing, were *always*
scaled using the current DPI value.

This is wrong; if the fonts are scaled using the output’s scaling
factor, then so should all other point values.

This also fixes an issue where e.g. letter-spacing would use one DPI
value at startup, but then when increasing/decreasing or resetting the
font size, would be re-calculated using a different DPI value, leading
to completely different spacing.

This happened when there were multiple monitors, with different DPI
values, and foot guessed the initial DPI value wrong. Normally, foot
would correct itself as soon as the window was mapped, and the
“correct” DPI value known. But if the fonts were scaled using the
scaling factor, it was possible that the font reload never happened.

This patch also updates the thickness calculation (for LIGHT and HEAVY
box drawing characters) to use the scaling factor when appropriate.

Closes #680
2021-08-13 17:38:56 +02:00
Daniel Eklöf
c2cc964116
input: implement support for mouse wheel left/right
We now emit button 6/7 events (when the client application grabs the
mouse). This buttons map to mouse wheel horizontal scroll events. Or, left/right
tilting, if you like.

Wayland report these as ‘axis’ events (just like regular scroll wheel events),
and thus we need to translate those scroll events to button events.

libinput does not define any mouse buttons for wheel tilts, so we add our own
defitions. These are added last in the BTN_* range, just before the BTN_JOYSTICK
events.
2021-08-07 12:27:44 +02:00
Daniel Eklöf
bdaa9a8991
term: disable debug logging 2021-08-05 18:24:52 +02:00
Daniel Eklöf
f1d440e139
term: send SIGTERM/SIGKILL to the entire process group 2021-07-31 22:50:19 +02:00
Daniel Eklöf
b7edfc2822
term: fix release builds when LOG_ENABLE_DBG=0 2021-07-31 19:52:23 +02:00
Daniel Eklöf
03f952cf4d
term: consolidate shutdown related state into an anonymous struct 2021-07-31 19:08:51 +02:00
Daniel Eklöf
c23bff4189
term: rename: slave_died() -> fdm_client_terminated() 2021-07-31 18:27:02 +02:00
Daniel Eklöf
384b1c330f
term: asynchronous client application termination
When the foot window is closed, and we need to terminate the client application,
do this in an asynchronous fashion:

* Don’t do a blocking call to waitpid(), instead, rely on the reaper callback
* Use a timer FD to implement the timeout before sending SIGKILL (instead of
  using SIGALRM).
* Send SIGTERM immediately (we used to *just* close the PTY, and then wait 2
  seconds before sending SIGTERM).
* Raise the timeout from 2 seconds to 60

Full shutdown now depends on *two* asynchronous tasks - unmapping the window,
and waiting for the client application to terminate.

Only when *both* of these have completed do we proceed and call term_destroy(),
and the user provided shutdown callback.
2021-07-31 18:18:48 +02:00
Daniel Eklöf
20fc80e57e
render: use a single backing SHM pool for CSD surface buffers 2021-07-18 16:46:43 +02:00
Daniel Eklöf
e8e9cd5595
term: erase_scrollback(): destroy sixels that touch the scrollback 2021-07-18 16:31:33 +02:00
Daniel Eklöf
d0a7f999c6
term: add unit test for term_erase_scrollback() 2021-07-18 16:14:25 +02:00
Daniel Eklöf
5f0ceb72f1
csi: erase scrollback: cancel selection if it touches the scrollback
This breaks out the scrollback erasing logic for \E[3J from csi.c, and
moves it to the new function term_erase_scrollback(), and changes the
logic to calculate the start and end row (absolute) numbers of the
scrollback, and only iterate those, instead of iterating *all* rows,
filtering out those that are on-screen.

It also adds an intersection range check of the selection range, and
cancels the selection if it touches any of the deleted scrollback
rows.

This fixes a crash when trying to render the next frame, since the
selection now references rows that have been freed.

Closes #633
2021-07-18 16:14:21 +02:00
Daniel Eklöf
53851e13ec
shm: refactor: move away from a single, global, buffer list
Up until now, *all* buffers have been tracked in a single, global
buffer list. We've used 'cookies' to separate buffers from different
contexts (so that shm_get_buffer() doesn't try to re-use e.g. a
search-box buffer for the main grid).

This patch refactors this, and completely removes the global
list.

Instead of cookies, we now use 'chains'. A chain tracks both the
properties to apply to newly created buffers (scrollable, number of
pixman instances to instantiate etc), as well as the instantiated
buffers themselves.

This means there's strictly speaking not much use for shm_fini()
anymore, since its up to the chain owner to call shm_chain_free(),
which will also purge all buffers.

However, since purging a buffer may be deferred, if the buffer is
owned by the compositor at the time of the call to shm_purge() or
shm_chain_free(), we still keep a global 'deferred' list, on to which
deferred buffers are pushed. shm_fini() iterates this list and
destroys the buffers _even_ if they are still owned by the
compositor. This only happens at program termination, and not when
destroying a terminal instance. I.e. closing a window in a “foot
--server” does *not* trigger this.

Each terminal instatiates a number of chains, and these chains are
destroyed when the terminal instance is destroyed. Note that some
buffers may be put on the deferred list, as mentioned above.
2021-07-17 19:14:42 +02:00
Daniel Eklöf
232fb20269
shm: replace 'locked' attribute with a ref-counter
The initial ref-count is either 1 or 0, depending on whether the
buffer is supposed to be released "immeidately" (meaning, as soon as
the compositor releases it).

Two new user facing functions have been added: shm_addref() and
shm_unref().

Our renderer now uses these two functions instead of manually setting
and clearing the 'locked' attribute.

shm_unref() will decrement the ref-counter, and destroy the buffer
when the counter reaches zero. Except if the buffer is currently
"busy" (compositor owned), in which case destruction is deferred to
the release event. The buffer is still removed from the list though.
2021-07-17 19:14:42 +02:00
Daniel Eklöf
fcb60abc13
config: add locked-title=no|yes
Closes #386
2021-07-04 17:59:40 +02:00
Daniel Eklöf
07652d3b9e
term: rows printed to now defaults to having a hard linebreak
That is, instead of requiring a ‘\n’ to be printed, non-empty lines
are now treated as having a hard linebreak by default.

The linebreak is cleared on an explicit wrap.
2021-07-03 18:05:45 +02:00
Daniel Eklöf
117e24dbf4
term: destroy: free URLs before free:ing the grids
Fixes use-after-free when destroying a terminal with “live”
URLs (i.e. when URL mode is active).
2021-06-28 22:33:57 +02:00
Daniel Eklöf
fe8ca23cfe
composed: store compose chains in a binary search tree
The previous implementation stored compose chains in a dynamically
allocated array. Adding a chain was easy: resize the array and append
the new chain at the end. Looking up a compose chain given a compose
chain key/index was also easy: just index into the array.

However, searching for a pre-existing chain given a codepoint sequence
was very slow. Since the array wasn’t sorted, we typically had to scan
through the entire array, just to realize that there is no
pre-existing chain, and that we need to add a new one.

Since this happens for *each* codepoint in a grapheme cluster, things
quickly became really slow.

Things were ok:ish as long as the compose chain struct was small, as
that made it possible to hold all the chains in the cache. Once the
number of chains reached a certain point, or when we were forced to
bump maximum number of allowed codepoints in a chain, we started
thrashing the cache and things got much much worse.

So what can we do?

We can’t sort the array, because

a) that would invalidate all existing chain keys in the grid (and
iterating the entire scrollback and updating compose keys is *not* an
option).

b) inserting a chain becomes slow as we need to first find _where_ to
insert it, and then memmove() the rest of the array.

This patch uses a binary search tree to store the chains instead of a
simple array.

The tree is sorted on a “key”, which is the XOR of all codepoints,
truncated to the CELL_COMB_CHARS_HI-CELL_COMB_CHARS_LO range.

The grid now stores CELL_COMB_CHARS_LO+key, instead of
CELL_COMB_CHARS_LO+index.

Since the key is truncated, collisions may occur. This is handled by
incrementing the key by 1.

Lookup is of course slower than before, O(log n) instead of
O(1).

Insertion is slightly slower as well: technically it’s O(log n)
instead of O(1). However, we also need to take into account the
re-allocating the array will occasionally force a full copy of the
array when it cannot simply be growed.

But finding a pre-existing chain is now *much* faster: O(log n)
instead of O(n). In most cases, the first lookup will either
succeed (return a true match), or fail (return NULL). However, since
key collisions are possible, it may also return false matches. This
means we need to verify the contents of the chain before deciding to
use it instead of inserting a new chain. But remember that this
comparison was being done for each and every chain in the previous
implementation.

With lookups being much faster, and in particular, no longer requiring
us to check the chain contents for every singlec chain, we can now use
a dynamically allocated ‘chars’ array in the chain. This was
previously a hardcoded array of 10 chars.

Using a dynamic allocated array means looking in the array is slower,
since we now need two loads: one to load the pointer, and a second to
load _from_ the pointer.

As a result, the base size of a compose chain (i.e. an “empty” chain)
has now been reduced from 48 bytes to 32. A chain with two codepoints
is 40 bytes. This means we have up to 4 codepoints while still using
less, or the same amount, of memory as before.

Furthermore, the Unicode random test (i.e. write random “unicode”
chars) is now **faster** than current master (i.e. before text-shaping
support was added), **with** test-shaping enabled. With text-shaping
disabled, we’re _even_ faster.
2021-06-24 17:30:49 +02:00
Daniel Eklöf
f7860aec76
config: add new function config_clone() 2021-06-23 10:39:14 +02:00
Daniel Eklöf
078f790b72
term: fix regression after merging #599
Don’t increment ‘j’ twice in each loop iteration, and fix typo in loop
condition (check ‘j’, not ‘i’).
2021-06-18 15:56:34 +02:00
Daniel Eklöf
07b455e882
render: don’t create/destroy the title update timer each time
Create it once when instantiating the terminal. Add a boolean to track
whether the timer is running or not.
2021-06-18 15:53:47 +02:00
Daniel Eklöf
535c82d628
render: use a timer instead of relying on the frame callback for title update throttling
Using the frame callback works most of the time, but e.g. Sway doesn’t
call it while the window is hidden, and thus prevents us from updating
the title in e.g. stacked views.

This patch uses a timer FD instead. We store a timestamp from when the
title was last updated. When the application wants to update the
title, we first check if we already have a timer running, and if so,
does nothing.

If no timer is running, check the timestamp. If enough time has
passed, update the title immediately.

If not, instantiate a timer and wait for it to trigger.

Set the minimum time between two updates to ~8ms (twice per frame, for
a 60Hz output, and ~once per frame on a 120Hz output).

Closes #591
2021-06-18 15:36:58 +02:00
Daniel Eklöf
495c730487
config: don’t use tllist where it isn’t necessary
tllists are great when dealing with dynamically changing lists. They
are also very easy to use when building lists/arrays where the final
size is unknown.

However, this ease of use comes at a price: code size. tll-macros
expand to a lot of code.

Since things in the config are static, once the config has been
loaded, using tllists for configuration data structures doesn’t make
much sense.

This patch replaces nearly all tllists used by the configuration, with
dynamically allocated arrays.
2021-06-18 15:35:57 +02:00
Daniel Eklöf
45a04393c4
term: erase_cell_range: early break out from URI loop
URI ranges are sorted. This means we don’t have to check any more
ranges once we’ve seen one that starts *after* the erase range.

Closes #594
2021-06-15 16:26:43 +02:00
Daniel Eklöf
5caa87adaf
term: no need to set attrs.clean=0 right after copying the VT attrs struct
When printing a character to a cell, we copy the current VT state’s
attributes to the cell. And then clear the ‘clean’ bit.

But the ‘clean’ bit is part of the VT state, and is *always*
zero. Thus there’s no need to explicitly clear it right after copying
the VT state.
2021-06-15 12:38:35 +02:00
Daniel Eklöf
cd37cdc940
term: free the data associated with the pixman image when destroying box-drawing glyphs
Closes #586
2021-06-09 11:27:08 +02:00
Craig Barnes
e030a2ca08 terminal: add 'charset_designator' enum to make code more self-documenting
This commit also renames the term_set_single_shift_ascii_printer()
function to term_single_shift(), since the former is overly verbose
and not really even accurate.
2021-06-09 10:00:25 +01:00
Craig Barnes
a2c9c56f19 vt: fix SS2/SS3 escape sequences to act correctly as single shifts
These sequences are supposed to affect the next printable ASCII
character and then reset to the previous character set, but before
this commit they were behaving like locking shifts.
2021-06-08 21:09:40 +01:00
Craig Barnes
b34d76f711 terminal: fix compilation error when debug logging is enabled
Without this fix, setting LOG_ENABLE_DBG to 1 in terminal.c would
cause the following error:

> terminal.c:1787: 'struct terminal' has no member named 'font_scale'

The 'font_scale' member was removed in commit
2afc678236.
2021-06-08 13:10:46 +01:00
Daniel Eklöf
a012c2fb3e
term: fix crash when an OSC-8 URI wraps around the scrollback
Long OSC-8 URIs, that are split up over multiple rows, are handled by
emitting one URI range on each row the URL touches.

This was done by initializing a row index variable, and then
incrementing it each loop iteration.

This caused an out-of-bounds array access when the row index reached
the maximum number of scrollback lines.

The fix is simple: make sure the row index variable wraps around,
instead of incrementing without any bounds.

Closes #552
2021-05-26 14:11:03 +02:00
Daniel Eklöf
1868fa27e4
term: osc8_close: debug: assert all URI coordinates are unique 2021-05-23 10:29:32 +02:00
Daniel Eklöf
0f483d65ce
config: move url-mode related options to a dedicated section, ‘url’ 2021-05-22 14:50:47 +02:00
Daniel Eklöf
a6d9f01c0d
extract: move ‘strip_trailing_empty’ parameter from extra_finish() to extract_begin() 2021-05-17 18:14:10 +02:00
Daniel Eklöf
1bc9fd5fe1
extract: add extract_finish_wide(), and optionally skip stripping trailing empty cells
extract_finish() returns the extracted text in UTF-8, while
extract_finish_wide() returns the extracted text in Unicode.

This patch also adds a new argument to extract_finish{,_wide},
that when set to true, skips stripping trailing empty cells.
2021-05-17 18:14:09 +02:00