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 of the flash and the
alpha to apply to.

Default values are the values which where currently used for flash,
altough I personally like a nice red (eb1313) better.
This commit is contained in:
Raimund Sacherer 2023-10-07 19:37:04 +02:00
parent 56d5d4cc21
commit 36ed07788e
7 changed files with 57 additions and 2 deletions

View file

@ -1031,6 +1031,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, "flash") == 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)
@ -1214,6 +1216,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;
@ -1297,6 +1300,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;
@ -2948,6 +2966,7 @@ config_load(struct config *conf, const char *conf_path,
.bell = {
.urgent = false,
.notify = false,
.flash = false,
.command = {
.argv = {.args = NULL},
},
@ -2971,6 +2990,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 */

View file

@ -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;

View file

@ -394,6 +394,12 @@ Note: do not set *TERM* here; use the *term* option in the main
Default: _no_
*flash*
When set to _yes_, foot will emit the bell signal flashing the
terminal window whenever *BEL* is received.
Default: _no_
*command*
When set, foot will execute this command when *BEL* is received.
Default: none
@ -609,6 +615,18 @@ 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: _7f7fff_.
*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.7_.
*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_.

View file

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

View file

@ -1582,7 +1582,7 @@ 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->colors.flash, term->colors.flash_alpha);
break;
}
@ -2186,7 +2186,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);
}

View file

@ -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))
{

View file

@ -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;