Commit graph

283 commits

Author SHA1 Message Date
Daniel Eklöf
9df7e8fa07
term: print_insert: early return 2020-06-09 17:31:28 +02:00
Daniel Eklöf
29630ac92e
term: set an initial TIOCSWINSZ right after opening the pty
Since foot is pretty aggressive about spawning the client early, it
was possible for a fast client to read a 0x0 terminal size. Not all
clients coped well.

Closes #20.
2020-06-02 19:59:28 +02:00
Daniel Eklöf
789617d5ad
term: don't double fork new terminal windows
Instead, register their PIDs with the new reaper module and let it
handle them.
2020-05-21 20:17:29 +02:00
Daniel Eklöf
08588cd0fc
selection: handle viewport wrap around correctly
When the viewport wraps around, the selection points may be
"incorrect".
2020-05-19 18:49:42 +02:00
Daniel Eklöf
550667a9ea
term: scrolling: calling function must clamp scroll amount 2020-05-19 18:47:38 +02:00
Daniel Eklöf
33346ba02d
term: erase_cell_range: set row->dirty before calling memset() 2020-05-17 16:29:09 +02:00
Daniel Eklöf
52e6a751b3
term: scrolling: mark selection top if-statement as 'unlikely' 2020-05-17 15:48:58 +02:00
Daniel Eklöf
96a4f1b993
term: scrolling: hopefully fix all selection/scrolling related crashes
When scrolling, there are a couple of cases where an existing
selection must be canceled because we cannot meaningfully represent it
after scrolling.

These are when the selection is (partly) inside:

* The top scrolling region
* The bottom scrolling region
* The new lines scrolled in. I.e. re-used lines

For the scrolling regions, the real problem is when the selection
crosses the scrolling region boundary; a selection that is completely
inside a scrolling regions _might_ be possible to keep, but we would
need to translate the selection coordinates to the new scrolling
region lines.

For simplicity, we cancel the selection if it touches the scrolling
region. Period.

The last item, newly scrolled in lines is when the selection covers
very old lines and we're now wrapping around the scrollback history.

Then there's a fourth problem case: when the user has started a
selection, but hasn't yet moved the cursor. In this case, we have no
end point.

What's more problematic is that when the user (after scrolling) moves
the cursor, we try to create a huge selection that covers mostly
empty (NULL) rows, causing us to crash.

This can happen e.g. when reverse scrolling in such a way that we wrap
around the scrollback history.

The actual viewport in this case is something like `-n - m`. But the
selection we'll end up trying to create will be `m - (rows - n)`. This
range may very well contain NULL rows.

To deal with this, we simply cancel the selection.
2020-05-17 15:34:49 +02:00
Daniel Eklöf
8f9e6127da
term: scrolling: sixel: simplify now that row count is clamped 2020-05-17 11:46:44 +02:00
Daniel Eklöf
cfd0b5d2d8
term: scrolling: in debug builds, verify all rows are allocated 2020-05-16 23:53:23 +02:00
Daniel Eklöf
ebd867372a
term: scrolling: simplify, now that scroll row count is clamped 2020-05-16 23:53:03 +02:00
Daniel Eklöf
a4f5938123
term: scrolling: clamp number of rows to number of rows in scrolling region 2020-05-16 23:44:54 +02:00
Daniel Eklöf
57e04a1320
grid: swap_row: remove unused parameter 'initialize' 2020-05-16 23:43:05 +02:00
Daniel Eklöf
a1c95562fb
term: scrolling: clear selection *before* scrolling
We normally don't clear the selection when scrolling. The exception is
when the selection covers re-used rows. I.e. rows that we scroll in
and clear.

In this case we cancel the selection (we _could_ modify it and keep as
much as possible and only remove the re-used rows...). We must do
this *before* scrolling, since scrolling will swap rows (when there's
a scrolling region). When this happens, the selection is "corrupted",
and canceling it afterwards will not work.
2020-05-16 21:27:56 +02:00
Daniel Eklöf
38c050746d
selection: on_row_in_view() -> on_rows_in_view(), and now takes a range
This allows us to check the selection once when scrolling, instead of
once for each scrolled in line.
2020-05-16 21:16:11 +02:00
Daniel Eklöf
c090a0664f
Revert "term: print: line-wrap multi-column characters instead of cutting them in half"
This reverts commit 8448296bb3.

