From e4804d11e8fab4b7ac691d0458d6608a4955d9e0 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Thu, 14 Nov 2024 17:19:08 +0100 Subject: [PATCH] xwayland: Add xdg-system-bell support For the Wayland compositors who do not implement XkbBellNotifyMask but support the Wayland protocol xdg-system-bell, use that to ring the bell. v2: Be more selective on the device, make sure it's a keyboard and it has core events. Signed-off-by: Olivier Fourdan Part-of: --- hw/xwayland/meson.build | 2 ++ hw/xwayland/xwayland-input.c | 34 ++++++++++++++++++++++++++++++++++ hw/xwayland/xwayland-screen.h | 1 + 3 files changed, 37 insertions(+) diff --git a/hw/xwayland/meson.build b/hw/xwayland/meson.build index 0ccb32a75..9616aae01 100644 --- a/hw/xwayland/meson.build +++ b/hw/xwayland/meson.build @@ -51,6 +51,7 @@ xwayland_shell_xml = join_paths(protodir, 'staging', 'xwayland-shell', 'xwayland tearing_xml = join_paths(protodir, 'staging', 'tearing-control', 'tearing-control-v1.xml') fractional_scale_xml = join_paths(protodir, 'staging', 'fractional-scale', 'fractional-scale-v1.xml') syncobj_xml = join_paths(protodir, 'staging', 'linux-drm-syncobj', 'linux-drm-syncobj-v1.xml') +system_bell_xml = join_paths(protodir, 'staging', 'xdg-system-bell', 'xdg-system-bell-v1.xml') proto_xml = [ relative_xml, @@ -68,6 +69,7 @@ proto_xml = [ tearing_xml, fractional_scale_xml, syncobj_xml, + system_bell_xml, ] client_header = generator(scanner, diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c index 7f1c2619a..ac67d478e 100644 --- a/hw/xwayland/xwayland-input.c +++ b/hw/xwayland/xwayland-input.c @@ -57,6 +57,7 @@ #include "pointer-gestures-unstable-v1-client-protocol.h" #include "xwayland-keyboard-grab-unstable-v1-client-protocol.h" #include "keyboard-shortcuts-inhibit-unstable-v1-client-protocol.h" +#include "xdg-system-bell-v1-client-protocol.h" #define SCROLL_AXIS_HORIZ 2 #define SCROLL_AXIS_VERT 3 @@ -3091,6 +3092,15 @@ init_keyboard_shortcuts_inhibit(struct xwl_screen *xwl_screen, 1); } +static void +init_system_bell(struct xwl_screen *xwl_screen, uint32_t id, uint32_t version) +{ + xwl_screen->system_bell = + wl_registry_bind(xwl_screen->registry, id, + &xdg_system_bell_v1_interface, + 1); +} + /* The compositor may send us wl_seat and its capabilities before sending e.g. relative_pointer_manager or pointer_gesture interfaces. This would result in devices being created in capabilities handler, but listeners not, because @@ -3142,6 +3152,8 @@ input_handler(void *data, struct wl_registry *registry, uint32_t id, init_keyboard_grab(xwl_screen, id, version); } else if (strcmp(interface, zwp_keyboard_shortcuts_inhibit_manager_v1_interface.name) == 0) { init_keyboard_shortcuts_inhibit(xwl_screen, id, version); + } else if (strcmp(interface, xdg_system_bell_v1_interface.name) == 0) { + init_system_bell(xwl_screen, id, version); } } @@ -3164,6 +3176,28 @@ ProcessInputEvents(void) void DDXRingBell(int volume, int pitch, int duration) { + ScreenPtr screen = screenInfo.screens[0]; + struct xwl_screen *xwl_screen; + struct xwl_seat *xwl_seat; + + xwl_screen = xwl_screen_get(screen); + if (!xwl_screen->system_bell) + return; + + xorg_list_for_each_entry(xwl_seat, &xwl_screen->seat_list, link) { + if (!xwl_seat->keyboard) + continue; + + if (!xwl_seat->keyboard->coreEvents) + continue; + + if (!xwl_seat->keyboard_focus) + continue; + + DebugF("XWAYLAND: Ringing the bell\n"); + xdg_system_bell_v1_ring (xwl_screen->system_bell, xwl_seat->keyboard_focus); + return; + } } static Bool diff --git a/hw/xwayland/xwayland-screen.h b/hw/xwayland/xwayland-screen.h index 0800fb392..49a167a12 100644 --- a/hw/xwayland/xwayland-screen.h +++ b/hw/xwayland/xwayland-screen.h @@ -117,6 +117,7 @@ struct xwl_screen { struct wp_tearing_control_manager_v1 *tearing_control_manager; struct wp_fractional_scale_manager_v1 *fractional_scale_manager; struct wp_linux_drm_syncobj_manager_v1 *explicit_sync; + struct xdg_system_bell_v1 *system_bell; struct xorg_list drm_lease_devices; struct xorg_list queued_drm_lease_devices; struct xorg_list drm_leases;