mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-21 20:35:58 +01:00
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]'
This commit is contained in:
parent
c2c536de03
commit
fe06e5f49a
29 changed files with 85 additions and 55 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue