Commit graph

75 commits

Author SHA1 Message Date
Daniel Eklöf
2e78dcc5e5
Don't use non-blocking FDs
We use epoll() to determine when we can read/write FDs so there's
absolutely no need for non-blocking.
2019-11-01 20:24:13 +01:00
Daniel Eklöf
4ae22b72a1
term: fdm_shutdown(): remove debug output 2019-10-30 20:28:21 +01:00
Daniel Eklöf
644585a3e5
term: term_shutdown(): set exit value in wayland 2019-10-30 20:25:45 +01:00
Daniel Eklöf
c7238ef7f3
term: assign client PID to term->slave 2019-10-30 20:24:54 +01:00
Daniel Eklöf
58e31728a0
term: term_init(): create wayland window *last*
* Configure all FDs *completely* before moving on
* Start client before creating the wayland window
2019-10-30 20:22:01 +01:00
Daniel Eklöf
9d5926ce12
term: add term_shutdown()
This function unmaps the terminal window, removes itself from the
wayland list of terminals and then finally destroys itself.

We ensure we don't get any callbacks/events referring to a free:d
terminal struct, we close all terminal related FDs and unmap the
wayland window.

Then, to be really really sure there aren't any (by the FDM) queued up
events, we delay the self-destruction to the next FDM poll iteration,
by opening an event FD and adding it to the FDM.

The callback for the event FD removes the FD from the FDM again, and
closes it. And then proceeds to destroy the terminal.
2019-10-30 20:03:11 +01:00
Daniel Eklöf
445bbe3469
wayland: track multiple terminals
The wayland 'term' member is gone and replaced by a list,
'terms'. This list contains all currently running terminal (windows).
2019-10-30 20:02:06 +01:00
Daniel Eklöf
18921f7f45
term: move client startup to a new function, slave_spawn() 2019-10-30 18:05:03 +01:00
Daniel Eklöf
348f3738da
term: break out font initialization to a separate function 2019-10-30 17:50:12 +01:00
Daniel Eklöf
7dcd6b7d55
term: break out render worker threads initialization to a separate function 2019-10-30 17:45:59 +01:00
Daniel Eklöf
54accd8060
term: break out color cube initialization to a separate function 2019-10-30 17:40:09 +01:00
Daniel Eklöf
8d6817a999
term: require all font variants to load 2019-10-30 17:37:30 +01:00
Daniel Eklöf
ce5f5e4d51
slave: rename slave_spawn() -> slave_exec() 2019-10-30 17:30:58 +01:00
Daniel Eklöf
4ec9db8e18
term: no need to stack-allocate an array of worker contexts 2019-10-28 19:23:41 +01:00
Daniel Eklöf
8e6f87eb17
render worker context: allocate, and let worker threads free
Since we now initialize the worker threads from term_init(), which
returns before the threads terminate, we can no longer use
stack-allocated worker contexts.

We _could_ put them in the terminal struct. But a simpler solution is
to allocate them in term_init(), and let the threads free them when
they don't need them anymore.
2019-10-28 18:51:04 +01:00
Daniel Eklöf
720d0df067
term: open FDs before allocating terminal struct 2019-10-28 18:46:03 +01:00
Daniel Eklöf
fe974956b0
term: integrate directly with FDM 2019-10-28 18:35:16 +01:00
Daniel Eklöf
0979a0e2e5
terminal: implement term_init() and term_destroy() 2019-10-28 18:25:19 +01:00
Daniel Eklöf
1adab32906
term: wayland struct is now not a part of the terminal struct
We do however need access to it, so provide a pointer. The difference
is that now we can have a *single* wayland instance, but multiple
terminal instances.
2019-10-27 18:51:14 +01:00
Daniel Eklöf
c9455d5f21
kbd: move into wayland 2019-10-27 17:10:32 +01:00
Daniel Eklöf
777863ac3e
term: add term_reset_view() - make view follow end-of-output again 2019-08-28 17:27:42 +02:00
Daniel Eklöf
0a40a5b6a2
term: remove commented out code 2019-08-23 20:07:05 +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
d8fb80ea32
term: rename colors256 -> table 2019-08-21 18:50:24 +02:00
Daniel Eklöf
631e0c0870
term: use colors256 array for *all* colors
That is, remove the 'regular' and 'bright' color arrays. This is
possible since the 256-color array is defined such that the first 16
colors map to the regular and bright colors.
2019-08-21 18:47:48 +02:00
Daniel Eklöf
d7aaeaedee
csi: move 256-color table into the terminal struct 2019-08-21 17:56:21 +02:00
Daniel Eklöf
776432ded3
erase-cells: don't memset when keeping background color 2019-08-20 21:11:09 +02:00
Daniel Eklöf
14d4a0a1c6
term: don't send mouse events if shift is being pressed 2019-08-08 17:58:50 +02:00
Daniel Eklöf
c06f141189
term: cancel selection when scrolling wraps
If we scroll enough, we'll eventually end up wrapping around the
entire scrollback buffer. At this point, a selection is no longer
valid, so cancel it.

