Commit graph

110 commits

Author SHA1 Message Date
Daniel Eklöf
9902a5732f
term: try to improve on a performance regression
When support was added for DECOM (absolute/relative row addressing), a
small but noticeable (~3.5%) performance regression was introduced.

Try to improve the situation by simplifying the relative-to-absolute
conversion; only the row needs to be transformed.
2019-11-17 18:52:27 +01:00
Daniel Eklöf
cf75528e86
Revert "term: new function: term_autowrap()"
This reverts commit 686405b703.
2019-11-17 17:22:34 +01:00
Daniel Eklöf
686405b703
term: new function: term_autowrap()
Adds a linebreak (+ scroll if necessary) if we're in a deferred wrap
and auto-margins are enabled.

Return true when we wrapped, false otherwise.
2019-11-17 12:13:36 +01:00
Daniel Eklöf
c9ebd527cf
term: save/restore charsets on save/restore cursor+attributes 2019-11-17 10:02:46 +01:00
Daniel Eklöf
ce544776ab
term: move charset variables into an anonymous struct 2019-11-17 09:59:12 +01:00
Daniel Eklöf
36bcb0dac1
term: restore_cursor: restore lcf flag 2019-11-17 09:46:30 +01:00
Daniel Eklöf
a70fe1f5d7
term: move lcf flag into 'cursor' struct 2019-11-17 09:46:20 +01:00
Daniel Eklöf
d637b8c9ba
term: add struct cursor 2019-11-17 09:44:31 +01:00
Daniel Eklöf
c1088d77ac
term: rename: print_needs_wrap -> lcf (Last Column Flag) 2019-11-17 09:39:43 +01:00
Daniel Eklöf
81215e5a72
term: cursor_{up,down}: limit cursor movements based on origin mode 2019-11-16 12:14:58 +01:00
Daniel Eklöf
f91073c362
term: add tab-stop list to terminal struct
This list is intended to store tab stop columns
2019-11-16 10:54:21 +01:00
Daniel Eklöf
95eaad7ce4
csi: implement DECOM - switch cursor origin between absolute and relative
The default is absolute mode, where 0,0 is the upper left corner of
the screen.

In relative mode, the origin is relative the top scroll margin.

Internally, we always track the current cursor position in absolute
mode. Every time we the client *sets* or *queries* the cursor position
in relative mode, we translate it to absolute.
2019-11-05 13:27:37 +01:00
Daniel Eklöf
fef07138b3
terminal: ptmx: ignore *both* EPOLLIN and EPOLLOUT on EPOLLHUP 2019-11-05 09:23:13 +01:00
Daniel Eklöf
3081898caf
terminal: use async_write() when writing to ptmx 2019-11-04 13:46:30 +01:00
Daniel Eklöf
60c3ff8737
selection: send primary/clipboard data asynchronously
TODO: try writing synchronously first
2019-11-04 13:11:15 +01:00
Daniel Eklöf
a706c1e804
terminal: add comments describing the sync/async writing modes 2019-11-04 12:36:43 +01:00
Daniel Eklöf
78cd93f030
terminal: malloc_trim() is a GNU extension 2019-11-03 12:57:47 +01:00
Daniel Eklöf
2195e2cf71
terminal: trim memory after free:ing a terminal
A terminal with lots of scrollback history will have allocated a lot
of memory.

Normally, free() wont return this memory to the OS, and we don't seem
to trigger the automatic trim calls.

This means the server would accumulate quite a lot of memory over
time, as terminals come and go.

Now we explicitly trim the memory every time a terminal is destroyed.
2019-11-03 12:48:18 +01:00
Daniel Eklöf
e76357eabb
terminal: ptmx fdm handler: tag unlikely branches 2019-11-03 12:14:09 +01:00
Daniel Eklöf
79945419eb
terminal: comments and cleanup 2019-11-03 12:13:51 +01:00
Daniel Eklöf
cba1551b03
terminal: cleanup asynchronous ptmx output handling
Break out actual writing to a separate function, and call this
function both from the synchronous and the asynchronous code paths.
2019-11-03 01:25:41 +01:00
Daniel Eklöf
f00c5fdac6
term: asynchronous writes to slave
Make ptmx non-blocking. Then, when writing data to the slave would
have blocked, use the FDM to asynchronously write the remaining data.

This is done by enabling EPOLLOUT on ptmx, and enqueueing all outgoing
data. The FDM handler will go through the enqueued data, and once all
of it has been written, we turn off EPOLLOUT again (thus switching
back to synchronous writes)
2019-11-03 01:03:52 +01:00
Daniel Eklöf
9f1525aef7
Rename: vt_to_slave() -> term_to_slave() 2019-11-03 00:52:24 +01:00
Daniel Eklöf
79c3121aa3
misc: fdm already logs failures 2019-11-03 00:52:24 +01:00
Daniel Eklöf
965d8a3a8e
terminal: don't get stuck waiting for misbehaving slaves to terminate
While unusual, it *is* possible for a client *not* to terminate when
we close ptmx.

We need to handle this *somehow*. Since it is so unusual, we'll go
with a fairly easy, but synchronous method:

* Register a signal handler for SIGALRM, and setup a 2 second alarm
* Wait for slave to die
* If it didn't die, sent SIGTERM, then re-set the alarm for another 2
  seconds.
* If it still hasn't died, send SIGKILL (this time without an alarm).
2019-11-02 12:09:32 +01:00
Daniel Eklöf
563c910127
terminal: 'child_ret' variables isn't needed 2019-11-02 11:30:32 +01:00
Daniel Eklöf
f28fb6c039
timerfd: read() returns -1 with errno == EAGAIN, not 0
When there hasn't been a timeout (or in our case, there was a timeout,
but we reset the timer before we got to the read()), read() returns,
not 0, but -1 with errno == EAGAIN.
2019-11-02 01:44:01 +01:00
Daniel Eklöf
b27cd9cedf
timerfd: use non-blocking mode, fixes dead lock
Since we cancel the timers every now and then, there's a (small)
chance that one handler cancels a timer that has triggered in the same
epoll() iteration.

When this happens, read() blocks.

Fix by making the timer FDs non-blocking, and simply returning when we
read 0 bytes.
2019-11-02 01:14:40 +01:00
Daniel Eklöf
0bd2ddd8ad
term_init(): initialize slave TERM from term_init() argument 2019-11-01 21:03:08 +01:00
Daniel Eklöf
69d62d3cd2
slave: set TERM environment variable in slave process 2019-11-01 21:01:15 +01:00
Daniel Eklöf
1e41a25f00
terminal: call user-defined callback when destroying terminal
main uses this to get the exit code of the terminal.
2019-11-01 20:34:32 +01:00
Daniel Eklöf
70b236d66d
term_shutdown(): cleanup
* Close FDs, then delay destruction to next epoll() call
* Destroy window before destroying terminal
2019-11-01 20:30:58 +01:00
Daniel Eklöf
c824aa2ef5
terminal: fdm_del() closes the FD 2019-11-01 20:29:16 +01:00
Daniel Eklöf
fb0801fa56
terminal: delayed rendering: fdm_delayed_render() may be called with is_armged==false
This would happen if *both* timers triggered in the same epoll() call.
2019-11-01 20:28:11 +01:00
Daniel Eklöf
2286bcf23d
terminal: no need to check for EAGAIN - we don't use non-blocking 2019-11-01 20:27:45 +01:00
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