aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-04-05 13:58:41 -0400
committeremersion <contact@emersion.fr>2018-04-05 14:00:53 -0400
commitaced024819fe990cf513e07899b9d22848fafcff (patch)
treeac1a403cda44e170d0c53212d28913793edeb43b
parentb6482bacf469326b8634bb1e78a96bb91556617f (diff)
Add wlr_surface_is_subsurface and wlr_subsurface_from_surface
-rw-r--r--include/wlr/types/wlr_compositor.h6
-rw-r--r--types/wlr_compositor.c16
2 files changed, 21 insertions, 1 deletions
diff --git a/include/wlr/types/wlr_compositor.h b/include/wlr/types/wlr_compositor.h
index 11bfac71..922d7c0f 100644
--- a/include/wlr/types/wlr_compositor.h
+++ b/include/wlr/types/wlr_compositor.h
@@ -4,6 +4,8 @@
#include <wayland-server.h>
#include <wlr/render/wlr_renderer.h>
+struct wlr_surface;
+
struct wlr_compositor {
struct wl_global *wl_global;
struct wl_list wl_resources;
@@ -22,4 +24,8 @@ void wlr_compositor_destroy(struct wlr_compositor *wlr_compositor);
struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
struct wlr_renderer *renderer);
+bool wlr_surface_is_subsurface(struct wlr_surface *surface);
+
+struct wlr_subsurface *wlr_subsurface_from_surface(struct wlr_surface *surface);
+
#endif
diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c
index 181d0323..2f9d12c9 100644
--- a/types/wlr_compositor.c
+++ b/types/wlr_compositor.c
@@ -7,6 +7,18 @@
#include <wlr/util/log.h>
#include "util/signal.h"
+static const char *subsurface_role = "wl_subsurface";
+
+bool wlr_surface_is_subsurface(struct wlr_surface *surface) {
+ return strcmp(surface->role, subsurface_role) == 0;
+}
+
+struct wlr_subsurface *wlr_subsurface_from_surface(
+ struct wlr_surface *surface) {
+ assert(wlr_surface_is_subsurface(surface));
+ return (struct wlr_subsurface *)surface->role_data;
+}
+
static const struct wl_compositor_interface wl_compositor_impl;
static struct wlr_compositor *compositor_from_resource(struct wl_resource *resource) {
@@ -134,7 +146,7 @@ static void subcompositor_get_subsurface(struct wl_client *client,
return;
}
- if (wlr_surface_set_role(surface, "wl_subsurface", resource,
+ if (wlr_surface_set_role(surface, subsurface_role, resource,
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) {
return;
}
@@ -144,6 +156,8 @@ static void subcompositor_get_subsurface(struct wl_client *client,
wl_resource_post_no_memory(resource);
return;
}
+
+ surface->role_data = surface->subsurface;
}