Refactor wlr_list inside wlroots

This commit is contained in:
emersion 2017-11-19 00:17:40 +01:00
parent fa36ac90f7
commit 016744ef4d
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
9 changed files with 87 additions and 82 deletions

View file

@ -14,7 +14,6 @@
#include <wlr/backend/drm.h>
#include <wlr/types/wlr_output.h>
#include <wlr/render/egl.h>
#include <wlr/types/wlr_list.h>
#include "iface.h"
#include "properties.h"

View file

@ -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 {

View file

@ -2,6 +2,7 @@
#define WLR_UTIL_LIST_H
#include <stddef.h>
#include <stdbool.h>
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);
/**
* Deinitialize a list.
*/
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_add(struct wlr_list *list, void *item);
ssize_t wlr_list_push(struct wlr_list *list, void *item);
/**
* Add `item` to the end of a 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_push(struct wlr_list *list, void *item);
ssize_t wlr_list_insert(struct wlr_list *list, size_t index, void *item);
/**
* 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);
/**
* 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
* 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);
ssize_t wlr_list_cat(struct wlr_list *list, const struct wlr_list *source);
/**
* 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

View file

@ -5,7 +5,6 @@
#include <stdbool.h>
#include <wlr/types/wlr_compositor.h>
#include <xcb/xcb.h>
#include <wlr/types/wlr_list.h>
#ifdef HAS_XCB_ICCCM
#include <xcb/xcb_icccm.h>
@ -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;