From 0e3d2222c2cb6566f6f5f3912b7bddb45eb7e5e5 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 7 Dec 2023 21:11:37 +0100 Subject: [PATCH] xdg-decoration: use wlr_surface_synced for toplevel --- include/wlr/types/wlr_xdg_decoration_v1.h | 9 ++++++--- types/wlr_xdg_decoration_v1.c | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/wlr/types/wlr_xdg_decoration_v1.h b/include/wlr/types/wlr_xdg_decoration_v1.h index d8ec038d..f1a8bc5b 100644 --- a/include/wlr/types/wlr_xdg_decoration_v1.h +++ b/include/wlr/types/wlr_xdg_decoration_v1.h @@ -36,7 +36,7 @@ struct wlr_xdg_toplevel_decoration_v1_state { struct wlr_xdg_toplevel_decoration_v1 { struct wl_resource *resource; - struct wlr_xdg_toplevel * toplevel; + struct wlr_xdg_toplevel *toplevel; struct wlr_xdg_decoration_manager_v1 *manager; struct wl_list link; // wlr_xdg_decoration_manager_v1.link @@ -52,12 +52,15 @@ struct wlr_xdg_toplevel_decoration_v1 { struct wl_signal request_mode; } events; + void *data; + + // private state + struct wl_listener toplevel_destroy; struct wl_listener surface_configure; struct wl_listener surface_ack_configure; - struct wl_listener surface_commit; - void *data; + struct wlr_surface_synced synced; }; struct wlr_xdg_decoration_manager_v1 * diff --git a/types/wlr_xdg_decoration_v1.c b/types/wlr_xdg_decoration_v1.c index 9d5cf747..d16ac7c5 100644 --- a/types/wlr_xdg_decoration_v1.c +++ b/types/wlr_xdg_decoration_v1.c @@ -62,7 +62,7 @@ static void toplevel_decoration_handle_resource_destroy( struct wlr_xdg_toplevel_decoration_v1 *decoration = toplevel_decoration_from_resource(resource); wl_signal_emit_mutable(&decoration->events.destroy, decoration); - wl_list_remove(&decoration->surface_commit.link); + wlr_surface_synced_finish(&decoration->synced); wl_list_remove(&decoration->toplevel_destroy.link); wl_list_remove(&decoration->surface_configure.link); wl_list_remove(&decoration->surface_ack_configure.link); @@ -141,13 +141,9 @@ static void toplevel_decoration_handle_surface_ack_configure( free(configure); } -static void toplevel_decoration_handle_surface_commit( - struct wl_listener *listener, void *data) { - struct wlr_xdg_toplevel_decoration_v1 *decoration = - wl_container_of(listener, decoration, surface_commit); - - decoration->current = decoration->pending; -} +static const struct wlr_surface_synced_impl surface_synced_impl = { + .state_size = sizeof(struct wlr_xdg_toplevel_decoration_v1_state), +}; static const struct zxdg_decoration_manager_v1_interface decoration_manager_impl; @@ -197,10 +193,18 @@ static void decoration_manager_handle_get_toplevel_decoration( decoration->manager = manager; decoration->toplevel = toplevel; + if (!wlr_surface_synced_init(&decoration->synced, toplevel->base->surface, + &surface_synced_impl, &decoration->pending, &decoration->current)) { + free(decoration); + wl_client_post_no_memory(client); + return; + } + uint32_t version = wl_resource_get_version(manager_resource); decoration->resource = wl_resource_create(client, &zxdg_toplevel_decoration_v1_interface, version, id); if (decoration->resource == NULL) { + wlr_surface_synced_finish(&decoration->synced); free(decoration); wl_client_post_no_memory(client); return; @@ -222,8 +226,6 @@ static void decoration_manager_handle_get_toplevel_decoration( decoration->surface_configure.notify = toplevel_decoration_handle_surface_configure; wl_signal_add(&toplevel->base->events.ack_configure, &decoration->surface_ack_configure); decoration->surface_ack_configure.notify = toplevel_decoration_handle_surface_ack_configure; - wl_signal_add(&toplevel->base->surface->events.commit, &decoration->surface_commit); - decoration->surface_commit.notify = toplevel_decoration_handle_surface_commit; wl_list_insert(&manager->decorations, &decoration->link);