mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-02 09:01:38 -05:00
Rename remaining refs to wlr_list
This commit is contained in:
parent
d3f0878d71
commit
169b68b17c
14 changed files with 51 additions and 51 deletions
|
|
@ -1,15 +1,20 @@
|
|||
lib_wlr_types = static_library(
|
||||
'wlr_types',
|
||||
files(
|
||||
'wlr_box.c',
|
||||
'wlr_compositor.c',
|
||||
'wlr_cursor.c',
|
||||
'wlr_data_device_manager.c',
|
||||
'wlr_data_source.c',
|
||||
'wlr_gamma_control.c',
|
||||
'wlr_input_device.c',
|
||||
'wlr_keyboard.c',
|
||||
'wlr_list.c',
|
||||
'wlr_output.c',
|
||||
'wlr_output_layout.c',
|
||||
'wlr_pointer.c',
|
||||
'wlr_cursor.c',
|
||||
'wlr_region.c',
|
||||
'wlr_screenshooter.c',
|
||||
'wlr_seat.c',
|
||||
'wlr_surface.c',
|
||||
'wlr_tablet_pad.c',
|
||||
|
|
@ -17,10 +22,6 @@ lib_wlr_types = static_library(
|
|||
'wlr_touch.c',
|
||||
'wlr_xdg_shell_v6.c',
|
||||
'wlr_wl_shell.c',
|
||||
'wlr_compositor.c',
|
||||
'wlr_box.c',
|
||||
'wlr_gamma_control.c',
|
||||
'wlr_screenshooter.c',
|
||||
),
|
||||
include_directories: wlr_inc,
|
||||
dependencies: [wayland_server, pixman, wlr_protos],
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/util/list.h>
|
||||
#include <wlr/types/wlr_list.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <wlr/types/wlr_data_source.h>
|
||||
#include <wlr/types/wlr_data_device_manager.h>
|
||||
|
|
|
|||
115
types/wlr_list.c
Normal file
115
types/wlr_list.c
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <wlr/types/wlr_list.h>
|
||||
|
||||
struct wlr_list *list_create(void) {
|
||||
struct wlr_list *list = malloc(sizeof(struct wlr_list));
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
list->capacity = 10;
|
||||
list->length = 0;
|
||||
list->items = malloc(sizeof(void*) * list->capacity);
|
||||
if (!list->items) {
|
||||
free(list);
|
||||
return NULL;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static bool list_resize(struct wlr_list *list) {
|
||||
if (list->length == list->capacity) {
|
||||
void *new_items = realloc(list->items, sizeof(void*) * (list->capacity + 10));
|
||||
if (!new_items) {
|
||||
return false;
|
||||
}
|
||||
list->capacity += 10;
|
||||
list->items = new_items;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void list_free(struct wlr_list *list) {
|
||||
if (list == NULL) {
|
||||
return;
|
||||
}
|
||||
free(list->items);
|
||||
free(list);
|
||||
}
|
||||
|
||||
void list_foreach(struct wlr_list *list, void (*callback)(void *item)) {
|
||||
if (list == NULL || callback == NULL) {
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < list->length; i++) {
|
||||
callback(list->items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int list_add(struct wlr_list *list, void *item) {
|
||||
if (!list_resize(list)) {
|
||||
return -1;
|
||||
}
|
||||
list->items[list->length++] = item;
|
||||
return list->length;
|
||||
}
|
||||
|
||||
int list_push(struct wlr_list *list, void *item) {
|
||||
return list_add(list, item);
|
||||
}
|
||||
|
||||
int list_insert(struct wlr_list *list, size_t index, void *item) {
|
||||
if (!list_resize(list)) {
|
||||
return -1;
|
||||
}
|
||||
memmove(&list->items[index + 1], &list->items[index], sizeof(void*) * (list->length - index));
|
||||
list->length++;
|
||||
list->items[index] = item;
|
||||
return list->length;
|
||||
}
|
||||
|
||||
void 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 *_ = list->items[list->length - 1];
|
||||
list_del(list, list->length - 1);
|
||||
return _;
|
||||
}
|
||||
|
||||
void *list_peek(struct wlr_list *list) {
|
||||
return list->items[list->length - 1];
|
||||
}
|
||||
|
||||
int 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) {
|
||||
list->length = old_len;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return list->length;
|
||||
}
|
||||
|
||||
void 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 compare(const void *item, const void *data),
|
||||
const void *data) {
|
||||
for (size_t i = 0; i < list->length; i++) {
|
||||
void *item = list->items[i];
|
||||
if (compare(item, data) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
#include <wlr/interfaces/wlr_output.h>
|
||||
#include <wlr/util/list.h>
|
||||
#include <wlr/types/wlr_list.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <wlr/render/matrix.h>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue