From 33477a69fe6bfa4b28cfbf65ca4710826001bb8f Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Mon, 4 Oct 2021 23:40:14 +0300 Subject: [PATCH] subsurface: use commit_request event --- include/wlr/types/wlr_surface.h | 1 + types/wlr_surface.c | 42 +++++++++++++++++---------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index 6828591ef5..fc399fabaa 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -186,6 +186,7 @@ struct wlr_subsurface { bool mapped; struct wl_listener surface_destroy; + struct wl_listener surface_commit_request; struct wl_listener parent_destroy; struct { diff --git a/types/wlr_surface.c b/types/wlr_surface.c index c792ff94c4..ccfa856e11 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -515,30 +515,10 @@ static void subsurface_parent_commit(struct wlr_subsurface *subsurface, } } -static void subsurface_commit(struct wlr_subsurface *subsurface) { - struct wlr_surface *surface = subsurface->surface; - - if (subsurface_is_synchronized(subsurface)) { - if (subsurface->has_cache) { - // We already lock a previous commit. The prevents any future - // commit to be applied before we release the previous commit. - return; - } - subsurface->has_cache = true; - subsurface->cached_seq = wlr_surface_lock_pending(surface); - } -} - static void surface_handle_commit(struct wl_client *client, struct wl_resource *resource) { struct wlr_surface *surface = wlr_surface_from_resource(resource); - struct wlr_subsurface *subsurface = wlr_surface_is_subsurface(surface) ? - wlr_subsurface_from_wlr_surface(surface) : NULL; - if (subsurface != NULL) { - subsurface_commit(subsurface); - } - surface_finalize_pending(surface); wlr_signal_emit_safe(&surface->events.commit_request, surface); @@ -549,6 +529,7 @@ static void surface_handle_commit(struct wl_client *client, surface_commit_state(surface, &surface->pending); } + struct wlr_subsurface *subsurface; wl_list_for_each(subsurface, &surface->current.subsurfaces_below, current.link) { subsurface_parent_commit(subsurface, false); } @@ -1135,6 +1116,23 @@ static void subsurface_handle_surface_destroy(struct wl_listener *listener, subsurface_destroy(subsurface); } +static void subsurface_handle_surface_commit_request( + struct wl_listener *listener, void *data) { + struct wlr_subsurface *subsurface = + wl_container_of(listener, subsurface, surface_commit_request); + struct wlr_surface *surface = data; + + if (subsurface_is_synchronized(subsurface)) { + if (subsurface->has_cache) { + // We already lock a previous commit. The prevents any future + // commit to be applied before we release the previous commit. + return; + } + subsurface->has_cache = true; + subsurface->cached_seq = wlr_surface_lock_pending(surface); + } +} + struct wlr_subsurface *subsurface_create(struct wlr_surface *surface, struct wlr_surface *parent, uint32_t version, uint32_t id) { struct wl_client *client = wl_resource_get_client(surface->resource); @@ -1163,6 +1161,10 @@ struct wlr_subsurface *subsurface_create(struct wlr_surface *surface, wl_signal_add(&surface->events.destroy, &subsurface->surface_destroy); subsurface->surface_destroy.notify = subsurface_handle_surface_destroy; + wl_signal_add(&surface->events.commit_request, + &subsurface->surface_commit_request); + subsurface->surface_commit_request.notify = + subsurface_handle_surface_commit_request; // link parent subsurface->parent = parent;