From 5d71ccc174aafc22053ae0ca98a58ca216737499 Mon Sep 17 00:00:00 2001 From: Ryan Farley Date: Thu, 29 Apr 2021 04:12:55 -0500 Subject: enhanced bell configuration Add a separate section for bell configuration, with a bell-specific command option and a setting to allow that command to run without regard to keyboard focus (for those of us who enjoy being beeped at at all times, for example). The actions are also no longer mutually exclusive; this is primarily anticipating urgency support which cannot be replicated outside the process (in server mode anyway) and would thus be complementary to any notification or arbitrary command. --- terminal.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index cd1ecbd9..f77a6d79 100644 --- a/terminal.c +++ b/terminal.c @@ -2627,23 +2627,26 @@ term_flash(struct terminal *term, unsigned duration_ms) void term_bell(struct terminal *term) { - if (term->kbd_focus || !term->bell_action_enabled) + if (!term->bell_action_enabled) return; - switch (term->conf->bell_action) { - case BELL_ACTION_NONE: - break; + if (!term->kbd_focus) { + if (term->conf->bell.urgent) { + /* There's no 'urgency' hint in Wayland - we just paint the + * margins red */ + term->render.urgency = true; + term_damage_margins(term); + } + if (term->conf->bell.notify) + notify_notify(term, "Bell", "Bell in terminal"); + } - 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; + if (term->conf->bell.command.argv && (!term->kbd_focus || term->conf->bell.command_focused)) { + int devnull = open("/dev/null", O_RDONLY); + spawn(term->reaper, NULL, term->conf->bell.command.argv, devnull, -1, -1); - case BELL_ACTION_NOTIFY: - notify_notify(term, "Bell", "Bell in terminal"); - break; + if (devnull >= 0) + close(devnull); } } -- cgit v1.3 From dc9751cbfe6adc8a7e7a8e6a1c61452b65a84dd6 Mon Sep 17 00:00:00 2001 From: Ryan Farley Date: Fri, 7 May 2021 04:40:07 -0500 Subject: style, consistent bool names, deprecate old config --- config.c | 26 ++++++++++++++++++++++++++ doc/foot.ini.5.scd | 10 +++++----- terminal.c | 2 +- 3 files changed, 32 insertions(+), 6 deletions(-) (limited to 'terminal.c') diff --git a/config.c b/config.c index bc3dc9c0..8dbd86d6 100644 --- a/config.c +++ b/config.c @@ -593,6 +593,32 @@ parse_section_main(const char *key, const char *value, struct config *conf, } } + else if (strcmp(key, "bell") == 0) { + LOG_WARN("deprecated: %s:%d: [default]: bell: set actions in section 'bell' instead", path, lineno); + + const char fmt[] = "%s:%d \033[1mbell\033[21m, use section \033[1m[bell]\033[21m instead"; + char *text = xasprintf(fmt, path, lineno); + + struct user_notification deprecation = { + .kind = USER_NOTIFICATION_DEPRECATED, + .text = text, + }; + tll_push_back(conf->notifications, deprecation); + + if (strcmp(value, "set-urgency") == 0) + conf->bell.urgent = true; + else if (strcmp(value, "notify") == 0) + conf->bell.notify = true; + /* we do nothing by default, so none may be ignored */ + else { + LOG_AND_NOTIFY_ERR( + "%s%d: [default]: bell: " + "expected either 'set-urgency', 'notify' or 'none'", + path, lineno); + return false; + } + } + else if (strcmp(key, "initial-window-mode") == 0) { if (strcmp(value, "windowed") == 0) conf->startup_mode = STARTUP_WINDOWED; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 59da6f2e..1030c841 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -265,7 +265,7 @@ in this order: # SECTION: bell *urgent* - When set to _true_, the margins will be painted in red + When set to _yes_, the margins will be painted in red whenever *BEL* is received while the window does *not* have keyboard focus. Note that Wayland currently does not have an _urgency_ hint like X11. The name *urgent* was chosen for @@ -278,13 +278,13 @@ in this order: _Note_: expect this feature to be *replaced* with proper compositor urgency support once/if that gets implemented. - Default: _false_ + Default: _no_ *notify* - When set to _true_, foot will emit a desktop notification using + When set to _yes_, foot will emit a desktop notification using the command specified in the *notify* option whenever *BEL* is received and the window does *not* have keyboard focus. Default: - _false_ + _no_ *command* When set, foot will execute this command when *BEL* is received. @@ -292,7 +292,7 @@ in this order: *command-focused* Whether to run the command on *BEL* even while focused. Default: - _false_ + _no_ # SECTION: scrollback diff --git a/terminal.c b/terminal.c index f77a6d79..ab82b75b 100644 --- a/terminal.c +++ b/terminal.c @@ -2641,7 +2641,7 @@ term_bell(struct terminal *term) notify_notify(term, "Bell", "Bell in terminal"); } - if (term->conf->bell.command.argv && (!term->kbd_focus || term->conf->bell.command_focused)) { + if ((term->conf->bell.command.argv != NULL) && (!term->kbd_focus || term->conf->bell.command_focused)) { int devnull = open("/dev/null", O_RDONLY); spawn(term->reaper, NULL, term->conf->bell.command.argv, devnull, -1, -1); -- cgit v1.3