From 55b343f69030c22fcd36b88d2af445acdd69b732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 7 Apr 2021 08:09:40 +0200 Subject: [PATCH] osc: implement OSC 17+19: change selection background/foreground colors And of course, we also implement the corresponding reset sequences, OSC 117+119. --- CHANGELOG.md | 2 ++ doc/foot-ctlseqs.7.scd | 29 ++++++++++++++++++++++------- osc.c | 34 +++++++++++++++++++++++++++++++--- render.c | 6 +++--- terminal.c | 6 ++++++ terminal.h | 3 +++ 6 files changed, 67 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a40e6a5..422dce6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ * URxvt OSC-11 extension to set background alpha (https://codeberg.org/dnkl/foot/issues/436). +* OSC 17+19 - change selection background/foreground color. +* OSC 117+119 - reset selection background/foreground color. ### Changed diff --git a/doc/foot-ctlseqs.7.scd b/doc/foot-ctlseqs.7.scd index 210e3269..78f5dfc8 100644 --- a/doc/foot-ctlseqs.7.scd +++ b/doc/foot-ctlseqs.7.scd @@ -564,7 +564,7 @@ All _OSC_ sequences begin with *\\E]*, sometimes abbreviated _OSC_. | \\E] 4 ; _c_ ; _spec_ \\E\\ : xterm : 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://*, or the legacy format (*#rgb*). | \\E] 7 ; _Uri_ \\E\\ : iTerm2 @@ -579,7 +579,7 @@ All _OSC_ sequences begin with *\\E]*, sometimes abbreviated _OSC_. | \\E] 10 ; _spec_ \\E\\ : xterm : Change the default foreground color to _spec_, a color in - *XParseColor* format. + XParseColor format. | \\E] 11 ; _spec_ \\E\\ : xterm : 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). | \\E] 12 ; _spec_ \\E\\ : 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\\ : xterm : Send clipboard data. _Pc_ can be either *c*, *s* or *p*. *c* uses the clipboard as source, and *s* and *p* uses the primary selection. The response is *OSC 52 ; Pc ; *, - where _Pc_ indicates the source used. + where _Pc_ denotes the source used. | \\E] 52 ; _Pc_ ; _Pd_ \\E\\ : 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 selection. -| \\E] 104 [; _c_] \\E\\ +| \\E] 104 ; _c_ \\E\\ : 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. | \\E] 110 \\E\\ : xterm @@ -613,6 +622,12 @@ All _OSC_ sequences begin with *\\E]*, sometimes abbreviated _OSC_. | \\E] 112 \\E\\ : xterm : Reset cursor color +| \\E] 117 \\E\\ +: xterm +: Reset selection background color +| \\E] 119 \\E\\ +: xterm +: Reset selection foreground color | \\E] 555 \\E\\ : foot : Flash the entire terminal (foot extension) diff --git a/osc.c b/osc.c index 157272d9..f5aa86a2 100644 --- a/osc.c +++ b/osc.c @@ -679,8 +679,10 @@ osc_dispatch(struct terminal *term) break; case 10: - case 11: { - /* Set default foreground/background color */ + case 11: + case 17: + case 19: { + /* Set default foreground/background/highlight-bg/highlight-fg color */ /* Client queried for current value */ if (strlen(string) == 1 && string[0] == '?') { @@ -714,7 +716,11 @@ osc_dispatch(struct terminal *term) } 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) { case 10: @@ -726,6 +732,16 @@ osc_dispatch(struct terminal *term) if (have_alpha) term->colors.alpha = alpha; 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); @@ -836,6 +852,18 @@ osc_dispatch(struct terminal *term) term_damage_cursor(term); 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: osc_flash(term); break; diff --git a/render.c b/render.c index a0c0696e..cee44e54 100644 --- a/render.c +++ b/render.c @@ -416,9 +416,9 @@ render_cell(struct terminal *term, pixman_image_t *pix, uint32_t _fg = 0; uint32_t _bg = 0; - if (is_selected && term->conf->colors.use_custom.selection) { - _fg = term->conf->colors.selection_fg; - _bg = term->conf->colors.selection_bg; + if (is_selected && term->colors.use_custom_selection) { + _fg = term->colors.selection_fg; + _bg = term->colors.selection_bg; } else { /* Use cell specific color, if set, otherwise the default colors (possible reversed) */ _fg = cell->attrs.have_fg ? cell->attrs.fg : term->colors.fg; diff --git a/terminal.c b/terminal.c index fd206090..c05eb84e 100644 --- a/terminal.c +++ b/terminal.c @@ -1087,6 +1087,9 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .fg = conf->colors.fg, .bg = conf->colors.bg, .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, .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.bg = term->conf->colors.bg; 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, sizeof(term->colors.table)); term->origin = ORIGIN_ABSOLUTE; diff --git a/terminal.h b/terminal.h index 7b463d22..3583cf61 100644 --- a/terminal.h +++ b/terminal.h @@ -407,6 +407,9 @@ struct terminal { uint32_t bg; uint32_t table[256]; uint16_t alpha; + uint32_t selection_fg; + uint32_t selection_bg; + bool use_custom_selection; } colors; enum cursor_style cursor_style;