diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index b278b8f7..781314a3 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -105,9 +105,9 @@ static void wlr_libinput_backend_destroy(struct wlr_backend *_backend) { wl_signal_emit(&backend->backend.events.input_remove, wlr_dev); wlr_input_device_destroy(wlr_dev); } - list_free(wlr_devices); + wlr_list_free(wlr_devices); } - list_free(backend->wlr_device_lists); + wlr_list_free(backend->wlr_device_lists); wl_event_source_remove(backend->input_event); libinput_unref(backend->libinput_context); free(backend); @@ -148,7 +148,7 @@ struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display, } wlr_backend_init(&backend->backend, &backend_impl); - if (!(backend->wlr_device_lists = list_create())) { + if (!(backend->wlr_device_lists = wlr_list_create())) { wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno)); goto error_backend; } diff --git a/backend/libinput/events.c b/backend/libinput/events.c index f6634814..053cab02 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -145,7 +145,7 @@ static void handle_device_added(struct wlr_libinput_backend *backend, if (wl_list_length(wlr_devices) > 0) { libinput_device_set_user_data(libinput_dev, wlr_devices); - list_add(backend->wlr_device_lists, wlr_devices); + wlr_list_add(backend->wlr_device_lists, wlr_devices); } else { free(wlr_devices); } @@ -177,7 +177,7 @@ static void handle_device_removed(struct wlr_libinput_backend *backend, } for (size_t i = 0; i < backend->wlr_device_lists->length; i++) { if (backend->wlr_device_lists->items[i] == wlr_devices) { - list_del(backend->wlr_device_lists, i); + wlr_list_del(backend->wlr_device_lists, i); break; } } diff --git a/examples/pointer.c b/examples/pointer.c index 8c3c8b85..66598ad4 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -213,7 +213,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) { for (size_t i = 0; i < sample->touch_points->length; ++i) { struct touch_point *point = sample->touch_points->items[i]; if (point->slot == event->slot) { - list_del(sample->touch_points, i); + wlr_list_del(sample->touch_points, i); break; } } @@ -228,7 +228,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { point->slot = event->slot; point->x = event->x_mm / event->width_mm; point->y = event->y_mm / event->height_mm; - if (list_add(sample->touch_points, point) == -1) { + if (wlr_list_add(sample->touch_points, point) == -1) { free(point); } @@ -270,7 +270,7 @@ int main(int argc, char *argv[]) { struct sample_state state = { .default_color = { 0.25f, 0.25f, 0.25f, 1 }, .clear_color = { 0.25f, 0.25f, 0.25f, 1 }, - .touch_points = list_create(), + .touch_points = wlr_list_create(), }; state.config = parse_args(argc, argv); diff --git a/examples/touch.c b/examples/touch.c index 60fb0ae4..3f0c4867 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -65,7 +65,7 @@ static void handle_touch_down(struct touch_state *tstate, int32_t slot, point->slot = slot; point->x = x / width; point->y = y / height; - if (list_add(sample->touch_points, point) == -1) { + if (wlr_list_add(sample->touch_points, point) == -1) { free(point); } } @@ -75,7 +75,7 @@ static void handle_touch_up(struct touch_state *tstate, int32_t slot) { for (size_t i = 0; i < sample->touch_points->length; ++i) { struct touch_point *point = sample->touch_points->items[i]; if (point->slot == slot) { - list_del(sample->touch_points, i); + wlr_list_del(sample->touch_points, i); break; } } @@ -96,7 +96,7 @@ static void handle_touch_motion(struct touch_state *tstate, int32_t slot, int main(int argc, char *argv[]) { struct sample_state state = { - .touch_points = list_create() + .touch_points = wlr_list_create() }; struct compositor_state compositor = { 0, .data = &state, diff --git a/include/wlr/types/wlr_list.h b/include/wlr/types/wlr_list.h index 6a4fe863..8ddd30b6 100644 --- a/include/wlr/types/wlr_list.h +++ b/include/wlr/types/wlr_list.h @@ -12,48 +12,48 @@ struct wlr_list { /** * Creates a new list, may return `NULL` on failure */ -struct wlr_list *list_create(void); -void list_free(struct wlr_list *list); -void list_foreach(struct wlr_list *list, void (*callback)(void *item)); +struct wlr_list *wlr_list_create(void); +void wlr_list_free(struct wlr_list *list); +void wlr_list_foreach(struct wlr_list *list, void (*callback)(void *item)); /** * Add `item` to the end of a list. * Returns: new list length or `-1` on failure */ -int list_add(struct wlr_list *list, void *item); +int wlr_list_add(struct wlr_list *list, void *item); /** * Add `item` to the end of a list. * Returns: new list length or `-1` on failure */ -int list_push(struct wlr_list *list, void *item); +int wlr_list_push(struct wlr_list *list, void *item); /** * Place `item` into index `index` in the list * Returns: new list length or `-1` on failure */ -int list_insert(struct wlr_list *list, size_t index, void *item); +int wlr_list_insert(struct wlr_list *list, size_t index, void *item); /** * Remove an item from the list */ -void list_del(struct wlr_list *list, size_t index); +void wlr_list_del(struct wlr_list *list, size_t index); /** * Remove and return an item from the end of the list */ -void *list_pop(struct wlr_list *list); +void *wlr_list_pop(struct wlr_list *list); /** * Get a reference to the last item of a list without removal */ -void *list_peek(struct wlr_list *list); +void *wlr_list_peek(struct wlr_list *list); /** * Append each item in `source` to `list` * Does not modify `source` * Returns: new list length or `-1` on failure */ -int list_cat(struct wlr_list *list, struct wlr_list *source); +int wlr_list_cat(struct wlr_list *list, struct wlr_list *source); // See qsort. Remember to use *_qsort functions as compare functions, // because they dereference the left and right arguments first! -void list_qsort(struct wlr_list *list, int compare(const void *left, const void *right)); +void wlr_list_qsort(struct wlr_list *list, int compare(const void *left, const void *right)); // Return index for first item in list that returns 0 for given compare // function or -1 if none matches. -int list_seq_find(struct wlr_list *list, +int wlr_list_seq_find(struct wlr_list *list, int compare(const void *item, const void *cmp_to), const void *cmp_to); diff --git a/rootston/cursor.c b/rootston/cursor.c index 3be4c2a6..2a3a7c25 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -183,8 +183,8 @@ void set_view_focus(struct roots_input *input, struct roots_desktop *desktop, } view_activate(view, true); // TODO: list_swap - list_del(desktop->views, index); - list_add(desktop->views, view); + wlr_list_del(desktop->views, index); + wlr_list_add(desktop->views, view); } static void handle_cursor_motion(struct wl_listener *listener, void *data) { diff --git a/rootston/desktop.c b/rootston/desktop.c index 70767f92..40d088b8 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -29,7 +29,7 @@ void view_destroy(struct roots_view *view) { for (size_t i = 0; i < desktop->views->length; ++i) { struct roots_view *_view = desktop->views->items[i]; if (view == _view) { - list_del(desktop->views, i); + wlr_list_del(desktop->views, i); break; } } @@ -209,7 +209,7 @@ struct roots_desktop *desktop_create(struct roots_server *server, return NULL; } - desktop->views = list_create(); + desktop->views = wlr_list_create(); if (desktop->views == NULL) { free(desktop); return NULL; diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 248514f0..88397af8 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -110,12 +110,12 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { view->close = close; view->desktop = desktop; roots_surface->view = view; - list_add(desktop->views, view); + wlr_list_add(desktop->views, view); view_initialize(view); if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) { // we need to map it relative to the parent - int i = list_seq_find(desktop->views, shell_surface_compare_equals, + int i = wlr_list_seq_find(desktop->views, shell_surface_compare_equals, surface->parent); if (i != -1) { struct roots_view *parent = desktop->views->items[i]; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 028545df..95b20a8b 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -124,7 +124,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->close = close; view->desktop = desktop; roots_surface->view = view; - list_add(desktop->views, view); + wlr_list_add(desktop->views, view); view_initialize(view); } diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 6ef33403..1149b966 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -98,7 +98,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->set_position = set_position; view->close = close; roots_surface->view = view; - list_add(desktop->views, view); + wlr_list_add(desktop->views, view); if (!surface->override_redirect) { view_initialize(view); diff --git a/types/wlr_data_source.c b/types/wlr_data_source.c index 2c227778..98de4f97 100644 --- a/types/wlr_data_source.c +++ b/types/wlr_data_source.c @@ -14,16 +14,16 @@ bool wlr_data_source_init(struct wlr_data_source *source, struct wlr_data_source_impl *impl) { source->impl = impl; wl_signal_init(&source->events.destroy); - return (source->types = list_create()); + return (source->types = wlr_list_create()); } void wlr_data_source_finish(struct wlr_data_source *source) { if (source) { wl_signal_emit(&source->events.destroy, source); if (source->types) { - list_foreach(source->types, free); + wlr_list_foreach(source->types, free); } - list_free(source->types); + wlr_list_free(source->types); } } @@ -81,7 +81,7 @@ static void data_source_offer(struct wl_client *client, return; } - list_add(src->base.types, dtype); + wlr_list_add(src->base.types, dtype); } static void data_source_destroy(struct wl_client *client, diff --git a/types/wlr_list.c b/types/wlr_list.c index 365ad236..33e3ea8a 100644 --- a/types/wlr_list.c +++ b/types/wlr_list.c @@ -5,7 +5,7 @@ #include #include -struct wlr_list *list_create(void) { +struct wlr_list *wlr_list_create(void) { struct wlr_list *list = malloc(sizeof(struct wlr_list)); if (!list) { return NULL; @@ -32,7 +32,7 @@ static bool list_resize(struct wlr_list *list) { return true; } -void list_free(struct wlr_list *list) { +void wlr_list_free(struct wlr_list *list) { if (list == NULL) { return; } @@ -40,7 +40,7 @@ void list_free(struct wlr_list *list) { free(list); } -void list_foreach(struct wlr_list *list, void (*callback)(void *item)) { +void wlr_list_foreach(struct wlr_list *list, void (*callback)(void *item)) { if (list == NULL || callback == NULL) { return; } @@ -49,7 +49,7 @@ void list_foreach(struct wlr_list *list, void (*callback)(void *item)) { } } -int list_add(struct wlr_list *list, void *item) { +int wlr_list_add(struct wlr_list *list, void *item) { if (!list_resize(list)) { return -1; } @@ -57,11 +57,11 @@ int list_add(struct wlr_list *list, void *item) { return list->length; } -int list_push(struct wlr_list *list, void *item) { - return list_add(list, item); +int wlr_list_push(struct wlr_list *list, void *item) { + return wlr_list_add(list, item); } -int list_insert(struct wlr_list *list, size_t index, void *item) { +int wlr_list_insert(struct wlr_list *list, size_t index, void *item) { if (!list_resize(list)) { return -1; } @@ -71,26 +71,26 @@ int list_insert(struct wlr_list *list, size_t index, void *item) { return list->length; } -void list_del(struct wlr_list *list, size_t index) { +void wlr_list_del(struct wlr_list *list, size_t index) { list->length--; memmove(&list->items[index], &list->items[index + 1], sizeof(void*) * (list->length - index)); } -void *list_pop(struct wlr_list *list) { +void *wlr_list_pop(struct wlr_list *list) { void *_ = list->items[list->length - 1]; - list_del(list, list->length - 1); + wlr_list_del(list, list->length - 1); return _; } -void *list_peek(struct wlr_list *list) { +void *wlr_list_peek(struct wlr_list *list) { return list->items[list->length - 1]; } -int list_cat(struct wlr_list *list, struct wlr_list *source) { +int wlr_list_cat(struct wlr_list *list, struct wlr_list *source) { size_t old_len = list->length; size_t i; for (i = 0; i < source->length; ++i) { - if (list_add(list, source->items[i]) == -1) { + if (wlr_list_add(list, source->items[i]) == -1) { list->length = old_len; return -1; } @@ -98,11 +98,11 @@ int list_cat(struct wlr_list *list, struct wlr_list *source) { return list->length; } -void list_qsort(struct wlr_list *list, int compare(const void *left, const void *right)) { +void wlr_list_qsort(struct wlr_list *list, int compare(const void *left, const void *right)) { qsort(list->items, list->length, sizeof(void *), compare); } -int list_seq_find(struct wlr_list *list, +int wlr_list_seq_find(struct wlr_list *list, int compare(const void *item, const void *data), const void *data) { for (size_t i = 0; i < list->length; i++) { diff --git a/xwayland/xwm.c b/xwayland/xwm.c index bc1bb4de..f58acb73 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -71,7 +71,7 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( surface->height = height; surface->override_redirect = override_redirect; wl_list_insert(&xwm->new_surfaces, &surface->link); - surface->state = list_create(); + surface->state = wlr_list_create(); wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.request_configure); wl_signal_init(&surface->events.set_class); @@ -92,7 +92,7 @@ static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) { free(surface->title); free(surface->class); free(surface->instance); - list_free(surface->state); + wlr_list_free(surface->state); free(surface->window_type); free(surface->protocols); free(surface->hints); @@ -199,7 +199,7 @@ static void handle_surface_state(struct wlr_xwm *xwm, if (action == NET_WM_STATE_REMOVE || action == NET_WM_STATE_TOGGLE) { free(surface->state->items[j]); - list_del(surface->state, j); + wlr_list_del(surface->state, j); } break; } @@ -209,7 +209,7 @@ static void handle_surface_state(struct wlr_xwm *xwm, action == NET_WM_STATE_TOGGLE)) { xcb_atom_t *atom_ptr = malloc(sizeof(xcb_atom_t)); *atom_ptr = atom; - list_add(surface->state, atom_ptr); + wlr_list_add(surface->state, atom_ptr); } }