osc: implement OSC 17+19: change selection background/foreground colors

And of course, we also implement the corresponding reset sequences,
OSC 117+119.
This commit is contained in:
Daniel Eklöf 2021-04-07 08:09:40 +02:00
parent deb08ddba0
commit 55b343f690
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
6 changed files with 67 additions and 13 deletions

View file

@ -30,6 +30,8 @@
* URxvt OSC-11 extension to set background alpha * URxvt OSC-11 extension to set background alpha
(https://codeberg.org/dnkl/foot/issues/436). (https://codeberg.org/dnkl/foot/issues/436).
* OSC 17+19 - change selection background/foreground color.
* OSC 117+119 - reset selection background/foreground color.
### Changed ### Changed

View file

@ -564,7 +564,7 @@ All _OSC_ sequences begin with *\\E]*, sometimes abbreviated _OSC_.
| \\E] 4 ; _c_ ; _spec_ \\E\\ | \\E] 4 ; _c_ ; _spec_ \\E\\
: xterm : xterm
: Change color number _c_ to _spec_, where _spec_ is a color in : Change color number _c_ to _spec_, where _spec_ is a color in
*XParseColor* format. foot only supports RGB colors; either XParseColor format. foot only supports RGB colors; either
*rgb:<red>/<green>/<blue>*, or the legacy format (*#rgb*). *rgb:<red>/<green>/<blue>*, or the legacy format (*#rgb*).
| \\E] 7 ; _Uri_ \\E\\ | \\E] 7 ; _Uri_ \\E\\
: iTerm2 : iTerm2
@ -579,7 +579,7 @@ All _OSC_ sequences begin with *\\E]*, sometimes abbreviated _OSC_.
| \\E] 10 ; _spec_ \\E\\ | \\E] 10 ; _spec_ \\E\\
: xterm : xterm
: Change the default foreground color to _spec_, a color in : Change the default foreground color to _spec_, a color in
*XParseColor* format. XParseColor format.
| \\E] 11 ; _spec_ \\E\\ | \\E] 11 ; _spec_ \\E\\
: xterm : xterm
: Change the default background color to _spec_, a color in : Change the default background color to _spec_, a color in
@ -588,21 +588,30 @@ All _OSC_ sequences begin with *\\E]*, sometimes abbreviated _OSC_.
75% alpha). 75% alpha).
| \\E] 12 ; _spec_ \\E\\ | \\E] 12 ; _spec_ \\E\\
: xterm : xterm
: Change cursor color to _spec_, a color in *XParseColor* format. : Change cursor color to _spec_, a color in XParseColor format.
| \\E] 17 ; _spec_ \\E\\
: xterm
: Change selection background color to _spec_, a color in
XParseColor format.
| \\E] 19 ; _spec_ \\E\\
: xterm
: Change selection foreground color to _spec_, a color in XParseColor
format.
| \\E] 52 ; _Pc_ ; ? \\E\\ | \\E] 52 ; _Pc_ ; ? \\E\\
: xterm : xterm
: Send clipboard data. _Pc_ can be either *c*, *s* or *p*. *c* uses : Send clipboard data. _Pc_ can be either *c*, *s* or *p*. *c* uses
the clipboard as source, and *s* and *p* uses the primary the clipboard as source, and *s* and *p* uses the primary
selection. The response is *OSC 52 ; Pc ; <base64-encoded data>*, selection. The response is *OSC 52 ; Pc ; <base64-encoded data>*,
where _Pc_ indicates the source used. where _Pc_ denotes the source used.
| \\E] 52 ; _Pc_ ; _Pd_ \\E\\ | \\E] 52 ; _Pc_ ; _Pd_ \\E\\
: xterm : xterm
: Copy _Pd_ (base64 encoded text) to the clipboard. _Pc_ indicates the : Copy _Pd_ (base64 encoded text) to the clipboard. _Pc_ denotes the
target: *c* targets the clipboard and *s* and *p* the primary target: *c* targets the clipboard and *s* and *p* the primary
selection. selection.
| \\E] 104 [; _c_] \\E\\ | \\E] 104 ; _c_ \\E\\
: xterm : xterm
: Reset color number _c_, or all colors (excluding the default : Reset color number _c_ (multiple semicolon separated _c_ values may
be provided), or all colors (excluding the default
foreground/background colors) if _c_ is omitted. foreground/background colors) if _c_ is omitted.
| \\E] 110 \\E\\ | \\E] 110 \\E\\
: xterm : xterm
@ -613,6 +622,12 @@ All _OSC_ sequences begin with *\\E]*, sometimes abbreviated _OSC_.
| \\E] 112 \\E\\ | \\E] 112 \\E\\
: xterm : xterm
: Reset cursor color : Reset cursor color
| \\E] 117 \\E\\
: xterm
: Reset selection background color
| \\E] 119 \\E\\
: xterm
: Reset selection foreground color
| \\E] 555 \\E\\ | \\E] 555 \\E\\
: foot : foot
: Flash the entire terminal (foot extension) : Flash the entire terminal (foot extension)