Note: this was very obvious when scrolling in the alt screen, since
its scrollback buffer is what you see on the screen (i.e. it has no
scrollback).
2019-08-05 20:16:17 +02:00
Daniel Eklöf
528ee9925c
term: re-order switch-cases to be in X button order 2019-08-05 18:59:12 +02:00
Daniel Eklöf
c15d546740
term: fix mouse button mapping to X button numbers
BACK should be 4, FORWARD 5.
2019-08-05 18:32:35 +02:00
Daniel Eklöf
9a0d440e95
term: cell erase: reset *all* attributes *except* background 2019-08-03 19:26:02 +02:00
Daniel Eklöf
4d7993b36f
cell: pack more efficiently and store glyph as a wchar
The 'attributes' struct is now 8 bytes and naturally packed (used to
be 9 bytes, artificially packed).

'cell' struct is now 12 bytes, naturally packed (used to be 13 bytes,
artificially packed).

Furthermore, the glyph is stored as a wchar instead of a char*. This
makes it easier (faster) to do glyph lookup when rendering.
2019-08-02 18:19:07 +02:00
Daniel Eklöf
ab92abbd21
term: implement reset 2019-08-01 20:51:11 +02:00
Daniel Eklöf
e3dc184882
term: break out 'flash' to a separate 'term' function 2019-07-30 22:06:02 +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
f5a6304850
term: make sure to update 'current row' when restoring saved cursor 2019-07-23 17:57:07 +02:00
Daniel Eklöf
97350f6488
term: track current window title in terminal struct 2019-07-21 17:35:53 +02:00
Daniel Eklöf
ccc8ef9606
terminal: foreground/background in cell attributes are now uint32_t
This reduces the cell size, and thus improves the cache behavour
2019-07-16 13:17:51 +02:00
Daniel Eklöf
7f6a4f4b6b
csi: implement FocusIn/Out events 2019-07-16 10:34:08 +02:00
Daniel Eklöf
7379198f4a
Use vt_to_slave() instead of calling write(term->ptmx, ...) everywhere 2019-07-15 15:42:21 +02:00
Daniel Eklöf
bcf763d417
selection: add a selection API 2019-07-11 17:38:01 +02:00
Daniel Eklöf
decb4503bf
grid: prefetch cells in grid_row() 2019-07-10 19:52:30 +02:00
Daniel Eklöf
e4a631f7f0
terminal: scrolling: prefetch cells of scrolled in lines
Since newly scrolled in lines will be erased, we want them in the
cache.

So, allocate and prefetch new lines, then repair non-scrolling
regions (to give the prefetch time to actually fetch the
data). Finally, erase the newly scrolled in lines.

This also fixes a bug where the fixup for the non-scrolling regions
could crash on an unallocated row (we were accessing rows that would
be, but hadn't yet been, scrolled in).
2019-07-10 19:18:53 +02:00
Daniel Eklöf
1d7bf3fbca
terminal: scrolling: better debug log messages 2019-07-10 19:18:36 +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
3ab68c575b
terminal: add term_linefeed() and term_reverse_index()
linefeed moves cursor down one row (columns stays the same), or, if
the cursor is at the last row, scrolls up one row.

reverse_index does the opposite; it moves the cursor *up* one row, or,
if the cursor is at the top row, scrolls *down* one row.
2019-07-10 16:02:03 +02:00
Daniel Eklöf
8a65d52b21
terminal: add term_damage_view()
This ensures everything *visible* (i.e. maybe scrolled back content)
is re-rendered.
2019-07-10 14:32:40 +02:00
Daniel Eklöf
bcd111d203
wip: initial scroll back support
Can scroll up and down, and stops when the beginning/end of history is
reached.

However, it probably breaks when the entire scrollback buffer has been
filled - we need to detect when the view has wrapped around to the
current terminal offset.

The detection of when we've reached the bottom of the history is also
flawed, and only works when we overshoot the bottom with at least a
page.

Resizing the windows while in a view most likely doesn't work.

The view will not detect a wrapped around scrollback buffer. I.e. if
the user has scrolled back, and is stationary at a view, but there is
still output being produced. Then eventually the scrollback buffer
will wrap around. In this case, the correct thing to do is make the
view start following the beginning of the history. Right now it
doesn't, meaning once the scrollback buffer wraps around, you'll start
seeing command output...
2019-07-09 16:26:36 +02:00
Daniel Eklöf
d7bb83022d
cleanup 2019-07-09 09:18:58 +02:00