aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-12-10 17:22:48 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-12-10 17:22:48 +0000
commit15d20af2a24664b09604f1ec5f121c38f1500c32 (patch)
tree34d9ab652f1c24399f098aafc5b80ad4de9e6016
parentnotify: don’t emit notification when we’re focused (diff)
config: add ‘notify’ to possible values for ‘bell’ in foot.ini
When `bell=notify`, foot will trigger a desktop notification when it receives a BEL in an unfocused window.
-rw-r--r--CHANGELOG.md3
-rw-r--r--config.c13
-rw-r--r--config.h6
-rw-r--r--csi.c6
-rw-r--r--doc/foot.ini.5.scd5
-rw-r--r--terminal.c25
-rw-r--r--terminal.h4
7 files changed, 45 insertions, 17 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1563aed1..13e82dbe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -89,6 +89,9 @@ means foot can be PGO:d in e.g. sandboxed build scripts. See
* OSC 777;notify: desktop notifications. Use in combination with the
new **notify** option in `foot.ini`
(https://codeberg.org/dnkl/foot/issues/224).
+* **bell** option can now be set to `notify`, in which case a desktop
+ notification is emitted when foot receives `BEL` in an unfocused
+ window.
### Changed
diff --git a/config.c b/config.c
index 8ec72918..085c9f7e 100644
--- a/config.c
+++ b/config.c
@@ -483,14 +483,17 @@ parse_section_main(const char *key, const char *value, struct config *conf,
else if (strcmp(key, "bell") == 0) {
if (strcmp(value, "set-urgency") == 0)
- conf->bell_is_urgent = true;
+ conf->bell_action = BELL_ACTION_URGENT;
+ else if (strcmp(value, "notify") == 0)
+ conf->bell_action = BELL_ACTION_NOTIFY;
else if (strcmp(value, "none") == 0)
- conf->bell_is_urgent = false;
+ conf->bell_action = BELL_ACTION_NONE;
else {
LOG_AND_NOTIFY_ERR(
"%s:%d: [default]: bell: "
- "expected either 'set-urgency' or 'none'", path, lineno);
- conf->bell_is_urgent = false;
+ "expected either 'set-urgency', 'notify' or 'none'",
+ path, lineno);
+ conf->bell_action = BELL_ACTION_NONE;
return false;
}
}
@@ -1945,7 +1948,7 @@ config_load(struct config *conf, const char *conf_path,
.pad_x = 2,
.pad_y = 2,
.bold_in_bright = false,
- .bell_is_urgent = false,
+ .bell_action = BELL_ACTION_NONE,
.startup_mode = STARTUP_WINDOWED,
.fonts = {tll_init(), tll_init(), tll_init(), tll_init()},
.dpi_aware = true, /* Use DPI by default, not scale factor */
diff --git a/config.h b/config.h
index 0a089912..9e5e8b4e 100644
--- a/config.h
+++ b/config.h
@@ -72,7 +72,11 @@ struct config {
unsigned pad_y;
bool bold_in_bright;
- bool bell_is_urgent;
+ enum {
+ BELL_ACTION_NONE,
+ BELL_ACTION_URGENT,
+ BELL_ACTION_NOTIFY,
+ } bell_action;
enum { STARTUP_WINDOWED, STARTUP_MAXIMIZED, STARTUP_FULLSCREEN } startup_mode;
diff --git a/csi.c b/csi.c
index 232f7b1d..eaa527a0 100644
--- a/csi.c
+++ b/csi.c
@@ -482,7 +482,7 @@ decset_decrst(struct terminal *term, unsigned param, bool enable)
break;
case 1042:
- term->bell_is_urgent = enable;
+ term->bell_action_enabled = enable;
break;
#if 0
@@ -591,7 +591,7 @@ xtsave(struct terminal *term, unsigned param)
case 1034: term->xtsave.meta_eight_bit = term->meta.eight_bit; break;
case 1035: term->xtsave.num_lock_modifier = term->num_lock_modifier; break;
case 1036: term->xtsave.meta_esc_prefix = term->meta.esc_prefix; break;
- case 1042: term->xtsave.bell_is_urgent = term->bell_is_urgent; break;
+ case 1042: term->xtsave.bell_action_enabled = term->bell_action_enabled; break;
case 1049: term->xtsave.alt_screen = term->grid == &term->alt; break;
case 2004: term->xtsave.bracketed_paste = term->bracketed_paste; break;
case 27127: term->xtsave.modify_escape_key = term->modify_escape_key; break;
@@ -626,7 +626,7 @@ xtrestore(struct terminal *term, unsigned param)
case 1034: enable = term->xtsave.meta_eight_bit; break;
case 1035: enable = term->xtsave.num_lock_modifier; break;
case 1036: enable = term->xtsave.meta_esc_prefix; break;
- case 1042: enable = term->xtsave.bell_is_urgent; break;
+ case 1042: enable = term->xtsave.bell_action_enabled; break;
case 1049: enable = term->xtsave.alt_screen; break;
case 2004: enable = term->xtsave.bracketed_paste; break;
case 27127: enable = term->xtsave.modify_escape_key; break;
diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd
index 9c3430cd..8397b118 100644
--- a/doc/foot.ini.5.scd
+++ b/doc/foot.ini.5.scd
@@ -120,7 +120,7 @@ in this order:
*bell*
Action to perform when receiving a *BEL* character. Can be set to
- either *set-urgency* or *none*.
+ either *set-urgency*, *notify* or *none*.
When set to *set-urgency*, the margins will be painted in red
whenever *BEL* is received while the window does *not* have
@@ -136,6 +136,9 @@ in this order:
_Note_: expect this feature to be *replaced* with proper
compositor urgency support once/if that gets implemented.
+ When set to *notify*, foot will emit a desktop notification (see
+ the *notify* option).
+
When set to *none*, no special action is taken when receiving *BEL*.
Default: _none_.
diff --git a/terminal.c b/terminal.c
index a626b88d..e9ccbcd0 100644
--- a/terminal.c
+++ b/terminal.c
@@ -25,6 +25,7 @@
#include "extract.h"
#include "grid.h"
#include "ime.h"
+#include "notify.h"
#include "quirks.h"
#include "reaper.h"
#include "render.h"
@@ -1091,7 +1092,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
.eight_bit = true,
},
.num_lock_modifier = true,
- .bell_is_urgent = conf->bell_is_urgent,
+ .bell_action_enabled = true,
.tab_stops = tll_init(),
.wl = wayl,
.render = {
@@ -1532,6 +1533,8 @@ term_reset(struct terminal *term, bool hard)
term->bracketed_paste = false;
term->focus_events = false;
term->modify_escape_key = false;
+ term->num_lock_modifier = true;
+ term->bell_action_enabled = true;
term->mouse_tracking = MOUSE_NONE;
term->mouse_reporting = MOUSE_NORMAL;
term->charsets.selected = 0;
@@ -2512,12 +2515,24 @@ term_flash(struct terminal *term, unsigned duration_ms)
void
term_bell(struct terminal *term)
{
- if (term->kbd_focus || !term->bell_is_urgent)
+ if (term->kbd_focus || !term->bell_action_enabled)
return;
- /* There's no 'urgency' hint in Wayland - we just paint the margins red */
- term->render.urgency = true;
- term_damage_margins(term);
+ switch (term->conf->bell_action) {
+ case BELL_ACTION_NONE:
+ break;
+
+ case BELL_ACTION_URGENT:
+ /* There's no 'urgency' hint in Wayland - we just paint the
+ * margins red */
+ term->render.urgency = true;
+ term_damage_margins(term);
+ break;
+
+ case BELL_ACTION_NOTIFY:
+ notify_notify(term, "Bell", "Bell in terminal");
+ break;
+ }
}
bool
diff --git a/terminal.h b/terminal.h
index 07723e1e..0b0e2685 100644
--- a/terminal.h
+++ b/terminal.h
@@ -271,7 +271,7 @@ struct terminal {
} meta;
bool num_lock_modifier;
- bool bell_is_urgent;
+ bool bell_action_enabled;
/* Saved DECSET modes - we save the SET state */
struct {
@@ -295,7 +295,7 @@ struct terminal {
uint32_t meta_eight_bit:1;
uint32_t meta_esc_prefix:1;
uint32_t num_lock_modifier:1;
- uint32_t bell_is_urgent:1;
+ uint32_t bell_action_enabled:1;
uint32_t alt_screen:1;
uint32_t modify_escape_key:1;
uint32_t ime:1;