aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/compositor/wl_compositor.c3
-rw-r--r--include/wlr/types/wlr_region.h3
-rw-r--r--types/wlr_region.c19
3 files changed, 21 insertions, 4 deletions
diff --git a/examples/compositor/wl_compositor.c b/examples/compositor/wl_compositor.c
index 89d23d6a..e5b1120e 100644
--- a/examples/compositor/wl_compositor.c
+++ b/examples/compositor/wl_compositor.c
@@ -3,6 +3,7 @@
#include <wayland-server.h>
#include <wlr/util/log.h>
#include <wlr/types/wlr_surface.h>
+#include <wlr/types/wlr_region.h>
#include "compositor.h"
static void destroy_surface_listener(struct wl_listener *listener, void *data) {
@@ -31,7 +32,7 @@ static void wl_compositor_create_surface(struct wl_client *client,
static void wl_compositor_create_region(struct wl_client *client,
struct wl_resource *resource, uint32_t id) {
- wlr_log(L_DEBUG, "TODO: implement create_region");
+ wlr_region_create(client, resource, id);
}
struct wl_compositor_interface wl_compositor_impl = {
diff --git a/include/wlr/types/wlr_region.h b/include/wlr/types/wlr_region.h
index 9fff0150..0aff48a3 100644
--- a/include/wlr/types/wlr_region.h
+++ b/include/wlr/types/wlr_region.h
@@ -5,6 +5,7 @@ struct wl_resource;
// Implements the given resource as region.
// Sets the associated pixman_region32_t as userdata.
-void wlr_region_create(struct wl_resource *res);
+void wlr_region_create(struct wl_client *client, struct wl_resource *res,
+ uint32_t id);
#endif
diff --git a/types/wlr_region.c b/types/wlr_region.c
index a1c45542..dead3784 100644
--- a/types/wlr_region.c
+++ b/types/wlr_region.c
@@ -37,8 +37,23 @@ static void destroy_region(struct wl_resource *resource) {
free(reg);
}
-void wlr_region_create(struct wl_resource *res) {
+void wlr_region_create(struct wl_client *client, struct wl_resource *res,
+ uint32_t id) {
pixman_region32_t *region = calloc(1, sizeof(pixman_region32_t));
+ if (region == NULL) {
+ wl_resource_post_no_memory(res);
+ return;
+ }
+
pixman_region32_init(region);
- wl_resource_set_implementation(res, &region_interface, region, destroy_region);
+
+ struct wl_resource *region_resource = wl_resource_create(client,
+ &wl_region_interface, 1, id);
+ if (region_resource == NULL) {
+ free(region);
+ wl_resource_post_no_memory(res);
+ return;
+ }
+ wl_resource_set_implementation(region_resource, &region_interface, region,
+ destroy_region);
}