From 2a07a2e6b9a9565287996c51ceb2824b37d3fba7 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 17 Jan 2025 10:10:10 +0100 Subject: 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. --- wayland.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index 9c184adc..3a46133f 100644 --- a/wayland.c +++ b/wayland.c @@ -1374,6 +1374,17 @@ handle_global(void *data, struct wl_registry *registry, } #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 else if (streq(interface, zwp_text_input_manager_v3_interface.name)) { const uint32_t required = 1; @@ -1696,6 +1707,10 @@ wayl_destroy(struct wayland *wayl) zwp_text_input_manager_v3_destroy(wayl->text_input_manager); #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 (wayl->toplevel_icon_manager != NULL) xdg_toplevel_icon_manager_v1_destroy(wayl->toplevel_icon_manager); @@ -2247,6 +2262,28 @@ wayl_win_set_urgent(struct wl_window *win) 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 wayl_win_csd_titlebar_visible(const struct wl_window *win) { -- cgit v1.3