From d3f0878d716011bf158b49b063f9391080c22c8a Mon Sep 17 00:00:00 2001 From: Heghedus Razvan Date: Sat, 14 Oct 2017 23:33:00 +0300 Subject: [PATCH] Replace list_t with wl_list in wlr_wl_backend Now wlr_backend->outputs is a list of wlr_wl_backend_output instead of wlr_output. Signed-off-by: Heghedus Razvan --- backend/wayland/backend.c | 35 ++++++++++------------------------ backend/wayland/output.c | 9 +++------ backend/wayland/wl_seat.c | 6 +----- include/backend/wayland.h | 7 ++++--- include/wlr/types/wlr_output.h | 1 + 5 files changed, 19 insertions(+), 39 deletions(-) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index e57f3583..84624bfe 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -64,16 +64,16 @@ static void wlr_wl_backend_destroy(struct wlr_backend *_backend) { return; } - for (size_t i = 0; i < backend->outputs->length; ++i) { - wlr_output_destroy(backend->outputs->items[i]); + struct wlr_wl_backend_output *output, *tmp_output; + wl_list_for_each_safe(output, tmp_output, &backend->outputs, link) { + wlr_output_destroy(&output->wlr_output); } - for (size_t i = 0; i < backend->devices->length; ++i) { - wlr_input_device_destroy(backend->devices->items[i]); + struct wlr_input_device *input_device, *tmp_input_device; + wl_list_for_each_safe(input_device, tmp_input_device, &backend->devices, link) { + wlr_input_device_destroy(input_device); } - list_free(backend->devices); - list_free(backend->outputs); free(backend->seat_name); wl_event_source_remove(backend->remote_display_src); @@ -104,8 +104,8 @@ bool wlr_backend_is_wl(struct wlr_backend *b) { struct wlr_wl_backend_output *wlr_wl_output_for_surface( struct wlr_wl_backend *backend, struct wl_surface *surface) { - for (size_t i = 0; i < backend->outputs->length; ++i) { - struct wlr_wl_backend_output *output = backend->outputs->items[i]; + struct wlr_wl_backend_output *output; + wl_list_for_each(output, &backend->outputs, link) { if (output->surface == surface) { return output; } @@ -123,15 +123,8 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) { } wlr_backend_init(&backend->backend, &backend_impl); - if (!(backend->devices = list_create())) { - wlr_log(L_ERROR, "Could not allocate devices list"); - goto error; - } - - if (!(backend->outputs = list_create())) { - wlr_log(L_ERROR, "Could not allocate outputs list"); - goto error; - } + wl_list_init(&backend->devices); + wl_list_init(&backend->outputs); backend->local_display = display; @@ -150,12 +143,4 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) { wlr_egl_bind_display(&backend->egl, backend->local_display); return &backend->backend; - -error: - if (backend) { - list_free(backend->devices); - list_free(backend->outputs); - } - free(backend); - return NULL; } diff --git a/backend/wayland/output.c b/backend/wayland/output.c index e1138ee1..1a0f0364 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -248,8 +248,8 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { wlr_output->height = 480; strncpy(wlr_output->make, "wayland", sizeof(wlr_output->make)); strncpy(wlr_output->model, "wayland", sizeof(wlr_output->model)); - snprintf(wlr_output->name, sizeof(wlr_output->name), "WL-%zd", - backend->outputs->length + 1); + snprintf(wlr_output->name, sizeof(wlr_output->name), "WL-%d", + wl_list_length(&backend->outputs) + 1); wlr_output_update_matrix(wlr_output); output->backend = backend; @@ -306,10 +306,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { goto error; } - if (list_add(backend->outputs, wlr_output) == -1) { - wlr_log(L_ERROR, "Allocation failed"); - goto error; - } + wl_list_insert(&backend->outputs, &output->link); wlr_output_create_global(wlr_output, backend->local_display); wl_signal_emit(&backend->backend.events.output_add, wlr_output); return wlr_output; diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index d3ff9b64..30074abd 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -204,11 +204,7 @@ static struct wlr_input_device *allocate_device(struct wlr_wl_backend *backend, struct wlr_input_device *wlr_device = &wlr_wl_dev->wlr_input_device; wlr_input_device_init(wlr_device, type, &input_device_impl, name, vendor, product); - if (list_add(backend->devices, wlr_device) == -1) { - wlr_log_errno(L_ERROR, "Allocation failed"); - free(wlr_wl_dev); - return NULL; - } + wl_list_insert(&backend->devices, &wlr_device->link); return wlr_device; } diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 508a7f52..bc3b6277 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include struct wlr_wl_backend { struct wlr_backend backend; @@ -17,8 +17,8 @@ struct wlr_wl_backend { /* local state */ bool started; struct wl_display *local_display; - list_t *devices; - list_t *outputs; + struct wl_list devices; + struct wl_list outputs; struct wlr_egl egl; size_t requested_outputs; /* remote state */ @@ -51,6 +51,7 @@ struct wlr_wl_backend_output { uint32_t enter_serial; void *egl_surface; + struct wl_list link; }; struct wlr_wl_input_device { diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 15df4efd..5c85ce91 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -1,6 +1,7 @@ #ifndef WLR_TYPES_WLR_OUTPUT_H #define WLR_TYPES_WLR_OUTPUT_H +#include #include #include