Commit graph

399 commits

Author SHA1 Message Date
Craig Barnes
e56136ce11 debug: rename assert() to xassert(), to avoid clashing with <assert.h> 2021-01-16 20:16:00 +00:00
Craig Barnes
22f25a9e4f Print stack trace on assert() failure or when calling fatal_error()
Note: this uses the __sanitizer_print_stack_trace() function from the
AddressSanitizer runtime, so it only works when AddressSanitizer is
in use.
2021-01-16 19:56:33 +00:00
Daniel Eklöf
bae3c871bb
term/vt/csi: break out cursor save/restore to dedicated functions 2021-01-15 17:08:30 +01:00
Daniel Eklöf
6b539ba373
term: remove client application’s pid from reaper when shutting down
When we are shutting down the terminal, we explicitly wait for the
child application to terminate (with a timeout, after which the child
process is killed).

I.e. there’s no need to let the reaper handle it. In fact, doing so
leads to a crash since we will have destroyed (and thus free:d) the
terminal instance when the reaper callback is called.
2021-01-12 09:21:01 +01:00
Daniel Eklöf
dce402ae42
config: pt_or_px cannot be a union 2021-01-11 19:37:05 +01:00
Daniel Eklöf
1830dfca55
term: use pt_or_px_as_pixels() 2021-01-11 09:31:08 +01:00
Daniel Eklöf
5ea37adaf4
term: add pt_or_px_as_pixels()
This function takes a ‘union pt_or_px’ and converts its value to a
pixel value.
2021-01-11 09:31:08 +01:00
Daniel Eklöf
a6fc8b5da4
config: line-height, letter-spacing: values are in pt by default, but we allow px
If the value is specified without a unit, then the value is assumed to
be in points, subject to DPI scaling.

The value can optionally have a ‘px’ suffix, in which case the value
is treated as a raw pixel count.
2021-01-11 09:31:08 +01:00
Daniel Eklöf
70cfcf11fb
config: letter-spacing: make this a relative value
0, the default, means no additional spacing; the cell width is defined
by the font metrics.

A positive value *adds* to the width from the font metrics, while a
negative value *subtracts*.
2021-01-11 09:31:06 +01:00
Daniel Eklöf
a0c359c24e
term: set_fonts: use custom line-height+letter-spacing, if set
If the user has configured a custom line-height and/or letter-spacing,
use that instead of the font metrics.
2021-01-11 09:31:06 +01:00
Daniel Eklöf
736c88c3fb
term: clear box drawing glyph cache when reloading fonts 2021-01-01 21:09:31 +01:00
Daniel Eklöf
7acdb3a0dd
box-drawing: add infrastructure for rendering box drawing characters ourselves
* ‘term’ struct contains an array of 160 fcft glyph pointers
* the glyph pointers are lazily allocated when we need to draw a box
  drawings character
* Filtering out box drawings characters is easy - they are (except
  unicode 13, which isn’t handled yet )all in a single range.
2021-01-01 21:09:31 +01:00
Daniel Eklöf
0dbd85ed9e
terminal: reaper callback: don’t close ptmx if already closed 2020-12-26 01:35:17 +01:00
Daniel Eklöf
8b0ef6aa85
terminal: shutdown (or --hold) when the client process terminates
Shutdown the terminal when the client process terminates, not when the
ptmx file descriptor is closed.

This fixes an issue where the terminal remains running after the
client process has terminated, if it spawned child processes that
inherited the ptmx file descriptor.
2020-12-26 01:29:40 +01:00
Daniel Eklöf
2a82096749
term: fix builds with debug logging enabled
DPI_AWARE_ON has been renamed to DPI_AWARE_YES
2020-12-18 17:32:54 +01:00
Daniel Eklöf
0a821f2ed4
fonts: size fonts using the scaling factor when output scaling is enabled
This extends the new ‘dpi-aware’ option with a new default value,
‘auto’.

When set to ‘auto’, fonts are sized using monitors’ DPI when output
scaling is disabled. When output scaling is enabled, fonts are instead
sized using the scaling factor.

The reasoning here is that a user that has enabled output scaling is
obviously *not* relying on DPI scaling.

Output scaling can also be a way to compensate for different viewing
distances, in which case we do *not* want to break that by using DPI
scaling.

Users can still force DPI-only font sizing by setting ‘dpi-aware=yes’,
or disable it completely by setting ‘dpi-aware=no’.
2020-12-17 12:05:22 +01:00
Daniel Eklöf
6c8b034aff
term: enabling application synchronized updates clear pending grid refresh
This fixes issues with de-synchronized frames being rendered; we may
have scheduled a redraw earlier, that hasn’t yet triggered (probably
because we’re waiting for a frame callback), when we enable
application synchronized updates.

