Commit graph

132 commits

Author SHA1 Message Date
Daniel Eklöf
d490cc84c0
term: cursor blink: cursor refresh now dirties the cursor cell
Normally we don't dirty the cell on cursor movement. But, since a
blinking cursor isn't a cursor that has moved, our normal cursor
rendering wont work.

Dirty the cursor cell to force a redraw of it.
2019-12-16 21:31:40 +01:00
Daniel Eklöf
7d29435d86
term: implement cursor blinking
Blinking can be enabled either by setting the cursor style with

 CSI Ps SP q

and selecting a blinking style.

Or, with 'CSI ? 12 h'

Note that both affect the same internal state. I.e. you can disable
blinking with CSI ? 12l after having selected a blinking cursor
style. This is consistent with XTerm behavior.
2019-12-15 15:07:56 +01:00
Daniel Eklöf
8dc9560431
term: determine cell width from the width of the space character 2019-12-05 19:34:47 +01:00
Daniel Eklöf
ad56afe2f4
term: test: set font DPI to the highest DPI we find
In most cases (i.e. when there's only a single output/monitor), this
will be *the* DPI value.

In other cases, well...

The _right_ thing to do is track the outputs our window is actually
mapped on, and re-instantiate fonts depending on the current output's
DPI. But that's for the future...
2019-12-04 22:02:02 +01:00
Daniel Eklöf
e9fbb371df
fcft: font_from_name() no longer accepts a tllist 2019-12-01 19:22:25 +01:00
Daniel Eklöf
fbeb1e9610
term: mouse reporting functions no longer take modifier state
The mouse reporting functions are called from input when we receive
Wayland mouse events.

We used to pass the current keyboard modifier (shift, alt, ctrl, etc)
to the terminal functions.

This however is wrong, since we may receive Wayland mouse events
without having keyboard focus. When we don't have keyboard focus, the
modifier state doesn't apply to us.

Remove the modifier arguments from the terminal mouse reporting
functions. These functions now read this state directly instead, but
only when the terminal instance in question has keyboard focus.
2019-11-30 17:11:00 +01:00
Daniel Eklöf
2208f4304b
term: add term_mouse_grabbed()
When this returns true, it means we have keyboard focus and are
grabbing the mouse (for e.g. selections), regardless of whether the
client has enabled mouse tracking or not.
2019-11-30 17:06:15 +01:00
Daniel Eklöf
62ed0ef4f2
term: "raw" mouse mode requires shift only to be pressed 2019-11-30 16:48:32 +01:00
Daniel Eklöf
8f8ef5df0e
term: define xcursor strings as global variables 2019-11-30 12:43:06 +01:00
Daniel Eklöf
c8d94931e6
term: xcursor: use selection_enabled()
Instead of duplicating the code from selection_enabled() that deals
with forced selection, just call selection_enabled().

This was previously not possible since selection_enabled() didn't
require keyboard_focus. Now it does.
2019-11-30 12:01:40 +01:00
Daniel Eklöf
a81c65caa2
term: reset: set 'origin' to ORIGIN_ABSOLUTE 2019-11-30 00:32:06 +01:00
Daniel Eklöf
8b7158703d
term: reset: don't access rows directly
We've just re-set the grid offsets, meaning rows 0..term->rows may not
all have been initialized.

Call grid_row_and_alloc() to ensure they are.
2019-11-29 23:36:04 +01:00
Daniel Eklöf
bf9a9e7b90
term: xcursor: use 'hand2' instead of 'left_ptr' when mouse tracking
Mouse tracking always reports clicks, so using a cursor that suggests
you can click makes sense I think.
2019-11-29 22:30:56 +01:00
Daniel Eklöf
f41788c185
term: xcursor cleanup
Show 'text' cursor when:

* we have no mouse tracking enabled
* forced selection has been enabled (shift being held down)
* We're *not* scrollback searching

In all other cases, show the 'left_ptr' cursor.
2019-11-29 22:15:03 +01:00
Daniel Eklöf
0dd37f0a36
terminal: use the 'text' xcursor pointer whenever selection is possible 2019-11-28 19:35:47 +01:00
Daniel Eklöf
903581b7eb
async: first synchronous write may succeed partially
When trying to write (to e.g. the slave, or to a clipboard receiver),
we first try to send the data synchronously, and only if that fails do
we switch to asynchronous mode.

However, the first synchronous may (in fact, is likely to) succeed
partially.
2019-11-28 19:20:25 +01:00
Daniel Eklöf
ae91c53fb2
font: pass dpi=96 to fontconfig
TODO: use actual output PPI. Question is *which* output...
2019-11-26 19:02:35 +01:00
Daniel Eklöf
bc86cd61c7
font: move metrics from terminal struct to font struct 2019-11-26 19:02:35 +01:00
Daniel Eklöf
ee45c48deb
term: shutdown: handle *not* being unmapped
When we're shutting down a terminal, we destroy our Wayland window,
and assume that will unmap us.

There are cases when this isn't true (most likely when e.g. a screen
locker is active, and the unmap is being deferred).

Handle by explicitly setting focused to NULL.
2019-11-21 18:18:35 +01:00
Daniel Eklöf
3c8a87168a
fonts: use 'weight' and 'slant', not 'style' when loading fonts 2019-11-19 17:35:02 +01:00
Daniel Eklöf
7ff5a8027a
term: report_mouse_click(): legacy mode only supports rows/cols up to 223.
In the legacy mouse reporting mode, line and column numbers are
limited to 223 (255-32). In case the current coordinate falls outside
this, simply ignore it (don't report it).
2019-11-18 11:31:21 +01:00
Daniel Eklöf
832cc8c269
term: assert(false) on MOUSE_X10
This mouse mode is never enabled. I.e. we don't support it. Add
asserts to catch usage of it, should we ever decide to implement it.
2019-11-18 11:18:48 +01:00
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