Add support for the new Wayland protocol xdg-system-bell

From the release notes:

    system bell - allowing e.g. terminal emulators to hand off system
    bell alerts to the compositor for among other things accessibility
    purposes

The new protocol is used when the new config option
bell.system=yes (and the compositor implements the protocol,
obviously).

The system bell is rung independent of whether the foot window has
keyboard focus or not (thus relying on compositor configuration to
determine whether anything should be done or not in response to the
bell).

The new option is enabled by default.
This commit is contained in:
Daniel Eklöf 2025-01-17 10:10:10 +01:00
parent 7e7fd0468d
commit 2a07a2e6b9
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
11 changed files with 91 additions and 11 deletions

View file

@ -58,7 +58,14 @@
## Unreleased ## Unreleased
### Added ### Added
* Support for the new Wayland protocol `xdg-system-bell-v1` protocol
(added in wayland-protocols 1.38), via the new config option
`bell.system=no|yes` (defaults to `yes`).
### Changed ### Changed
* The `CSI 21 t` (report window title) and `OSC 176 ?` (report app-id) * The `CSI 21 t` (report window title) and `OSC 176 ?` (report app-id)

View file

@ -1139,6 +1139,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 (streq(key, "notify")) else if (streq(key, "notify"))
return value_to_bool(ctx, &conf->bell.notify); return value_to_bool(ctx, &conf->bell.notify);
else if (streq(key, "system"))
return value_to_bool(ctx, &conf->bell.system_bell);
else if (streq(key, "visual")) else if (streq(key, "visual"))
return value_to_bool(ctx, &conf->bell.flash); return value_to_bool(ctx, &conf->bell.flash);
else if (streq(key, "command")) else if (streq(key, "command"))
@ -3182,6 +3184,7 @@ config_load(struct config *conf, const char *conf_path,
.urgent = false, .urgent = false,
.notify = false, .notify = false,
.flash = false, .flash = false,
.system_bell = true,
.command = { .command = {
.argv = {.args = NULL}, .argv = {.args = NULL},
}, },

View file

@ -186,6 +186,7 @@ struct config {
bool urgent; bool urgent;
bool notify; bool notify;
bool flash; bool flash;
bool system_bell;
struct config_spawn_template command; struct config_spawn_template command;
bool command_focused; bool command_focused;
} bell; } bell;

View file

@ -445,10 +445,17 @@ Note: do not set *TERM* here; use the *term* option in the main
# SECTION: bell # SECTION: bell
*system*
Boolean, when set to _yes_, ring the system bell. The bell is rung
independent of whether the foot window has keyboard focus or
not. Exact behavior is compositor dependent.
Default: _yes_
*urgent* *urgent*
When set to _yes_, foot will signal urgency to the compositor Boolean, when set to _yes_, foot will signal urgency to the
through the XDG activation protocol whenever *BEL* is received, compositor through the XDG activation protocol whenever *BEL* is
and the window does NOT have keyboard focus. received, and the window does NOT have keyboard focus.
If the compositor does not implement this protocol, the margins If the compositor does not implement this protocol, the margins
will be painted in red instead. will be painted in red instead.
@ -459,25 +466,25 @@ Note: do not set *TERM* here; use the *term* option in the main
Default: _no_ Default: _no_
*notify* *notify*
When set to _yes_, foot will emit a desktop notification using the Boolean, when set to _yes_, foot will emit a desktop notification
command specified in the *notify* option whenever *BEL* is using the command specified in the *notify* option whenever *BEL*
received. By default, bell notifications are shown only when the is received. By default, bell notifications are shown only when
window does *not* have keyboard focus. See the window does *not* have keyboard focus. See
_desktop-notifications.inhibit-when-focused_. _desktop-notifications.inhibit-when-focused_.
Default: _no_ Default: _no_
*visual* *visual*
When set to _yes_, foot will flash the terminal window. Default: Boolean, when set to _yes_, foot will flash the terminal
_no_ 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
*command-focused* *command-focused*
Whether to run the command on *BEL* even while focused. Default: Boolean, whether to run the command on *BEL* even while
_no_ focused. Default: _no_
# SECTION: desktop-notifications # SECTION: desktop-notifications