34
osc.c
View file

@ -679,8 +679,10 @@ osc_dispatch(struct terminal *term)
break; break;
case 10: case 10:
case 11: { case 11:
/* Set default foreground/background color */ case 17:
case 19: {
/* Set default foreground/background/highlight-bg/highlight-fg color */
/* Client queried for current value */ /* Client queried for current value */
if (strlen(string) == 1 && string[0] == '?') { if (strlen(string) == 1 && string[0] == '?') {
@ -714,7 +716,11 @@ osc_dispatch(struct terminal *term)
} }
LOG_DBG("change color definition for %s to %06x", LOG_DBG("change color definition for %s to %06x",
param == 10 ? "foreground" : "background", color); param == 10 ? "foreground" :
param == 11 ? "background" :
param == 17 ? "selection background" :
"selection foreground",
color);
switch (param) { switch (param) {
case 10: case 10:
@ -726,6 +732,16 @@ osc_dispatch(struct terminal *term)
if (have_alpha) if (have_alpha)
term->colors.alpha = alpha; term->colors.alpha = alpha;
break; break;
case 17:
term->colors.selection_bg = color;
term->colors.use_custom_selection = true;
break;
case 19:
term->colors.selection_fg = color;
term->colors.use_custom_selection = true;
break;
} }
term_damage_view(term); term_damage_view(term);
@ -836,6 +852,18 @@ osc_dispatch(struct terminal *term)
term_damage_cursor(term); term_damage_cursor(term);
break; break;
case 117:
LOG_DBG("resetting selection background color");
term->colors.selection_bg = term->conf->colors.selection_bg;
term->colors.use_custom_selection = term->conf->colors.use_custom.selection;
break;
case 119:
LOG_DBG("resetting selection foreground color");
term->colors.selection_fg = term->conf->colors.selection_fg;
term->colors.use_custom_selection = term->conf->colors.use_custom.selection;
break;
case 555: case 555:
osc_flash(term); osc_flash(term);
break; break;

View file

@ -416,9 +416,9 @@ render_cell(struct terminal *term, pixman_image_t *pix,
uint32_t _fg = 0; uint32_t _fg = 0;
uint32_t _bg = 0; uint32_t _bg = 0;
if (is_selected && term->conf->colors.use_custom.selection) { if (is_selected && term->colors.use_custom_selection) {
_fg = term->conf->colors.selection_fg; _fg = term->colors.selection_fg;
_bg = term->conf->colors.selection_bg; _bg = term->colors.selection_bg;
} else { } else {
/* Use cell specific color, if set, otherwise the default colors (possible reversed) */ /* Use cell specific color, if set, otherwise the default colors (possible reversed) */
_fg = cell->attrs.have_fg ? cell->attrs.fg : term->colors.fg; _fg = cell->attrs.have_fg ? cell->attrs.fg : term->colors.fg;

View file

@ -1087,6 +1087,9 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
.fg = conf->colors.fg, .fg = conf->colors.fg,
.bg = conf->colors.bg, .bg = conf->colors.bg,
.alpha = conf->colors.alpha, .alpha = conf->colors.alpha,
.selection_fg = conf->colors.selection_fg,
.selection_bg = conf->colors.selection_bg,
.use_custom_selection = conf->colors.use_custom.selection,
}, },
.origin = ORIGIN_ABSOLUTE, .origin = ORIGIN_ABSOLUTE,
.cursor_style = conf->cursor.style, .cursor_style = conf->cursor.style,
@ -1683,6 +1686,9 @@ term_reset(struct terminal *term, bool hard)
term->colors.fg = term->conf->colors.fg; term->colors.fg = term->conf->colors.fg;
term->colors.bg = term->conf->colors.bg; term->colors.bg = term->conf->colors.bg;
term->colors.alpha = term->conf->colors.alpha; term->colors.alpha = term->conf->colors.alpha;
term->colors.selection_fg = term->conf->colors.selection_fg;
term->colors.selection_bg = term->conf->colors.selection_bg;
term->colors.use_custom_selection = term->conf->colors.use_custom.selection;
memcpy(term->colors.table, term->conf->colors.table, memcpy(term->colors.table, term->conf->colors.table,
sizeof(term->colors.table)); sizeof(term->colors.table));
term->origin = ORIGIN_ABSOLUTE; term->origin = ORIGIN_ABSOLUTE;

View file

@ -407,6 +407,9 @@ struct terminal {
uint32_t bg; uint32_t bg;
uint32_t table[256]; uint32_t table[256];
uint16_t alpha; uint16_t alpha;
uint32_t selection_fg;
uint32_t selection_bg;
bool use_custom_selection;
} colors; } colors;
enum cursor_style cursor_style; enum cursor_style cursor_style;