Commit graph

67 commits

Author SHA1 Message Date
Daniel Eklöf
dbfc636ade
sixel: implement reflow
Move sixel reflow from grid_reflow() to sixel_reflow(). This lets us
use internal sixel functions to update the sixels.

Note that grid_reflow() still needs to remap the sixelss coordinates.
2020-10-09 07:44:16 +02:00
Daniel Eklöf
323119a645
grid: reflow: re-insert sixels *after* new grid offset has been set
Also make sure to destroy sixels that are too big to fit in the scrollback.

Fixes issues with the sixel list not being sorted correctly.
2020-10-09 07:44:15 +02:00
Daniel Eklöf
1718449ca6
grid: reflow: fix release build; ‘idx’ is only used in an assert() 2020-09-29 19:40:17 +02:00
Daniel Eklöf
8c18304287
grid: reflow: handle viewport being too far down when enlarging the window
If the viewport is close to the bottom, but not *at* the bottom, and
we’re enlarging the window, the translated viewport will be too far
down.
2020-09-29 19:40:17 +02:00
Daniel Eklöf
a0d1d2f1c8
grid: reflow: retain scrollback position
Closes #142
2020-09-29 19:40:14 +02:00
Daniel Eklöf
a1ab31eea5
grid: reflow: make sure cursor is within the visible screen area
Even though we translate the cursor position from the old grid
coordinates to the new, the cursor may _still_ end up outside the
visible area.

Make sure it doesn’t.
2020-09-10 07:37:08 +02:00
Daniel Eklöf
61f950f77a
grid: reflow: calculate width of composed characters correctly
Before this patch, reflow called `wcwidth()` on our magic values for
composed characters.
2020-09-06 19:14:46 +02:00
Craig Barnes
7a77958ba2 Convert most dynamic allocations to use functions from xmalloc.h 2020-08-08 20:37:57 +01:00
Daniel Eklöf
c07d14e1c0
grid: reflow: don't insert <width> spacer cells for *every* empty cell
Only do it for the last, non-empty cell.
2020-08-04 18:07:54 +02:00
Daniel Eklöf
b0798ad0be
grid: reflow: use macro print_spacer() to insert multi-column character spacers 2020-07-14 20:29:59 +02:00
Daniel Eklöf
9ea42ef226
grid: reflow: handle multi column character spacers
Ignore *old* cells containing spacers.

Pad new grid with spacers if a multi-column character doesn't fit at
the end of a line.

Insert spacers after a multi-column character.
2020-07-14 17:04:59 +02:00
Daniel Eklöf
3fd61fa120
grid: reflow: always emit *all* cells of a multi-column character 2020-07-14 12:15:25 +02:00
Daniel Eklöf
466466c19e
grid: reflow: use width=1 for invalid characters 2020-07-14 12:03:10 +02:00
Daniel Eklöf
803c87bb65
grid: reflow: force line-wrap if a multi-column character does not fit on current line 2020-07-14 11:03:33 +02:00
Daniel Eklöf
a136987678
reflow: ensure sixels are correctly sorted when re-inserted
And make sure to remove re-inserted sixels that has wrapped around the
scrollback (this may happen when the window size decreases).
2020-06-29 21:59:40 +02:00
Daniel Eklöf
deb61d20d8
grid: reflow: delete sixels that end up crossing the scrollback wrap around
Our sixel handling code requires sixels to *not* cross the scrollback
wrap around.

Until we've fixes the reflow code that split up such sixels (much like
we do when we generate a sixel), simply delete it.
2020-06-27 20:16:39 +02:00
Daniel Eklöf
644c8ef879
grid: add TODO, and an assert, that sixels must not cross wrap-around 2020-06-27 15:34: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
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
40bf01a8e6
grid: reflow: copy combining characters 2020-05-01 11:55:22 +02:00
Daniel Eklöf
b2c4115f3e
grid: add per-cell combining characters
The data is *not* added to the cell struct, since that one is too
performance critical.

Instead, the data is added as a separate array in the row struct.

This allows our performance critical code paths that e.g. clear cells
to perform as before.
2020-05-01 11:49:11 +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
5e2e59679b
grid: reflow: make tracking_points array 'const'
The elements aren't, and cannot be, const. But the array itself can,
and should be.
2020-04-17 22:19:59 +02:00
Daniel Eklöf
ef52ed8a10
grid: reflow: caller may now pass a list of coordinates that should be translated 2020-04-17 21:04:32 +02:00
Daniel Eklöf
e5521ff79a
grid: reflow: generalize cursor coordinate translation
Define a list of "tracking points" - coordinates that should be
translated while reflowing.

Add the cursor coordinates to this list.

When a coordinate have been translated, it is removed from the
list. This means we don't have to create a copy of the 'cursor'
coordinate struct.
2020-04-17 21:00:37 +02:00
Daniel Eklöf
91a71b4147
grid: reflow: remove commented out code 2020-04-17 20:48:22 +02:00
Daniel Eklöf
aede474a52
grid: reflow: turn line-wrapping code into a macro 2020-04-17 20:46:08 +02:00
Daniel Eklöf
e37aa3b369
grid: reflow: don't randomly insert hard linebreaks
Not sure why I added this code; maybe to workaround issues caused by
the fact that the cursor position wasn't properly translated.
2020-04-17 20:33:08 +02:00
Daniel Eklöf
5546b40369
grid: grid_reflow() now translates cursor coordinates 2020-04-16 19:38:30 +02:00
Daniel Eklöf
d482bf0a30
sixel: improve handling of images when reflowing the grids
Update the sixels' 'row' attribute when re-flowing a grid, to ensure
it is rendered at the correct place.