View file

@ -45,6 +45,7 @@
# osc52=enabled # disabled|copy-enabled|paste-enabled|enabled # osc52=enabled # disabled|copy-enabled|paste-enabled|enabled
[bell] [bell]
# system=yes
# urgent=no # urgent=no
# notify=no # notify=no
# visual=no # visual=no

View file

@ -179,6 +179,15 @@ else
xdg_toplevel_icon = false xdg_toplevel_icon = false
endif endif
if wayland_protocols.version().version_compare('>=1.38')
add_project_arguments('-DHAVE_XDG_SYSTEM_BELL', language: 'c')
wl_proto_xml += [wayland_protocols_datadir / 'staging/xdg-system-bell/xdg-system-bell-v1.xml']
xdg_system_bell = true
else
xdg_system_bell = false
endif
foreach prot : wl_proto_xml foreach prot : wl_proto_xml
wl_proto_headers += custom_target( wl_proto_headers += custom_target(
prot.underscorify() + '-client-header', prot.underscorify() + '-client-header',
@ -414,6 +423,7 @@ summary(
'IME': get_option('ime'), 'IME': get_option('ime'),
'Grapheme clustering': utf8proc.found(), 'Grapheme clustering': utf8proc.found(),
'Wayland: xdg-toplevel-icon-v1': xdg_toplevel_icon, 'Wayland: xdg-toplevel-icon-v1': xdg_toplevel_icon,
'Wayland: xdg-system-bell-v1': xdg_system_bell,
'utmp backend': utmp_backend, 'utmp backend': utmp_backend,
'utmp helper default path': utmp_default_helper_path, 'utmp helper default path': utmp_default_helper_path,
'Build terminfo': tic.found(), 'Build terminfo': tic.found(),

View file

@ -101,6 +101,7 @@ wayl_win_init(struct terminal *term, const char *token)
void wayl_win_destroy(struct wl_window *win) {} void wayl_win_destroy(struct wl_window *win) {}
void wayl_win_alpha_changed(struct wl_window *win) {} void wayl_win_alpha_changed(struct wl_window *win) {}
bool wayl_win_set_urgent(struct wl_window *win) { return true; } bool wayl_win_set_urgent(struct wl_window *win) { return true; }
bool wayl_win_ring_bell(const struct wl_window *win) { return true; }
bool wayl_fractional_scaling(const struct wayland *wayl) { return true; } bool wayl_fractional_scaling(const struct wayland *wayl) { return true; }
pid_t pid_t

View file

@ -3683,6 +3683,9 @@ term_bell(struct terminal *term)
} }
} }
if (term->conf->bell.system_bell)
wayl_win_ring_bell(term->window);
if (term->conf->bell.notify) { if (term->conf->bell.notify) {
notify_notify(term, &(struct notification){ notify_notify(term, &(struct notification){
.title = xstrdup("Bell"), .title = xstrdup("Bell"),

View file

@ -579,6 +579,7 @@ test_section_bell(void)
test_boolean(&ctx, &parse_section_bell, "urgent", &conf.bell.urgent); test_boolean(&ctx, &parse_section_bell, "urgent", &conf.bell.urgent);
test_boolean(&ctx, &parse_section_bell, "notify", &conf.bell.notify); test_boolean(&ctx, &parse_section_bell, "notify", &conf.bell.notify);
test_boolean(&ctx, &parse_section_bell, "system", &conf.bell.system_bell);
test_boolean(&ctx, &parse_section_bell, "command-focused", test_boolean(&ctx, &parse_section_bell, "command-focused",
&conf.bell.command_focused); &conf.bell.command_focused);
test_spawn_template(&ctx, &parse_section_bell, "command", test_spawn_template(&ctx, &parse_section_bell, "command",

View file

@ -1374,6 +1374,17 @@ handle_global(void *data, struct wl_registry *registry,
} }
#endif #endif
#if defined(HAVE_XDG_SYSTEM_BELL)
else if (streq(interface, xdg_system_bell_v1_interface.name)) {
const uint32_t required = 1;
if (!verify_iface_version(interface, version, required))
return;
wayl->system_bell = wl_registry_bind(
wayl->registry, name, &xdg_system_bell_v1_interface, required);
}
#endif
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED #if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
else if (streq(interface, zwp_text_input_manager_v3_interface.name)) { else if (streq(interface, zwp_text_input_manager_v3_interface.name)) {
const uint32_t required = 1; const uint32_t required = 1;
@ -1696,6 +1707,10 @@ wayl_destroy(struct wayland *wayl)
zwp_text_input_manager_v3_destroy(wayl->text_input_manager); zwp_text_input_manager_v3_destroy(wayl->text_input_manager);
#endif #endif
#if defined(HAVE_XDG_SYSTEM_BELL)
if (wayl->system_bell != NULL)
xdg_system_bell_v1_destroy(wayl->system_bell);
#endif
#if defined(HAVE_XDG_TOPLEVEL_ICON) #if defined(HAVE_XDG_TOPLEVEL_ICON)
if (wayl->toplevel_icon_manager != NULL) if (wayl->toplevel_icon_manager != NULL)
xdg_toplevel_icon_manager_v1_destroy(wayl->toplevel_icon_manager); xdg_toplevel_icon_manager_v1_destroy(wayl->toplevel_icon_manager);
@ -2247,6 +2262,28 @@ wayl_win_set_urgent(struct wl_window *win)
return false; return false;
} }
bool
wayl_win_ring_bell(const struct wl_window *win)
{
#if defined(HAVE_XDG_SYSTEM_BELL)
if (win->term->wl->system_bell == NULL) {
static bool have_warned = false;
if (!have_warned) {
LOG_WARN("compositor does not implement the XDG system bell protocol");
have_warned = true;
}
return false;
}
xdg_system_bell_v1_ring(win->term->wl->system_bell, win->surface.surf);
return true;
#else
return false;
#endif
}
bool bool
wayl_win_csd_titlebar_visible(const struct wl_window *win) wayl_win_csd_titlebar_visible(const struct wl_window *win)
{ {

View file

@ -24,6 +24,10 @@
#include <xdg-toplevel-icon-v1.h> #include <xdg-toplevel-icon-v1.h>
#endif #endif
#if defined(HAVE_XDG_SYSTEM_BELL)
#include <xdg-system-bell-v1.h>
#endif
#include <fcft/fcft.h> #include <fcft/fcft.h>
#include <tllist.h> #include <tllist.h>
@ -451,6 +455,10 @@ struct wayland {
struct xdg_toplevel_icon_manager_v1 *toplevel_icon_manager; struct xdg_toplevel_icon_manager_v1 *toplevel_icon_manager;
#endif #endif
#if defined(HAVE_XDG_SYSTEM_BELL)
struct xdg_system_bell_v1 *system_bell;
#endif
bool presentation_timings; bool presentation_timings;
struct wp_presentation *presentation; struct wp_presentation *presentation;
uint32_t presentation_clock_id; uint32_t presentation_clock_id;
@ -492,6 +500,7 @@ void wayl_win_destroy(struct wl_window *win);
void wayl_win_scale(struct wl_window *win, const struct buffer *buf); void wayl_win_scale(struct wl_window *win, const struct buffer *buf);
void wayl_win_alpha_changed(struct wl_window *win); void wayl_win_alpha_changed(struct wl_window *win);
bool wayl_win_set_urgent(struct wl_window *win); bool wayl_win_set_urgent(struct wl_window *win);
bool wayl_win_ring_bell(const struct wl_window *win);
bool wayl_win_csd_titlebar_visible(const struct wl_window *win); bool wayl_win_csd_titlebar_visible(const struct wl_window *win);
bool wayl_win_csd_borders_visible(const struct wl_window *win); bool wayl_win_csd_borders_visible(const struct wl_window *win);