<feed xmlns='http://www.w3.org/2005/Atom'>
<title>mirrors/foot.git/terminal.c, branch 1.8.2</title>
<subtitle>A fast, lightweight and minimalistic Wayland terminal emulator</subtitle>
<id>https://git.0x0f.dev/mirrors/foot.git/atom?h=1.8.2</id>
<link rel='self' href='https://git.0x0f.dev/mirrors/foot.git/atom?h=1.8.2'/>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/'/>
<updated>2021-07-18T14:46:43Z</updated>
<entry>
<title>render: use a single backing SHM pool for CSD surface buffers</title>
<updated>2021-07-18T14:46:43Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-18T14:46:43Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=20fc80e57e365f2e002eead7de110cb23ffa7adc'/>
<id>urn:sha1:20fc80e57e365f2e002eead7de110cb23ffa7adc</id>
<content type='text'>
</content>
</entry>
<entry>
<title>term: erase_scrollback(): destroy sixels that touch the scrollback</title>
<updated>2021-07-18T14:31:33Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-18T14:31:33Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=e8e9cd559529b91968af9f776df8b87751df7b97'/>
<id>urn:sha1:e8e9cd559529b91968af9f776df8b87751df7b97</id>
<content type='text'>
</content>
</entry>
<entry>
<title>term: add unit test for term_erase_scrollback()</title>
<updated>2021-07-18T14:14:25Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-18T13:34:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=d0a7f999c662759d1704d97d5217736e84f508c1'/>
<id>urn:sha1:d0a7f999c662759d1704d97d5217736e84f508c1</id>
<content type='text'>
</content>
</entry>
<entry>
<title>csi: erase scrollback: cancel selection if it touches the scrollback</title>
<updated>2021-07-18T14:14:21Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-16T14:45:36Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=5f0ceb72f176caf7673ea1d4bc5195f26f4b4df7'/>
<id>urn:sha1:5f0ceb72f176caf7673ea1d4bc5195f26f4b4df7</id>
<content type='text'>
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
</content>
</entry>
<entry>
<title>shm: refactor: move away from a single, global, buffer list</title>
<updated>2021-07-17T17:14:42Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-16T14:48:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=53851e13ec976001cdec2077d7963c292bcd6d20'/>
<id>urn:sha1:53851e13ec976001cdec2077d7963c292bcd6d20</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>shm: replace 'locked' attribute with a ref-counter</title>
<updated>2021-07-17T17:14:42Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-16T14:47:57Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=232fb20269b68157874f57d676c1b0b95c2386aa'/>
<id>urn:sha1:232fb20269b68157874f57d676c1b0b95c2386aa</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>config: add locked-title=no|yes</title>
<updated>2021-07-04T15:59:40Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-04T15:59:40Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=fcb60abc132b12ccf8fb8ff215acc924a44773d6'/>
<id>urn:sha1:fcb60abc132b12ccf8fb8ff215acc924a44773d6</id>
<content type='text'>
Closes #386
</content>
</entry>
<entry>
<title>term: rows printed to now defaults to having a hard linebreak</title>
<updated>2021-07-03T16:05:45Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-02T14:31:46Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=07652d3b9e58dd99f5fedd6776092ed815ccb7fa'/>
<id>urn:sha1:07652d3b9e58dd99f5fedd6776092ed815ccb7fa</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>term: destroy: free URLs before free:ing the grids</title>
<updated>2021-06-28T20:33:57Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-28T20:33:57Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=117e24dbf4e5a54c8209f7415a97dbd2da906cd5'/>
<id>urn:sha1:117e24dbf4e5a54c8209f7415a97dbd2da906cd5</id>
<content type='text'>
Fixes use-after-free when destroying a terminal with “live”
URLs (i.e. when URL mode is active).
</content>
</entry>
<entry>
<title>composed: store compose chains in a binary search tree</title>
<updated>2021-06-24T15:30:49Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-24T11:17:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=fe8ca23cfee77a6cac433892755dd7455e354a9d'/>
<id>urn:sha1:fe8ca23cfee77a6cac433892755dd7455e354a9d</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>config: add new function config_clone()</title>
<updated>2021-06-23T08:39:14Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-18T14:18:41Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=f7860aec7610be897155046bd730ad0b406bd56c'/>
<id>urn:sha1:f7860aec7610be897155046bd730ad0b406bd56c</id>
<content type='text'>
</content>
</entry>
<entry>
<title>term: fix regression after merging #599</title>
<updated>2021-06-18T13:56:34Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-18T13:56:34Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=078f790b721fc9f998f333081396d57dbc2adee9'/>
<id>urn:sha1:078f790b721fc9f998f333081396d57dbc2adee9</id>
<content type='text'>
Don’t increment ‘j’ twice in each loop iteration, and fix typo in loop
condition (check ‘j’, not ‘i’).
</content>
</entry>
<entry>
<title>render: don’t create/destroy the title update timer each time</title>
<updated>2021-06-18T13:53:47Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-18T13:53:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=07b455e882f1925930963b643011a53906cadb9d'/>
<id>urn:sha1:07b455e882f1925930963b643011a53906cadb9d</id>
<content type='text'>
Create it once when instantiating the terminal. Add a boolean to track
whether the timer is running or not.
</content>
</entry>
<entry>
<title>render: use a timer instead of relying on the frame callback for title update throttling</title>
<updated>2021-06-18T13:36:58Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-15T15:27:50Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=535c82d628909b4f54774885e7de366c07fa9779'/>
<id>urn:sha1:535c82d628909b4f54774885e7de366c07fa9779</id>
<content type='text'>
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
</content>
</entry>
<entry>
<title>config: don’t use tllist where it isn’t necessary</title>
<updated>2021-06-18T13:35:57Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-17T16:15:29Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=495c7304878bdd010dc5d25620dc68f41ac4cd36'/>
<id>urn:sha1:495c7304878bdd010dc5d25620dc68f41ac4cd36</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>term: erase_cell_range: early break out from URI loop</title>
<updated>2021-06-15T14:26:43Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-15T14:26:43Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=45a04393c478881ebc84a26afbe8b90854cd1f85'/>
<id>urn:sha1:45a04393c478881ebc84a26afbe8b90854cd1f85</id>
<content type='text'>
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
</content>
</entry>
<entry>
<title>term: no need to set attrs.clean=0 right after copying the VT attrs struct</title>
<updated>2021-06-15T10:38:35Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-15T10:38:35Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=5caa87adaf6c54a412fcd8a070c4275619e8c410'/>
<id>urn:sha1:5caa87adaf6c54a412fcd8a070c4275619e8c410</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>term: free the data associated with the pixman image when destroying box-drawing glyphs</title>
<updated>2021-06-09T09:27:08Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-06-09T08:31:24Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=cd37cdc940453ddf97470206d87fb564be21a276'/>
<id>urn:sha1:cd37cdc940453ddf97470206d87fb564be21a276</id>
<content type='text'>
Closes #586
</content>
</entry>
<entry>
<title>terminal: add 'charset_designator' enum to make code more self-documenting</title>
<updated>2021-06-09T09:00:25Z</updated>
<author>
<name>Craig Barnes</name>
<email>craigbarnes@protonmail.com</email>
</author>
<published>2021-06-09T08:51:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=e030a2ca08d92eb431e9b8e494c63affeeb8c0e1'/>
<id>urn:sha1:e030a2ca08d92eb431e9b8e494c63affeeb8c0e1</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>vt: fix SS2/SS3 escape sequences to act correctly as single shifts</title>
<updated>2021-06-08T20:09:40Z</updated>
<author>
<name>Craig Barnes</name>
<email>craigbarnes@protonmail.com</email>
</author>
<published>2021-06-08T20:09:40Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=a2c9c56f1962ce02e71582c06f389e53d1869e90'/>
<id>urn:sha1:a2c9c56f1962ce02e71582c06f389e53d1869e90</id>
<content type='text'>
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.
</content>
</entry>
</feed>
