Merge branch 'visual-bell-remastered'

Closes #1337
This commit is contained in:
Daniel Eklöf 2023-10-10 08:15:11 +02:00
commit 5c58fc2a28
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 49 additions and 2 deletions

View file

@ -74,10 +74,13 @@
- `scrollback-down-page` (shift+page-down) - `scrollback-down-page` (shift+page-down)
- `scrollback-down-half-page` (none) - `scrollback-down-half-page` (none)
- `scrollback-down-line` (none) - `scrollback-down-line` (none)
* Support for visual bell which flashes the terminal window.
([#1337][1337]).
[1077]: https://codeberg.org/dnkl/foot/issues/1077 [1077]: https://codeberg.org/dnkl/foot/issues/1077
[1364]: https://codeberg.org/dnkl/foot/issues/1364 [1364]: https://codeberg.org/dnkl/foot/issues/1364
[419]: https://codeberg.org/dnkl/foot/issues/419 [419]: https://codeberg.org/dnkl/foot/issues/419
[1337]: https://codeberg.org/dnkl/foot/issues/1337
### Changed ### Changed

View file

@ -1054,6 +1054,8 @@ parse_section_bell(struct context *ctx)
return value_to_bool(ctx, &conf->bell.urgent); return value_to_bool(ctx, &conf->bell.urgent);
else if (strcmp(key, "notify") == 0) else if (strcmp(key, "notify") == 0)
return value_to_bool(ctx, &conf->bell.notify); 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) else if (strcmp(key, "command") == 0)
return value_to_spawn_template(ctx, &conf->bell.command); return value_to_spawn_template(ctx, &conf->bell.command);
else if (strcmp(key, "command-focused") == 0) else if (strcmp(key, "command-focused") == 0)
@ -1237,6 +1239,7 @@ parse_section_colors(struct context *ctx)
return true; 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, "foreground") == 0) color = &conf->colors.fg;
else if (strcmp(key, "background") == 0) color = &conf->colors.bg; else if (strcmp(key, "background") == 0) color = &conf->colors.bg;
else if (strcmp(key, "selection-foreground") == 0) color = &conf->colors.selection_fg; else if (strcmp(key, "selection-foreground") == 0) color = &conf->colors.selection_fg;
@ -1320,6 +1323,21 @@ parse_section_colors(struct context *ctx)
return true; 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 { else {
LOG_CONTEXTUAL_ERR("not valid option"); LOG_CONTEXTUAL_ERR("not valid option");
return false; return false;
@ -2980,6 +2998,7 @@ config_load(struct config *conf, const char *conf_path,
.bell = { .bell = {
.urgent = false, .urgent = false,
.notify = false, .notify = false,
.flash = false,
.command = { .command = {
.argv = {.args = NULL}, .argv = {.args = NULL},
}, },
@ -3003,6 +3022,8 @@ config_load(struct config *conf, const char *conf_path,
.colors = { .colors = {
.fg = default_foreground, .fg = default_foreground,
.bg = default_background, .bg = default_background,
.flash = 0x7f7f00,
.flash_alpha = 0x7fff,
.alpha = 0xffff, .alpha = 0xffff,
.selection_fg = 0x80000000, /* Use default bg */ .selection_fg = 0x80000000, /* Use default bg */
.selection_bg = 0x80000000, /* Use default fg */ .selection_bg = 0x80000000, /* Use default fg */

View file

@ -160,6 +160,7 @@ struct config {
struct { struct {
bool urgent; bool urgent;
bool notify; bool notify;
bool flash;
struct config_spawn_template command; struct config_spawn_template command;
bool command_focused; bool command_focused;
} bell; } bell;
@ -202,6 +203,8 @@ struct config {
struct { struct {
uint32_t fg; uint32_t fg;
uint32_t bg; uint32_t bg;
uint32_t flash;
uint32_t flash_alpha;
uint32_t table[256]; uint32_t table[256];
uint16_t alpha; uint16_t alpha;
uint32_t selection_fg; uint32_t selection_fg;

View file

@ -394,6 +394,10 @@ Note: do not set *TERM* here; use the *term* option in the main
Default: _no_ Default: _no_
*visual*
When set to _yes_, foot will flash the terminal window. Default:
_no_
*command* *command*
When set, foot will execute this command when *BEL* is received. When set, foot will execute this command when *BEL* is received.
Default: none Default: none
@ -642,6 +646,13 @@ can configure the background transparency with the _alpha_ option.
Color to use for the underline used to highlight URLs in URL Color to use for the underline used to highlight URLs in URL
mode. Default: _regular3_. 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 # SECTION: csd
This section controls the look of the _CSDs_ (Client Side This section controls the look of the _CSDs_ (Client Side

View file

@ -43,6 +43,7 @@
[bell] [bell]
# urgent=no # urgent=no
# notify=no # notify=no
# visual=no
# command= # command=
# command-focused=no # command-focused=no
@ -77,6 +78,8 @@
# alpha=1.0 # alpha=1.0
# background=242424 # background=242424
# foreground=ffffff # foreground=ffffff
# flash=7f7f00
# flash-alpha=0.5
## Normal/regular colors (color palette 0-7) ## Normal/regular colors (color palette 0-7)
# regular0=242424 # black # regular0=242424 # black

View file

@ -1588,7 +1588,9 @@ render_overlay(struct terminal *term)
break; break;
case OVERLAY_FLASH: 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; break;
} }

View file

@ -3270,6 +3270,7 @@ term_flash(struct terminal *term, unsigned duration_ms)
void void
term_bell(struct terminal *term) term_bell(struct terminal *term)
{ {
if (!term->bell_action_enabled) if (!term->bell_action_enabled)
return; return;
@ -3288,6 +3289,9 @@ term_bell(struct terminal *term)
if (term->conf->bell.notify) if (term->conf->bell.notify)
notify_notify(term, "Bell", "Bell in terminal"); notify_notify(term, "Bell", "Bell in terminal");
if (term->conf->bell.flash)
term_flash(term, 100);
if ((term->conf->bell.command.argv.args != NULL) && if ((term->conf->bell.command.argv.args != NULL) &&
(!term->kbd_focus || term->conf->bell.command_focused)) (!term->kbd_focus || term->conf->bell.command_focused))
{ {