swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 08b530bde8b5fa06dc069241a13a61979840220a
parent fc84dad0bde3f0dbe903f65772c95451684b3da6
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 20 Feb 2020 11:52:19 -0800

xdg_decoration: Add destroy listener for xdg_toplevel

This way, if the xdg_toplevel is destroyed, the decoration is
destroyed as well.

Thanks to Thomas Gardner for the suggestion.

Diffstat:
Mlibswc/xdg_decoration.c | 38++++++++++++++++++++++++++++++--------
1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/libswc/xdg_decoration.c b/libswc/xdg_decoration.c @@ -27,6 +27,11 @@ #include <wayland-server.h> #include "xdg-decoration-unstable-v1-server-protocol.h" +struct xdg_toplevel_decoration { + struct wl_resource *resource; + struct wl_listener toplevel_destroy_listener; +}; + static void set_mode(struct wl_client *client, struct wl_resource *resource, uint32_t mode) { @@ -43,17 +48,34 @@ static const struct zxdg_toplevel_decoration_v1_interface decoration_impl = { }; static void +handle_toplevel_destroy(struct wl_listener *listener, void *data) +{ + struct xdg_toplevel_decoration *decoration = wl_container_of(listener, decoration, toplevel_destroy_listener); + + wl_resource_destroy(decoration->resource); +} + +static void get_toplevel_decoration(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *toplevel_resource) { - struct wl_resource *decoration; + struct xdg_toplevel_decoration *decoration; - decoration = wl_resource_create(client, &zxdg_toplevel_decoration_v1_interface, wl_resource_get_version(resource), id); - if (!decoration) { - wl_resource_post_no_memory(resource); - return; - } - wl_resource_set_implementation(decoration, &decoration_impl, NULL, NULL); - zxdg_toplevel_decoration_v1_send_configure(decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + decoration = malloc(sizeof(*decoration)); + if (!decoration) + goto error0; + decoration->resource = wl_resource_create(client, &zxdg_toplevel_decoration_v1_interface, wl_resource_get_version(resource), id); + if (!decoration->resource) + goto error1; + decoration->toplevel_destroy_listener.notify = &handle_toplevel_destroy; + wl_resource_add_destroy_listener(decoration->resource, &decoration->toplevel_destroy_listener); + wl_resource_set_implementation(decoration->resource, &decoration_impl, NULL, NULL); + zxdg_toplevel_decoration_v1_send_configure(decoration->resource, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + return; + +error1: + free(decoration); +error0: + wl_resource_post_no_memory(resource); } static const struct zxdg_decoration_manager_v1_interface decoration_manager_impl = {