This means we risk rendering a partially updated state when the frame
callback finally arrives, if the application hasn’t yet ended its
synchronized update.
2020-12-14 19:05:54 +01:00
Daniel Eklöf
15d20af2a2
config: add ‘notify’ to possible values for ‘bell’ in foot.ini
When `bell=notify`, foot will trigger a desktop notification when it
receives a BEL in an unfocused window.
2020-12-10 18:22:48 +01:00
Daniel Eklöf
194fbff883
ime: store wchar version of pre-edit string in terminal struct 2020-12-07 20:44:14 +01:00
Daniel Eklöf
e3b5a98ade
codespell: currenly -> currently, second instance 2020-12-07 20:44:11 +01:00
Daniel Eklöf
0fc2a1188c
codespell: currenly -> currently 2020-12-07 20:44:11 +01:00
Daniel Eklöf
b59d695b2b
ime: add functions to enable/disable IME, simplify code that enables IME
We may want to be able to enable/disable IME run-time, even though we
have received an ‘enter’ IME event.

This enables us to do that.

Also add functions to enable/disable IME on a per-terminal instance
basis.

A terminal may have multiple seats focusing it, and enabling/disabling
IME in a terminal instance enables/disables IME on all those seats.

Finally, the code to enable IME is simplified; the *only* surface that
can ever receive ‘enter’ IME events is the main grid. All other
surfaces are sub-surfaces, without their own keyboard focus.
2020-12-07 20:44:11 +01:00
Daniel Eklöf
05083110c3
ime: make IME compile-time optional 2020-12-07 20:44:10 +01:00
Daniel Eklöf
8c3d48c5cd
ime: render pre-edit text
This is done by allocating cells for the pre-edit text when receiving
the text-input::done() call, and populating them by converting the
utf-8 formatted pre-edit text to wchars.

We also convert the pre-edit cursor position to cell positions (it can
cover multiple cells).

When rendering, we simply render the pre-edit cells on-top off the
regular grid. While doing so, we also mark the underlying, “real”,
cells as dirty, to ensure they are re-rendered when the pre-edit text
is modified or removed.
2020-12-07 20:44:10 +01:00
Craig Barnes
31c73f0cf0 csi: add new private mode that makes the Escape key emit "\E[27;1;27~"
This mode can be set by client programs with the DECSET, DECRST,
XTSAVE and XTRESTORE sequences by using 27127 as the parameter.

The sequence "\E[27;1;27~" is encoded in the same way as is done by
xterm's "modifyOtherKeys" mode. Even though xterm itself never emits
such a sequence for the Escape key, many programs already have
support for parsing this style of key sequence.
2020-11-29 04:04:57 +00:00
Daniel Eklöf
360cc8e6de
term: remove read-only properties copied from the config
Use the config directly instead.
2020-11-26 18:08:28 +01:00
Daniel Eklöf
ba8b15d675
sixel: change default max size to 10000x10000
It used to be the size of the window. This caused images to be cropped
when the application emitting them didn’t change the max size.
2020-11-23 20:10:55 +01:00
Daniel Eklöf
daa8d129c1
pgo: feed VT data through fdm_ptmx(), not vt_from_slave()
fdm_ptmx(), the FDM callback handler for ptmx data, is just as much in
the hot path as vt_from_slave(). It is also slightly more complicated
than a read() followed by a call to vt_from_slave().

As a result, some benchmarks performed significantly worse in a
partial PGO build than in a full PGO build, since fdm_ptmx() wasn’t
PGO:d.

To be able to feed data through fdm_ptmx(), we need to set up the
delayed rendering timer FDs, configure the timeout values, and provide
a readable FD it can read the VT data from.

The latter is done with a memory FD. This ensures *all* VT data is
loaded into memory before we feed it to the parser.
2020-11-22 19:29:44 +01:00
Daniel Eklöf
c65fcacf43
terminal: use 96, not 75, for DPI when being DPI unaware 2020-11-19 19:25:48 +01:00
Daniel Eklöf
8e7658a135
config: add ‘dpi-aware’ option, defaulting to enabled
When disabled, foot no longers uses outputs’ DPI to scale the
font. Instead, it uses the outputs’ scaling factor.

That is, instead of appending “:dpi=123” to the fontconfig string,
modify the “:pixelsize” or “:size” attribute.

Closes #206
2020-11-19 19:25:48 +01:00
Daniel Eklöf
2382d6b448
csi: implement “CSI ? 1035” - toggle Num Lock override
This adds a num_lock_modifier state to the terminal, and hooks up
“CSI?1035h/l” to toggle it.
2020-11-11 18:26:47 +01:00
Daniel Eklöf
beaf220f39
tiocswinsz: fix compilation error on e.g. ppc64
On some platforms, TIOCSWINSZ has a very large value, >
0x80000000.

On some platforms, the `request` argument to `ioctl(3)` is an `int`.

For platforms where both of the above is true, gcc will warn (and
error out if compiled with `-Werror`) on:

  ioctl(fd, TIOCSWINSZ, ...)

To silence this warning, we need to cast `TIOCSWINSZ` to an
integer.

However, doing this on platforms where `request` is an `unsigned long`
will result in `TIOCSWINSZ` being sign-extended (and thus we end up
with an invalid value).

