Commit graph

97 commits

Author SHA1 Message Date
Craig Barnes
0d1e6960af
osc: avoid unnecessary calls to strlen(3)
Checking for specific strings of length 0 or 1 can be done with e.g.:

    if (str[0] == '\0') {...}
    if (str[0] == '?' && str[1] == '\0') {...}

Doing it this way instead of using strlen(3) means we avoid the
function call overhead and also avoid scanning through more of the
string than is neceessary.

A compiler could perhaps optimize away calls to strlen(3) when the
result is compared to a small constant, but GCC 11.2 only seems to
actually do this[1] for lengths of 0.

[1]: https://godbolt.org/z/qxoW8qqW6
2022-04-06 18:19:47 +02:00
Daniel Eklöf
3cefe78b40
osc: use four digits in OSC-4 and OSC-11 rgb:r/g/b replies
Closes #971
2022-03-13 19:44:32 +01:00
Craig Barnes
a3c5e8927d osc: grow OSC buffer exponentially instead of by fixed increments of 128
With fixed increments of 128 bytes, an OSC 52 copy operation could end
up doing thousands or tens of thousands of realloc(3) calls just to
copy a few MB.
2022-03-02 01:55:25 +00:00
Daniel Eklöf
d34c8007f1
osc: don’t damage the entire view on a single color palette update
Instead, loop the viewport and dirty only those cells that are
affected by the palette change.
2022-02-10 20:09:11 +01:00
Daniel Eklöf
6cdaa4fd0a
osc: implement OSC-22 - set xcursor pointer 2022-02-07 17:28:37 +01:00
Daniel Eklöf
c2bf2d3650
csi: store color index, not actual color, in cell’s fg/bg attributes
When using indexed colors (i.e. SGR 30/40/90/100), store the index
into the cell’s fg/bg attributes, not the actual color value.

This has a couple of consequences:

Color table lookup is now done when rendering. This means a rendered
cell will always reflect the *current* color table, not the color
table that was in use when the cell was printed to.

This simplifies the OSC-4/104 logic, since we no longer need to update
the grid - we just have to damage it to trigger rendering.

Furthermore, this change simplifies the VT parsing, since we no longer
need to do any memory loads (except loading the SGR parameter values),
only writes.
2021-12-26 12:37:48 +01:00
Daniel Eklöf
a3016a6cc9
osc-4: don’t update the color of cells with RGB fg/bg colors
OSC 4/104 changes the 256-color palette. We also run a pass over the
visible cells, and update their colors.

This was previously done by comparing the actual color of the cell,
with the “old” color in the palette. If they matched, the cell was
updated.

This meant that cells with an RGB color (i.e. not a palette based
color) was also updated, _if_ its color matched the palette color.

Now that each cell tracks its color *source*, we can ignore all
non-palette based cells.

Note that this still isn’t perfect: if the palette contains multiple
entries with the same color, we’ll end up updating the “wrong” cells.

Closes #678
2021-12-01 20:07:53 +01:00
Daniel Eklöf
d46af6bd7a
term: track cell color source
Each cell now tracks it’s current color source:

* default fg/bg
* base16 fg/bg (maps to *both* the regular and bright colors)
* base256 fg/bg
* RGB

Note that we don’t have enough bits to separate the regular from the
bright colors. These _shouldn’t_ be the same, so we ought to be
fine...
2021-11-20 16:46:38 +01:00
Daniel Eklöf
174f8870c7
Merge branch 'parse-rgb-strlen' 2021-10-20 19:59:05 +02:00
Craig Barnes
2e87889279 osc: use STRLEN() macro to make parse_rgb() more self-documenting
The empty literals in the macro are to ensure the argument itself
is a string literal, so it can't be used on anything else.
2021-10-20 17:05:36 +01:00
Craig Barnes
52dcf72d0b osc: use BEL terminator in OSC replies to BEL-terminated OSC queries
This matches the documented (and observed) behavior in xterm:

> XTerm accepts either BEL or ST for terminating OSC sequences, and
> when returning information, uses the same terminator used in a query

