From 016744ef4d2692c800d613e40fbf5d6267fab2e9 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 19 Nov 2017 00:17:40 +0100 Subject: Refactor wlr_list inside wlroots --- include/backend/drm/drm.h | 1 - include/backend/libinput.h | 2 +- include/wlr/types/wlr_list.h | 71 +++++++++++++++++++++++++++----------------- include/wlr/xwayland.h | 2 -- 4 files changed, 44 insertions(+), 32 deletions(-) (limited to 'include') diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index e08965e5..4fad9678 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -14,7 +14,6 @@ #include #include #include -#include #include "iface.h" #include "properties.h" diff --git a/include/backend/libinput.h b/include/backend/libinput.h index 93b859a7..be2557ed 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -18,7 +18,7 @@ struct wlr_libinput_backend { struct wl_listener session_signal; - struct wlr_list *wlr_device_lists; + struct wlr_list wlr_device_lists; // list of struct wl_list }; struct wlr_libinput_input_device { diff --git a/include/wlr/types/wlr_list.h b/include/wlr/types/wlr_list.h index 8ddd30b6..78a30995 100644 --- a/include/wlr/types/wlr_list.h +++ b/include/wlr/types/wlr_list.h @@ -2,6 +2,7 @@ #define WLR_UTIL_LIST_H #include +#include struct wlr_list { size_t capacity; @@ -10,51 +11,65 @@ struct wlr_list { }; /** - * Creates a new list, may return `NULL` on failure + * Initialize a list. Returns true on success, false on failure. */ -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)); +bool wlr_list_init(struct wlr_list *list); + /** - * Add `item` to the end of a list. - * Returns: new list length or `-1` on failure + * Deinitialize a list. */ -int wlr_list_add(struct wlr_list *list, void *item); +void wlr_list_finish(struct wlr_list *list); + +/** + * Executes `callback` on each element in the list. + */ +void wlr_list_for_each(struct wlr_list *list, void (*callback)(void *item)); + /** * Add `item` to the end of a list. - * Returns: new list length or `-1` on failure + * Returns: new list length or `-1` on failure. */ -int wlr_list_push(struct wlr_list *list, void *item); +ssize_t 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 + * Place `item` into index `index` in the list. + * Returns: new list length or `-1` on failure. */ -int wlr_list_insert(struct wlr_list *list, size_t index, void *item); +ssize_t wlr_list_insert(struct wlr_list *list, size_t index, void *item); + /** - * Remove an item from the list + * Remove an item from the list. */ void wlr_list_del(struct wlr_list *list, size_t index); + /** - * Remove and return an item from the end of the list + * Remove and return an item from the end of the list. */ void *wlr_list_pop(struct wlr_list *list); + /** - * Get a reference to the last item of a list without removal + * Get a reference to the last item of a list without removal. */ 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. + */ +ssize_t wlr_list_cat(struct wlr_list *list, const struct wlr_list *source); + /** - * Append each item in `source` to `list` - * Does not modify `source` - * Returns: new list length or `-1` on failure - */ -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 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 wlr_list_seq_find(struct wlr_list *list, - int compare(const void *item, const void *cmp_to), - const void *cmp_to); + * Sort a list using `qsort`. + */ +void wlr_list_qsort(struct wlr_list *list, + int compare(const void *left, const void *right)); + +/** + * Return the index of the first item in the list that returns 0 for the given + * `compare` function, or -1 if none matches. + */ +ssize_t wlr_list_find(struct wlr_list *list, + int compare(const void *item, const void *cmp_to), const void *cmp_to); #endif diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 6518b703..9b493d88 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -5,7 +5,6 @@ #include #include #include -#include #ifdef HAS_XCB_ICCCM #include @@ -86,7 +85,6 @@ struct wlr_xwayland_surface { char *class; char *instance; struct wlr_xwayland_surface *parent; - struct wlr_list *state; // list of xcb_atom_t pid_t pid; xcb_atom_t *window_type; -- cgit v1.2.3