It seems that casting to `unsigned int` works in both cases; it
silences the long -> int conversion warning, while also preserving the
correct value in all cases.
2020-10-29 18:06:04 +01:00
Daniel Eklöf
2c101a21ee
config: add font-bold, font-italic and font-bold-italic options
These options lets the user configure custom fonts and styles, to use
with the bold and italic cell attributes.

By default, they are unset, meaning we use the bold/italic variants of
the regular font.

Closes #169.
2020-10-20 21:04:47 +02:00
Daniel Eklöf
e6737034e5
term: reset: enable/disable cursor blink depending on user configuration 2020-10-13 19:28:56 +02:00
Daniel Eklöf
2cac832ef3
term: reset: kill blink timer 2020-10-13 19:28:42 +02:00
Daniel Eklöf
1f650a7fdf
term: remove unneeded blink.active field
We now use the timer FD instead; if it is -1, blinking is not active.
2020-10-13 19:28:05 +02:00
Daniel Eklöf
ac55e4067a
term: instantiate cursor blink timer on-demand 2020-10-13 19:23:04 +02:00
Daniel Eklöf
c63199429e
term: create/destroy blink timer on-demand
Blinking text is uncommon. It doesn’t make that much sense to keep a
timer opened (but unarmed) at all times.

This patch makes it so the timer is instantiated on-demand, and
destroyed again when it no longer is needed.
2020-10-13 18:40:20 +02:00
Daniel Eklöf
7a218cba08
term: subpixel changed: fix build with LOG_ENABLE_DBG=1 2020-10-13 18:39:36 +02:00
Daniel Eklöf
d75e50230e
Merge branch 'scroll-up-down-while-selecting' into master
Closes #149
2020-10-12 20:20:26 +02:00
Daniel Eklöf
17761dce63
csi: implement ‘CSI ? 1042 h/l’ - enable/disable bell-is-urgent 2020-10-11 17:44:29 +02:00
Daniel Eklöf
7fedf2f801
selection: auto-scroll: selection keeps scrolling while mouse is outside grid
Moving the mouse outside the grid while we have an on-going selection
now starts a timer. The interval of this timer depends on the mouse’s
distance from the grid - the further away the mouse is, the shorter
interval.

On each timer timeout, we scroll one line, and update the
selection. Thus, the shorter the interval, the faster we scroll.

The timer is canceled as soon as the mouse enters the grid again, or
the selection is either canceled or finalized.

The timer FD is created and destroyed on-demand.

Most of the logic is now in selection.c. The exception is the
calculation of the timer interval, which depends on the mouse’s
position. Thus, this is done in input.c.

The scroll+selection update logic needs to know a) which direction
we’re scrolling in, and b) which *column* the selection should be
updated with.

If the mouse is outside the grid’s left or right margins, the stored
mouse column will be -1. I.e. we don’t know whether the mouse is on
the left or right side of the grid. This is why the caller, that
starts the timer, must provide this value.

The same applies to top and bottom margins, but since we already have
the scroll *direction*, which row value to use can be derived from this.
2020-10-11 15:44:20 +02:00
Daniel Eklöf
892730e5b9
term: update sixel rows/cols *after* cell dimension change, *before* resize
This fixes an issue where we resized+reflowed with bad rows/cols
values in the sixels.
2020-10-09 07:44:16 +02:00
Daniel Eklöf
6cf86d67d9
term: re-calculate sixel images’ rows/cols values when cell size changes 2020-10-09 07:44:15 +02:00
Daniel Eklöf
7c6686221f
bell: optionally render margins in red when receiving BEL
Add anew config option, ‘bell=none|set-urgency’. When set to
‘set-urgency’, the margins will be painted in red (if the window did
not have keyboard focus).

This is intended as a cheap replacement for the ‘urgency’ hint, that
doesn’t (yet) exist on Wayland.

Closes #157
2020-10-08 19:55:32 +02:00
Daniel Eklöf
9f9ad69849
term: cursor-left: unlikely -> likely for reverse-wrap
Since reverse wrap-around is enabled by default, we’re *likely* to
take this branch.
2020-10-06 19:05:11 +02:00
Daniel Eklöf
207b24538d
term: enable reverse wrap-around by default
Since we’re now doing reverse auto-wrapping by default, we add
‘bw’ (‘auto_left_margin’)to terminfo.
2020-10-06 18:42:26 +02:00
Daniel Eklöf
97e07c1ea1
term: cursor-left: don’t do reverse-wrapping unless auto-margins are enabled
This matches XTerm’s behavior.
2020-10-03 10:50:28 +02:00
Daniel Eklöf
03cacaba86
term: cursor-left: reverse-wrap when cursor is at the left margin
Assuming the private mode ‘reverse-wrap’ has been enabled.
2020-10-02 21:30:32 +02:00
Daniel Eklöf
5594746e49
Revert "term: cursor-left: reduce move count by one when lcf=true"
This reverts commit 02e3e4ac9b.

This broke at least Emacs. Cursor movement at the margins *is*
undefined, and the behavior we’re now reverting to matches XTerm.
2020-10-02 20:02:36 +02:00