Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
subsurface: use commit_request event
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Primak committed Oct 4, 2021
1 parent 776998d commit 33477a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
1 change: 1 addition & 0 deletions include/wlr/types/wlr_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
42 changes: 22 additions & 20 deletions types/wlr_surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 33477a6

Please sign in to comment.