Skip to content

Commit da42d19

Browse files
committed
[Wayland] Add support for xdg-system-bell-v1 protocol
1 parent 25f17c1 commit da42d19

File tree

6 files changed

+126
-1
lines changed

6 files changed

+126
-1
lines changed

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ gudev_req = '>= 232'
3838

3939
# wayland version requirements
4040
wayland_server_req = '>= 1.20'
41-
wayland_protocols_req = '>= 1.36'
41+
wayland_protocols_req = '>= 1.38'
4242

4343
# native backend version requirements
4444
libinput_req = '>= 1.19.0'

src/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ if have_wayland
559559
'wayland/meta-wayland-surface.c',
560560
'wayland/meta-wayland-surface.h',
561561
'wayland/meta-wayland-tablet.c',
562+
'wayland/meta-wayland-system-bell.c',
563+
'wayland/meta-wayland-system-bell.h',
562564
'wayland/meta-wayland-tablet-cursor-surface.c',
563565
'wayland/meta-wayland-tablet-cursor-surface.h',
564566
'wayland/meta-wayland-tablet.h',
@@ -812,6 +814,7 @@ if have_wayland
812814
['pointer-gestures', 'unstable', 'v1', ],
813815
['primary-selection', 'unstable', 'v1', ],
814816
['relative-pointer', 'unstable', 'v1', ],
817+
['xdg-system-bell', 'staging', 'v1', ],
815818
['tablet', 'unstable', 'v2', ],
816819
['text-input', 'unstable', 'v3', ],
817820
['viewporter', 'stable', ],
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (C) 2024 Red Hat Inc.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
#include "compositor/compositor-private.h"
20+
#include "config.h"
21+
22+
#include "wayland/meta-wayland-system-bell.h"
23+
24+
#include "core/bell.h"
25+
#include "wayland/meta-wayland-private.h"
26+
#include "wayland/meta-wayland-surface.h"
27+
#include "wayland/meta-wayland-versions.h"
28+
#include "wayland/meta-wayland.h"
29+
30+
#include "xdg-system-bell-v1-server-protocol.h"
31+
32+
static void
33+
system_bell_destroy (struct wl_client *client,
34+
struct wl_resource *resource)
35+
{
36+
wl_resource_destroy (resource);
37+
}
38+
39+
static MetaWindow *
40+
find_window_from_resource (struct wl_resource *surface_resource)
41+
{
42+
MetaWaylandSurface *surface;
43+
44+
surface = wl_resource_get_user_data (surface_resource);
45+
if (!surface)
46+
return NULL;
47+
48+
return meta_wayland_surface_get_window (surface);
49+
}
50+
51+
static void
52+
system_bell_ring (struct wl_client *client,
53+
struct wl_resource *resource,
54+
struct wl_resource *surface_resource)
55+
{
56+
MetaDisplay *display = meta_get_display ();
57+
58+
if (surface_resource)
59+
meta_bell_notify (display, find_window_from_resource (surface_resource));
60+
else
61+
meta_bell_notify (display, NULL);
62+
}
63+
64+
static const struct xdg_system_bell_v1_interface system_bell_implementation =
65+
{
66+
system_bell_destroy,
67+
system_bell_ring,
68+
};
69+
70+
static void
71+
system_bell_bind (struct wl_client *client,
72+
void *user_data,
73+
uint32_t version,
74+
uint32_t id)
75+
{
76+
MetaWaylandCompositor *compositor = user_data;
77+
struct wl_resource *resource;
78+
79+
resource = wl_resource_create (client,
80+
&xdg_system_bell_v1_interface,
81+
version, id);
82+
wl_resource_set_implementation (resource,
83+
&system_bell_implementation,
84+
compositor, NULL);
85+
}
86+
87+
void
88+
meta_wayland_init_system_bell (MetaWaylandCompositor *compositor)
89+
{
90+
if (wl_global_create (compositor->wayland_display,
91+
&xdg_system_bell_v1_interface,
92+
META_WP_SYSTEM_BELL_V1_VERSION,
93+
compositor,
94+
system_bell_bind) == NULL)
95+
g_error ("Failed to create xdg_system_bell_v1 global");
96+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (C) 2024 Red Hat Inc.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
#pragma once
20+
21+
#include "wayland/meta-wayland-types.h"
22+
23+
void meta_wayland_init_system_bell (MetaWaylandCompositor *compositor);

src/wayland/meta-wayland-versions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@
5959
#define META_XDG_DIALOG_VERSION 1
6060
#define META_ZWP_PRIMARY_SELECTION_V1_VERSION 1
6161
#define META_XDG_TOPLEVEL_TAG_V1_VERSION 1
62+
#define META_WP_SYSTEM_BELL_V1_VERSION 1
6263

6364
#endif

src/wayland/meta-wayland.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "wayland/meta-wayland-region.h"
4646
#include "wayland/meta-wayland-seat.h"
4747
#include "wayland/meta-wayland-subsurface.h"
48+
#include "wayland/meta-wayland-system-bell.h"
4849
#include "wayland/meta-wayland-tablet-manager.h"
4950
#include "wayland/meta-wayland-xdg-dialog.h"
5051
#include "wayland/meta-wayland-xdg-foreign.h"
@@ -447,6 +448,7 @@ meta_wayland_compositor_setup (MetaWaylandCompositor *wayland_compositor)
447448
meta_wayland_idle_inhibit_init (compositor);
448449
meta_wayland_init_xdg_wm_dialog (compositor);
449450
meta_wayland_xdg_toplevel_tag_init (compositor);
451+
meta_wayland_init_system_bell (compositor);
450452

451453
/* Xwayland specific protocol, needs to be filtered out for all other clients */
452454
if (meta_xwayland_grab_keyboard_init (compositor))

0 commit comments

Comments
 (0)