From 827396237253d3c784c7455a9f3f2c26a8128c51 Mon Sep 17 00:00:00 2001 From: Raimund Sacherer Date: Sat, 7 Oct 2023 19:37:04 +0200 Subject: [PATCH 1/7] Enable the use of flash as visual bell With this patch we can configure flash in the bell section. The colors section allow now to configure the color and translucency of the flash. --- CHANGELOG.md | 3 +++ config.c | 21 +++++++++++++++++++++ config.h | 3 +++ doc/foot.ini.5.scd | 16 ++++++++++++++++ foot.ini | 3 +++ render.c | 6 ++++-- terminal.c | 8 ++++++++ terminal.h | 2 ++ 8 files changed, 60 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 667b1662..cc6e57bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,10 +74,13 @@ - `scrollback-down-page` (shift+page-down) - `scrollback-down-half-page` (none) - `scrollback-down-line` (none) +* Support for visual bell which flashes the terminal window. + ([#1508][1508]). [1077]: https://codeberg.org/dnkl/foot/issues/1077 [1364]: https://codeberg.org/dnkl/foot/issues/1364 [419]: https://codeberg.org/dnkl/foot/issues/419 +[1508]: https://codeberg.org/dnkl/foot/issues/1508 ### Changed diff --git a/config.c b/config.c index 4722cfdd..35c847e9 100644 --- a/config.c +++ b/config.c @@ -1054,6 +1054,8 @@ parse_section_bell(struct context *ctx) return value_to_bool(ctx, &conf->bell.urgent); else if (strcmp(key, "notify") == 0) return value_to_bool(ctx, &conf->bell.notify); + else if (strcmp(key, "visual") == 0) + return value_to_bool(ctx, &conf->bell.flash); else if (strcmp(key, "command") == 0) return value_to_spawn_template(ctx, &conf->bell.command); else if (strcmp(key, "command-focused") == 0) @@ -1237,6 +1239,7 @@ parse_section_colors(struct context *ctx) return true; } + else if (strcmp(key, "flash") == 0) color = &conf->colors.flash; else if (strcmp(key, "foreground") == 0) color = &conf->colors.fg; else if (strcmp(key, "background") == 0) color = &conf->colors.bg; else if (strcmp(key, "selection-foreground") == 0) color = &conf->colors.selection_fg; @@ -1320,6 +1323,21 @@ parse_section_colors(struct context *ctx) return true; } + else if (strcmp(key, "flash-alpha") == 0) { + float alpha; + if (!value_to_float(ctx, &alpha)) + return false; + + if (alpha < 0. || alpha > 1.) { + LOG_CONTEXTUAL_ERR("not in range 0.0-1.0"); + return false; + } + + conf->colors.flash_alpha = alpha * 65535.; + return true; + } + + else { LOG_CONTEXTUAL_ERR("not valid option"); return false; @@ -2980,6 +2998,7 @@ config_load(struct config *conf, const char *conf_path, .bell = { .urgent = false, .notify = false, + .flash = false, .command = { .argv = {.args = NULL}, }, @@ -3003,6 +3022,8 @@ config_load(struct config *conf, const char *conf_path, .colors = { .fg = default_foreground, .bg = default_background, + .flash = 0x7f7f00, + .flash_alpha = 0x7fff, .alpha = 0xffff, .selection_fg = 0x80000000, /* Use default bg */ .selection_bg = 0x80000000, /* Use default fg */ diff --git a/config.h b/config.h index 4d2838c4..3c5b3df7 100644 --- a/config.h +++ b/config.h @@ -160,6 +160,7 @@ struct config { struct { bool urgent; bool notify; + bool flash; struct config_spawn_template command; bool command_focused; } bell; @@ -202,6 +203,8 @@ struct config { struct { uint32_t fg; uint32_t bg; + uint32_t flash; + uint32_t flash_alpha; uint32_t table[256]; uint16_t alpha; uint32_t selection_fg; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 5ef4dcb4..84250b40 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -394,6 +394,11 @@ Note: do not set *TERM* here; use the *term* option in the main Default: _no_ +*visual* + When set to _yes_, foot will flash terminal window. + + Default: _no_ + *command* When set, foot will execute this command when *BEL* is received. Default: none @@ -609,6 +614,17 @@ can configure the background transparency with the _alpha_ option. https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit for an explanation of the remainder. +*flash* + Color to use for the terminal window flash. + + Default: _7f7f00_. + +*flash_alpha* + Flash translucency. A value in the range 0.0-1.0, where 0.0 + means completely transparent, and 1.0 is opaque. + + Default: _0.5_. + *alpha* Background translucency. A value in the range 0.0-1.0, where 0.0 means completely transparent, and 1.0 is opaque. Default: _1.0_. diff --git a/foot.ini b/foot.ini index cdbd8259..bdfcd582 100644 --- a/foot.ini +++ b/foot.ini @@ -43,6 +43,7 @@ [bell] # urgent=no # notify=no +# visual=no # command= # command-focused=no @@ -77,6 +78,8 @@ # alpha=1.0 # background=242424 # foreground=ffffff +# flash=7f7f00 +# flash_alpha=0.5 ## Normal/regular colors (color palette 0-7) # regular0=242424 # black diff --git a/render.c b/render.c index 9296223a..9f858bf1 100644 --- a/render.c +++ b/render.c @@ -1588,7 +1588,9 @@ render_overlay(struct terminal *term) break; case OVERLAY_FLASH: - color = (pixman_color_t){.red=0x7fff, .green=0x7fff, .blue=0, .alpha=0x7fff}; + color = color_hex_to_pixman_with_alpha( + term->conf->colors.flash, + term->conf->colors.flash_alpha); break; } @@ -2193,7 +2195,7 @@ render_csd_button_maximize_maximized( { x_margin + shrink, y_margin + thick, thick, width - 2 * thick - shrink }, { x_margin + width - thick - shrink, y_margin + thick, thick, width - 2 * thick - shrink }, { x_margin + shrink, y_margin + width - thick - shrink, width - 2 * shrink, thick }}); - + pixman_image_unref(src); } diff --git a/terminal.c b/terminal.c index 91c46a11..da64740e 100644 --- a/terminal.c +++ b/terminal.c @@ -1170,6 +1170,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .colors = { .fg = conf->colors.fg, .bg = conf->colors.bg, + .flash = conf->colors.flash, + .flash_alpha = conf->colors.flash_alpha, .alpha = conf->colors.alpha, .selection_fg = conf->colors.selection_fg, .selection_bg = conf->colors.selection_bg, @@ -1922,7 +1924,9 @@ term_reset(struct terminal *term, bool hard) fdm_del(term->fdm, term->blink.fd); term->blink.fd = -1; term->colors.fg = term->conf->colors.fg; term->colors.bg = term->conf->colors.bg; + term->colors.flash = term->conf->colors.flash; term->colors.alpha = term->conf->colors.alpha; + term->colors.flash_alpha = term->conf->colors.flash_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; @@ -3270,6 +3274,7 @@ term_flash(struct terminal *term, unsigned duration_ms) void term_bell(struct terminal *term) { + if (!term->bell_action_enabled) return; @@ -3288,6 +3293,9 @@ term_bell(struct terminal *term) if (term->conf->bell.notify) notify_notify(term, "Bell", "Bell in terminal"); + if (term->conf->bell.flash) + term_flash(term, 100); + if ((term->conf->bell.command.argv.args != NULL) && (!term->kbd_focus || term->conf->bell.command_focused)) { diff --git a/terminal.h b/terminal.h index da873ae6..4939b91e 100644 --- a/terminal.h +++ b/terminal.h @@ -508,6 +508,8 @@ struct terminal { struct { uint32_t fg; uint32_t bg; + uint32_t flash; + uint32_t flash_alpha; uint32_t table[256]; uint16_t alpha; uint32_t selection_fg; From 8a2a45077812efdf74a0fbcf565ed280a9e37954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 10 Oct 2023 08:07:02 +0200 Subject: [PATCH 2/7] doc: foot.ini: flash: tweak grammar, use consistent formatting --- doc/foot.ini.5.scd | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 84250b40..bc63bb27 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -395,9 +395,8 @@ Note: do not set *TERM* here; use the *term* option in the main Default: _no_ *visual* - When set to _yes_, foot will flash terminal window. - - Default: _no_ + When set to _yes_, foot will flash the terminal window. Default: + _no_ *command* When set, foot will execute this command when *BEL* is received. @@ -615,15 +614,11 @@ can configure the background transparency with the _alpha_ option. explanation of the remainder. *flash* - Color to use for the terminal window flash. - - Default: _7f7f00_. + Color to use for the terminal window flash. Default: _7f7f00_. *flash_alpha* - Flash translucency. A value in the range 0.0-1.0, where 0.0 - means completely transparent, and 1.0 is opaque. - - Default: _0.5_. + Flash translucency. A value in the range 0.0-1.0, where 0.0 means + completely transparent, and 1.0 is opaque. Default: _0.5_. *alpha* Background translucency. A value in the range 0.0-1.0, where 0.0 From eea995637d2e65c206734a4d8084a9b500f77f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 10 Oct 2023 08:09:26 +0200 Subject: [PATCH 3/7] term: remove unneeded (and mostly unused) term->flash{,_alpha} --- terminal.c | 4 ---- terminal.h | 2 -- 2 files changed, 6 deletions(-) diff --git a/terminal.c b/terminal.c index da64740e..9a76488e 100644 --- a/terminal.c +++ b/terminal.c @@ -1170,8 +1170,6 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .colors = { .fg = conf->colors.fg, .bg = conf->colors.bg, - .flash = conf->colors.flash, - .flash_alpha = conf->colors.flash_alpha, .alpha = conf->colors.alpha, .selection_fg = conf->colors.selection_fg, .selection_bg = conf->colors.selection_bg, @@ -1924,9 +1922,7 @@ term_reset(struct terminal *term, bool hard) fdm_del(term->fdm, term->blink.fd); term->blink.fd = -1; term->colors.fg = term->conf->colors.fg; term->colors.bg = term->conf->colors.bg; - term->colors.flash = term->conf->colors.flash; term->colors.alpha = term->conf->colors.alpha; - term->colors.flash_alpha = term->conf->colors.flash_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; diff --git a/terminal.h b/terminal.h index 4939b91e..da873ae6 100644 --- a/terminal.h +++ b/terminal.h @@ -508,8 +508,6 @@ struct terminal { struct { uint32_t fg; uint32_t bg; - uint32_t flash; - uint32_t flash_alpha; uint32_t table[256]; uint16_t alpha; uint32_t selection_fg; From 9cf22df784a7d081ac9eb52b1d0225714f9cda99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 10 Oct 2023 08:11:13 +0200 Subject: [PATCH 4/7] foot.ini: flash_alpha -> flash-alpha --- foot.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/foot.ini b/foot.ini index bdfcd582..55eb42de 100644 --- a/foot.ini +++ b/foot.ini @@ -79,7 +79,7 @@ # background=242424 # foreground=ffffff # flash=7f7f00 -# flash_alpha=0.5 +# flash-alpha=0.5 ## Normal/regular colors (color palette 0-7) # regular0=242424 # black From 0c6a3731c3ccb82eeeea92e82578d26d79b3f115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 10 Oct 2023 08:11:22 +0200 Subject: [PATCH 5/7] doc: foot.ini.5: flash_alpha -> flash-alpha --- doc/foot.ini.5.scd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index bc63bb27..e4444c6f 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -616,7 +616,7 @@ can configure the background transparency with the _alpha_ option. *flash* Color to use for the terminal window flash. Default: _7f7f00_. -*flash_alpha* +*flash-alpha* Flash translucency. A value in the range 0.0-1.0, where 0.0 means completely transparent, and 1.0 is opaque. Default: _0.5_. From ce64da2fe1836883323d618664cb0f9e090fbbb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 10 Oct 2023 08:12:04 +0200 Subject: [PATCH 6/7] doc: foot.ini.5: move flash{,-alpha} to the bottom of the 'colors' section --- doc/foot.ini.5.scd | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index e4444c6f..b7b79e75 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -613,13 +613,6 @@ can configure the background transparency with the _alpha_ option. https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit for an explanation of the remainder. -*flash* - Color to use for the terminal window flash. Default: _7f7f00_. - -*flash-alpha* - Flash translucency. A value in the range 0.0-1.0, where 0.0 means - completely transparent, and 1.0 is opaque. Default: _0.5_. - *alpha* Background translucency. A value in the range 0.0-1.0, where 0.0 means completely transparent, and 1.0 is opaque. Default: _1.0_. @@ -653,6 +646,13 @@ can configure the background transparency with the _alpha_ option. Color to use for the underline used to highlight URLs in URL mode. Default: _regular3_. +*flash* + Color to use for the terminal window flash. Default: _7f7f00_. + +*flash-alpha* + Flash translucency. A value in the range 0.0-1.0, where 0.0 means + completely transparent, and 1.0 is opaque. Default: _0.5_. + # SECTION: csd This section controls the look of the _CSDs_ (Client Side From af0feed3e5e5061d913b3d34ce500917f13fb71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 10 Oct 2023 08:14:43 +0200 Subject: [PATCH 7/7] changelog: fix issue number for visual bell 1508 refers to the pull request, not the feature request. --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc6e57bb..4ae5f985 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,12 +75,12 @@ - `scrollback-down-half-page` (none) - `scrollback-down-line` (none) * Support for visual bell which flashes the terminal window. - ([#1508][1508]). + ([#1337][1337]). [1077]: https://codeberg.org/dnkl/foot/issues/1077 [1364]: https://codeberg.org/dnkl/foot/issues/1364 [419]: https://codeberg.org/dnkl/foot/issues/419 -[1508]: https://codeberg.org/dnkl/foot/issues/1508 +[1337]: https://codeberg.org/dnkl/foot/issues/1337 ### Changed