-- https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
2021-10-20 12:48:37 +01:00
Craig Barnes
0a22183fdf osc: fix typo in LOG_DBG() message 2021-07-24 01:58:34 +01:00
Daniel Eklöf
405b887a82
osc: implement iTerm2’s OSC-9 - desktop notifications 2021-06-04 07:44:00 +02:00
Daniel Eklöf
55b343f690
osc: implement OSC 17+19: change selection background/foreground colors
And of course, we also implement the corresponding reset sequences,
OSC 117+119.
2021-04-08 10:43:36 +02:00
Daniel Eklöf
28c2bea800
osc: reset background alpha when resetting the background color 2021-04-08 10:41:39 +02:00
Daniel Eklöf
8020c14637
osc: parse_legacy_color(): the alpha component is not a floating point number
When using the urxvt extension of the XParseColor format, the alpha
component is not a floating point number, but a decimal number in the
range 0-100.
2021-04-08 10:41:38 +02:00
Daniel Eklöf
5ff655506d
osc: parse_rgb(): ensure ‘alpha’ has been initialized 2021-04-08 10:41:38 +02:00
Daniel Eklöf
ed41bffc28
osc: add support for URxvt extension to include alpha in OSC-11
There are two variants, either using a ‘[percent]’ prefix for legacy
colors, or using ‘rgba:r/g/b/a’ instead of ‘rgb:r/g/b’.

Closes #436
2021-04-08 10:41:38 +02:00
Daniel Eklöf
936063271f
config/terminal: refactor: remove “default_*” color members from terminal struct
Access the original colors in the configuration instead.
2021-04-07 08:07:43 +02:00
Daniel Eklöf
4f0c0628a2
osc: verify OSC 4/104 color index is valid
Closes #434
2021-04-05 21:13:32 +02:00
Daniel Eklöf
d44cda11bf
osc-8: fix thinko: can’t use the ID parameters *address* as actual ID
Doing so means the next OSC-8 URL emitted by the client application,
with the same ID, will get a *new* id internally.

Instead, hash the string and use that as ID.
2021-02-21 20:15:31 +01:00
Daniel Eklöf
b934969b85
term: add ‘id’ parameter to term_osc8_open()
The current OSC-8 URL’s ID is now tracked along with the URI itself,
and its starting point.
2021-02-21 20:14:52 +01:00
Daniel Eklöf
ecbfc2bbe9
osc: 8: parse params, and the ‘id’ parameter specifically
Applications can assign an ID to the URL. This is used to associate
the parts of a split up URL with each other:

  ╔═ file1 ════╗
  ║          ╔═ file2 ═══╗
  ║http://exa║Lorem ipsum║
  ║le.com    ║ dolor sit ║
  ║          ║amet, conse║
  ╚══════════║ctetur adip║
             ╚═══════════╝

In the example above, ‘http://exa’ and ‘le.com’ are part of the same
URL, but by necessity split up into two OSC-8 URLs.

If the application sets the same ID for those two OSC-8 URLs, the
terminal can ensure they are handled as one.
2021-02-21 20:14:52 +01:00
Daniel Eklöf
b55f6925d3
osc: parse OSC-8, by calling term_osc8_{open,close} as appropriate 2021-02-21 20:14:51 +01:00
Craig Barnes
e56136ce11 debug: rename assert() to xassert(), to avoid clashing with <assert.h> 2021-01-16 20:16:00 +00:00
Craig Barnes
3f4cfa338b Add xsnprintf() and remove some unnecessary strlen(3) calls 2021-01-14 21:30:06 +00:00
Daniel Eklöf
03cbb6ad90
notify: break out desktop notifications from osc.c 2020-12-10 18:06:24 +01:00
Daniel Eklöf
21cc68d49e
osc: implement urxvt’s “OSC 777;notify”
OSC 777 is URxvt’s generic escape to send commands to its perl
extensions. The first parameter is the name of the extension, followed
by its arguments.

OSC 777;notify is a, if not well established, at least a fairly well
known escape sequence to request a (desktop) notification. The syntax
is:

  \e]777;notify;<title>;<body>\e\\

Neither title nor body is escaped in any way, meaning they should not
contain a ‘;’.

Foot will split title from body at the *first* ‘;’. Any remaining ‘;’
characters are treated as part of ‘body’.

Instead of adding built-in support for the freedesktop notification
specification (which would require us to link against at least dbus),
add a new config option to foot.ini: ‘notify’.

This option specifies the command to execute when a notification is
received. ‘${title}’ and ‘${body}’ can be used anywhere, in any
combination, and as many times as you want, in any of the command
arguments.

