|
| 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 "config.h" |
| 20 | +#include "compositor/compositor-private.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 | +} |
0 commit comments