aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2023-07-11 17:54:08 +0200
committerSimon Ser <contact@emersion.fr>2023-07-11 20:16:17 +0200
commitfe06e5f49a12174ceeb5e307bf5c3d7f623177d5 (patch)
tree40984fb21cd0cbf6be531206a86167298ab2d537
parentc2c536de034cc27d3a15001cc478f5a327b8f910 (diff)
Use wl_container_of() instead of casts
This slightly improves type safety. The culprits were found with: git grep -E '\([a-z0-9_ ]+ \*\)\W?[a-z]'
-rw-r--r--backend/drm/backend.c3
-rw-r--r--backend/drm/drm.c3
-rw-r--r--backend/headless/backend.c3
-rw-r--r--backend/headless/output.c3
-rw-r--r--backend/libinput/backend.c3
-rw-r--r--backend/multi/backend.c3
-rw-r--r--backend/wayland/backend.c7
-rw-r--r--backend/wayland/output.c3
-rw-r--r--backend/x11/backend.c3
-rw-r--r--backend/x11/output.c3
-rw-r--r--render/allocator/drm_dumb.c6
-rw-r--r--render/allocator/gbm.c14
-rw-r--r--render/allocator/shm.c3
-rw-r--r--render/gles2/renderer.c5
-rw-r--r--render/gles2/texture.c3
-rw-r--r--render/pixman/renderer.c6
-rw-r--r--render/vulkan/renderer.c3
-rw-r--r--render/vulkan/texture.c3
-rw-r--r--types/buffer/client.c7
-rw-r--r--types/buffer/dmabuf.c7
-rw-r--r--types/buffer/readonly_data.c7
-rw-r--r--types/data_device/wlr_data_source.c3
-rw-r--r--types/scene/wlr_scene.c3
-rw-r--r--types/wlr_data_control_v1.c6
-rw-r--r--types/wlr_drm.c7
-rw-r--r--types/wlr_keyboard_group.c3
-rw-r--r--types/wlr_linux_dmabuf_v1.c7
-rw-r--r--types/wlr_primary_selection_v1.c4
-rw-r--r--xwayland/selection/incoming.c9
29 files changed, 85 insertions, 55 deletions
diff --git a/backend/drm/backend.c b/backend/drm/backend.c
index b3af3005..54852185 100644
--- a/backend/drm/backend.c
+++ b/backend/drm/backend.c
@@ -16,7 +16,8 @@
struct wlr_drm_backend *get_drm_backend_from_backend(
struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_drm(wlr_backend));
- return (struct wlr_drm_backend *)wlr_backend;
+ struct wlr_drm_backend *backend = wl_container_of(wlr_backend, backend, backend);
+ return backend;
}
static bool backend_start(struct wlr_backend *backend) {
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index 5f71f923..fdbab3bf 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -331,7 +331,8 @@ void finish_drm_resources(struct wlr_drm_backend *drm) {
static struct wlr_drm_connector *get_drm_connector_from_output(
struct wlr_output *wlr_output) {
assert(wlr_output_is_drm(wlr_output));
- return (struct wlr_drm_connector *)wlr_output;
+ struct wlr_drm_connector *conn = wl_container_of(wlr_output, conn, output);
+ return conn;
}
static void layer_handle_addon_destroy(struct wlr_addon *addon) {
diff --git a/backend/headless/backend.c b/backend/headless/backend.c
index df14d6af..f0cde0c7 100644
--- a/backend/headless/backend.c
+++ b/backend/headless/backend.c
@@ -7,7 +7,8 @@
struct wlr_headless_backend *headless_backend_from_backend(
struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_headless(wlr_backend));
- return (struct wlr_headless_backend *)wlr_backend;
+ struct wlr_headless_backend *backend = wl_container_of(wlr_backend, backend, backend);
+ return backend;
}
static bool backend_start(struct wlr_backend *wlr_backend) {
diff --git a/backend/headless/output.c b/backend/headless/output.c
index db7b707f..9cac54d1 100644
--- a/backend/headless/output.c
+++ b/backend/headless/output.c
@@ -17,7 +17,8 @@ static size_t last_output_num = 0;
static struct wlr_headless_output *headless_output_from_output(
struct wlr_output *wlr_output) {
assert(wlr_output_is_headless(wlr_output));
- return (struct wlr_headless_output *)wlr_output;
+ struct wlr_headless_output *output = wl_container_of(wlr_output, output, wlr_output);
+ return output;
}
static bool output_set_custom_mode(struct wlr_headless_output *output,
diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c
index 688fae5d..e95127bd 100644
--- a/backend/libinput/backend.c
+++ b/backend/libinput/backend.c
@@ -11,7 +11,8 @@
static struct wlr_libinput_backend *get_libinput_backend_from_backend(
struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_libinput(wlr_backend));
- return (struct wlr_libinput_backend *)wlr_backend;
+ struct wlr_libinput_backend *backend = wl_container_of(wlr_backend, backend, backend);
+ return backend;
}
static int libinput_open_restricted(const char *path,
diff --git a/backend/multi/backend.c b/backend/multi/backend.c
index 49792ff9..1ee21c14 100644
--- a/backend/multi/backend.c
+++ b/backend/multi/backend.c
@@ -21,7 +21,8 @@ struct subbackend_state {
static struct wlr_multi_backend *multi_backend_from_backend(
struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_multi(wlr_backend));
- return (struct wlr_multi_backend *)wlr_backend;
+ struct wlr_multi_backend *backend = wl_container_of(wlr_backend, backend, backend);
+ return backend;
}
static bool multi_backend_start(struct wlr_backend *wlr_backend) {
diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c
index ba13aa30..82285be9 100644
--- a/backend/wayland/backend.c
+++ b/backend/wayland/backend.c
@@ -46,9 +46,10 @@ struct wlr_wl_linux_dmabuf_v1_table_entry {
uint64_t modifier;
};
-struct wlr_wl_backend *get_wl_backend_from_backend(struct wlr_backend *backend) {
- assert(wlr_backend_is_wl(backend));
- return (struct wlr_wl_backend *)backend;
+struct wlr_wl_backend *get_wl_backend_from_backend(struct wlr_backend *wlr_backend) {
+ assert(wlr_backend_is_wl(wlr_backend));
+ struct wlr_wl_backend *backend = wl_container_of(wlr_backend, backend, backend);
+ return backend;
}
static int dispatch_events(int fd, uint32_t mask, void *data) {
diff --git a/backend/wayland/output.c b/backend/wayland/output.c
index bf668cc4..9371ca72 100644
--- a/backend/wayland/output.c
+++ b/backend/wayland/output.c
@@ -39,7 +39,8 @@ static size_t last_output_num = 0;
static struct wlr_wl_output *get_wl_output_from_output(
struct wlr_output *wlr_output) {
assert(wlr_output_is_wl(wlr_output));
- return (struct wlr_wl_output *)wlr_output;
+ struct wlr_wl_output *output = wl_container_of(wlr_output, output, wlr_output);
+ return output;
}
static void surface_frame_callback(void *data, struct wl_callback *cb,
diff --git a/backend/x11/backend.c b/backend/x11/backend.c
index 51cb5ca4..fcaab618 100644
--- a/backend/x11/backend.c
+++ b/backend/x11/backend.c
@@ -154,7 +154,8 @@ static int x11_event(int fd, uint32_t mask, void *data) {
struct wlr_x11_backend *get_x11_backend_from_backend(
struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_x11(wlr_backend));
- return (struct wlr_x11_backend *)wlr_backend;
+ struct wlr_x11_backend *backend = wl_container_of(wlr_backend, backend, backend);
+ return backend;
}
static bool backend_start(struct wlr_backend *backend) {
diff --git a/backend/x11/output.c b/backend/x11/output.c
index 175204fa..36ce0c4f 100644
--- a/backend/x11/output.c
+++ b/backend/x11/output.c
@@ -54,7 +54,8 @@ static void parse_xcb_setup(struct wlr_output *output,
static struct wlr_x11_output *get_x11_output_from_output(
struct wlr_output *wlr_output) {
assert(wlr_output_is_x11(wlr_output));
- return (struct wlr_x11_output *)wlr_output;
+ struct wlr_x11_output *output = wl_container_of(wlr_output, output, wlr_output);
+ return output;
}
static bool output_set_custom_mode(struct wlr_output *wlr_output,
diff --git a/render/allocator/drm_dumb.c b/render/allocator/drm_dumb.c
index 684ba2e3..03ff8e3f 100644
--- a/render/allocator/drm_dumb.c
+++ b/render/allocator/drm_dumb.c
@@ -25,7 +25,8 @@ static const struct wlr_buffer_impl buffer_impl;
static struct wlr_drm_dumb_buffer *drm_dumb_buffer_from_buffer(
struct wlr_buffer *wlr_buf) {
assert(wlr_buf->impl == &buffer_impl);
- return (struct wlr_drm_dumb_buffer *)wlr_buf;
+ struct wlr_drm_dumb_buffer *buf = wl_container_of(wlr_buf, buf, base);
+ return buf;
}
static struct wlr_drm_dumb_buffer *create_buffer(
@@ -163,7 +164,8 @@ static const struct wlr_allocator_interface allocator_impl;
static struct wlr_drm_dumb_allocator *drm_dumb_alloc_from_alloc(
struct wlr_allocator *wlr_alloc) {
assert(wlr_alloc->impl == &allocator_impl);
- return (struct wlr_drm_dumb_allocator *)wlr_alloc;
+ struct wlr_drm_dumb_allocator *alloc = wl_container_of(wlr_alloc, alloc, base);
+ return alloc;
}
static struct wlr_buffer *allocator_create_buffer(
diff --git a/render/allocator/gbm.c b/render/allocator/gbm.c
index 149ff6b9..32636d30 100644
--- a/render/allocator/gbm.c
+++ b/render/allocator/gbm.c
@@ -17,9 +17,10 @@
static const struct wlr_buffer_impl buffer_impl;
static struct wlr_gbm_buffer *get_gbm_buffer_from_buffer(
- struct wlr_buffer *buffer) {
- assert(buffer->impl == &buffer_impl);
- return (struct wlr_gbm_buffer *)buffer;
+ struct wlr_buffer *wlr_buffer) {
+ assert(wlr_buffer->impl == &buffer_impl);
+ struct wlr_gbm_buffer *buffer = wl_container_of(wlr_buffer, buffer, base);
+ return buffer;
}
static bool export_gbm_bo(struct gbm_bo *bo,
@@ -179,9 +180,10 @@ static const struct wlr_buffer_impl buffer_impl = {
static const struct wlr_allocator_interface allocator_impl;
static struct wlr_gbm_allocator *get_gbm_alloc_from_alloc(
- struct wlr_allocator *alloc) {
- assert(alloc->impl == &allocator_impl);
- return (struct wlr_gbm_allocator *)alloc;
+ struct wlr_allocator *wlr_alloc) {
+ assert(wlr_alloc->impl == &allocator_impl);
+ struct wlr_gbm_allocator *alloc = wl_container_of(wlr_alloc, alloc, base);
+ return alloc;
}
struct wlr_allocator *wlr_gbm_allocator_create(int fd) {
diff --git a/render/allocator/shm.c b/render/allocator/shm.c
index 55a8fab2..b6d3138c 100644
--- a/render/allocator/shm.c
+++ b/render/allocator/shm.c
@@ -17,7 +17,8 @@ static const struct wlr_buffer_impl buffer_impl;
static struct wlr_shm_buffer *shm_buffer_from_buffer(
struct wlr_buffer *wlr_buffer) {
assert(wlr_buffer->impl == &buffer_impl);
- return (struct wlr_shm_buffer *)wlr_buffer;
+ struct wlr_shm_buffer *buffer = wl_container_of(wlr_buffer, buffer, base);
+ return buffer;
}
static void buffer_destroy(struct wlr_buffer *wlr_buffer) {
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index 9cbc646e..2b6c04b9 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -45,7 +45,8 @@ bool wlr_renderer_is_gles2(struct wlr_renderer *wlr_renderer) {
struct wlr_gles2_renderer *gles2_get_renderer(
struct wlr_renderer *wlr_renderer) {
assert(wlr_renderer_is_gles2(wlr_renderer));
- return (struct wlr_gles2_renderer *)wlr_renderer;
+ struct wlr_gles2_renderer *renderer = wl_container_of(wlr_renderer, renderer, wlr_renderer);
+ return renderer;
}
static struct wlr_gles2_renderer *gles2_get_renderer_in_context(
@@ -634,7 +635,7 @@ static int gles2_get_render_time(struct wlr_render_timer *wlr_timer) {
}
static void gles2_render_timer_destroy(struct wlr_render_timer *wlr_timer) {
- struct wlr_gles2_render_timer *timer = (struct wlr_gles2_render_timer *)wlr_timer;
+ struct wlr_gles2_render_timer *timer = wl_container_of(wlr_timer, timer, base);
struct wlr_gles2_renderer *renderer = timer->renderer;
struct wlr_egl_context prev_ctx;
diff --git a/render/gles2/texture.c b/render/gles2/texture.c
index 4f884d73..6cfd103d 100644
--- a/render/gles2/texture.c
+++ b/render/gles2/texture.c
@@ -25,7 +25,8 @@ bool wlr_texture_is_gles2(struct wlr_texture *wlr_texture) {
struct wlr_gles2_texture *gles2_get_texture(
struct wlr_texture *wlr_texture) {
assert(wlr_texture_is_gles2(wlr_texture));
- return (struct wlr_gles2_texture *)wlr_texture;
+ struct wlr_gles2_texture *texture = wl_container_of(wlr_texture, texture, wlr_texture);
+ return texture;
}
static bool gles2_texture_update_from_buffer(struct wlr_texture *wlr_texture,
diff --git a/render/pixman/renderer.c b/render/pixman/renderer.c
index e7185e56..770f47ca 100644
--- a/render/pixman/renderer.c
+++ b/render/pixman/renderer.c
@@ -20,7 +20,8 @@ bool wlr_renderer_is_pixman(struct wlr_renderer *wlr_renderer) {
static struct wlr_pixman_renderer *get_renderer(
struct wlr_renderer *wlr_renderer) {
assert(wlr_renderer_is_pixman(wlr_renderer));
- return (struct wlr_pixman_renderer *)wlr_renderer;
+ struct wlr_pixman_renderer *renderer = wl_container_of(wlr_renderer, renderer, wlr_renderer);
+ return renderer;
}
bool begin_pixman_data_ptr_access(struct wlr_buffer *wlr_buffer, pixman_image_t **image_ptr,
@@ -76,7 +77,8 @@ bool wlr_texture_is_pixman(struct wlr_texture *texture) {
static struct wlr_pixman_texture *get_texture(
struct wlr_texture *wlr_texture) {
assert(wlr_texture_is_pixman(wlr_texture));
- return (struct wlr_pixman_texture *)wlr_texture;
+ struct wlr_pixman_texture *texture = wl_container_of(wlr_texture, texture, wlr_texture);
+ return texture;
}
static void texture_destroy(struct wlr_texture *wlr_texture) {
diff --git a/render/vulkan/renderer.c b/render/vulkan/renderer.c
index 76da79fe..4419cf2c 100644
--- a/render/vulkan/renderer.c
+++ b/render/vulkan/renderer.c
@@ -52,7 +52,8 @@ bool wlr_renderer_is_vk(struct wlr_renderer *wlr_renderer) {
struct wlr_vk_renderer *vulkan_get_renderer(struct wlr_renderer *wlr_renderer) {
assert(wlr_renderer_is_vk(wlr_renderer));
- return (struct wlr_vk_renderer *)wlr_renderer;
+ struct wlr_vk_renderer *renderer = wl_container_of(wlr_renderer, renderer, wlr_renderer);
+ return renderer;
}
static struct wlr_vk_render_format_setup *find_or_create_render_setup(
diff --git a/render/vulkan/texture.c b/render/vulkan/texture.c
index 083931ff..a72124d2 100644
--- a/render/vulkan/texture.c
+++ b/render/vulkan/texture.c
@@ -22,7 +22,8 @@ bool wlr_texture_is_vk(struct wlr_texture *wlr_texture) {
struct wlr_vk_texture *vulkan_get_texture(struct wlr_texture *wlr_texture) {
assert(wlr_texture_is_vk(wlr_texture));
- return (struct wlr_vk_texture *)wlr_texture;
+ struct wlr_vk_texture *texture = wl_container_of(wlr_texture, texture, wlr_texture);
+ return texture;
}
static VkImageAspectFlagBits mem_plane_aspect(unsigned i) {
diff --git a/types/buffer/client.c b/types/buffer/client.c
index ff25bd29..adec87e1 100644
--- a/types/buffer/client.c
+++ b/types/buffer/client.c
@@ -7,11 +7,12 @@
static const struct wlr_buffer_impl client_buffer_impl;
-struct wlr_client_buffer *wlr_client_buffer_get(struct wlr_buffer *buffer) {
- if (buffer->impl != &client_buffer_impl) {
+struct wlr_client_buffer *wlr_client_buffer_get(struct wlr_buffer *wlr_buffer) {
+ if (wlr_buffer->impl != &client_buffer_impl) {
return NULL;
}
- return (struct wlr_client_buffer *)buffer;
+ struct wlr_client_buffer *buffer = wl_container_of(wlr_buffer, buffer, base);
+ return buffer;
}
static struct wlr_client_buffer *client_buffer_from_buffer(
diff --git a/types/buffer/dmabuf.c b/types/buffer/dmabuf.c
index 5ceb5172..af0c8c5c 100644
--- a/types/buffer/dmabuf.c
+++ b/types/buffer/dmabuf.c
@@ -7,9 +7,10 @@
static const struct wlr_buffer_impl dmabuf_buffer_impl;
static struct wlr_dmabuf_buffer *dmabuf_buffer_from_buffer(
- struct wlr_buffer *buffer) {
- assert(buffer->impl == &dmabuf_buffer_impl);
- return (struct wlr_dmabuf_buffer *)buffer;
+ struct wlr_buffer *wlr_buffer) {
+ assert(wlr_buffer->impl == &dmabuf_buffer_impl);
+ struct wlr_dmabuf_buffer *buffer = wl_container_of(wlr_buffer, buffer, base);
+ return buffer;
}
static void dmabuf_buffer_destroy(struct wlr_buffer *wlr_buffer) {
diff --git a/types/buffer/readonly_data.c b/types/buffer/readonly_data.c
index 205c12ce..f934ddc7 100644
--- a/types/buffer/readonly_data.c
+++ b/types/buffer/readonly_data.c
@@ -8,9 +8,10 @@
static const struct wlr_buffer_impl readonly_data_buffer_impl;
static struct wlr_readonly_data_buffer *readonly_data_buffer_from_buffer(
- struct wlr_buffer *buffer) {
- assert(buffer->impl == &readonly_data_buffer_impl);
- return (struct wlr_readonly_data_buffer *)buffer;
+ struct wlr_buffer *wlr_buffer) {
+ assert(wlr_buffer->impl == &readonly_data_buffer_impl);
+ struct wlr_readonly_data_buffer *buffer = wl_container_of(wlr_buffer, buffer, base);
+ return buffer;
}
static void readonly_data_buffer_destroy(struct wlr_buffer *wlr_buffer) {
diff --git a/types/data_device/wlr_data_source.c b/types/data_device/wlr_data_source.c
index acd2b707..55390464 100644
--- a/types/data_device/wlr_data_source.c
+++ b/types/data_device/wlr_data_source.c
@@ -91,7 +91,8 @@ static void client_data_source_accept(struct wlr_data_source *wlr_source,
static struct wlr_client_data_source *client_data_source_from_wlr_data_source(
struct wlr_data_source *wlr_source) {
assert(wlr_source->impl->accept == client_data_source_accept);
- return (struct wlr_client_data_source *)wlr_source;
+ struct wlr_client_data_source *source = wl_container_of(wlr_source, source, source);
+ return source;
}
static void client_data_source_accept(struct wlr_data_source *wlr_source,
diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c
index a6a786f5..47075f0a 100644
--- a/types/scene/wlr_scene.c
+++ b/types/scene/wlr_scene.c
@@ -52,7 +52,8 @@ struct wlr_scene *scene_node_get_root(struct wlr_scene_node *node) {
while (tree->node.parent != NULL) {
tree = tree->node.parent;
}
- return (struct wlr_scene *)tree;
+ struct wlr_scene *scene = wl_container_of(tree, scene, tree);
+ return scene;
}
static void scene_node_init(struct wlr_scene_node *node,
diff --git a/types/wlr_data_control_v1.c b/types/wlr_data_control_v1.c
index f148fa87..9dac7329 100644
--- a/types/wlr_data_control_v1.c
+++ b/types/wlr_data_control_v1.c
@@ -120,7 +120,8 @@ static const struct wlr_data_source_impl client_source_impl;
static struct client_data_source *
client_data_source_from_source(struct wlr_data_source *wlr_source) {
assert(wlr_source->impl == &client_source_impl);
- return (struct client_data_source *)wlr_source;
+ struct client_data_source *source = wl_container_of(wlr_source, source, source);
+ return source;
}
static void client_source_send(struct wlr_data_source *wlr_source,
@@ -166,7 +167,8 @@ static struct client_primary_selection_source *
client_primary_selection_source_from_source(
struct wlr_primary_selection_source *wlr_source) {
assert(wlr_source->impl == &client_primary_selection_source_impl);
- return (struct client_primary_selection_source *)wlr_source;
+ struct client_primary_selection_source *source = wl_container_of(wlr_source, source, source);
+ return source;
}
static void client_primary_selection_source_send(
diff --git a/types/wlr_drm.c b/types/wlr_drm.c
index 2be70631..8a6521a1 100644
--- a/types/wlr_drm.c
+++ b/types/wlr_drm.c
@@ -27,9 +27,10 @@ static const struct wl_buffer_interface wl_buffer_impl = {
static const struct wlr_buffer_impl buffer_impl;
static struct wlr_drm_buffer *drm_buffer_from_buffer(
- struct wlr_buffer *buffer) {
- assert(buffer->impl == &buffer_impl);
- return (struct wlr_drm_buffer *)buffer;
+ struct wlr_buffer *wlr_buffer) {
+ assert(wlr_buffer->impl == &buffer_impl);
+ struct wlr_drm_buffer *buffer = wl_container_of(wlr_buffer, buffer, base);
+ return buffer;
}
static void buffer_destroy(struct wlr_buffer *wlr_buffer) {
diff --git a/types/wlr_keyboard_group.c b/types/wlr_keyboard_group.c
index 26354584..ac8be385 100644
--- a/types/wlr_keyboard_group.c
+++ b/types/wlr_keyboard_group.c
@@ -64,7 +64,8 @@ struct wlr_keyboard_group *wlr_keyboard_group_from_wlr_keyboard(
if (keyboard->impl != &impl) {
return NULL;
}
- return (struct wlr_keyboard_group *)keyboard;
+ struct wlr_keyboard_group *group = wl_container_of(keyboard, group, keyboard);
+ return group;
}
static bool process_key(struct keyboard_group_device *group_device,
diff --git a/types/wlr_linux_dmabuf_v1.c b/types/wlr_linux_dmabuf_v1.c
index 767c481f..48dc9a34 100644
--- a/types/wlr_linux_dmabuf_v1.c
+++ b/types/wlr_linux_dmabuf_v1.c
@@ -90,9 +90,10 @@ struct wlr_dmabuf_v1_buffer *wlr_dmabuf_v1_buffer_from_buffer_resource(
static const struct wlr_buffer_impl buffer_impl;
static struct wlr_dmabuf_v1_buffer *dmabuf_v1_buffer_from_buffer(
- struct wlr_buffer *buffer) {
- assert(buffer->impl == &buffer_impl);
- return (struct wlr_dmabuf_v1_buffer *)buffer;
+ struct wlr_buffer *wlr_buffer) {
+ assert(wlr_buffer->impl == &buffer_impl);
+ struct wlr_dmabuf_v1_buffer *buffer = wl_container_of(wlr_buffer, buffer, base);
+ return buffer;
}
static void buffer_destroy(struct wlr_buffer *wlr_buffer) {
diff --git a/types/wlr_primary_selection_v1.c b/types/wlr_primary_selection_v1.c
index 218595b2..e4cb514a 100644
--- a/types/wlr_primary_selection_v1.c
+++ b/types/wlr_primary_selection_v1.c
@@ -103,14 +103,14 @@ struct client_data_source {
static void client_source_send(
struct wlr_primary_selection_source *wlr_source,
const char *mime_type, int fd) {
- struct client_data_source *source = (struct client_data_source *)wlr_source;
+ struct client_data_source *source = wl_container_of(wlr_source, source, source);
zwp_primary_selection_source_v1_send_send(source->resource, mime_type, fd);
close(fd);
}
static void client_source_destroy(
struct wlr_primary_selection_source *wlr_source) {
- struct client_data_source *source = (struct client_data_source *)wlr_source;
+ struct client_data_source *source = wl_container_of(wlr_source, source, source);
zwp_primary_selection_source_v1_send_cancelled(source->resource);
// Make the source resource inert
wl_resource_set_user_data(source->resource, NULL);
diff --git a/xwayland/selection/incoming.c b/xwayland/selection/incoming.c
index 791eb5cf..755ce16c 100644
--- a/xwayland/selection/incoming.c
+++ b/xwayland/selection/incoming.c
@@ -257,7 +257,8 @@ bool data_source_is_xwayland(
static struct x11_data_source *data_source_from_wlr_data_source(
struct wlr_data_source *wlr_source) {
assert(data_source_is_xwayland(wlr_source));
- return (struct x11_data_source *)wlr_source;
+ struct x11_data_source *source = wl_container_of(wlr_source, source, base);
+ return source;
}
static void data_source_send(struct wlr_data_source *wlr_source,
@@ -299,8 +300,7 @@ bool primary_selection_source_is_xwayland(
static void primary_selection_source_send(
struct wlr_primary_selection_source *wlr_source,
const char *mime_type, int fd) {
- struct x11_primary_selection_source *source =
- (struct x11_primary_selection_source *)wlr_source;
+ struct x11_primary_selection_source *source = wl_container_of(wlr_source, source, base);
struct wlr_xwm_selection *selection = source->selection;
source_send(selection, &wlr_source->mime_types, &source->mime_types_atoms,
@@ -309,8 +309,7 @@ static void primary_selection_source_send(
static void primary_selection_source_destroy(
struct wlr_primary_selection_source *wlr_source) {
- struct x11_primary_selection_source *source =
- (struct x11_primary_selection_source *)wlr_source;
+ struct x11_primary_selection_source *source = wl_container_of(wlr_source, source, base);
wl_array_release(&source->mime_types_atoms);
free(source);
}