Applications need to be multi-column character aware anyway, and they
should deal with this.
2020-05-09 12:04:55 +02:00
Daniel Eklöf
8448296bb3
term: print: line-wrap multi-column characters instead of cutting them in half 2020-05-09 11:57:19 +02:00
Daniel Eklöf
56d53ec2a1
term: don't register ptmx with FDM if we're shutting down
This can happen when there's an error instantiating the
terminal *after* we've spawned the slave process.
2020-05-04 20:49:28 +02:00
Daniel Eklöf
9864d91975
term: set 'is_shutting_down' before calling term_destroy() on error 2020-05-04 20:46:27 +02:00
Daniel Eklöf
921331854a
term: check return value when instantiating thread synchronization primitives 2020-05-04 20:11:45 +02:00
Daniel Eklöf
6bac1bd257
term: thrd_success isn't necessarily 0 2020-05-03 14:17:54 +02:00
Daniel Eklöf
7525fa20c2
thrd_create(): handle errors correctly
* Detect thrd_create() failures in all places where we instantiate
  threads
* Log error correctl; thrd_create() does not return an errno value
2020-05-03 12:25:04 +02:00
Daniel Eklöf
62e0774319
unicode-combining: store seen combining chains "globally" in the term struct
Instead of storing combining data per cell, realize that most
combinations are re-occurring and that there's lots of available space
left in the unicode range, and store seen base+combining combinations
chains in a per-terminal array.

When we encounter a combining character, we first try to pre-compose,
like before. If that fails, we then search for the current
base+combining combo in the list of previously seen combinations. If
not found there either, we allocate a new combo and add it to the
list. Regardless, the result is an index into this array. We store
this index, offsetted by COMB_CHARS_LO=0x40000000ul in the cell.

When rendering, we need to check if the cell character is a plain
character, or if it's a composed character (identified by checking if
the cell character is >= COMB_CHARS_LO).

Then we render the grapheme pretty much like before.
2020-05-03 11:03:22 +02:00
Daniel Eklöf
d945b68b73
unicode-combine: remove utf8proc dependency
We only used utf8proc to try to pre-compose a glyph from a base and
combining character.

We can do this ourselves by using a pre-compiled table of valid
pre-compositions. This table isn't _that_ big, and binary searching it
is fast.

That is, for a very small amount of code, and not too much extra RO
data, we can get rid of the utf8proc dependency.
2020-05-02 17:29:00 +02:00
Daniel Eklöf
3474624c2c
unicode-combining: completely remove unicode combining characters when feature is disabled 2020-05-01 12:05:38 +02:00
Daniel Eklöf
76567e9ef0
render: render combining characters
This is basically just a loop that renders additional glyphs on top
off the base glyph.

Since we now need access to the row struct, for the combining
characters, the function prototype for 'render_cell()' has changed.

When rendering the combining characters we also need to deal with
broken fonts; some fonts use positive offsets (as if the combining
character was a regular character), while others use a negative
offset (to be used as if you had already advanced the pen position).

We handle both - a positive offset is rendered just like a regular
glyph. When we see a negative offset we simply add the width of a cell
first.
2020-05-01 11:56:13 +02:00
Daniel Eklöf
67614df9f9
term: print: reset combining characters for this cell
This is the *only* place combining characters are reset. In
particular, we do *not* reset them in a normal cell erase.

This is a performance design decision - clearing the combining
characters in erase is way too slow.

This way, we clear it only when we *have* to. Anything looking at the
combining characters must first ensure the base character is not 0.
2020-05-01 11:50:38 +02:00
Daniel Eklöf
69c3e74498
util.h: new header file defining commonly used macros 2020-05-01 11:46:24 +02:00
Daniel Eklöf
fc2e385d87
term: don't enable ptmx FDM callback until Wayland window has been configured
The way things works right now, we cannot enable the ptmx FDM callback
right away. We need to wait for the Wayland window to have been
configured.

Before the window is configured, we don't have a size, and no
grid. Thus, if we try to process ptmx data we'll crash since we have
no where to write it to.

