From 1d716241afbc721c3ae65d4a2bb0e25866fe081c Mon Sep 17 00:00:00 2001 From: Heghedus Razvan Date: Sun, 15 Oct 2017 13:32:37 +0300 Subject: [PATCH] Replace list_t with wl_list in wlr_output Signed-off-by: Heghedus Razvan --- backend/drm/drm.c | 6 +----- examples/shared.c | 6 ++++-- include/wlr/types/wlr_output.h | 4 ++-- rootston/output.c | 8 +++++--- types/wlr_output.c | 14 +++++++------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 74a63f79..60ac8e3e 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -782,11 +782,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { mode->wlr_mode.width, mode->wlr_mode.height, mode->wlr_mode.refresh); - if (list_add(wlr_conn->output.modes, mode) == -1) { - wlr_log_errno(L_ERROR, "Allocation failed"); - free(mode); - continue; - } + wl_list_insert(&wlr_conn->output.modes, &mode->wlr_mode.link); } wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET; diff --git a/examples/shared.c b/examples/shared.c index bb1d2737..d9f9ae61 100644 --- a/examples/shared.c +++ b/examples/shared.c @@ -427,8 +427,10 @@ static void output_add_notify(struct wl_listener *listener, void *data) { wlr_log(L_DEBUG, "Output '%s' added", output->name); wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", output->make, output->model, output->phys_width, output->phys_height); - if (output->modes->length > 0) { - wlr_output_set_mode(output, output->modes->items[0]); + if (wl_list_length(&output->modes) > 0) { + struct wlr_output_mode *mode = NULL; + wl_container_of((&output->modes)->prev, mode, link); + wlr_output_set_mode(output, mode); } struct output_state *ostate = calloc(1, sizeof(struct output_state)); clock_gettime(CLOCK_MONOTONIC, &ostate->last_frame); diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index dc637e26..15df4efd 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -2,13 +2,13 @@ #define WLR_TYPES_WLR_OUTPUT_H #include -#include #include struct wlr_output_mode { uint32_t flags; // enum wl_output_mode int32_t width, height; int32_t refresh; // mHz + struct wl_list link; }; struct wlr_output_impl; @@ -32,7 +32,7 @@ struct wlr_output { float transform_matrix[16]; /* Note: some backends may have zero modes */ - list_t *modes; + struct wl_list modes; struct wlr_output_mode *current_mode; struct { diff --git a/rootston/output.c b/rootston/output.c index 39a90fe3..95e052fb 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -166,9 +166,11 @@ void output_add_notify(struct wl_listener *listener, void *data) { wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", wlr_output->make, wlr_output->model, wlr_output->phys_width, wlr_output->phys_height); - if (wlr_output->modes->length > 0) { - wlr_output_set_mode(wlr_output, wlr_output->modes->items[0]); - } + if (wl_list_length(&wlr_output->modes) > 0) { + struct wlr_output_mode *mode = NULL; + mode = wl_container_of((&wlr_output->modes)->prev, mode, link); + wlr_output_set_mode(wlr_output, mode); + } struct roots_output *output = calloc(1, sizeof(struct roots_output)); clock_gettime(CLOCK_MONOTONIC, &output->last_frame); diff --git a/types/wlr_output.c b/types/wlr_output.c index eb969b9a..82e04ebf 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -26,8 +26,8 @@ static void wl_output_send_to_resource(struct wl_resource *resource) { output->make, output->model, output->transform); } if (version >= WL_OUTPUT_MODE_SINCE_VERSION) { - for (size_t i = 0; i < output->modes->length; ++i) { - struct wlr_output_mode *mode = output->modes->items[i]; + struct wlr_output_mode *mode; + wl_list_for_each(mode, &output->modes, link) { // TODO: mode->flags should just be preferred uint32_t flags = mode->flags; if (output->current_mode == mode) { @@ -37,7 +37,7 @@ static void wl_output_send_to_resource(struct wl_resource *resource) { mode->width, mode->height, mode->refresh); } - if (output->modes->length == 0) { + if (wl_list_length(&output->modes) == 0) { // Output has no mode, send the current width/height wl_output_send_mode(resource, WL_OUTPUT_MODE_CURRENT, output->width, output->height, 0); @@ -296,7 +296,7 @@ bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) { void wlr_output_init(struct wlr_output *output, const struct wlr_output_impl *impl) { output->impl = impl; - output->modes = list_create(); + wl_list_init(&output->modes); output->transform = WL_OUTPUT_TRANSFORM_NORMAL; output->scale = 1; wl_signal_init(&output->events.frame); @@ -320,11 +320,11 @@ void wlr_output_destroy(struct wlr_output *output) { wlr_texture_destroy(output->cursor.texture); wlr_renderer_destroy(output->cursor.renderer); - for (size_t i = 0; output->modes && i < output->modes->length; ++i) { - struct wlr_output_mode *mode = output->modes->items[i]; + struct wlr_output_mode *mode, *tmp_mode; + wl_list_for_each_safe(mode, tmp_mode, &output->modes, link) { free(mode); } - list_free(output->modes); + wl_list_remove(&output->modes); if (output->impl && output->impl->destroy) { output->impl->destroy(output); } else {