The default value is ‘notify-send -a foot -i foot ${title} ${body}’
2020-12-09 20:54:51 +01: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
cad0ae957d
osc: use new uri_parse() to parse an OSC7 PWD URI 2020-10-28 19:11:22 +01:00
Daniel Eklöf
b507d3a55e
osc: change info logging to debug logging when changing the cursor color 2020-10-20 21:03:51 +02:00
Daniel Eklöf
edb904a187
osc: don’t explicitly call render_refresh() when changing the color palette
Doing so will schedule the renderer “as soon as possible”. I.e we’re
by-passing the regular scheduler, and thus we’re by-passing the user’s
setting of the delayed-render-* timers.

The fact that we’re scheduling “as soon as possible” also means we’re
much more likely to trigger flickering, or color flashes, if the
application is changing colors which are on the screen.

To handle changes to the cursor color(s), use the new
term_damage_cursor() instead of render_refresh().

To handle background color changes, which affect the margins, use the
new term_damage_margins() instead of render_refresh_margins(),

Closes #141
2020-09-29 10:05:52 +02:00
Daniel Eklöf
419bd87098
osc52: use first source that actually *has* data 2020-09-09 19:01:42 +02:00
Daniel Eklöf
776b831d89
osc52: unset (clear) selection when an invalid payload is received 2020-09-09 19:01:39 +02:00
Daniel Eklöf
d579c0e1e4
osc: explicitly refresh margins on a background color change 2020-09-01 07:34:41 +02:00
Daniel Eklöf
aa3985a298
Don't use "case X ... Y:", if possible/where it makes sense 2020-08-23 10:07:08 +02:00
Daniel Eklöf
3e1636c013
osc: dirty grids on *all* color modifying sequences
We only updated the grid for OSC 4 - Set color <idx>. But we did *not*
do it for 104 (reset color <idx>), 10 - set default foreground, 11 -
set default background, 110 - reset default foreground, or 111 - reset
default background.
2020-08-18 17:54:11 +02:00
Craig Barnes
104fe2fa55 Fix some spelling mistakes 2020-08-15 19:39:00 +01:00
Craig Barnes
7a77958ba2 Convert most dynamic allocations to use functions from xmalloc.h 2020-08-08 20:37:57 +01:00
Craig Barnes
11a1d99da7 Replace non-portable "\e" escape in string literals with "\033" 2020-08-02 23:54:04 +01:00
Daniel Eklöf
71584aed38
seat: use separate 'enter' serials for keyboard and mouse 2020-07-09 11:20:46 +02:00
Daniel Eklöf
11373a6561
multi-seat: re-enable OSC 52 support 2020-07-08 19:28:08 +02:00
Daniel Eklöf
c470825067
wip: multi-seat support
Compiles and runs, but mouse, clipboard and other things have been
disabled.
2020-07-08 16:45:26 +02:00
Daniel Eklöf
c94cbdeb64
osc: set color: update both grids, but exclude scrollback 2020-06-14 09:34:46 +02:00
Daniel Eklöf
957e482f45
osc: 'Set Color' now updates already rendered cells in current grid
Since we don't have the original palette index in already rendered
cells, we compare the color *value*. If it matches, we assume this was
the color index used, and updates the cell's color.

Note that for performance reasons, we only update the current
grid. This is of course wrong, strictly speaking.

However, it is expected that _Set Color_ is used by full-screen
applications using the alternate grid.
2020-06-11 17:13:32 +02:00
Daniel Eklöf
f72c982c89
osc: don't assert on \E]4 being followed by a ';'
This fixes a crash (in debug builds) that could be triggered by
e.g. cat:ing /dev/urandom.
2020-06-09 17:33:26 +02:00
Daniel Eklöf
ae7383189a
osc: fix scaling of RGB formatted color specifiers 2020-05-02 23:07:26 +02:00
Daniel Eklöf
9eda632c97
osc: OSC 12: mimic xterm - a color value of 0 means use inverted fg/bg 2020-05-02 23:00:21 +02:00
Daniel Eklöf
db9b99e8ac
osc: fix 'OSC 12 ?' to return the cursor color, not the cursor text color 2020-05-02 22:58:30 +02:00
Daniel Eklöf
ac58d05c6b
osc: fix scaling of legacy formatted color specifiers 2020-05-02 22:57:12 +02:00