So, registering the ptmx fd with the FDM is now delayed until we've
received the first 'configure' event from Wayland.
2020-04-30 17:22:57 +02:00
Daniel Eklöf
ae5af7bb06
term: start slave before loading fonts and starting rendering threads
This allows the client to load in parallel with our font loading,
which should improve startup time.
2020-04-30 11:39:41 +02:00
Daniel Eklöf
589e984b91
term: font size adjust: re-load fonts in parallel 2020-04-29 20:09:21 +02:00
Daniel Eklöf
1d67f37045
term: destroy: handle rendering threads not being initialized
We sort of already did this. However, we did not handle the case where
the thread array itself hadn't yet been allocated.
2020-04-29 20:08:19 +02:00
Daniel Eklöf
84e945a851
term: initialize rendering worker threads after instantiating fonts
This ensures the resources (e.g. stack) used by the transient threads
used to load the primary fonts can be re-used by the rendering worker
threads.
2020-04-29 20:07:21 +02:00
Daniel Eklöf
3adcbf7d4d
term: load primary fonts in parallel
Use four threads to load the four primary font variants - normal,
bold, italic and bold italic.

This speeds up initial startup, and reloading of fonts on a DPI
change.
2020-04-28 22:07:02 +02:00
Daniel Eklöf
e9ed3025a8
damage: remove 'scroll' sub struct
There is no other types of damage but scroll damage.
2020-04-26 12:47:19 +02:00
Daniel Eklöf
0b2006ecd5
term: fcft: max/space advance fields have been renamed 2020-04-23 11:54:03 +02:00
Daniel Eklöf
05bb0ae590
term: guess subpixel mode after initializing wayland window
At this point, we're not mapped, but we should have all the outputs
initialized. Which means we can at least guess which subpixel mode to
use.

If that turns out to be wrong, something we'll detect when we're
mapped, we'll just have to re-render.
2020-04-22 19:38:38 +02:00
Daniel Eklöf
7194f65ae9
fcft: adjust to fcft-2.0 API changes
* font_*() -> fcft_*()
* struct font -> struct fcft_font
* struct glyph -> struct fcft_glyph
* enum subpixel_order -> enum fcft_subpixel
2020-04-21 19:29:36 +02:00
Daniel Eklöf
6f83ef81e5
render: use output's subpixel mode when rasterizing glyphs 2020-04-20 18:38:55 +02:00
Daniel Eklöf
5c4f5ab414
term: destroy: free scroll damage lists
These lists are typically empty when we destroy the terminal. However,
if we had queued up damage, and then manage to destroy the terminal
instance before the last changes were rendered, then they will *not*
be empty.

Found by the address sanitizer.
2020-04-19 15:26:52 +02:00
Daniel Eklöf
89559d5466
grid: move 'cursor' state from terminal to grid
This way, the 'normal' and 'alt' grids have their own cursor state,
and we don't need to switch between them.
2020-04-16 18:51:14 +02:00
Daniel Eklöf
c96a0b3b3c
misc: replace all explicit zero-initializers with empty initializers 2020-04-13 12:03:11 +02:00
Daniel Eklöf
27a205e90f
term: reset: plug memory leak
In reset, we allocated new rows for all the currently visible
lines. We did **not** however, free the 'old' rows.

Fix by not explicitly allocating new rows, but instead allocating
uninitialized rows when needed, and then explicitly erasing the row.

If there already was a row allocated, it is simply erased. If there
wasn't, the a new line is malloc:ed, and then erased.
2020-04-13 11:42:10 +02:00
Daniel Eklöf
ec7a768487
conf: add 'title' conf option and --title command line option 2020-04-01 19:59:47 +02:00
Daniel Eklöf
598ac4bcd0
Merge branch 'master' into scroll-damage-performance 2020-03-27 21:16:42 +01:00
Daniel Eklöf
758fd9fd58
client: add --maximized and --fullscreen
We now create a copy of the config for each client, and updates it
with the values passed from the client.

Since we're not actually cloning it (and e.g. strdup() all strings
etc) we can't call conf_destroy() to free it, but need to free just
the strings we've replaced.
2020-03-27 21:14:49 +01:00
Daniel Eklöf
e197368c0f
config: add 'startup-mode' option
This option controls the initial window mode: windowed, maximized or
fullscreen. The default is windowed.
2020-03-26 19:39:12 +01:00
Daniel Eklöf
1891489cd6
app synchronized updates: set is_armed=false when enabling 2020-03-25 18:24:58 +01:00
Daniel Eklöf
9bbbd26c7a
render: pace title updates
Synchronize window title updates with window rendering.
2020-03-25 18:23:55 +01:00
Daniel Eklöf
b79ed6f3e4
term: delayed rendering: failure to read timers is always an error 2020-03-24 17:41:33 +01:00