This should work in most cases, but will break when the cell size has
changed (e.g. font size increase/decrease, or a DPI change).

This patch also moves the sixel image list from the terminal struct
into the grid struct. The sixels are per-grid after all.
2020-03-13 18:47:16 +01:00
Daniel Eklöf
45ba9f9c8f
grid: grid_reflow(): may be called with old_rows/cols == new_rows/cols
TODO: avoid calling grid_reflow() in this case.
2020-02-25 20:33:27 +01:00
Daniel Eklöf
38a682f0d0
render/grid: move grid reflow code to grid.c 2020-02-15 22:19:08 +01:00
Daniel Eklöf
ce8005545d
term: convert cell 'linefeed' attribute to a row 'linebreak' property
To do text reflow, we only need to know if a line has been explicitly
linebreaked or not. If not, that means it wrapped, and that we
should *not* insert a linebreak when reflowing text.

When reflowing text, when reaching the end of a row in the old grid,
only insert a linebreak in the new grid if the old row had been
explicitly linebreaked.

Furthermore, when reflowing text and wrapping a row in the new grid,
mark the previous row as linebreaked if either the last cell was
(the last column in the last row) empty, or the current cell (the
first column in the new row) is empty. If both are non-empty, then we
assume a linewrap.
2020-02-14 22:39:26 +01:00
Daniel Eklöf
0c90717249
grid: remove commented out code 2019-08-23 20:07:27 +02:00
Daniel Eklöf
7c7720a3ab
scrolling: optimize row access by assuming number of rows is a power of 2
With this assumption, we can replace 'a % b' with 'a & (b - 1)'. In
terms of instructions, this means a fast 'and' instead of a slow
'div'.

Further optimize scrolling by:

* not double-initializing empty rows. Previously, grid_row_alloc()
  called calloc(), which was then followed by a memset() when
  scrolling. This is of course unnecessary.

* Don't loop the entire set of visible rows (this was done to ensure
  all visible rows had been allocated, and to prefetch the cell
  contents).

  This isn't necessary; only newly pulled in rows can be NULL. For
  now, don't prefetch at all.
2019-08-22 17:33:23 +02:00
Daniel Eklöf
85ef9df586
render: add a 'clean' bit to each cell; only render cells that aren't clean
This patch takes a bit from the foreground color value in a
cell (todo: split up foreground/background into bitfields with a
separate field for 'foreground/background' has been set), and only
re-renders cells that aren't marked as clean.

Note: we use a 'clean' bit rather than a 'dirty' bit to make it easy
to erase cells - we can (keep doing) do that by simply memsetting a
cell range to 0.
2019-07-30 18:03:03 +02:00
Daniel Eklöf
f7519b5725
grid: swap rows doesn't mark rows as dirty 2019-07-23 17:56:07 +02:00
Daniel Eklöf
379f7cf646
grid: swap_row: drop requirement that row indices be positive 2019-07-10 19:17:53 +02:00
Daniel Eklöf
1ff1b3a71e
grid: don't pre-allocate the entire grid (with all scrollback lines)
The row array may now contain NULL pointers. This means the
corresponding row hasn't yet been allocated and initialized.

On a resize, we explicitly allocate the visible rows.

Uninitialized rows are then allocated the first time they are
referenced.
2019-07-10 16:27:55 +02:00
Daniel Eklöf
8f0d574dcb
grid: don't implement grid_swap_row() in the header file 2019-07-10 16:08:53 +02:00
Daniel Eklöf
4e25019ba6
wip: grid is now represented as a grid, not a linear array
The grid is now represented with an array of row *pointers*. Each row
contains an array of cells (the row's columns).

The main point of having row pointers is we can now move rows around
almost for free.

This is useful when scrolling with scroll margins for example, where
we previously had to copy the lines in the margins. Now it's just a
matter of swapping two pointers.
2019-07-08 13:57:31 +02:00
Daniel Eklöf
f2363c2391
grid: add a fast path to grid_memmove()
Recognize the case where both the destination and source can be fully
accessed, and to a plain memmove() in this case.
2019-07-07 17:10:30 +02:00
Daniel Eklöf
48528419c4
grid: grid_memset() -> grid_memclear() 2019-07-07 17:10:15 +02:00
Daniel Eklöf
1373d18dbc
logging: disable debug logging by default 2019-07-03 20:21:03 +02:00
Daniel Eklöf
a7a28ff581
scrolling: initial reverse scrolling support - no scroll regions 2019-07-03 10:45:49 +02:00
Daniel Eklöf
482f56b4a2
grid: implement a memmove-sort-of function
grid_memmove() moves cell data from one index to another, taking the
grid offset into account.
2019-07-01 19:18:52 +02:00
Daniel Eklöf
d70956da08
wip: use a sliding window instead of memmove() to scroll
Instead of memmoving a large amount of data on every scroll, use a
sliding window. That is, each time we scroll, we offset origin.
2019-07-01 12:23:38 +02:00
Daniel Eklöf
1ecd4a6ae1
Rename grid_* functions to term_* 2019-06-29 21:03:28 +02:00