<feed xmlns='http://www.w3.org/2005/Atom'>
<title>mirrors/foot.git/terminal.c, branch 1.8.0</title>
<subtitle>A fast, lightweight and minimalistic Wayland terminal emulator</subtitle>
<id>https://git.0x0f.dev/mirrors/foot.git/atom?h=1.8.0</id>
<link rel='self' href='https://git.0x0f.dev/mirrors/foot.git/atom?h=1.8.0'/>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/'/>
<updated>2021-06-24T15:30:49Z</updated>
<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>
<entry>
<title>terminal: fix compilation error when debug logging is enabled</title>
<updated>2021-06-08T12:10:46Z</updated>
<author>
<name>Craig Barnes</name>
<email>craigbarnes@protonmail.com</email>
</author>
<published>2021-06-08T12:10:46Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=b34d76f7113fcfb53b310a8e06fedab32d3cbf4c'/>
<id>urn:sha1:b34d76f7113fcfb53b310a8e06fedab32d3cbf4c</id>
<content type='text'>
Without this fix, setting LOG_ENABLE_DBG to 1 in terminal.c would
cause the following error:

&gt; terminal.c:1787: 'struct terminal' has no member named 'font_scale'

The 'font_scale' member was removed in commit
2afc6782361d0deaa443234466775b1121feec8f.
</content>
</entry>
<entry>
<title>term: fix crash when an OSC-8 URI wraps around the scrollback</title>
<updated>2021-05-26T12:11:03Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-26T11:59:32Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=a012c2fb3efbac49b4333a62cfd7cc1df9ee6aef'/>
<id>urn:sha1:a012c2fb3efbac49b4333a62cfd7cc1df9ee6aef</id>
<content type='text'>
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
</content>
</entry>
<entry>
<title>term: osc8_close: debug: assert all URI coordinates are unique</title>
<updated>2021-05-23T08:29:32Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-22T18:19:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=1868fa27e444968cfd8a825d8c27a0187faf0730'/>
<id>urn:sha1:1868fa27e444968cfd8a825d8c27a0187faf0730</id>
<content type='text'>
</content>
</entry>
<entry>
<title>config: move url-mode related options to a dedicated section, ‘url’</title>
<updated>2021-05-22T12:50:47Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-20T15:56:56Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=0f483d65ceb06e40eab8d5f5291e681112f06249'/>
<id>urn:sha1:0f483d65ceb06e40eab8d5f5291e681112f06249</id>
<content type='text'>
</content>
</entry>
<entry>
<title>extract: move ‘strip_trailing_empty’ parameter from extra_finish() to extract_begin()</title>
<updated>2021-05-17T16:14:10Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-30T12:40:21Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=a6d9f01c0d1d914362b73eacd89e1e09877632cb'/>
<id>urn:sha1:a6d9f01c0d1d914362b73eacd89e1e09877632cb</id>
<content type='text'>
</content>
</entry>
<entry>
<title>extract: add extract_finish_wide(), and optionally skip stripping trailing empty cells</title>
<updated>2021-05-17T16:14:09Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-03-28T19:04:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=1bc9fd5fe14a60db861fb317f731a5e27e857bf3'/>
<id>urn:sha1:1bc9fd5fe14a60db861fb317f731a5e27e857bf3</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>term: get rid of term-&gt;font_scale, use term-&gt;scale only</title>
<updated>2021-05-17T15:55:49Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-13T09:10:51Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=2afc6782361d0deaa443234466775b1121feec8f'/>
<id>urn:sha1:2afc6782361d0deaa443234466775b1121feec8f</id>
<content type='text'>
We only needed term-&gt;font_scale to be able to detect scaling factor
changes (term-&gt;font_scale != term-&gt;scale).

But, we already have the old scaling factor in all places where
term_font_dpi_changed() is called, so let’s pass the old scaling
factor as an argument instead.
</content>
</entry>
<entry>
<title>term: remove get_font_scale()</title>
<updated>2021-05-17T15:55:39Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-12T22:15:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=09354286955a6a7eb05e0e336ce7fc9cc43cb5f3'/>
<id>urn:sha1:09354286955a6a7eb05e0e336ce7fc9cc43cb5f3</id>
<content type='text'>
get_font_scale() was used to get the new scaling factor when loading
fonts. This was then compared to the last seen font scaling factor. If
there was no difference, the fonts were not reloaded.

The problem was, the initial term-&gt;scale was set differently. This
sometimes led to term-&gt;scale=2, while get_font_scale() return 1. That
meant, fonts were initially scaled by 2 (when dpi-aware=no). Later,
when mapped on an output (and thus term-&gt;scale being set to 1), the
fonts weren’t reloaded with the correct scaling factor since the
cached term-&gt;font_scale value was already 1.

Since term-&gt;scale always reflects the *new* scaling factor when
term_font_dpi_changed() is called, use that directly, and remove
get_font_scale().

Also rename the following functions:

* font_should_size_by_dpi() -&gt; font_size_by_dpi_for_scale()
* font_size_by_dpi() -&gt; font_sized_by_dpi()
* font_size_by_scale() -&gt; font_sized_by_scale()
</content>
</entry>
<entry>
<title>term: rename CELL_MULT_COL_SPACER -&gt; CELL_SPACER, and change its definition</title>
<updated>2021-05-14T12:41:02Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-14T12:41:02Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=d9e1aefb9173857f0632227de5ac368a505c69bf'/>
<id>urn:sha1:d9e1aefb9173857f0632227de5ac368a505c69bf</id>
<content type='text'>
Instead of using CELL_SPACER for *all* cells that previously used
CELL_MULT_COL_SPACER, include the remaining number of spacers
following, and including, itself. This is encoded by adding to the
CELL_SPACER value.

So, a double width character will now store the character itself in
the first cell (just like before), and CELL_SPACER+1 in the second
cell.

A three-cell character would store the character itself, then
CELL_SPACER+2, and finally CELL_SPACER+1.

In other words, the last spacer is always CELL_SPACER+1.

CELL_SPACER+0 is used when padding at the right margin. I.e. when
writing e.g. a double width character in the last column, we insert a
CELL_SPACER+0 pad character, and then write the double width character
in the first column on the next row.
</content>
</entry>
</feed>
