xdg-decoration: use wlr_surface_synced for toplevel

This commit is contained in:
Simon Ser 2023-12-07 21:11:37 +01:00
parent 96aec06b0a
commit 0e3d2222c2
2 changed files with 18 additions and 13 deletions

View file

@ -36,7 +36,7 @@ struct wlr_xdg_toplevel_decoration_v1_state {
struct wlr_xdg_toplevel_decoration_v1 { struct wlr_xdg_toplevel_decoration_v1 {
struct wl_resource *resource; struct wl_resource *resource;
struct wlr_xdg_toplevel * toplevel; struct wlr_xdg_toplevel *toplevel;
struct wlr_xdg_decoration_manager_v1 *manager; struct wlr_xdg_decoration_manager_v1 *manager;
struct wl_list link; // wlr_xdg_decoration_manager_v1.link 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; struct wl_signal request_mode;
} events; } events;
void *data;
// private state
struct wl_listener toplevel_destroy; struct wl_listener toplevel_destroy;
struct wl_listener surface_configure; struct wl_listener surface_configure;
struct wl_listener surface_ack_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 * struct wlr_xdg_decoration_manager_v1 *

View file

@ -62,7 +62,7 @@ static void toplevel_decoration_handle_resource_destroy(
struct wlr_xdg_toplevel_decoration_v1 *decoration = struct wlr_xdg_toplevel_decoration_v1 *decoration =
toplevel_decoration_from_resource(resource); toplevel_decoration_from_resource(resource);
wl_signal_emit_mutable(&decoration->events.destroy, decoration); 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->toplevel_destroy.link);
wl_list_remove(&decoration->surface_configure.link); wl_list_remove(&decoration->surface_configure.link);
wl_list_remove(&decoration->surface_ack_configure.link); wl_list_remove(&decoration->surface_ack_configure.link);
@ -141,13 +141,9 @@ static void toplevel_decoration_handle_surface_ack_configure(
free(configure); free(configure);
} }
static void toplevel_decoration_handle_surface_commit( static const struct wlr_surface_synced_impl surface_synced_impl = {
struct wl_listener *listener, void *data) { .state_size = sizeof(struct wlr_xdg_toplevel_decoration_v1_state),
struct wlr_xdg_toplevel_decoration_v1 *decoration = };
wl_container_of(listener, decoration, surface_commit);
decoration->current = decoration->pending;
}
static const struct zxdg_decoration_manager_v1_interface decoration_manager_impl; 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->manager = manager;
decoration->toplevel = toplevel; 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); uint32_t version = wl_resource_get_version(manager_resource);
decoration->resource = wl_resource_create(client, decoration->resource = wl_resource_create(client,
&zxdg_toplevel_decoration_v1_interface, version, id); &zxdg_toplevel_decoration_v1_interface, version, id);
if (decoration->resource == NULL) { if (decoration->resource == NULL) {
wlr_surface_synced_finish(&decoration->synced);
free(decoration); free(decoration);
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
return; return;
@ -222,8 +226,6 @@ static void decoration_manager_handle_get_toplevel_decoration(
decoration->surface_configure.notify = toplevel_decoration_handle_surface_configure; decoration->surface_configure.notify = toplevel_decoration_handle_surface_configure;
wl_signal_add(&toplevel->base->events.ack_configure, &decoration->surface_ack_configure); wl_signal_add(&toplevel->base->events.ack_configure, &decoration->surface_ack_configure);
decoration->surface_ack_configure.notify = toplevel_decoration_handle_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); wl_list_insert(&manager->decorations, &decoration->link);