This commit is contained in:
ascent12 2017-06-07 00:36:32 +00:00 committed by GitHub
commit d67a004989
56 changed files with 1125 additions and 955 deletions

View file

@ -1,134 +1,271 @@
#include "list.h"
#include <stdio.h>
#include "log.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
list_t *create_list(void) {
list_t *list = malloc(sizeof(list_t));
list_t *list_new(size_t memb_size, size_t capacity) {
if (capacity == 0) {
capacity = 8;
}
list_t *list = malloc(sizeof(*list));
if (!list) {
return NULL;
}
list->capacity = 10;
list->capacity = capacity;
list->length = 0;
list->items = malloc(sizeof(void*) * list->capacity);
list->memb_size = memb_size;
list->items = malloc(memb_size * capacity);
if (!list->items) {
free(list);
return NULL;
}
return list;
}
static void list_resize(list_t *list) {
if (list->length == list->capacity) {
list->capacity += 10;
list->items = realloc(list->items, sizeof(void*) * list->capacity);
}
}
void list_free(list_t *list) {
if (list == NULL) {
if (!list) {
return;
}
free(list->items);
free(list);
}
void list_foreach(list_t *list, void (*callback)(void *item)) {
if (list == NULL || callback == NULL) {
static bool resize(list_t *list) {
if (list->length < list->capacity) {
return true;
}
size_t new_cap = list->capacity * 2;
void *items = realloc(list->items, list->memb_size * new_cap);
if (!items) {
return false;
}
list->items = items;
list->capacity = new_cap;
return true;
}
void list_insert(list_t *list, size_t index, const void *data) {
if (!sway_assert(list && data && index <= list->length, "Invalid argument") ||
!resize(list)) {
return;
}
for (int i = 0; i < list->length; i++) {
callback(list->items[i]);
size_t size = list->memb_size;
uint8_t (*array)[size] = list->items;
memmove(&array[index + 1], &array[index], size * (list->length - index));
memcpy(&array[index], data, size);
++list->length;
}
void list_add(list_t *list, const void *data) {
if (!sway_assert(list && data, "Invalid argument")) {
return;
}
list_insert(list, list->length, data);
}
static void shrink(list_t *list) {
/* We shrink very sparse lists, but only down to a certain size.
* The choice of >= 8 is somewhat arbitrary, but leaves a minimum
* size of 4 elements.
*/
if (list->length <= list->capacity / 4 && list->capacity >= 8) {
size_t new_cap = list->capacity / 2;
void *items = realloc(list->items, list->memb_size * new_cap);
if (!items) {
return;
}
list->items = items;
list->capacity = new_cap;
}
}
void list_add(list_t *list, void *item) {
list_resize(list);
list->items[list->length++] = item;
void list_delete(list_t *list, size_t index) {
if (!sway_assert(list && index < list->length, "Invalid argument")) {
return;
}
size_t size = list->memb_size;
uint8_t (*array)[size] = list->items;
memmove(&array[index], &array[index + 1], size * (list->length - index));
--list->length;
shrink(list);
}
void list_insert(list_t *list, int index, void *item) {
list_resize(list);
memmove(&list->items[index + 1], &list->items[index], sizeof(void*) * (list->length - index));
list->length++;
list->items[index] = item;
void list_remove(list_t *list) {
if (!sway_assert(list, "Invalid argument") || list->length == 0) {
return;
}
list_delete(list, list->length - 1);
}
void list_del(list_t *list, int index) {
list->length--;
memmove(&list->items[index], &list->items[index + 1], sizeof(void*) * (list->length - index));
void list_swap(list_t *list, size_t i1, size_t i2) {
if (!sway_assert(list && i1 < list->length && i2 < list->length, "Invalid argument")) {
return;
}
size_t size = list->memb_size;
uint8_t (*array)[size] = list->items;
uint8_t tmp[size];
memcpy(tmp, &array[i1], size);
memcpy(&array[i1], &array[i2], size);
memcpy(&array[i2], tmp, size);
}
void list_cat(list_t *list, list_t *source) {
int i;
for (i = 0; i < source->length; ++i) {
list_add(list, source->items[i]);
void *list_get(list_t *list, size_t index) {
if (!sway_assert(list && index < list->length, "Invalid argument")) {
return NULL;
}
size_t size = list->memb_size;
uint8_t (*array)[size] = list->items;
return &array[index];
}
void *list_getp(list_t *list, size_t index) {
void **elem = list_get(list, index);
return elem ? *elem : NULL;
}
void list_qsort(list_t *list, int compare(const void *, const void *)) {
if (!sway_assert(list && compare, "Invalid argument")) {
return;
}
qsort(list->items, list->length, list->memb_size, compare);
}
void list_isort(list_t *list, int compare(const void *, const void *)) {
if (!sway_assert(list && compare, "Invalid argument")) {
return;
}
size_t size = list->memb_size;
uint8_t (*array)[size] = list->items;
for (size_t i = 1; i < list->length; ++i) {
uint8_t tmp[size];
memcpy(tmp, &array[i], size);
ssize_t j = i - 1;
while (j >= 0 && compare(&array[j], tmp) > 0) {
memcpy(&array[j + 1], &array[j], size);
--j;
}
memcpy(array[j + 1], tmp, size);
}
}
void list_qsort(list_t *list, int compare(const void *left, const void *right)) {
qsort(list->items, list->length, sizeof(void *), compare);
}
ssize_t list_lsearch(const list_t *list, int compare(const void *key, const void *item),
const void *key, void *ret) {
int list_seq_find(list_t *list, int compare(const void *item, const void *data), const void *data) {
for (int i = 0; i < list->length; i++) {
void *item = list->items[i];
if (compare(item, data) == 0) {
if (!sway_assert(list && compare && key, "Invalid argument")) {
return -1;
}
size_t size = list->memb_size;
uint8_t (*array)[size] = list->items;
for (size_t i = 0; i < list->length; ++i) {
if (compare(&array[i], key) == 0) {
if (ret) {
memcpy(ret, &array[i], size);
}
return i;
}
}
return -1;
}
void list_swap(list_t *list, int src, int dest) {
void *tmp = list->items[src];
list->items[src] = list->items[dest];
list->items[dest] = tmp;
}
ssize_t list_lsearchp(const list_t *list, int compare(const void *key, const void *item),
const void *key, void *ret) {
static void list_rotate(list_t *list, int from, int to) {
void *tmp = list->items[to];
while (to > from) {
list->items[to] = list->items[to - 1];
to--;
if (!sway_assert(list && compare && key, "Invalid argument")) {
return -1;
}
list->items[from] = tmp;
size_t size = list->memb_size;
uint8_t (*array)[size] = list->items;
for (size_t i = 0; i < list->length; ++i) {
if (compare(*(void **)&array[i], key) == 0) {
if (ret) {
memcpy(ret, &array[i], size);
}
return i;
}
}
return -1;
}
static void list_inplace_merge(list_t *list, int left, int last, int mid, int compare(const void *a, const void *b)) {
int right = mid + 1;
if (compare(&list->items[mid], &list->items[right]) <= 0) {
void list_foreach(list_t *list, void callback(void *item)) {
if (!sway_assert(list && callback, "Invalid argument")) {
return;
}
while (left <= mid && right <= last) {
if (compare(&list->items[left], &list->items[right]) <= 0) {
left++;
} else {
list_rotate(list, left, right);
left++;
mid++;
right++;
}
size_t size = list->memb_size;
uint8_t (*array)[size] = list->items;
for (size_t i = 0; i < list->length; ++i) {
callback(&array[i]);
}
}
static void list_inplace_sort(list_t *list, int first, int last, int compare(const void *a, const void *b)) {
if (first >= last) {
void list_foreachp(list_t *list, void callback(void *item)) {
if (!sway_assert(list && callback, "Invalid argument")) {
return;
} else if ((last - first) == 1) {
if (compare(&list->items[first], &list->items[last]) > 0) {
list_swap(list, first, last);
}
} else {
int mid = (int)((last + first) / 2);
list_inplace_sort(list, first, mid, compare);
list_inplace_sort(list, mid + 1, last, compare);
list_inplace_merge(list, first, last, mid, compare);
}
size_t size = list->memb_size;
uint8_t (*array)[size] = list->items;
for (size_t i = 0; i < list->length; ++i) {
callback(*(void **)&array[i]);
}
}
void list_stable_sort(list_t *list, int compare(const void *a, const void *b)) {
if (list->length > 1) {
list_inplace_sort(list, 0, list->length - 1, compare);
void list_free_with(list_t *list, freefn_t callback) {
if (!sway_assert(callback, "Invalid argument") || !list) {
return;
}
list_foreach(list, callback);
list_free(list);
}
void list_free_withp(list_t *list, freefn_t callback) {
if (!sway_assert(callback, "Invalid argument") || !list) {
return;
}
list_foreachp(list, callback);
list_free(list);
}
void *list_end(list_t *list) {
if (!sway_assert(list, "Invalid argument")) {
return NULL;
}
return (uint8_t *)list->items + list->memb_size * list->length;
}

View file

@ -69,28 +69,20 @@ int lenient_strcmp(char *a, char *b) {
}
list_t *split_string(const char *str, const char *delims) {
list_t *res = create_list();
list_t *res = list_new(sizeof(char *), 0);
char *copy = strdup(str);
char *token;
token = strtok(copy, delims);
while(token) {
token = strdup(token);
list_add(res, token);
list_add(res, &token);
token = strtok(NULL, delims);
}
free(copy);
return res;
}
void free_flat_list(list_t *list) {
int i;
for (i = 0; i < list->length; ++i) {
free(list->items[i]);
}
list_free(list);
}
char **split_args(const char *start, int *argc) {
*argc = 0;
int alloc = 2;
@ -315,22 +307,25 @@ char *join_list(list_t *list, char *separator) {
len += (list->length - 1) * sep_len;
}
for (int i = 0; i < list->length; i++) {
len += strlen(list->items[i]);
for (size_t i = 0; i < list->length; i++) {
char *item = list_getp(list, i);
len += strlen(item);
}
char *res = malloc(len);
char *p = res + strlen(list->items[0]);
strcpy(res, list->items[0]);
char *item = list_getp(list, 0);
char *p = res + strlen(item);
strcpy(res, item);
for (int i = 1; i < list->length; i++) {
for (size_t i = 1; i < list->length; i++) {
item = list_getp(list, i);
if (sep_len) {
memcpy(p, separator, sep_len);
p += sep_len;
}
strcpy(p, list->items[i]);
p += strlen(list->items[i]);
strcpy(p, item);
p += strlen(item);
}
*p = '\0';
@ -387,3 +382,7 @@ char *argsep(char **stringp, const char *delim) {
found:
return start;
}
int strcmp_ptr(const void *a, const void *b) {
return strcmp(*(char **)a, *(char **)b);
}

View file

@ -1,27 +1,151 @@
#ifndef _SWAY_LIST_H
#define _SWAY_LIST_H
#include <stddef.h>
#include <sys/types.h>
typedef struct {
int capacity;
int length;
void **items;
size_t capacity;
size_t length;
size_t memb_size;
void *items;
} list_t;
list_t *create_list(void);
/*
* Creates a new list with an inital capacity.
* If capacity is zero, some default value is used instead.
*
* memb_size must be the size of the type stored in this list.
* If an element is added to this list which is not the same type
* as the elements of the list, the behavior is undefined.
*/
list_t *list_new(size_t memb_size, size_t capacity);
/*
* Frees a list.
* If list is null, no action is taken.
*/
void list_free(list_t *list);
void list_foreach(list_t *list, void (*callback)(void* item));
void list_add(list_t *list, void *item);
void list_insert(list_t *list, int index, void *item);
void list_del(list_t *list, int index);
void list_cat(list_t *list, list_t *source);
// See qsort. Remember to use *_qsort functions as compare functions,
// because they dereference the left and right arguments first!
typedef void (*freefn_t)(void *arg);
/*
* Frees a list, calling a function on each element before doing so.
* If list is null, no action is taken.
* DO NOT pass free as the callback. Use list_free_withp for that.
*/
void list_free_with(list_t *list, freefn_t callback);
/*
* Frees a list, calling a function on each dereferenced element.
* For example, if you have a list of char * allocated with malloc,
* callback would receive a char * instead of a char **, meaning it's
* safe to use free as the callback.
* If list is null, no action is taken.
* list must be a list of pointers.
*/
void list_free_withp(list_t *list, freefn_t callback);
/*
* Adds an element at the end of the list.
*/
void list_add(list_t *list, const void *data);
/*
* Deletes the last element of the list.
* If the list is empty, no action is taken.
*/
void list_remove(list_t *list);
/*
* Adds an element at an arbitrary position in the list, moving
* the elements past index to make space.
* index must be less than or equal to the length of the list.
*/
void list_insert(list_t *list, size_t index, const void *data);
/*
* Deletes the element at an arbitrary position in the list,
* moving the elements past index into the space.
* index must be less than the length of the list.
*/
void list_delete(list_t *list, size_t index);
/*
* Swaps the elements at i1 and i2.
* i1 and i2 must both be less than the length of the list.
*/
void list_swap(list_t *list, size_t i1, size_t i2);
/*
* Gets the element of the list at the index.
* index must be less than the length of the list.
*/
void *list_get(list_t *list, size_t index);
/*
* Gets an dereferenced element of a list.
* For example, if you have a list of char *, this function
* will return a char * instead of a char **, unlike list_get.
* index must be less than the length of the list.
* list must be a list of pointers.
*/
void *list_getp(list_t *list, size_t index);
/*
* Sorts the list using the stdlib qsort() function.
*/
void list_qsort(list_t *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(list_t *list, int compare(const void *item, const void *cmp_to), const void *cmp_to);
// stable sort since qsort is not guaranteed to be stable
void list_stable_sort(list_t *list, int compare(const void *a, const void *b));
// swap two elements in a list
void list_swap(list_t *list, int src, int dest);
/*
* Sorts the list using insertion sort.
* This should be used if you need a stable sort, and your list is
* short and/or nearly sorted.
*/
void list_isort(list_t *list, int compare(const void *left, const void *right));
/*
* Returns the index of the key in the list, using a linear search,
* or -1 if it was not found. If ret is not null, the found element will be
* copied into it.
*/
ssize_t list_lsearch(const list_t *list, int compare(const void *item, const void *key),
const void *key, void *ret);
/*
* Returns the index of the key in the list, using a linear search,
* or -1 if it was not found. If ret is not null, the found element will be
* copied into it. The item passed into compare will be dereferenced first.
* For example, if you have a list of char *, it will get a char * instead
* of a char **, unlike list_lsearch.
* list must be a list of pointers.
*/
ssize_t list_lsearchp(const list_t *list, int compare(const void *item, const void *key),
const void *key, void *ret);
/*
* Calls a function on every item in the list.
*/
void list_foreach(list_t *list, void callback(void *item));
/*
* Calls a function on every dereferenced item in the list.
* For example, if you have a list of char *, callback will
* receive a char * instead of a char **, unlike list_foreach.
* list must be a list of pointers.
*/
void list_foreachp(list_t *list, void callback(void *item));
/*
* Returns a pointer to just past the end of the list.
* This can be used to write for loops more easily.
*
* Example (for a list of char *):
* char **end = list_end(list);
* for (char **ptr = list->items; ptr < end; ++ptr) {
* printf("%s\n", *ptr);
* }
*/
void *list_end(list_t *list);
#endif

View file

@ -14,12 +14,15 @@ char *strip_whitespace(char *str);
char *strip_comments(char *str);
void strip_quotes(char *str);
// strcmp that dereferences args first.
// Designed to be taken by list_lsearch and such
int strcmp_ptr(const void *a, const void *b);
// strcmp that also handles null pointers.
int lenient_strcmp(char *a, char *b);
// Simply split a string with delims, free with `free_flat_list`
// Simply split a string with delims, free with `list_free_withp(..., free)`
list_t *split_string(const char *str, const char *delims);
void free_flat_list(list_t *list);
// Splits an argument string, keeping quotes intact
char **split_args(const char *str, int *argc);

View file

@ -344,7 +344,7 @@ char *do_var_replacement(char *str);
struct cmd_results *check_security_config();
int input_identifier_cmp(const void *item, const void *data);
int input_identifier_cmp(const void *key, const void *item);
void merge_input_config(struct input_config *dst, struct input_config *src);
void apply_input_config(struct input_config *ic, struct libinput_device *dev);
void free_input_config(struct input_config *ic);

View file

@ -22,7 +22,7 @@ struct criteria {
char *cmdlist;
};
int criteria_cmp(const void *item, const void *data);
int criteria_cmp(const void *key, const void *item);
void free_criteria(struct criteria *crit);
// Pouplate list with crit_tokens extracted from criteria string, returns error
@ -39,4 +39,6 @@ list_t *container_for(list_t *tokens);
// Returns true if any criteria in the given list matches this container
bool criteria_any(swayc_t *cont, list_t *criteria);
struct crit_token;
#endif

View file

@ -24,7 +24,7 @@ void add_child(swayc_t *parent, swayc_t *child);
// Adds child to parent at index, if parent has no focus, it is set to child
// parent must be of type C_WORKSPACE or C_CONTAINER
void insert_child(swayc_t *parent, swayc_t *child, int index);
void insert_child(swayc_t *parent, swayc_t *child, size_t index);
// Adds child as floating window to ws, if there is no focus it is set to child.
// ws must be of type C_WORKSPACE

View file

@ -198,7 +198,7 @@ static void render_title_bar(swayc_t *view, cairo_t *cr, struct wlc_geometry *b,
int total_len = 0;
for(int i = view->marks->length - 1; i >= 0; --i) {
char *mark = (char *)view->marks->items[i];
char *mark = list_getp(view->marks, i);
if (*mark != '_') {
int width, height;
get_text_size(cr, config->font, &width, &height, 1, false, "[%s]", mark);
@ -271,10 +271,9 @@ static char *generate_container_title(swayc_t *container) {
}
snprintf(name, len, "sway: %c[", layout);
int i;
for (i = 0; i < container->children->length; ++i) {
for (size_t i = 0; i < container->children->length; ++i) {
prev_name = name;
swayc_t* child = container->children->items[i];
swayc_t* child = list_getp(container->children, i);
const char *title = NULL;
if (child->type == C_VIEW) {
title = child->app_id ? child->app_id :
@ -330,9 +329,8 @@ void update_tabbed_stacked_titlebars(swayc_t *c, cairo_t *cr, struct wlc_geometr
return;
}
int i;
for (i = 0; i < c->children->length; ++i) {
swayc_t *child = c->children->items[i];
for (size_t i = 0; i < c->children->length; ++i) {
swayc_t *child = list_getp(c->children, i);
update_tabbed_stacked_titlebars(child, cr, g, focused, focused_inactive);
}
} else {
@ -402,9 +400,8 @@ static void update_view_border(swayc_t *view) {
}
// generate container titles
int i;
for (i = 0; i < p->children->length; ++i) {
swayc_t *child = p->children->items[i];
for (size_t i = 0; i < p->children->length; ++i) {
swayc_t *child = list_getp(p->children, i);
if (child->type == C_CONTAINER) {
generate_container_title(child);
}
@ -471,8 +468,9 @@ void update_container_border(swayc_t *container) {
update_view_border(container);
return;
} else {
for (int i = 0; i < container->children->length; ++i) {
update_container_border(container->children->items[i]);
for (size_t i = 0; i < container->children->length; ++i) {
swayc_t *item = list_getp(container->children, i);
update_container_border(item);
}
}
}

View file

@ -102,16 +102,15 @@ void hide_view_in_scratchpad(swayc_t *sp_view) {
}
void input_cmd_apply(struct input_config *input) {
int i;
i = list_seq_find(config->input_configs, input_identifier_cmp, input->identifier);
struct input_config *ic;
ssize_t i = list_lsearchp(config->input_configs, input_identifier_cmp, input->identifier, &ic);
if (i >= 0) {
// merge existing config
struct input_config *ic = config->input_configs->items[i];
merge_input_config(ic, input);
free_input_config(input);
input = ic;
} else {
list_add(config->input_configs, input);
list_add(config->input_configs, &input);
}
current_input_config = input;
@ -121,8 +120,8 @@ void input_cmd_apply(struct input_config *input) {
// this is during startup then there will be no container and config
// will be applied during normal "new input" event from wlc.
struct libinput_device *device = NULL;
for (int i = 0; i < input_devices->length; ++i) {
device = input_devices->items[i];
for (size_t i = 0; i < input_devices->length; ++i) {
device = list_getp(input_devices, i);
char* dev_identifier = libinput_dev_unique_id(device);
if (!dev_identifier) {
break;
@ -138,15 +137,15 @@ void input_cmd_apply(struct input_config *input) {
}
void remove_view_from_scratchpad(swayc_t *view) {
int i;
for (i = 0; i < scratchpad->length; i++) {
if (scratchpad->items[i] == view) {
for (size_t i = 0; i < scratchpad->length; i++) {
swayc_t *item = list_getp(scratchpad, i);
if (item == view) {
if (sp_index == 0) {
sp_index = scratchpad->length - 1;
} else {
sp_index--;
}
list_del(scratchpad, sp_index);
list_delete(scratchpad, sp_index);
sp_view = NULL;
}
}
@ -384,7 +383,7 @@ struct cmd_results *handle_command(char *_exec, enum command_context context) {
char *criteria_string = argsep(&head, "]");
if (head) {
++head;
list_t *tokens = create_list();
list_t *tokens = list_new(sizeof(struct crit_token *), 0);
char *error;
if ((error = extract_crit_tokens(tokens, criteria_string))) {
@ -448,14 +447,14 @@ struct cmd_results *handle_command(char *_exec, enum command_context context) {
free_argv(argc, argv);
goto cleanup;
}
int i = 0;
size_t i = 0;
do {
if (!containers) {
current_container = get_focused_container(&root_container);
} else if (containers->length == 0) {
break;
} else {
current_container = (swayc_t *)containers->items[i];
current_container = list_getp(containers, i);
}
sway_log(L_INFO, "Running on container '%s'", current_container->name);
@ -483,7 +482,7 @@ struct cmd_results *handle_command(char *_exec, enum command_context context) {
cleanup:
free(exec);
if (containers) {
free(containers);
list_free(containers);
}
if (!results) {
results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
@ -594,8 +593,8 @@ struct cmd_results *config_commands_command(char *exec) {
}
struct command_policy *policy = NULL;
for (int i = 0; i < config->command_policies->length; ++i) {
struct command_policy *p = config->command_policies->items[i];
for (size_t i = 0; i < config->command_policies->length; ++i) {
struct command_policy *p = list_getp(config->command_policies, i);
if (strcmp(p->command, cmd) == 0) {
policy = p;
break;
@ -606,7 +605,7 @@ struct cmd_results *config_commands_command(char *exec) {
if (!policy) {
sway_abort("Unable to allocate security policy");
}
list_add(config->command_policies, policy);
list_add(config->command_policies, &policy);
}
policy->context = context;

View file

@ -36,7 +36,7 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
}
crit->crit_raw = strdup(criteria);
crit->cmdlist = cmdlist;
crit->tokens = create_list();
crit->tokens = list_new(sizeof(struct crit_token *), 0);
char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
if (err_str) {
@ -46,12 +46,12 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
} else if (crit->tokens->length == 0) {
error = cmd_results_new(CMD_INVALID, "assign", "Found no name/value pairs in criteria");
free_criteria(crit);
} else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) {
} else if (list_lsearchp(config->criteria, criteria_cmp, crit, NULL) != -1) {
sway_log(L_DEBUG, "assign: Duplicate, skipping.");
free_criteria(crit);
} else {
sway_log(L_DEBUG, "assign: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist);
list_add(config->criteria, crit);
list_add(config->criteria, &crit);
}
return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

View file

@ -38,13 +38,12 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
}
// set bar id
int i;
for (i = 0; i < config->bars->length; ++i) {
if (bar == config->bars->items[i]) {
for (size_t i = 0; i < config->bars->length; ++i) {
if (bar == list_getp(config->bars, i)) {
const int len = 5 + numlen(i); // "bar-" + i + \0
bar->id = malloc(len * sizeof(char));
if (bar->id) {
snprintf(bar->id, len, "bar-%d", i);
snprintf(bar->id, len, "bar-%zu", i);
} else {
return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar ID");
}

View file

@ -33,14 +33,14 @@ struct cmd_results *bar_cmd_bindsym(int argc, char **argv) {
binding->command = join_args(argv + 1, argc - 1);
struct bar_config *bar = config->current_bar;
int i = list_seq_find(bar->bindings, sway_mouse_binding_cmp_buttons, binding);
struct sway_mouse_binding *dup;
ssize_t i = list_lsearchp(bar->bindings, sway_mouse_binding_cmp_buttons, binding, &dup);
if (i > -1) {
sway_log(L_DEBUG, "bindsym - '%s' for swaybar already exists, overwriting", argv[0]);
struct sway_mouse_binding *dup = bar->bindings->items[i];
free_sway_mouse_binding(dup);
list_del(bar->bindings, i);
list_delete(bar->bindings, i);
}
list_add(bar->bindings, binding);
list_add(bar->bindings, &binding);
list_qsort(bar->bindings, sway_mouse_binding_cmp_qsort);
sway_log(L_DEBUG, "bindsym - Bound %s to command %s when clicking swaybar", argv[0], binding->command);

View file

@ -58,10 +58,8 @@ struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
id = argv[1];
}
int i;
struct bar_config *bar;
for (i = 0; i < config->bars->length; ++i) {
bar = config->bars->items[i];
for (size_t i = 0; i < config->bars->length; ++i) {
struct bar_config *bar = list_getp(config->bars, i);
if (id && strcmp(id, bar->id) == 0) {
return bar_set_hidden_state(bar, state);
}

View file

@ -13,9 +13,8 @@ struct cmd_results *bar_cmd_id(int argc, char **argv) {
const char *oldname = config->current_bar->id;
// check if id is used by a previously defined bar
int i;
for (i = 0; i < config->bars->length; ++i) {
struct bar_config *find = config->bars->items[i];
for (size_t i = 0; i < config->bars->length; ++i) {
struct bar_config *find = list_getp(config->bars, i);
if (strcmp(name, find->id) == 0 && config->current_bar != find) {
return cmd_results_new(CMD_FAILURE, "id",
"Id '%s' already defined for another bar. Id unchanged (%s).",

View file

@ -63,10 +63,8 @@ struct cmd_results *bar_cmd_mode(int argc, char **argv) {
id = argv[1];
}
int i;
struct bar_config *bar;
for (i = 0; i < config->bars->length; ++i) {
bar = config->bars->items[i];
for (size_t i = 0; i < config->bars->length; ++i) {
struct bar_config *bar = list_getp(config->bars, i);
if (id && strcmp(id, bar->id) == 0) {
return bar_set_mode(bar, mode);
}

View file

@ -17,17 +17,18 @@ struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
uint32_t mod = 0;
list_t *split = split_string(argv[0], "+");
for (int i = 0; i < split->length; ++i) {
for (size_t i = 0; i < split->length; ++i) {
uint32_t tmp_mod;
if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) {
char *item = list_getp(split, i);
if ((tmp_mod = get_modifier_mask_by_name(item)) > 0) {
mod |= tmp_mod;
continue;
} else {
free_flat_list(split);
return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", split->items[i]);
list_free_withp(split, free);
return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", item);
}
}
free_flat_list(split);
list_free_withp(split, free);
config->current_bar->modifier = mod;
sway_log(L_DEBUG, "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]);

View file

@ -17,23 +17,23 @@ struct cmd_results *bar_cmd_output(int argc, char **argv) {
const char *output = argv[0];
list_t *outputs = config->current_bar->outputs;
if (!outputs) {
outputs = create_list();
outputs = list_new(sizeof(char *), 0);
config->current_bar->outputs = outputs;
}
int i;
int add_output = 1;
if (strcmp("*", output) == 0) {
// remove all previous defined outputs and replace with '*'
for (i = 0; i < outputs->length; ++i) {
free(outputs->items[i]);
list_del(outputs, i);
for (size_t i = 0; i < outputs->length; ++i) {
char *item = list_getp(outputs, i);
free(item);
list_delete(outputs, i);
}
} else {
// only add output if not already defined with either the same
// name or as '*'
for (i = 0; i < outputs->length; ++i) {
const char *find = outputs->items[i];
for (size_t i = 0; i < outputs->length; ++i) {
const char *find = list_getp(outputs, i);
if (strcmp("*", find) == 0 || strcmp(output, find) == 0) {
add_output = 0;
break;
@ -42,7 +42,8 @@ struct cmd_results *bar_cmd_output(int argc, char **argv) {
}
if (add_output) {
list_add(outputs, strdup(output));
char *ptr = strdup(output);
list_add(outputs, &ptr);
sway_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output);
}

View file

@ -22,7 +22,7 @@ struct cmd_results *cmd_bindsym(int argc, char **argv) {
return cmd_results_new(CMD_FAILURE, "bindsym",
"Unable to allocate binding");
}
binding->keys = create_list();
binding->keys = list_new(sizeof(xkb_keysym_t *), 0);
binding->modifiers = 0;
binding->release = false;
binding->bindcode = false;
@ -44,50 +44,51 @@ struct cmd_results *cmd_bindsym(int argc, char **argv) {
binding->command = join_args(argv + 1, argc - 1);
list_t *split = split_string(argv[0], "+");
for (int i = 0; i < split->length; ++i) {
for (size_t i = 0; i < split->length; ++i) {
// Check for a modifier key
uint32_t mod;
if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) {
char *item = list_getp(split, i);
if ((mod = get_modifier_mask_by_name(item)) > 0) {
binding->modifiers |= mod;
continue;
}
// Check for xkb key
xkb_keysym_t sym = xkb_keysym_from_name(split->items[i],
xkb_keysym_t sym = xkb_keysym_from_name(item,
XKB_KEYSYM_CASE_INSENSITIVE);
// Check for mouse binding
if (strncasecmp(split->items[i], "button", strlen("button")) == 0 &&
strlen(split->items[i]) == strlen("button0")) {
sym = ((char *)split->items[i])[strlen("button")] - '1' + M_LEFT_CLICK;
if (strncasecmp(item, "button", strlen("button")) == 0 &&
strlen(item) == strlen("button0")) {
sym = ((char *)item)[strlen("button")] - '1' + M_LEFT_CLICK;
}
if (!sym) {
free_sway_binding(binding);
free_flat_list(split);
list_free_withp(split, free);
return cmd_results_new(CMD_INVALID, "bindsym", "Unknown key '%s'",
(char *)split->items[i]);
item);
}
xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t));
if (!key) {
free_sway_binding(binding);
free_flat_list(split);
list_free_withp(split, free);
return cmd_results_new(CMD_FAILURE, "bindsym",
"Unable to allocate binding");
}
*key = sym;
list_add(binding->keys, key);
list_add(binding->keys, &key);
}
free_flat_list(split);
list_free_withp(split, free);
struct sway_mode *mode = config->current_mode;
int i = list_seq_find(mode->bindings, sway_binding_cmp_keys, binding);
struct sway_binding *dup;
ssize_t i = list_lsearchp(mode->bindings, sway_binding_cmp_keys, binding, &dup);
if (i > -1) {
sway_log(L_DEBUG, "bindsym - '%s' already exists, overwriting", argv[0]);
struct sway_binding *dup = mode->bindings->items[i];
free_sway_binding(dup);
list_del(mode->bindings, i);
list_delete(mode->bindings, i);
}
binding->order = binding_order++;
list_add(mode->bindings, binding);
list_add(mode->bindings, &binding);
list_qsort(mode->bindings, sway_binding_cmp_qsort);
sway_log(L_DEBUG, "bindsym - Bound %s to command %s", argv[0], binding->command);
@ -105,7 +106,7 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) {
return cmd_results_new(CMD_FAILURE, "bindsym",
"Unable to allocate binding");
}
binding->keys = create_list();
binding->keys = list_new(sizeof(xkb_keycode_t *), 0);
binding->modifiers = 0;
binding->release = false;
binding->bindcode = true;
@ -127,41 +128,42 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) {
binding->command = join_args(argv + 1, argc - 1);
list_t *split = split_string(argv[0], "+");
for (int i = 0; i < split->length; ++i) {
for (size_t i = 0; i < split->length; ++i) {
// Check for a modifier key
uint32_t mod;
if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) {
char *item = list_getp(split, i);
if ((mod = get_modifier_mask_by_name(item)) > 0) {
binding->modifiers |= mod;
continue;
}
// parse keycode
xkb_keycode_t keycode = (int)strtol(split->items[i], NULL, 10);
xkb_keycode_t keycode = (int)strtol(item, NULL, 10);
if (!xkb_keycode_is_legal_ext(keycode)) {
error = cmd_results_new(CMD_INVALID, "bindcode", "Invalid keycode '%s'", (char *)split->items[i]);
error = cmd_results_new(CMD_INVALID, "bindcode", "Invalid keycode '%s'", item);
free_sway_binding(binding);
list_free(split);
return error;
}
xkb_keycode_t *key = malloc(sizeof(xkb_keycode_t));
*key = keycode - 8;
list_add(binding->keys, key);
list_add(binding->keys, &key);
}
free_flat_list(split);
list_free_withp(split, free);
struct sway_mode *mode = config->current_mode;
int i = list_seq_find(mode->bindings, sway_binding_cmp_keys, binding);
struct sway_binding *dup;
ssize_t i = list_lsearchp(mode->bindings, sway_binding_cmp_keys, binding, &dup);
if (i > -1) {
struct sway_binding *dup = mode->bindings->items[i];
if (dup->bindcode) {
sway_log(L_DEBUG, "bindcode - '%s' already exists, overwriting", argv[0]);
} else {
sway_log(L_DEBUG, "bindcode - '%s' already exists as bindsym, overwriting", argv[0]);
}
free_sway_binding(dup);
list_del(mode->bindings, i);
list_delete(mode->bindings, i);
}
binding->order = binding_order++;
list_add(mode->bindings, binding);
list_add(mode->bindings, &binding);
list_qsort(mode->bindings, sway_binding_cmp_qsort);
sway_log(L_DEBUG, "bindcode - Bound %s to command %s", argv[0], binding->command);

View file

@ -12,15 +12,14 @@ struct cmd_results *cmd_floating_mod(int argc, char **argv) {
if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) {
return error;
}
int i;
list_t *split = split_string(argv[0], "+");
config->floating_mod = 0;
// set modifier keys
for (i = 0; i < split->length; ++i) {
config->floating_mod |= get_modifier_mask_by_name(split->items[i]);
for (size_t i = 0; i < split->length; ++i) {
config->floating_mod |= get_modifier_mask_by_name(list_getp(split, i));
}
free_flat_list(split);
list_free_withp(split, free);
if (!config->floating_mod) {
error = cmd_results_new(CMD_INVALID, "floating_modifier", "Unknown keys %s", argv[0]);
return error;

View file

@ -36,8 +36,8 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
} else if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1))) {
return error;
}
static int floating_toggled_index = 0;
static int tiled_toggled_index = 0;
static size_t floating_toggled_index = 0;
static size_t tiled_toggled_index = 0;
if (strcasecmp(argv[0], "left") == 0) {
move_focus(MOVE_LEFT);
} else if (strcasecmp(argv[0], "right") == 0) {
@ -55,37 +55,40 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
} else if (strcasecmp(argv[0], "prev") == 0) {
move_focus(MOVE_PREV);
} else if (strcasecmp(argv[0], "mode_toggle") == 0) {
int i;
swayc_t *workspace = swayc_active_workspace();
swayc_t *focused = get_focused_view(workspace);
if (focused->is_floating) {
if (workspace->children->length > 0) {
for (i = 0;i < workspace->floating->length; i++) {
if (workspace->floating->items[i] == focused) {
for (size_t i = 0;i < workspace->floating->length; i++) {
swayc_t *item = list_getp(workspace->floating, i);
if (item == focused) {
floating_toggled_index = i;
break;
}
}
if (workspace->children->length > tiled_toggled_index) {
set_focused_container(get_focused_view(workspace->children->items[tiled_toggled_index]));
swayc_t *item = list_getp(workspace->children, tiled_toggled_index);
set_focused_container(get_focused_view(item));
} else {
set_focused_container(get_focused_view(workspace->children->items[0]));
swayc_t *item = list_getp(workspace->children, 0);
set_focused_container(get_focused_view(item));
tiled_toggled_index = 0;
}
}
} else {
if (workspace->floating->length > 0) {
for (i = 0;i < workspace->children->length; i++) {
if (workspace->children->items[i] == focused) {
for (size_t i = 0;i < workspace->children->length; i++) {
swayc_t *item = list_getp(workspace->children, i);
if (item == focused) {
tiled_toggled_index = i;
break;
}
}
if (workspace->floating->length > floating_toggled_index) {
swayc_t *floating = workspace->floating->items[floating_toggled_index];
swayc_t *floating = list_getp(workspace->floating, floating_toggled_index);
set_focused_container(get_focused_view(floating));
} else {
swayc_t *floating = workspace->floating->items[workspace->floating->length - 1];
swayc_t *floating = list_getp(workspace->floating, workspace->floating->length - 1);
set_focused_container(get_focused_view(floating));
tiled_toggled_index = workspace->floating->length - 1;
}

View file

@ -20,7 +20,7 @@ struct cmd_results *cmd_for_window(int argc, char **argv) {
}
crit->crit_raw = strdup(criteria);
crit->cmdlist = cmdlist;
crit->tokens = create_list();
crit->tokens = list_new(sizeof(struct crit_token *), 0);
char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
if (err_str) {
@ -30,12 +30,12 @@ struct cmd_results *cmd_for_window(int argc, char **argv) {
} else if (crit->tokens->length == 0) {
error = cmd_results_new(CMD_INVALID, "for_window", "Found no name/value pairs in criteria");
free_criteria(crit);
} else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) {
} else if (list_lsearchp(config->criteria, criteria_cmp, crit, NULL) != -1) {
sway_log(L_DEBUG, "for_window: Duplicate, skipping.");
free_criteria(crit);
} else {
sway_log(L_DEBUG, "for_window: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist);
list_add(config->criteria, crit);
list_add(config->criteria, &crit);
}
return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

View file

@ -133,11 +133,10 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
arrange_windows(cont->parent, -1, -1);
} else if (inout == OUTER) {
//resize all workspace.
int i,j;
for (i = 0; i < root_container.children->length; ++i) {
swayc_t *op = root_container.children->items[i];
for (j = 0; j < op->children->length; ++j) {
swayc_t *ws = op->children->items[j];
for (size_t i = 0; i < root_container.children->length; ++i) {
swayc_t *op = list_getp(root_container.children, i);
for (size_t j = 0; j < op->children->length; ++j) {
swayc_t *ws = list_getp(op->children, j);
if (method == SET) {
ws->gaps = amount;
} else if ((ws->gaps += amount) < 0) {

View file

@ -37,7 +37,7 @@ struct cmd_results *cmd_ipc(int argc, char **argv) {
}
current_policy = alloc_ipc_policy(program);
list_add(config->ipc_policies, current_policy);
list_add(config->ipc_policies, &current_policy);
free(program);
return cmd_results_new(CMD_BLOCK_IPC, NULL, NULL);

View file

@ -154,10 +154,11 @@ static struct cmd_results *cmd_layout_auto(swayc_t *container, int argc, char **
}
if (inc) {
for (int i = container->nb_master;
i >= 0 && i < container->children->length
i >= 0 && (size_t)i < container->children->length
&& i != (int)container->nb_master + inc;) {
((swayc_t *)container->children->items[i])->height = -1;
((swayc_t *)container->children->items[i])->width = -1;
swayc_t *item = list_getp(container->children, i);
item->height = -1;
item->width = -1;
i += inc > 0 ? 1 : -1;
}
container->nb_master += inc;

View file

@ -8,9 +8,13 @@
static void find_marks_callback(swayc_t *container, void *_mark) {
char *mark = (char *)_mark;
int index;
if (container->marks && ((index = list_seq_find(container->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1)) {
list_del(container->marks, index);
if (!container->marks) {
return;
}
ssize_t index = list_lsearchp(container->marks, (int (*)(const void *, const void *))strcmp, mark, NULL);
if (index != -1) {
list_delete(container->marks, index);
}
}
@ -45,11 +49,12 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
if (view->marks) {
if (add) {
int index;
if ((index = list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1) {
ssize_t index;
char *item;
if ((index = list_lsearchp(view->marks, (int (*)(const void *, const void *))strcmp, mark, &item)) != -1) {
if (toggle) {
free(view->marks->items[index]);
list_del(view->marks, index);
free(item);
list_delete(view->marks, index);
if (0 == view->marks->length) {
list_free(view->marks);
@ -58,26 +63,24 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
}
free(mark);
} else {
list_add(view->marks, mark);
list_add(view->marks, &mark);
}
} else {
if (toggle && list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark) != -1) {
if (toggle && list_lsearchp(view->marks, (int (*)(const void *, const void *))strcmp, mark, NULL) != -1) {
// Delete the list
list_foreach(view->marks, free);
list_free(view->marks);
list_free_withp(view->marks, free);
view->marks = NULL;
} else {
// Delete and replace with a new list
list_foreach(view->marks, free);
list_free(view->marks);
list_free_withp(view->marks, free);
view->marks = create_list();
list_add(view->marks, mark);
view->marks = list_new(sizeof(char *), 0);
list_add(view->marks, &mark);
}
}
} else {
view->marks = create_list();
list_add(view->marks, mark);
view->marks = list_new(sizeof(char *), 0);
list_add(view->marks, &mark);
}
} else {
return cmd_results_new(CMD_FAILURE, "mark",

View file

@ -22,9 +22,8 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
}
struct sway_mode *mode = NULL;
// Find mode
int i, len = config->modes->length;
for (i = 0; i < len; ++i) {
struct sway_mode *find = config->modes->items[i];
for (size_t i = 0; i < config->modes->length; ++i) {
struct sway_mode *find = list_getp(config->modes, i);
if (strcasecmp(find->name, mode_name) == 0) {
mode = find;
break;
@ -37,8 +36,8 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
return cmd_results_new(CMD_FAILURE, "mode", "Unable to allocate mode");
}
mode->name = strdup(mode_name);
mode->bindings = create_list();
list_add(config->modes, mode);
mode->bindings = list_new(sizeof(struct sway_mode *), 0);
list_add(config->modes, &mode);
}
if (!mode) {
error = cmd_results_new(CMD_INVALID, "mode", "Unknown mode `%s'", mode_name);

View file

@ -126,15 +126,15 @@ struct cmd_results *cmd_move(int argc, char **argv) {
return cmd_results_new(CMD_FAILURE, "move scratchpad", "Can only move containers and views.");
}
swayc_t *view = current_container;
int i;
for (i = 0; i < scratchpad->length; i++) {
if (scratchpad->items[i] == view) {
for (size_t i = 0; i < scratchpad->length; i++) {
swayc_t *item = list_getp(scratchpad, i);
if (item == view) {
hide_view_in_scratchpad(view);
sp_view = NULL;
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
}
list_add(scratchpad, view);
list_add(scratchpad, &view);
if (!view->is_floating) {
destroy_container(remove_child(view));
} else {

View file

@ -19,7 +19,7 @@ struct cmd_results *cmd_no_focus(int argc, char **argv) {
return cmd_results_new(CMD_FAILURE, "no_focus", "Unable to allocate criteria");
}
crit->crit_raw = strdup(criteria);
crit->tokens = create_list();
crit->tokens = list_new(sizeof(struct crit_token *), 0);
crit->cmdlist = NULL;
char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
@ -30,12 +30,12 @@ struct cmd_results *cmd_no_focus(int argc, char **argv) {
} else if (crit->tokens->length == 0) {
error = cmd_results_new(CMD_INVALID, "no_focus", "Found no name/value pairs in criteria");
free_criteria(crit);
} else if (list_seq_find(config->no_focus, criteria_cmp, crit) != -1) {
} else if (list_lsearchp(config->no_focus, criteria_cmp, crit, NULL) != -1) {
sway_log(L_DEBUG, "no_focus: Duplicate, skipping.");
free_criteria(crit);
} else {
sway_log(L_DEBUG, "no_focus: '%s' added", crit->crit_raw);
list_add(config->no_focus, crit);
list_add(config->no_focus, &crit);
}
return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

View file

@ -38,8 +38,7 @@ struct cmd_results *cmd_output(int argc, char **argv) {
// TODO: atoi doesn't handle invalid numbers
int i;
for (i = 1; i < argc; ++i) {
for (int i = 1; i < argc; ++i) {
const char *command = argv[i];
if (strcasecmp(command, "disable") == 0) {
@ -157,15 +156,15 @@ struct cmd_results *cmd_output(int argc, char **argv) {
}
}
i = list_seq_find(config->output_configs, output_name_cmp, name);
struct output_config *oc;
ssize_t i = list_lsearchp(config->output_configs, output_name_cmp, name, &oc);
if (i >= 0) {
// merge existing config
struct output_config *oc = config->output_configs->items[i];
merge_output_config(oc, output);
free_output_config(output);
output = oc;
} else {
list_add(config->output_configs, output);
list_add(config->output_configs, &output);
}
sway_log(L_DEBUG, "Config stored for output %s (enabled:%d) (%d x %d @ %d, %d scale %d) (bg %s %s)",
@ -178,8 +177,8 @@ struct cmd_results *cmd_output(int argc, char **argv) {
// this is during startup then there will be no container and config
// will be applied during normal "new output" event from wlc.
swayc_t *cont = NULL;
for (int i = 0; i < root_container.children->length; ++i) {
cont = root_container.children->items[i];
for (size_t i = 0; i < root_container.children->length; ++i) {
cont = list_getp(root_container.children, i);
if (cont->name && ((strcmp(cont->name, output->name) == 0) || (strcmp(output->name, "*") == 0))) {
apply_output_config(output, cont);

View file

@ -118,12 +118,12 @@ static bool resize_tiled(int amount, bool use_width) {
// 2. Ensure that the resize operation will not make one of the resized containers drop
// below the "sane" size threshold.
bool valid = true;
swayc_t *focused = parent->children->items[idx_focused];
int start = use_major ? 0 : auto_group_start_index(parent, idx_focused);
int end = use_major ? parent->children->length : auto_group_end_index(parent, idx_focused);
sway_log(L_DEBUG, "Check children of container %p [%d,%d[", container, start, end);
for (int i = start; i < end; ) {
swayc_t *sibling = parent->children->items[i];
swayc_t *focused = list_getp(parent->children, idx_focused);
size_t start = use_major ? 0 : (size_t)auto_group_start_index(parent, idx_focused);
size_t end = use_major ? parent->children->length : (size_t)auto_group_end_index(parent, idx_focused);
sway_log(L_DEBUG, "Check children of container %p [%zu,%zu[", container, start, end);
for (size_t i = start; i < end; ) {
swayc_t *sibling = list_getp(parent->children, i);
double pixels = amount;
bool is_before = use_width ? sibling->x < focused->x : sibling->y < focused->y;
bool is_after = use_width ? sibling->x > focused->x : sibling->y > focused->y;
@ -142,14 +142,14 @@ static bool resize_tiled(int amount, bool use_width) {
sway_log(L_DEBUG, "Container size no longer sane");
break;
}
i = use_major ? auto_group_end_index(parent, i) : (i + 1);
sway_log(L_DEBUG, "+++++ check %i", i);
i = use_major ? (size_t)auto_group_end_index(parent, i) : (i + 1);
sway_log(L_DEBUG, "+++++ check %zu", i);
}
// 3. Apply the size change
if (valid) {
for (int i = start; i < end; ) {
int next_i = use_major ? auto_group_end_index(parent, i) : (i + 1);
swayc_t *sibling = parent->children->items[i];
for (size_t i = start; i < end; ) {
int next_i = use_major ? (size_t)auto_group_end_index(parent, i) : (i + 1);
swayc_t *sibling = list_getp(parent->children, i);
double pixels = amount;
bool is_before = use_width ? sibling->x < focused->x : sibling->y < focused->y;
bool is_after = use_width ? sibling->x > focused->x : sibling->y > focused->y;
@ -162,7 +162,8 @@ static bool resize_tiled(int amount, bool use_width) {
sway_log(L_DEBUG, "%p: %s", sibling, is_before ? "before" : "after");
if (use_major) {
for (int j = i; j < next_i; ++j) {
recursive_resize(parent->children->items[j], pixels,
swayc_t *item = list_getp(parent->children, j);
recursive_resize(item, pixels,
use_width ?
(is_before ? WLC_RESIZE_EDGE_RIGHT : WLC_RESIZE_EDGE_LEFT) :
(is_before ? WLC_RESIZE_EDGE_BOTTOM : WLC_RESIZE_EDGE_TOP));
@ -176,9 +177,10 @@ static bool resize_tiled(int amount, bool use_width) {
} else {
if (use_major) {
for (int j = i; j < next_i; ++j) {
recursive_resize(parent->children->items[j], pixels / 2,
swayc_t *item = list_getp(parent->children, j);
recursive_resize(item, pixels / 2,
use_width ? WLC_RESIZE_EDGE_LEFT : WLC_RESIZE_EDGE_TOP);
recursive_resize(parent->children->items[j], pixels / 2,
recursive_resize(item, pixels / 2,
use_width ? WLC_RESIZE_EDGE_RIGHT : WLC_RESIZE_EDGE_BOTTOM);
}
} else {

View file

@ -7,10 +7,10 @@
#include "sway/layout.h"
static swayc_t *fetch_view_from_scratchpad() {
if (sp_index >= scratchpad->length) {
if ((size_t)sp_index >= scratchpad->length) {
sp_index = 0;
}
swayc_t *view = scratchpad->items[sp_index++];
swayc_t *view = list_getp(scratchpad, sp_index++);
if (wlc_view_get_output(view->handle) != swayc_active_output()->handle) {
wlc_view_set_output(view->handle, swayc_active_output()->handle);

View file

@ -37,9 +37,8 @@ struct cmd_results *cmd_set(int argc, char **argv) {
struct sway_variable *var = NULL;
// Find old variable if it exists
int i;
for (i = 0; i < config->symbols->length; ++i) {
var = config->symbols->items[i];
for (size_t i = 0; i < config->symbols->length; ++i) {
var = list_getp(config->symbols, i);
if (strcmp(var->name, argv[0]) == 0) {
break;
}
@ -53,7 +52,7 @@ struct cmd_results *cmd_set(int argc, char **argv) {
return cmd_results_new(CMD_FAILURE, "set", "Unable to allocate variable");
}
var->name = strdup(argv[0]);
list_add(config->symbols, var);
list_add(config->symbols, &var);
list_qsort(config->symbols, compare_set_qsort);
}
var->value = join_args(argv + 1, argc - 1);

View file

@ -10,10 +10,11 @@ struct cmd_results *cmd_unmark(int argc, char **argv) {
if (view->marks) {
if (argc) {
char *mark = join_args(argv, argc);
int index;
if ((index = list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1) {
free(view->marks->items[index]);
list_del(view->marks, index);
char *item;
ssize_t index;
if ((index = list_lsearchp(view->marks, (int (*)(const void *, const void *))strcmp, mark, &item)) != -1) {
free(item);
list_delete(view->marks, index);
if (view->marks->length == 0) {
list_free(view->marks);
@ -22,8 +23,7 @@ struct cmd_results *cmd_unmark(int argc, char **argv) {
}
free(mark);
} else {
list_foreach(view->marks, free);
list_free(view->marks);
list_free_with(view->marks, free);
view->marks = NULL;
}
}

View file

@ -34,14 +34,14 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
}
wso->workspace = join_args(argv, argc - 2);
wso->output = strdup(argv[output_location + 1]);
int i = -1;
if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) {
struct workspace_output *old = config->workspace_outputs->items[i];
ssize_t i = -1;
struct workspace_output *old;
if ((i = list_lsearchp(config->workspace_outputs, workspace_output_cmp_workspace, wso, &old)) != -1) {
free(old); // workspaces can only be assigned to a single output
list_del(config->workspace_outputs, i);
list_delete(config->workspace_outputs, i);
}
sway_log(L_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output);
list_add(config->workspace_outputs, wso);
list_add(config->workspace_outputs, &wso);
} else {
if (config->reading || !config->active) {
return cmd_results_new(CMD_DEFER, "workspace", NULL);

View file

@ -45,7 +45,7 @@ static void free_binding(struct sway_binding *bind) {
if (!bind) {
return;
}
free_flat_list(bind->keys);
list_free_withp(bind->keys, free);
free(bind->command);
free(bind);
}
@ -55,9 +55,8 @@ static void free_mode(struct sway_mode *mode) {
return;
}
free(mode->name);
int i;
for (i = 0; mode->bindings && i < mode->bindings->length; ++i) {
free_binding(mode->bindings->items[i]);
for (size_t i = 0; mode->bindings && i < mode->bindings->length; ++i) {
free_binding(list_getp(mode->bindings, i));
}
list_free(mode->bindings);
free(mode);
@ -72,14 +71,13 @@ static void free_bar(struct bar_config *bar) {
free(bar->status_command);
free(bar->font);
free(bar->separator_symbol);
int i;
for (i = 0; bar->bindings && i < bar->bindings->length; ++i) {
free_sway_mouse_binding(bar->bindings->items[i]);
for (size_t i = 0; bar->bindings && i < bar->bindings->length; ++i) {
free_sway_mouse_binding(list_getp(bar->bindings, i));
}
list_free(bar->bindings);
if (bar->outputs) {
free_flat_list(bar->outputs);
list_free_withp(bar->outputs, free);
}
if (bar->pid != 0) {
@ -144,12 +142,12 @@ static void pid_workspace_cleanup() {
// work backwards through list and remove any entries
// older than PID_WORKSPACE_TIMEOUT
for (int i = config->pid_workspaces->length - 1; i > -1; i--) {
pw = config->pid_workspaces->items[i];
for (ssize_t i = config->pid_workspaces->length - 1; i > -1; i--) {
pw = list_getp(config->pid_workspaces, i);
if (difftime(ts.tv_sec, *pw->time_added) >= PID_WORKSPACE_TIMEOUT) {
free_pid_workspace(config->pid_workspaces->items[i]);
list_del(config->pid_workspaces, i);
free_pid_workspace(pw);
list_delete(config->pid_workspaces, i);
}
}
}
@ -174,16 +172,16 @@ void pid_workspace_add(struct pid_workspace *pw) {
// work backwards through list and delete any entries that
// have the same pid as that in our new pid_workspace
for (int i = config->pid_workspaces->length - 1; i > -1; i--) {
list_pw = config->pid_workspaces->items[i];
for (ssize_t i = config->pid_workspaces->length - 1; i > -1; i--) {
list_pw = list_getp(config->pid_workspaces, i);
if (pw->pid == list_pw->pid) {
free_pid_workspace(config->pid_workspaces->items[i]);
list_del(config->pid_workspaces, i);
free_pid_workspace(list_pw);
list_delete(config->pid_workspaces, i);
}
}
list_add(config->pid_workspaces, pw);
list_add(config->pid_workspaces, &pw);
}
void free_pid_workspace(struct pid_workspace *pw) {
@ -216,66 +214,22 @@ void free_config(struct sway_config *config) {
if (!config) {
return;
}
int i;
for (i = 0; config->symbols && i < config->symbols->length; ++i) {
free_variable(config->symbols->items[i]);
}
list_free(config->symbols);
for (i = 0; config->modes && i < config->modes->length; ++i) {
free_mode(config->modes->items[i]);
}
list_free(config->modes);
for (i = 0; config->bars && i < config->bars->length; ++i) {
free_bar(config->bars->items[i]);
}
list_free(config->bars);
free_flat_list(config->cmd_queue);
for (i = 0; config->workspace_outputs && i < config->workspace_outputs->length; ++i) {
free_workspace_output(config->workspace_outputs->items[i]);
}
list_free(config->workspace_outputs);
for (i = 0; config->pid_workspaces && i < config->pid_workspaces->length; ++i) {
free_pid_workspace(config->pid_workspaces->items[i]);
}
list_free(config->pid_workspaces);
for (i = 0; config->criteria && i < config->criteria->length; ++i) {
free_criteria(config->criteria->items[i]);
}
list_free(config->criteria);
for (i = 0; config->no_focus && i < config->no_focus->length; ++i) {
free_criteria(config->no_focus->items[i]);
}
list_free(config->no_focus);
for (i = 0; config->input_configs && i < config->input_configs->length; ++i) {
free_input_config(config->input_configs->items[i]);
}
list_free(config->input_configs);
for (i = 0; config->output_configs && i < config->output_configs->length; ++i) {
free_output_config(config->output_configs->items[i]);
}
list_free(config->output_configs);
for (i = 0; config->command_policies && i < config->command_policies->length; ++i) {
free_command_policy(config->command_policies->items[i]);
}
list_free(config->command_policies);
for (i = 0; config->feature_policies && i < config->feature_policies->length; ++i) {
free_feature_policy(config->feature_policies->items[i]);
}
list_free(config->feature_policies);
list_free_withp(config->symbols, (freefn_t)free_variable);
list_free_withp(config->modes, (freefn_t)free_mode);
list_free_withp(config->bars, (freefn_t)free_bar);
list_free_withp(config->cmd_queue, free);
list_free_withp(config->workspace_outputs, (freefn_t)free_workspace_output);
list_free_withp(config->pid_workspaces, (freefn_t)free_pid_workspace);
list_free_withp(config->criteria, (freefn_t)free_criteria);
list_free_withp(config->no_focus, (freefn_t)free_criteria);
list_free_withp(config->input_configs, (freefn_t)free_input_config);
list_free_withp(config->output_configs, (freefn_t)free_output_config);
list_free_withp(config->command_policies, (freefn_t)free_command_policy);
list_free_withp(config->feature_policies, (freefn_t)free_feature_policy);
list_free(config->active_bar_modifiers);
free_flat_list(config->config_chain);
list_free_withp(config->config_chain, free);
free(config->font);
free(config->floating_scroll_up_cmd);
free(config->floating_scroll_down_cmd);
@ -290,23 +244,23 @@ static bool file_exists(const char *path) {
}
static void config_defaults(struct sway_config *config) {
if (!(config->symbols = create_list())) goto cleanup;
if (!(config->modes = create_list())) goto cleanup;
if (!(config->bars = create_list())) goto cleanup;
if (!(config->workspace_outputs = create_list())) goto cleanup;
if (!(config->pid_workspaces = create_list())) goto cleanup;
if (!(config->criteria = create_list())) goto cleanup;
if (!(config->no_focus = create_list())) goto cleanup;
if (!(config->input_configs = create_list())) goto cleanup;
if (!(config->output_configs = create_list())) goto cleanup;
if (!(config->symbols = list_new(sizeof(struct sway_variable *), 0))) goto cleanup;
if (!(config->modes = list_new(sizeof(struct sway_mode *), 0))) goto cleanup;
if (!(config->bars = list_new(sizeof(struct bar_config *), 0))) goto cleanup;
if (!(config->workspace_outputs = list_new(sizeof(struct workspace_output *), 0))) goto cleanup;
if (!(config->pid_workspaces = list_new(sizeof(struct pid_workspace *), 0))) goto cleanup;
if (!(config->criteria = list_new(sizeof(struct criteria *), 0))) goto cleanup;
if (!(config->no_focus = list_new(sizeof(struct criterua *), 0))) goto cleanup;
if (!(config->input_configs = list_new(sizeof(struct list_config *), 0))) goto cleanup;
if (!(config->output_configs = list_new(sizeof(struct output_config *), 0))) goto cleanup;
if (!(config->cmd_queue = create_list())) goto cleanup;
if (!(config->cmd_queue = list_new(sizeof(char *), 0))) goto cleanup;
if (!(config->current_mode = malloc(sizeof(struct sway_mode)))) goto cleanup;
if (!(config->current_mode->name = malloc(sizeof("default")))) goto cleanup;
strcpy(config->current_mode->name, "default");
if (!(config->current_mode->bindings = create_list())) goto cleanup;
list_add(config->modes, config->current_mode);
if (!(config->current_mode->bindings = list_new(sizeof(struct sway_binding *), 0))) goto cleanup;
list_add(config->modes, &config->current_mode);
config->floating_mod = 0;
config->dragging_key = M_LEFT_CLICK;
@ -342,9 +296,9 @@ static void config_defaults(struct sway_config *config) {
config->gaps_inner = 0;
config->gaps_outer = 0;
if (!(config->active_bar_modifiers = create_list())) goto cleanup;
if (!(config->active_bar_modifiers = list_new(sizeof(uint32_t *), 0))) goto cleanup;
if (!(config->config_chain = create_list())) goto cleanup;
if (!(config->config_chain = list_new(sizeof(char *), 0))) goto cleanup;
config->current_config = NULL;
// borders
@ -388,9 +342,9 @@ static void config_defaults(struct sway_config *config) {
config->border_colors.background = 0xFFFFFFFF;
// Security
if (!(config->command_policies = create_list())) goto cleanup;
if (!(config->feature_policies = create_list())) goto cleanup;
if (!(config->ipc_policies = create_list())) goto cleanup;
if (!(config->command_policies = list_new(sizeof(struct command_policy *), 0))) goto cleanup;
if (!(config->feature_policies = list_new(sizeof(struct feature_policy *), 0))) goto cleanup;
if (!(config->ipc_policies = list_new(sizeof(struct ipc_policy *), 0))) goto cleanup;
return;
cleanup:
@ -407,15 +361,13 @@ static int compare_modifiers(const void *left, const void *right) {
void update_active_bar_modifiers() {
if (config->active_bar_modifiers->length > 0) {
list_free(config->active_bar_modifiers);
config->active_bar_modifiers = create_list();
config->active_bar_modifiers = list_new(sizeof(uint32_t *), 0);
}
struct bar_config *bar;
int i;
for (i = 0; i < config->bars->length; ++i) {
bar = config->bars->items[i];
for (size_t i = 0; i < config->bars->length; ++i) {
struct bar_config *bar = list_getp(config->bars, i);
if (strcmp(bar->mode, "hide") == 0 && strcmp(bar->hidden_state, "hide") == 0) {
if (list_seq_find(config->active_bar_modifiers, compare_modifiers, &bar->modifier) < 0) {
if (list_lsearchp(config->active_bar_modifiers, compare_modifiers, &bar->modifier, NULL) < 0) {
list_add(config->active_bar_modifiers, &bar->modifier);
}
}
@ -524,7 +476,7 @@ bool load_main_config(const char *file, bool is_active) {
}
config->current_config = path;
list_add(config->config_chain, path);
list_add(config->config_chain, &path);
config->reading = true;
@ -535,7 +487,7 @@ bool load_main_config(const char *file, bool is_active) {
sway_log(L_ERROR, "%s does not exist, sway will have no security configuration"
" and will probably be broken", SYSCONFDIR "/sway/security.d");
} else {
list_t *secconfigs = create_list();
list_t *secconfigs = list_new(sizeof(char *), 0);
char *base = SYSCONFDIR "/sway/security.d/";
struct dirent *ent = readdir(dir);
struct stat s;
@ -545,15 +497,15 @@ bool load_main_config(const char *file, bool is_active) {
strcat(_path, ent->d_name);
lstat(_path, &s);
if (S_ISREG(s.st_mode)) {
list_add(secconfigs, _path);
list_add(secconfigs, &_path);
}
ent = readdir(dir);
}
closedir(dir);
list_qsort(secconfigs, qstrcmp);
for (int i = 0; i < secconfigs->length; ++i) {
char *_path = secconfigs->items[i];
for (size_t i = 0; i < secconfigs->length; ++i) {
char *_path = list_getp(secconfigs, i);
if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || (((s.st_mode & 0777) != 0644) && (s.st_mode & 0777) != 0444)) {
sway_log(L_ERROR, "Refusing to load %s - it must be owned by root and mode 644 or 444", _path);
success = false;
@ -562,7 +514,7 @@ bool load_main_config(const char *file, bool is_active) {
}
}
free_flat_list(secconfigs);
list_free_withp(secconfigs, free);
}
success = success && load_config(path, config);
@ -608,9 +560,8 @@ static bool load_include_config(const char *path, const char *parent_dir, struct
}
// check if config has already been included
int j;
for (j = 0; j < config->config_chain->length; ++j) {
char *old_path = config->config_chain->items[j];
for (size_t j = 0; j < config->config_chain->length; ++j) {
char *old_path = list_getp(config->config_chain, j);
if (strcmp(real_path, old_path) == 0) {
sway_log(L_DEBUG, "%s already included once, won't be included again.", real_path);
free(real_path);
@ -619,13 +570,13 @@ static bool load_include_config(const char *path, const char *parent_dir, struct
}
config->current_config = real_path;
list_add(config->config_chain, real_path);
int index = config->config_chain->length - 1;
list_add(config->config_chain, &real_path);
size_t index = config->config_chain->length - 1;
if (!load_config(real_path, config)) {
free(real_path);
config->current_config = parent_config;
list_del(config->config_chain, index);
list_delete(config->config_chain, index);
return false;
}
@ -715,7 +666,8 @@ bool read_config(FILE *file, struct sway_config *config) {
case CMD_DEFER:
sway_log(L_DEBUG, "Defferring command `%s'", line);
list_add(config->cmd_queue, strdup(line));
char *ptr = strdup(line);
list_add(config->cmd_queue, &ptr);
break;
case CMD_BLOCK_MODE:
@ -778,7 +730,7 @@ bool read_config(FILE *file, struct sway_config *config) {
switch(block) {
case CMD_BLOCK_MODE:
sway_log(L_DEBUG, "End of mode block");
config->current_mode = config->modes->items[0];
config->current_mode = list_getp(config->modes, 0);
block = CMD_BLOCK_END;
break;
@ -1003,10 +955,8 @@ void terminate_swaybg(pid_t pid) {
}
static bool active_output(const char *name) {
int i;
swayc_t *cont = NULL;
for (i = 0; i < root_container.children->length; ++i) {
cont = root_container.children->items[i];
for (size_t i = 0; i < root_container.children->length; ++i) {
swayc_t *cont = list_getp(root_container.children, i);
if (cont->type == C_OUTPUT && strcasecmp(name, cont->name) == 0) {
return true;
}
@ -1017,16 +967,14 @@ static bool active_output(const char *name) {
void load_swaybars() {
// Check for bars
list_t *bars = create_list();
list_t *bars = list_new(sizeof(struct bar_config *), 0);
struct bar_config *bar = NULL;
int i;
for (i = 0; i < config->bars->length; ++i) {
bar = config->bars->items[i];
for (size_t i = 0; i < config->bars->length; ++i) {
bar = list_getp(config->bars, i);
bool apply = false;
if (bar->outputs) {
int j;
for (j = 0; j < bar->outputs->length; ++j) {
char *o = bar->outputs->items[j];
for (size_t j = 0; j < bar->outputs->length; ++j) {
char *o = list_getp(bar->outputs, j);
if (!strcmp(o, "*") || active_output(o)) {
apply = true;
break;
@ -1036,12 +984,12 @@ void load_swaybars() {
apply = true;
}
if (apply) {
list_add(bars, bar);
list_add(bars, &bar);
}
}
for (i = 0; i < bars->length; ++i) {
bar = bars->items[i];
for (size_t i = 0; i < bars->length; ++i) {
bar = list_getp(bars, i);
if (bar->pid != 0) {
terminate_swaybar(bar->pid);
}
@ -1130,8 +1078,8 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
output->y = oc->y;
} else {
int x = 0;
for (int i = 0; i < root_container.children->length; ++i) {
swayc_t *c = root_container.children->items[i];
for (size_t i = 0; i < root_container.children->length; ++i) {
swayc_t *c = list_getp(root_container.children, i);
if (c->type == C_OUTPUT) {
if (c->width + c->x > x) {
x = c->width + c->x;
@ -1143,17 +1091,19 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
if (!oc || !oc->background) {
// Look for a * config for background
int i = list_seq_find(config->output_configs, output_name_cmp, "*");
if (i >= 0) {
oc = config->output_configs->items[i];
struct output_config *item;
const char *str = "*";
if (list_lsearchp(config->output_configs, output_name_cmp, str, &item) != -1) {
oc = item;
} else {
oc = NULL;
}
}
int output_i;
size_t output_i;
for (output_i = 0; output_i < root_container.children->length; ++output_i) {
if (root_container.children->items[output_i] == output) {
swayc_t *item = list_getp(root_container.children, output_i);
if (item == output) {
break;
}
}
@ -1163,11 +1113,11 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
terminate_swaybg(output->bg_pid);
}
sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, oc->background);
sway_log(L_DEBUG, "Setting background for output %zu to %s", output_i, oc->background);
size_t bufsize = 12;
char output_id[bufsize];
snprintf(output_id, bufsize, "%d", output_i);
snprintf(output_id, bufsize, "%zu", output_i);
output_id[bufsize-1] = 0;
char *const cmd[] = {
@ -1186,7 +1136,6 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
}
char *do_var_replacement(char *str) {
int i;
char *find = str;
while ((find = strchr(find, '$'))) {
// Skip if escaped.
@ -1196,9 +1145,10 @@ char *do_var_replacement(char *str) {
continue;
}
}
size_t i;
// Find matching variable
for (i = 0; i < config->symbols->length; ++i) {
struct sway_variable *var = config->symbols->items[i];
struct sway_variable *var = list_getp(config->symbols, i);
int vnlen = strlen(var->name);
if (strncmp(find, var->name, vnlen) == 0) {
int vvlen = strlen(var->value);
@ -1259,16 +1209,16 @@ int sway_binding_cmp_keys(const void *a, const void *b) {
return -1;
}
struct wlc_modifiers no_mods = { 0, 0 };
for (int i = 0; i < binda->keys->length; i++) {
xkb_keysym_t ka = *(xkb_keysym_t *)binda->keys->items[i],
kb = *(xkb_keysym_t *)bindb->keys->items[i];
for (size_t i = 0; i < binda->keys->length; i++) {
xkb_keysym_t ka = *(xkb_keysym_t *)list_getp(binda->keys, i),
kb = *(xkb_keysym_t *)list_getp(bindb->keys, i);
if (binda->bindcode) {
uint32_t *keycode = binda->keys->items[i];
uint32_t *keycode = list_getp(binda->keys, i);
ka = wlc_keyboard_get_keysym_for_key(*keycode, &no_mods);
}
if (bindb->bindcode) {
uint32_t *keycode = bindb->keys->items[i];
uint32_t *keycode = list_getp(bindb->keys, i);
kb = wlc_keyboard_get_keysym_for_key(*keycode, &no_mods);
}
@ -1296,15 +1246,8 @@ int sway_binding_cmp_qsort(const void *a, const void *b) {
}
void free_sway_binding(struct sway_binding *binding) {
if (binding->keys) {
for (int i = 0; i < binding->keys->length; i++) {
free(binding->keys->items[i]);
}
list_free(binding->keys);
}
if (binding->command) {
free(binding->command);
}
list_free_withp(binding->keys, free);
free(binding->command);
free(binding);
}
@ -1349,16 +1292,15 @@ struct sway_binding *sway_binding_dup(struct sway_binding *sb) {
new_sb->modifiers = sb->modifiers;
new_sb->command = strdup(sb->command);
new_sb->keys = create_list();
int i;
for (i = 0; i < sb->keys->length; ++i) {
new_sb->keys = list_new(sizeof(xkb_keysym_t *), 0);
for (size_t i = 0; i < sb->keys->length; ++i) {
xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t));
if (!key) {
free_sway_binding(new_sb);
return NULL;
}
*key = *(xkb_keysym_t *)sb->keys->items[i];
list_add(new_sb->keys, key);
*key = *(xkb_keysym_t *)list_getp(sb->keys, i);
list_add(new_sb->keys, &key);
}
return new_sb;
@ -1375,7 +1317,7 @@ struct bar_config *default_bar_config(void) {
bar->modifier = WLC_BIT_MOD_LOGO;
bar->outputs = NULL;
bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
if (!(bar->bindings = create_list())) goto cleanup;
if (!(bar->bindings = list_new(sizeof(struct sway_binding *), 0))) goto cleanup;
if (!(bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p'; sleep 1; done"))) goto cleanup;
bar->pango_markup = false;
bar->swaybar_command = NULL;
@ -1414,7 +1356,7 @@ struct bar_config *default_bar_config(void) {
bar->colors.binding_mode_bg = NULL;
bar->colors.binding_mode_text = NULL;
list_add(config->bars, bar);
list_add(config->bars, &bar);
return bar;

View file

@ -35,7 +35,7 @@ static swayc_t *new_swayc(enum swayc_types type) {
c->nb_master = 1;
c->nb_slave_groups = 1;
if (type != C_VIEW) {
c->children = create_list();
c->children = list_new(sizeof(swayc_t *), 0);
}
return c;
}
@ -48,7 +48,7 @@ static void free_swayc(swayc_t *cont) {
// remove children until there are no more, free_swayc calls
// remove_child, which removes child from this container
while (cont->children->length) {
free_swayc(cont->children->items[0]);
free_swayc(list_getp(cont->children, 0));
}
list_free(cont->children);
}
@ -57,7 +57,7 @@ static void free_swayc(swayc_t *cont) {
}
if (cont->floating) {
while (cont->floating->length) {
free_swayc(cont->floating->items[0]);
free_swayc(list_getp(cont->floating, 0));
}
list_free(cont->floating);
}
@ -99,8 +99,8 @@ static void update_root_geometry() {
int child_width;
int child_height;
for (int i = 0; i < root_container.children->length; ++i) {
child = root_container.children->items[i];
for (size_t i = 0; i < root_container.children->length; ++i) {
child = list_getp(root_container.children, i);
child_width = child->width + child->x;
child_height = child->height + child->y;
if (child_width > width) {
@ -123,24 +123,20 @@ swayc_t *new_output(wlc_handle handle) {
output_get_scaled_size(handle, &size);
const char *name = wlc_output_get_name(handle);
// Find current outputs to see if this already exists
{
int i, len = root_container.children->length;
for (i = 0; i < len; ++i) {
swayc_t *op = root_container.children->items[i];
const char *op_name = op->name;
if (op_name && name && strcmp(op_name, name) == 0) {
sway_log(L_DEBUG, "restoring output %" PRIuPTR ":%s", handle, op_name);
return op;
}
for (size_t i = 0; i < root_container.children->length; ++i) {
swayc_t *op = list_getp(root_container.children, i);
const char *op_name = op->name;
if (op_name && name && strcmp(op_name, name) == 0) {
sway_log(L_DEBUG, "restoring output %" PRIuPTR ":%s", handle, op_name);
return op;
}
}
sway_log(L_DEBUG, "New output %" PRIuPTR ":%s", handle, name);
struct output_config *oc = NULL, *all = NULL;
int i;
for (i = 0; i < config->output_configs->length; ++i) {
struct output_config *cur = config->output_configs->items[i];
for (size_t i = 0; i < config->output_configs->length; ++i) {
struct output_config *cur = list_getp(config->output_configs, i);
if (strcasecmp(name, cur->name) == 0) {
sway_log(L_DEBUG, "Matched output config for %s", name);
oc = cur;
@ -168,7 +164,7 @@ swayc_t *new_output(wlc_handle handle) {
output->name = name ? strdup(name) : NULL;
output->width = size.w;
output->height = size.h;
output->unmanaged = create_list();
output->unmanaged = list_new(sizeof(wlc_handle *), 0);
output->bg_pid = 0;
apply_output_config(oc, output);
@ -180,8 +176,8 @@ swayc_t *new_output(wlc_handle handle) {
swayc_t *ws = NULL;
if (name) {
for (i = 0; i < config->workspace_outputs->length; ++i) {
struct workspace_output *wso = config->workspace_outputs->items[i];
for (size_t i = 0; i < config->workspace_outputs->length; ++i) {
struct workspace_output *wso = list_getp(config->workspace_outputs, i);
if (strcasecmp(wso->output, name) == 0) {
sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output);
// Check if any other workspaces are using this name
@ -206,7 +202,7 @@ swayc_t *new_output(wlc_handle handle) {
ws->is_focused = true;
} else {
sort_workspaces(output);
set_focused_container(output->children->items[0]);
set_focused_container(list_getp(output->children, 0));
}
free(ws_name);
@ -231,7 +227,7 @@ swayc_t *new_workspace(swayc_t *output, const char *name) {
workspace->height = output->height;
workspace->name = !name ? NULL : strdup(name);
workspace->visible = false;
workspace->floating = create_list();
workspace->floating = list_new(sizeof(swayc_t *), 0);
add_child(output, workspace);
sort_workspaces(output);
@ -265,9 +261,8 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) {
cont->focused = workspace->focused;
workspace->focused = cont;
// set all children focu to container
int i;
for (i = 0; i < workspace->children->length; ++i) {
((swayc_t *)workspace->children->items[i])->parent = cont;
for (size_t i = 0; i < workspace->children->length; ++i) {
((swayc_t *)list_getp(workspace->children, i))->parent = cont;
}
// Swap children
list_t *tmp_list = workspace->children;
@ -378,7 +373,7 @@ swayc_t *new_floating_view(wlc_handle handle) {
view->is_floating = true;
// Case of focused workspace, just create as child of it
list_add(swayc_active_workspace()->floating, view);
list_add(swayc_active_workspace()->floating, &view);
view->parent = swayc_active_workspace();
if (swayc_active_workspace()->focused == NULL) {
set_focused_container_for(swayc_active_workspace(), view);
@ -437,16 +432,17 @@ swayc_t *destroy_output(swayc_t *output) {
// TODO also check if there will ever be no outputs except for exiting
// program
if (root_container.children->length > 1) {
int p = root_container.children->items[0] == output;
int p = list_getp(root_container.children, 0) == output;
// Move workspace from this output to another output
swayc_t *item = list_getp(root_container.children, p);
while (output->children->length) {
swayc_t *child = output->children->items[0];
swayc_t *child = list_getp(output->children, 0);
remove_child(child);
add_child(root_container.children->items[p], child);
add_child(item, child);
}
sort_workspaces(root_container.children->items[p]);
update_visibility(root_container.children->items[p]);
arrange_windows(root_container.children->items[p], -1, -1);
sort_workspaces(item);
update_visibility(item);
arrange_windows(item, -1, -1);
}
}
sway_log(L_DEBUG, "OUTPUT: Destroying output '%" PRIuPTR "'", output->handle);
@ -474,23 +470,24 @@ swayc_t *destroy_workspace(swayc_t *workspace) {
} else {
// Move children to a different workspace on this output
swayc_t *new_workspace = NULL;
int i;
for(i = 0; i < output->children->length; i++) {
if(output->children->items[i] != workspace) {
for(size_t i = 0; i < output->children->length; i++) {
new_workspace = list_getp(output->children, i);
if (new_workspace != workspace) {
break;
}
}
new_workspace = output->children->items[i];
sway_log(L_DEBUG, "moving children to different workspace '%s' -> '%s'",
workspace->name, new_workspace->name);
for(i = 0; i < workspace->children->length; i++) {
move_container_to(workspace->children->items[i], new_workspace);
for (size_t i = 0; i < workspace->children->length; i++) {
swayc_t *item = list_getp(workspace->children, i);
move_container_to(item, new_workspace);
}
for(i = 0; i < workspace->floating->length; i++) {
move_container_to(workspace->floating->items[i], new_workspace);
for (size_t i = 0; i < workspace->floating->length; i++) {
swayc_t *item = list_getp(workspace->floating, i);
move_container_to(item, new_workspace);
}
}
@ -534,17 +531,16 @@ swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *dat
return NULL;
}
// Special case for checking floating stuff
int i;
if (container->type == C_WORKSPACE) {
for (i = 0; i < container->floating->length; ++i) {
swayc_t *child = container->floating->items[i];
for (size_t i = 0; i < container->floating->length; ++i) {
swayc_t *child = list_getp(container->floating, i);
if (test(child, data)) {
return child;
}
}
}
for (i = 0; i < container->children->length; ++i) {
swayc_t *child = container->children->items[i];
for (size_t i = 0; i < container->children->length; ++i) {
swayc_t *child = list_getp(container->children, i);
if (test(child, data)) {
return child;
} else {
@ -710,8 +706,6 @@ swayc_t *container_under_pointer(void) {
struct wlc_point origin;
wlc_pointer_get_position(&origin);
while (lookup && lookup->type != C_VIEW) {
int i;
int len;
// if tabbed/stacked go directly to focused container, otherwise search
// children
if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) {
@ -720,11 +714,13 @@ swayc_t *container_under_pointer(void) {
}
// if workspace, search floating
if (lookup->type == C_WORKSPACE) {
ssize_t i, len;
i = len = lookup->floating->length;
bool got_floating = false;
while (--i > -1) {
if (pointer_test(lookup->floating->items[i], &origin)) {
lookup = lookup->floating->items[i];
swayc_t *item = list_getp(lookup->floating, i);
if (pointer_test(item, &origin)) {
lookup = item;
got_floating = true;
break;
}
@ -734,10 +730,11 @@ swayc_t *container_under_pointer(void) {
}
}
// search children
len = lookup->children->length;
size_t i, len = lookup->children->length;
for (i = 0; i < len; ++i) {
if (pointer_test(lookup->children->items[i], &origin)) {
lookup = lookup->children->items[i];
swayc_t *item = list_getp(lookup->children, i);
if (pointer_test(item, &origin)) {
lookup = item;
break;
}
}
@ -756,8 +753,8 @@ swayc_t *container_find(swayc_t *container, bool (*f)(swayc_t *, const void *),
swayc_t *con;
if (container->type == C_WORKSPACE) {
for (int i = 0; i < container->floating->length; ++i) {
con = container->floating->items[i];
for (size_t i = 0; i < container->floating->length; ++i) {
con = list_getp(container->floating, i);
if (f(con, data)) {
return con;
}
@ -768,8 +765,8 @@ swayc_t *container_find(swayc_t *container, bool (*f)(swayc_t *, const void *),
}
}
for (int i = 0; i < container->children->length; ++i) {
con = container->children->items[i];
for (size_t i = 0; i < container->children->length; ++i) {
con = list_getp(container->children, i);
if (f(con, data)) {
return con;
}
@ -837,16 +834,15 @@ int swayc_gap(swayc_t *container) {
void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) {
if (container) {
f(container, data);
int i;
if (container->children) {
for (i = 0; i < container->children->length; ++i) {
swayc_t *child = container->children->items[i];
for (size_t i = 0; i < container->children->length; ++i) {
swayc_t *child = list_getp(container->children, i);
container_map(child, f, data);
}
}
if (container->floating) {
for (i = 0; i < container->floating->length; ++i) {
swayc_t *child = container->floating->items[i];
for (size_t i = 0; i < container->floating->length; ++i) {
swayc_t *child = list_getp(container->floating, i);
container_map(child, f, data);
}
}
@ -870,15 +866,15 @@ void update_visibility_output(swayc_t *container, wlc_handle output) {
// Update visibility for children
else {
if (container->children) {
int i, len = container->children->length;
for (i = 0; i < len; ++i) {
update_visibility_output(container->children->items[i], output);
for (size_t i = 0; i < container->children->length; ++i) {
swayc_t *item = list_getp(container->children, i);
update_visibility_output(item, output);
}
}
if (container->floating) {
int i, len = container->floating->length;
for (i = 0; i < len; ++i) {
update_visibility_output(container->floating->items[i], output);
for (size_t i = 0; i < container->floating->length; ++i) {
swayc_t *item = list_getp(container->floating, i);
update_visibility_output(item, output);
}
}
}
@ -890,9 +886,9 @@ void update_visibility(swayc_t *container) {
case C_ROOT:
container->visible = true;
if (container->children) {
int i, len = container->children->length;
for (i = 0; i < len; ++i) {
update_visibility(container->children->items[i]);
for (size_t i = 0; i < container->children->length; ++i) {
swayc_t *item = list_getp(container->children, i);
update_visibility(item);
}
}
return;
@ -900,9 +896,9 @@ void update_visibility(swayc_t *container) {
case C_OUTPUT:
container->visible = true;
if (container->children) {
int i, len = container->children->length;
for (i = 0; i < len; ++i) {
update_visibility_output(container->children->items[i], container->handle);
for (size_t i = 0; i < container->children->length; ++i) {
swayc_t *item = list_getp(container->children, i);
update_visibility_output(item, container->handle);
}
}
return;
@ -983,8 +979,8 @@ swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) {
layout == L_AUTO_LEFT || layout == L_AUTO_RIGHT
? L_HORIZ : L_VERT;
if (new_major != prev_major) {
for (int i = 0; i < container->children->length; ++i) {
swayc_t *child = container->children->items[i];
for (size_t i = 0; i < container->children->length; ++i) {
swayc_t *child = list_getp(container->children, i);
double h = child->height;
child->height = child->width;
child->width = h;

View file

@ -52,8 +52,8 @@ static void free_crit_token(struct crit_token *crit) {
}
static void free_crit_tokens(list_t *crit_tokens) {
for (int i = 0; i < crit_tokens->length; i++) {
free_crit_token(crit_tokens->items[i]);
for (size_t i = 0; i < crit_tokens->length; i++) {
free_crit_token(list_getp(crit_tokens, i));
}
list_free(crit_tokens);
}
@ -223,13 +223,13 @@ char *extract_crit_tokens(list_t *tokens, const char * const criteria) {
goto ect_cleanup;
} else if (token->type == CRIT_URGENT || crit_is_focused(value)) {
sway_log(L_DEBUG, "%s -> \"%s\"", name, value);
list_add(tokens, token);
list_add(tokens, &token);
} else if((error = generate_regex(&token->regex, value))) {
free_crit_token(token);
goto ect_cleanup;
} else {
sway_log(L_DEBUG, "%s -> /%s/", name, value);
list_add(tokens, token);
list_add(tokens, &token);
}
}
ect_cleanup:
@ -247,9 +247,9 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
if (cont->type != C_VIEW) {
return false;
}
int matches = 0;
for (int i = 0; i < tokens->length; i++) {
struct crit_token *crit = tokens->items[i];
size_t matches = 0;
for (size_t i = 0; i < tokens->length; i++) {
struct crit_token *crit = list_getp(tokens, i);
switch (crit->type) {
case CRIT_CLASS:
if (!cont->class) {
@ -264,9 +264,9 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
}
break;
case CRIT_CON_MARK:
if (crit->regex && cont->marks && (list_seq_find(cont->marks, (int (*)(const void *, const void *))regex_cmp, crit->regex) != -1)) {
if (crit->regex && cont->marks && (list_lsearchp(cont->marks, (int (*)(const void *, const void *))regex_cmp, crit->regex, NULL) != -1)) {
// Make sure it isn't matching the NUL string
if ((strcmp(crit->raw, "") == 0) == (list_seq_find(cont->marks, (int (*)(const void *, const void *))strcmp, "") != -1)) {
if ((strcmp(crit->raw, "") == 0) == (list_lsearchp(cont->marks, (int (*)(const void *, const void *))strcmp, "", NULL) != -1)) {
++matches;
}
}
@ -360,8 +360,8 @@ void free_criteria(struct criteria *crit) {
}
bool criteria_any(swayc_t *cont, list_t *criteria) {
for (int i = 0; i < criteria->length; i++) {
struct criteria *bc = criteria->items[i];
for (size_t i = 0; i < criteria->length; i++) {
struct criteria *bc = list_getp(criteria, i);
if (criteria_test(cont, bc->tokens)) {
return true;
}
@ -370,11 +370,11 @@ bool criteria_any(swayc_t *cont, list_t *criteria) {
}
list_t *criteria_for(swayc_t *cont) {
list_t *criteria = config->criteria, *matches = create_list();
for (int i = 0; i < criteria->length; i++) {
struct criteria *bc = criteria->items[i];
list_t *matches = list_new(sizeof(struct criteria *), 0);
for (size_t i = 0; i < config->criteria->length; i++) {
struct criteria *bc = list_getp(config->criteria, i);
if (criteria_test(cont, bc->tokens)) {
list_add(matches, bc);
list_add(matches, &bc);
}
}
return matches;
@ -385,15 +385,16 @@ struct list_tokens {
list_t *tokens;
};
static void container_match_add(swayc_t *container, struct list_tokens *list_tokens) {
static void container_match_add(swayc_t *container, void *arg) {
struct list_tokens *list_tokens = arg;
if (criteria_test(container, list_tokens->tokens)) {
list_add(list_tokens->list, container);
list_add(list_tokens->list, &container);
}
}
list_t *container_for(list_t *tokens) {
struct list_tokens list_tokens = (struct list_tokens){create_list(), tokens};
struct list_tokens list_tokens = {list_new(sizeof(swayc_t *), 0), tokens};
container_map(&root_container, (void (*)(swayc_t *, void *))container_match_add, &list_tokens);
container_map(&root_container, container_match_add, &list_tokens);
return list_tokens.list;
}

View file

@ -47,7 +47,7 @@ static void container_log(const swayc_t *c, int depth) {
fprintf(stderr, "x:%4.f|y:%4.f|", c->x, c->y);
fprintf(stderr, "g:%3d|",c->gaps);
fprintf(stderr, "vis:%c|", c->visible?'t':'f');
fprintf(stderr, "children:%2d|",c->children?c->children->length:0);
fprintf(stderr, "children:%2zu|",c->children?c->children->length:0);
fprintf(stderr, "name:%.16s\n", c->name);
}
void layout_log(const swayc_t *c, int depth) {
@ -59,7 +59,7 @@ void layout_log(const swayc_t *c, int depth) {
for (i = 0; i < e; ++i) {
fputc('|',stderr);
for (d = 0; d < depth; ++d) fputc('-', stderr);
layout_log(c->children->items[i], depth + 1);
layout_log(list_getp(c->children, i), depth + 1);
}
}
if (c->type == C_WORKSPACE) {
@ -68,7 +68,7 @@ void layout_log(const swayc_t *c, int depth) {
for (i = 0; i < e; ++i) {
fputc('|',stderr);
for (d = 0; d < depth; ++d) fputc('=', stderr);
layout_log(c->floating->items[i], depth + 1);
layout_log(list_getp(c->floating, i), depth + 1);
}
}
}

View file

@ -15,8 +15,8 @@
struct desktop_shell_state desktop_shell;
static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) {
for (int i = 0; i < desktop_shell.panels->length; i++) {
struct panel_config *conf = desktop_shell.panels->items[i];
for (size_t i = 0; i < desktop_shell.panels->length; i++) {
struct panel_config *conf = list_getp(desktop_shell.panels, i);
if (conf->wl_resource == resource) {
sway_log(L_DEBUG, "Found existing panel config for resource %p", resource);
return conf;
@ -28,18 +28,17 @@ static struct panel_config *find_or_create_panel_config(struct wl_resource *reso
sway_log(L_ERROR, "Unable to create panel config");
return NULL;
}
list_add(desktop_shell.panels, config);
list_add(desktop_shell.panels, &config);
config->wl_resource = resource;
return config;
}
void background_surface_destructor(struct wl_resource *resource) {
sway_log(L_DEBUG, "Background surface killed");
int i;
for (i = 0; i < desktop_shell.backgrounds->length; ++i) {
struct background_config *config = desktop_shell.backgrounds->items[i];
for (size_t i = 0; i < desktop_shell.backgrounds->length; ++i) {
struct background_config *config = list_getp(desktop_shell.backgrounds, i);
if (config->wl_surface_res == resource) {
list_del(desktop_shell.backgrounds, i);
list_delete(desktop_shell.backgrounds, i);
break;
}
}
@ -47,11 +46,10 @@ void background_surface_destructor(struct wl_resource *resource) {
void panel_surface_destructor(struct wl_resource *resource) {
sway_log(L_DEBUG, "Panel surface killed");
int i;
for (i = 0; i < desktop_shell.panels->length; ++i) {
struct panel_config *config = desktop_shell.panels->items[i];
for (size_t i = 0; i < desktop_shell.panels->length; ++i) {
struct panel_config *config = list_getp(desktop_shell.panels, i);
if (config->wl_surface_res == resource) {
list_del(desktop_shell.panels, i);
list_delete(desktop_shell.panels, i);
arrange_windows(&root_container, -1, -1);
break;
}
@ -60,11 +58,10 @@ void panel_surface_destructor(struct wl_resource *resource) {
void lock_surface_destructor(struct wl_resource *resource) {
sway_log(L_DEBUG, "Lock surface killed");
int i;
for (i = 0; i < desktop_shell.lock_surfaces->length; ++i) {
struct wl_resource *surface = desktop_shell.lock_surfaces->items[i];
for (size_t i = 0; i < desktop_shell.lock_surfaces->length; ++i) {
struct wl_resource *surface = list_getp(desktop_shell.lock_surfaces, i);
if (surface == resource) {
list_del(desktop_shell.lock_surfaces, i);
list_delete(desktop_shell.lock_surfaces, i);
arrange_windows(&root_container, -1, -1);
break;
}
@ -104,7 +101,7 @@ static void set_background(struct wl_client *client, struct wl_resource *resourc
config->output = output;
config->surface = wlc_resource_from_wl_surface_resource(surface);
config->wl_surface_res = surface;
list_add(desktop_shell.backgrounds, config);
list_add(desktop_shell.backgrounds, &config);
wl_resource_set_destructor(surface, background_surface_destructor);
arrange_windows(swayc_by_handle(output), -1, -1);
wlc_output_schedule_render(config->output);
@ -214,7 +211,7 @@ static void set_lock_surface(struct wl_client *client, struct wl_resource *resou
desktop_shell.is_locked = true;
input_init();
arrange_windows(workspace, -1, -1);
list_add(desktop_shell.lock_surfaces, surface);
list_add(desktop_shell.lock_surfaces, &surface);
wl_resource_set_destructor(surface, lock_surface_destructor);
} else {
sway_log(L_ERROR, "Attempted to set lock surface to non-view");
@ -322,9 +319,9 @@ static void gamma_control_manager_bind(struct wl_client *client, void *data,
void register_extensions(void) {
wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind);
desktop_shell.backgrounds = create_list();
desktop_shell.panels = create_list();
desktop_shell.lock_surfaces = create_list();
desktop_shell.backgrounds = list_new(sizeof(struct background_config *), 0);
desktop_shell.panels = list_new(sizeof(struct panel_config *), 0);
desktop_shell.lock_surfaces = list_new(sizeof(struct wl_resource *), 0);
desktop_shell.is_locked = false;
wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind);
wl_global_create(wlc_get_wl_display(), &gamma_control_manager_interface, 1,

View file

@ -252,7 +252,7 @@ swayc_t *get_focused_float(swayc_t *ws) {
ws = swayc_active_workspace();
}
if (ws->floating->length) {
return ws->floating->items[ws->floating->length - 1];
return list_getp(ws->floating, ws->floating->length - 1);
}
return NULL;
}

View file

@ -35,9 +35,8 @@
#define EVENT_HANDLED true
static struct panel_config *if_panel_find_config(struct wl_client *client) {
int i;
for (i = 0; i < desktop_shell.panels->length; i++) {
struct panel_config *config = desktop_shell.panels->items[i];
for (size_t i = 0; i < desktop_shell.panels->length; i++) {
struct panel_config *config = list_getp(desktop_shell.panels, i);
if (config->client == client) {
return config;
}
@ -46,9 +45,8 @@ static struct panel_config *if_panel_find_config(struct wl_client *client) {
}
static struct background_config *if_background_find_config(struct wl_client *client) {
int i;
for (i = 0; i < desktop_shell.backgrounds->length; i++) {
struct background_config *config = desktop_shell.backgrounds->items[i];
for (size_t i = 0; i < desktop_shell.backgrounds->length; i++) {
struct background_config *config = list_getp(desktop_shell.backgrounds, i);
if (config->client == client) {
return config;
}
@ -98,8 +96,8 @@ static void update_panel_geometry(struct panel_config *config) {
}
static void update_panel_geometries(wlc_handle output) {
for (int i = 0; i < desktop_shell.panels->length; i++) {
struct panel_config *config = desktop_shell.panels->items[i];
for (size_t i = 0; i < desktop_shell.panels->length; i++) {
struct panel_config *config = list_getp(desktop_shell.panels, i);
if (config->output == output) {
update_panel_geometry(config);
}
@ -113,8 +111,8 @@ static void update_background_geometry(struct background_config *config) {
}
static void update_background_geometries(wlc_handle output) {
for (int i = 0; i < desktop_shell.backgrounds->length; i++) {
struct background_config *config = desktop_shell.backgrounds->items[i];
for (size_t i = 0; i < desktop_shell.backgrounds->length; i++) {
struct background_config *config = list_getp(desktop_shell.backgrounds, i);
if (config->output == output) {
update_background_geometry(config);
}
@ -132,12 +130,11 @@ static bool handle_input_created(struct libinput_device *device) {
}
sway_log(L_INFO, "Found input device (%s)", identifier);
list_add(input_devices, device);
list_add(input_devices, &device);
struct input_config *ic = NULL;
int i;
for (i = 0; i < config->input_configs->length; ++i) {
struct input_config *cur = config->input_configs->items[i];
for (size_t i = 0; i < config->input_configs->length; ++i) {
struct input_config *cur = list_getp(config->input_configs, i);
if (strcasecmp(identifier, cur->identifier) == 0) {
sway_log(L_DEBUG, "Matched input config for %s",
identifier);
@ -157,11 +154,10 @@ static bool handle_input_created(struct libinput_device *device) {
}
static void handle_input_destroyed(struct libinput_device *device) {
int i;
list_t *list = input_devices;
for (i = 0; i < list->length; ++i) {
if(((struct libinput_device *)list->items[i]) == device) {
list_del(list, i);
for (size_t i = 0; i < input_devices->length; ++i) {
struct libinput_device *item = list_getp(input_devices, i);
if (item == device) {
list_delete(input_devices, i);
break;
}
}
@ -179,7 +175,7 @@ static bool handle_output_created(wlc_handle output) {
// Switch to workspace if we need to
if (swayc_active_workspace() == NULL) {
swayc_t *ws = op->children->items[0];
swayc_t *ws = list_getp(op->children, 0);
workspace_switch(ws);
}
@ -191,21 +187,21 @@ static bool handle_output_created(wlc_handle output) {
}
static void handle_output_destroyed(wlc_handle output) {
int i;
size_t i;
list_t *list = root_container.children;
for (i = 0; i < list->length; ++i) {
if (((swayc_t *)list->items[i])->handle == output) {
if (((swayc_t *)list_getp(list, i))->handle == output) {
break;
}
}
if (i < list->length) {
destroy_output(list->items[i]);
destroy_output(list_getp(list, i));
} else {
return;
}
if (list->length > 0) {
// switch to other outputs active workspace
workspace_switch(((swayc_t *)root_container.children->items[0])->focused);
workspace_switch(((swayc_t *)list_getp(root_container.children, 0))->focused);
}
}
@ -246,16 +242,16 @@ static void handle_output_focused(wlc_handle output, bool focus) {
static void ws_cleanup() {
swayc_t *op, *ws;
int i = 0, j;
size_t i = 0, j;
if (!root_container.children)
return;
while (i < root_container.children->length) {
op = root_container.children->items[i++];
op = list_getp(root_container.children, i++);
if (!op->children)
continue;
j = 0;
while (j < op->children->length) {
ws = op->children->items[j++];
ws = list_getp(op->children, j++);
if (ws->children->length == 0 && ws->floating->length == 0 && ws != op->focused) {
if (destroy_workspace(ws)) {
j--;
@ -403,7 +399,7 @@ static bool handle_view_created(wlc_handle handle) {
// TODO find a better way of doing this
// Or to focused container
else {
focused = get_focused_container(focused->parent->children->items[0]);
focused = get_focused_container(list_getp(focused->parent->children, 0));
}
}
}
@ -466,8 +462,8 @@ static bool handle_view_created(wlc_handle handle) {
arrange_windows(output, -1, -1);
// check if it matches for_window in config and execute if so
list_t *criteria = criteria_for(newview);
for (int i = 0; i < criteria->length; i++) {
struct criteria *crit = criteria->items[i];
for (size_t i = 0; i < criteria->length; i++) {
struct criteria *crit = list_getp(criteria, i);
sway_log(L_DEBUG, "for_window '%s' matches new view %p, cmd: '%s'",
crit->crit_raw, newview, crit->cmdlist);
struct cmd_results *res = handle_command(crit->cmdlist, CONTEXT_CRITERIA);
@ -492,7 +488,7 @@ static bool handle_view_created(wlc_handle handle) {
}
*h = handle;
sway_log(L_DEBUG, "Adding unmanaged window %p to %p", h, output->unmanaged);
list_add(output->unmanaged, h);
list_add(output->unmanaged, &h);
wlc_view_set_mask(handle, VISIBLE);
}
@ -559,14 +555,12 @@ static void handle_view_destroyed(wlc_handle handle) {
ipc_event_window(parent, "close");
} else {
// Is it unmanaged?
int i;
for (i = 0; i < root_container.children->length; ++i) {
swayc_t *output = root_container.children->items[i];
int j;
for (j = 0; j < output->unmanaged->length; ++j) {
wlc_handle *_handle = output->unmanaged->items[j];
for (size_t i = 0; i < root_container.children->length; ++i) {
swayc_t *output = list_getp(root_container.children, i);
for (size_t j = 0; j < output->unmanaged->length; ++j) {
wlc_handle *_handle = list_getp(output->unmanaged, j);
if (*_handle == handle) {
list_del(output->unmanaged, j);
list_delete(output->unmanaged, j);
free(_handle);
break;
}
@ -693,16 +687,15 @@ static void handle_binding_command(struct sway_binding *binding) {
}
static bool handle_bindsym(struct sway_binding *binding, uint32_t keysym, uint32_t keycode) {
int i;
for (i = 0; i < binding->keys->length; ++i) {
for (size_t i = 0; i < binding->keys->length; ++i) {
if (binding->bindcode) {
xkb_keycode_t *key = binding->keys->items[i];
xkb_keycode_t *key = list_getp(binding->keys, i);
if (keycode == *key) {
handle_binding_command(binding);
return true;
}
} else {
xkb_keysym_t *key = binding->keys->items[i];
xkb_keysym_t *key = list_getp(binding->keys, i);
if (keysym == *key) {
handle_binding_command(binding);
return true;
@ -715,15 +708,14 @@ static bool handle_bindsym(struct sway_binding *binding, uint32_t keysym, uint32
static bool valid_bindsym(struct sway_binding *binding) {
bool match = false;
int i;
for (i = 0; i < binding->keys->length; ++i) {
for (size_t i = 0; i < binding->keys->length; ++i) {
if (binding->bindcode) {
xkb_keycode_t *key = binding->keys->items[i];
xkb_keycode_t *key = list_getp(binding->keys, i);
if ((match = check_key(0, *key)) == false) {
break;
}
} else {
xkb_keysym_t *key = binding->keys->items[i];
xkb_keysym_t *key = list_getp(binding->keys, i);
if ((match = check_key(*key, 0)) == false) {
break;
}
@ -735,7 +727,7 @@ static bool valid_bindsym(struct sway_binding *binding) {
static bool handle_bindsym_release(struct sway_binding *binding) {
if (binding->keys->length == 1) {
xkb_keysym_t *key = binding->keys->items[0];
xkb_keysym_t *key = list_getp(binding->keys, 0);
if (check_released_key(*key)) {
handle_binding_command(binding);
return true;
@ -762,8 +754,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
struct wlc_modifiers no_mods = { 0, 0 };
uint32_t sym = tolower(wlc_keyboard_get_keysym_for_key(key, &no_mods));
int i;
if (state == WLC_KEY_STATE_PRESSED) {
press_key(sym, key);
} else { // WLC_KEY_STATE_RELEASED
@ -772,8 +762,8 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
// handle bar modifiers pressed/released
uint32_t modifier;
for (i = 0; i < config->active_bar_modifiers->length; ++i) {
modifier = *(uint32_t *)config->active_bar_modifiers->items[i];
for (size_t i = 0; i < config->active_bar_modifiers->length; ++i) {
modifier = *(uint32_t *)list_getp(config->active_bar_modifiers, i);
switch (modifier_state_changed(modifiers->mods, modifier)) {
case MOD_STATE_PRESSED:
@ -788,14 +778,14 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
modifiers_state_update(modifiers->mods);
// handle bindings
list_t *candidates = create_list();
for (i = 0; i < mode->bindings->length; ++i) {
struct sway_binding *binding = mode->bindings->items[i];
list_t *candidates = list_new(sizeof(struct sway_binding *), 0);
for (size_t i = 0; i < mode->bindings->length; ++i) {
struct sway_binding *binding = list_getp(mode->bindings, i);
if ((modifiers->mods ^ binding->modifiers) == 0) {
switch (state) {
case WLC_KEY_STATE_PRESSED: {
if (!binding->release && valid_bindsym(binding)) {
list_add(candidates, binding);
list_add(candidates, &binding);
}
}
case WLC_KEY_STATE_RELEASED:
@ -808,8 +798,8 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
}
}
for (i = 0; i < candidates->length; ++i) {
struct sway_binding *binding = candidates->items[i];
for (size_t i = 0; i < candidates->length; ++i) {
struct sway_binding *binding = list_getp(candidates, i);
if (state == WLC_KEY_STATE_PRESSED) {
if (!binding->release && handle_bindsym(binding, sym, key)) {
list_free(candidates);
@ -919,8 +909,8 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
struct sway_mode *mode = config->current_mode;
// handle bindings
for (int i = 0; i < mode->bindings->length; ++i) {
struct sway_binding *binding = mode->bindings->items[i];
for (size_t i = 0; i < mode->bindings->length; ++i) {
struct sway_binding *binding = list_getp(mode->bindings, i);
if ((modifiers->mods ^ binding->modifiers) == 0) {
switch (state) {
case WLC_BUTTON_STATE_PRESSED: {
@ -1014,11 +1004,11 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
}
// Send to front if floating
if (pointer->is_floating) {
int i;
for (i = 0; i < pointer->parent->floating->length; i++) {
if (pointer->parent->floating->items[i] == pointer) {
list_del(pointer->parent->floating, i);
list_add(pointer->parent->floating, pointer);
for (size_t i = 0; i < pointer->parent->floating->length; i++) {
swayc_t *item = list_getp(pointer->parent->floating, i);
if (item == pointer) {
list_delete(pointer->parent->floating, i);
list_add(pointer->parent->floating, &pointer);
break;
}
}
@ -1077,14 +1067,14 @@ static void handle_wlc_ready(void) {
// Execute commands until there are none left
config->active = true;
while (config->cmd_queue->length) {
char *line = config->cmd_queue->items[0];
char *line = list_getp(config->cmd_queue, 0);
struct cmd_results *res = handle_command(line, CONTEXT_CONFIG);
if (res->status != CMD_SUCCESS) {
sway_log(L_ERROR, "Error on line '%s': %s", line, res->error);
}
free_cmd_results(res);
free(line);
list_del(config->cmd_queue, 0);
list_delete(config->cmd_queue, 0);
}
}

View file

@ -145,9 +145,9 @@ static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object)
// window is in the scratchpad ? changed : none
static const char *ipc_json_get_scratchpad_state(swayc_t *c) {
int i;
for (i = 0; i < scratchpad->length; i++) {
if (scratchpad->items[i] == c) {
for (size_t i = 0; i < scratchpad->length; i++) {
swayc_t *item = list_getp(scratchpad, i);
if (item == c) {
return "changed";
}
}
@ -420,9 +420,8 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
// Add outputs if defined
if (bar->outputs && bar->outputs->length > 0) {
json_object *outputs = json_object_new_array();
int i;
for (i = 0; i < bar->outputs->length; ++i) {
const char *name = bar->outputs->items[i];
for (size_t i = 0; i < bar->outputs->length; ++i) {
const char *name = list_getp(bar->outputs, i);
json_object_array_add(outputs, json_object_new_string(name));
}
json_object_object_add(json, "outputs", outputs);
@ -433,30 +432,30 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
json_object *ipc_json_describe_container_recursive(swayc_t *c) {
json_object *object = ipc_json_describe_container(c);
int i;
json_object *floating = json_object_new_array();
if (c->type != C_VIEW && c->floating && c->floating->length > 0) {
for (i = 0; i < c->floating->length; ++i) {
json_object_array_add(floating, ipc_json_describe_container_recursive(c->floating->items[i]));
for (size_t i = 0; i < c->floating->length; ++i) {
swayc_t *item = list_getp(c->floating, i);
json_object_array_add(floating, ipc_json_describe_container_recursive(item));
}
}
json_object_object_add(object, "floating_nodes", floating);
json_object *children = json_object_new_array();
if (c->type != C_VIEW && c->children && c->children->length > 0) {
for (i = 0; i < c->children->length; ++i) {
json_object_array_add(children, ipc_json_describe_container_recursive(c->children->items[i]));
for (size_t i = 0; i < c->children->length; ++i) {
swayc_t *item = list_getp(c->children, i);
json_object_array_add(children, ipc_json_describe_container_recursive(item));
}
}
json_object_object_add(object, "nodes", children);
if (c->type == C_ROOT) {
json_object *scratchpad_json = json_object_new_array();
if (scratchpad->length > 0) {
for (i = 0; i < scratchpad->length; ++i) {
json_object_array_add(scratchpad_json, ipc_json_describe_container_recursive(scratchpad->items[i]));
}
for (size_t i = 0; i < scratchpad->length; ++i) {
swayc_t *item = list_getp(scratchpad, i);
json_object_array_add(scratchpad_json, ipc_json_describe_container_recursive(item));
}
json_object_object_add(object, "scratchpad", scratchpad_json);
}

View file

@ -92,8 +92,8 @@ void ipc_init(void) {
setenv("I3SOCK", ipc_sockaddr->sun_path, 1);
setenv("SWAYSOCK", ipc_sockaddr->sun_path, 1);
ipc_client_list = create_list();
ipc_get_pixel_requests = create_list();
ipc_client_list = list_new(sizeof(struct ipc_client *), 0);
ipc_get_pixel_requests = list_new(sizeof(struct get_pixels_request), 0);
ipc_event_source = wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL);
}
@ -183,7 +183,7 @@ int ipc_handle_connection(int fd, uint32_t mask, void *data) {
pid_t pid = get_client_pid(client->fd);
client->security_policy = get_ipc_policy_mask(pid);
list_add(ipc_client_list, client);
list_add(ipc_client_list, &client);
return 0;
}
@ -260,9 +260,9 @@ void ipc_client_disconnect(struct ipc_client *client) {
sway_log(L_INFO, "IPC Client %d disconnected", client->fd);
wlc_event_source_remove(client->event_source);
int i = 0;
while (i < ipc_client_list->length && ipc_client_list->items[i] != client) i++;
list_del(ipc_client_list, i);
size_t i = 0;
while (i < ipc_client_list->length && list_getp(ipc_client_list, i) != client) i++;
list_delete(ipc_client_list, i);
close(client->fd);
free(client);
}
@ -280,14 +280,13 @@ void ipc_get_pixels(wlc_handle output) {
return;
}
list_t *unhandled = create_list();
list_t *unhandled = list_new(sizeof(struct get_pixels_request *), 0);
struct get_pixels_request *req;
int i;
for (i = 0; i < ipc_get_pixel_requests->length; ++i) {
req = ipc_get_pixel_requests->items[i];
for (size_t i = 0; i < ipc_get_pixel_requests->length; ++i) {
req = list_getp(ipc_get_pixel_requests, i);
if (req->output != output) {
list_add(unhandled, req);
list_add(unhandled, &req);
continue;
}
@ -421,8 +420,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
}
json_object *inputs = json_object_new_array();
if (input_devices) {
for(int i = 0; i<input_devices->length; i++) {
struct libinput_device *device = input_devices->items[i];
for(size_t i = 0; i<input_devices->length; i++) {
struct libinput_device *device = list_getp(input_devices, i);
json_object_array_add(inputs, ipc_json_describe_input(device));
}
}
@ -520,7 +519,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
req->client = client;
req->output = output->handle;
req->geo = g;
list_add(ipc_get_pixel_requests, req);
list_add(ipc_get_pixel_requests, &req);
wlc_output_schedule_render(output->handle);
goto exit_cleanup;
}
@ -533,9 +532,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
if (!buf[0]) {
// Send list of configured bar IDs
json_object *bars = json_object_new_array();
int i;
for (i = 0; i < config->bars->length; ++i) {
struct bar_config *bar = config->bars->items[i];
for (size_t i = 0; i < config->bars->length; ++i) {
struct bar_config *bar = list_getp(config->bars, i);
json_object_array_add(bars, json_object_new_string(bar->id));
}
const char *json_string = json_object_to_json_string(bars);
@ -544,9 +542,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
} else {
// Send particular bar's details
struct bar_config *bar = NULL;
int i;
for (i = 0; i < config->bars->length; ++i) {
bar = config->bars->items[i];
for (size_t i = 0; i < config->bars->length; ++i) {
bar = list_getp(config->bars, i);
if (strcmp(buf, bar->id) == 0) {
break;
}
@ -626,8 +623,8 @@ void ipc_get_outputs_callback(swayc_t *container, void *data) {
static void ipc_get_marks_callback(swayc_t *container, void *data) {
json_object *object = (json_object *)data;
if (container->marks) {
for (int i = 0; i < container->marks->length; ++i) {
char *mark = (char *)container->marks->items[i];
for (size_t i = 0; i < container->marks->length; ++i) {
char *mark = list_getp(container->marks, i);
json_object_array_add(object, json_object_new_string(mark));
}
}
@ -654,10 +651,8 @@ void ipc_send_event(const char *json_string, enum ipc_command_type event) {
}
}
int i;
struct ipc_client *client;
for (i = 0; i < ipc_client_list->length; i++) {
client = ipc_client_list->items[i];
for (size_t i = 0; i < ipc_client_list->length; i++) {
struct ipc_client *client = list_getp(ipc_client_list, i);
if (!(client->security_policy & security_mask)) {
continue;
}
@ -765,9 +760,8 @@ void ipc_event_binding_keyboard(struct sway_binding *sb) {
const char *names[10];
int len = get_modifier_names(names, sb->modifiers);
int i;
json_object *modifiers = json_object_new_array();
for (i = 0; i < len; ++i) {
for (int i = 0; i < len; ++i) {
json_object_array_add(modifiers, json_object_new_string(names[i]));
}
@ -780,8 +774,8 @@ void ipc_event_binding_keyboard(struct sway_binding *sb) {
if (sb->bindcode) { // bindcode: populate input_codes
uint32_t keycode;
for (i = 0; i < sb->keys->length; ++i) {
keycode = *(uint32_t *)sb->keys->items[i];
for (size_t i = 0; i < sb->keys->length; ++i) {
keycode = *(uint32_t *)list_getp(sb->keys, i);
json_object_array_add(input_codes, json_object_new_int(keycode));
if (i == 0) {
input_code = keycode;
@ -790,8 +784,8 @@ void ipc_event_binding_keyboard(struct sway_binding *sb) {
} else { // bindsym: populate symbols
uint32_t keysym;
char buffer[64];
for (i = 0; i < sb->keys->length; ++i) {
keysym = *(uint32_t *)sb->keys->items[i];
for (size_t i = 0; i < sb->keys->length; ++i) {
keysym = *(uint32_t *)list_getp(sb->keys, i);
if (xkb_keysym_get_name(keysym, buffer, 64) > 0) {
json_object *str = json_object_new_string(buffer);
json_object_array_add(symbols, str);

View file

@ -27,11 +27,11 @@ void init_layout(void) {
root_container.type = C_ROOT;
root_container.layout = L_NONE;
root_container.name = strdup("root");
root_container.children = create_list();
root_container.children = list_new(sizeof(swayc_t *), 0);
root_container.handle = -1;
root_container.visible = true;
current_focus = &root_container;
scratchpad = create_list();
scratchpad = list_new(sizeof(swayc_t *), 0);
}
int index_child(const swayc_t *child) {
@ -40,14 +40,16 @@ int index_child(const swayc_t *child) {
if (!child->is_floating) {
len = parent->children->length;
for (i = 0; i < len; ++i) {
if (parent->children->items[i] == child) {
swayc_t *item = list_getp(parent->children, i);
if (item == child) {
break;
}
}
} else {
len = parent->floating->length;
for (i = 0; i < len; ++i) {
if (parent->floating->items[i] == child) {
swayc_t *item = list_getp(parent->floating, i);
if (item == child) {
break;
}
}
@ -61,7 +63,7 @@ int index_child(const swayc_t *child) {
void add_child(swayc_t *parent, swayc_t *child) {
sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type,
child->width, child->height, parent, parent->type, parent->width, parent->height);
list_add(parent->children, child);
list_add(parent->children, &child);
child->parent = parent;
// set focus for this container
if (!parent->focused) {
@ -80,14 +82,11 @@ static double *get_width(swayc_t *cont) {
return &cont->width;
}
void insert_child(swayc_t *parent, swayc_t *child, int index) {
void insert_child(swayc_t *parent, swayc_t *child, size_t index) {
if (index > parent->children->length) {
index = parent->children->length;
}
if (index < 0) {
index = 0;
}
list_insert(parent->children, index, child);
list_insert(parent->children, index, &child);
child->parent = parent;
if (!parent->focused) {
parent->focused = child;
@ -106,21 +105,21 @@ void insert_child(swayc_t *parent, swayc_t *child, int index) {
get_maj_dim = get_height;
get_min_dim = get_width;
}
for (int i = index; i < parent->children->length;) {
int start = auto_group_start_index(parent, i);
int end = auto_group_end_index(parent, i);
swayc_t *first = parent->children->items[start];
for (size_t i = index; i < parent->children->length;) {
size_t start = auto_group_start_index(parent, i);
size_t end = auto_group_end_index(parent, i);
swayc_t *first = list_getp(parent->children, start);
if (start + 1 < parent->children->length) {
/* preserve the group's dimension along major axis */
*get_maj_dim(first) = *get_maj_dim(parent->children->items[start + 1]);
*get_maj_dim(first) = *get_maj_dim(list_getp(parent->children, start + 1));
} else {
/* new group, let the apply_layout handle it */
first->height = first->width = 0;
break;
}
double remaining = *get_min_dim(parent);
for (int j = end - 1; j > start; --j) {
swayc_t *sibling = parent->children->items[j];
for (size_t j = end - 1; j > start; --j) {
swayc_t *sibling = list_getp(parent->children, j);
if (sibling == child) {
/* the inserted child won't yet have its minor
dimension set */
@ -141,7 +140,7 @@ void add_floating(swayc_t *ws, swayc_t *child) {
if (!sway_assert(ws->type == C_WORKSPACE, "Must be of workspace type")) {
return;
}
list_add(ws->floating, child);
list_add(ws->floating, &child);
child->parent = ws;
child->is_floating = true;
if (!ws->focused) {
@ -155,19 +154,19 @@ swayc_t *add_sibling(swayc_t *fixed, swayc_t *active) {
if (fixed->is_floating) {
if (active->is_floating) {
int i = index_child(fixed);
list_insert(parent->floating, i + 1, active);
list_insert(parent->floating, i + 1, &active);
} else {
list_add(parent->children, active);
list_add(parent->children, &active);
}
} else {
if (active->is_floating) {
list_add(parent->floating, active);
list_add(parent->floating, &active);
} else {
int i = index_child(fixed);
if (is_auto_layout(parent->layout)) {
list_add(parent->children, active);
list_add(parent->children, &active);
} else {
list_insert(parent->children, i + 1, active);
list_insert(parent->children, i + 1, &active);
}
}
}
@ -184,9 +183,9 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
}
int i = index_child(child);
if (child->is_floating) {
parent->floating->items[i] = new_child;
*(swayc_t **)list_get(parent->floating, i) = new_child;
} else {
parent->children->items[i] = new_child;
*(swayc_t **)list_get(parent->children, i) = new_child;
}
// Set parent and focus for new_child
new_child->parent = child->parent;
@ -213,21 +212,23 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
}
swayc_t *remove_child(swayc_t *child) {
int i;
size_t i;
swayc_t *parent = child->parent;
if (child->is_floating) {
// Special case for floating views
for (i = 0; i < parent->floating->length; ++i) {
if (parent->floating->items[i] == child) {
list_del(parent->floating, i);
swayc_t *item = list_getp(parent->floating, i);
if (item == child) {
list_delete(parent->floating, i);
break;
}
}
i = 0;
} else {
for (i = 0; i < parent->children->length; ++i) {
if (parent->children->items[i] == child) {
list_del(parent->children, i);
swayc_t *item = list_getp(parent->children, i);
if (item == child) {
list_delete(parent->children, i);
break;
}
}
@ -242,27 +243,27 @@ swayc_t *remove_child(swayc_t *child) {
get_maj_dim = get_height;
get_min_dim = get_width;
}
for (int j = parent->children->length - 1; j >= i;) {
int start = auto_group_start_index(parent, j);
int end = auto_group_end_index(parent, j);
swayc_t *first = parent->children->items[start];
for (size_t j = parent->children->length - 1; j >= i;) {
size_t start = auto_group_start_index(parent, j);
size_t end = auto_group_end_index(parent, j);
swayc_t *first = list_getp(parent->children, start);
if (i == start) {
/* removed element was first child in the current group,
use its size along the major axis */
*get_maj_dim(first) = *get_maj_dim(child);
} else if (start > i) {
/* preserve the group's dimension along major axis */
*get_maj_dim(first) = *get_maj_dim(parent->children->items[start - 1]);
*get_maj_dim(first) = *get_maj_dim(list_getp(parent->children, start - 1));
}
if (end != parent->children->length) {
double remaining = *get_min_dim(parent);
for (int k = start; k < end - 1; ++k) {
swayc_t *sibling = parent->children->items[k];
for (size_t k = start; k < end - 1; ++k) {
swayc_t *sibling = list_getp(parent->children, k);
remaining -= *get_min_dim(sibling);
}
/* last element of the group gets remaining size, elements
that don't change groups keep their ratio */
*get_min_dim((swayc_t *) parent->children->items[end - 1]) = remaining;
*get_min_dim(list_getp(parent->children, end - 1)) = remaining;
} /* else last group, let apply_layout handle it */
j = start - 1;
}
@ -271,9 +272,9 @@ swayc_t *remove_child(swayc_t *child) {
// Set focused to new container
if (parent->focused == child) {
if (parent->children->length > 0) {
parent->focused = parent->children->items[i ? i-1:0];
parent->focused = list_getp(parent->children, i ? i-1:0);
} else if (parent->floating && parent->floating->length) {
parent->focused = parent->floating->items[parent->floating->length - 1];
parent->focused = list_getp(parent->floating, parent->floating->length - 1);
} else {
parent->focused = NULL;
}
@ -297,14 +298,14 @@ void swap_container(swayc_t *a, swayc_t *b) {
swayc_t *b_parent = b->parent;
// Swap the pointers
if (a->is_floating) {
a_parent->floating->items[a_index] = b;
*(swayc_t **)list_get(a_parent->floating, a_index) = b;
} else {
a_parent->children->items[a_index] = b;
*(swayc_t **)list_get(a_parent->children, a_index) = b;
}
if (b->is_floating) {
b_parent->floating->items[b_index] = a;
*(swayc_t **)list_get(b_parent->floating, b_index) = a;
} else {
b_parent->children->items[b_index] = a;
*(swayc_t **)list_get(b_parent->children, b_index) = a;
}
a->parent = b_parent;
b->parent = a_parent;
@ -332,14 +333,12 @@ void swap_geometry(swayc_t *a, swayc_t *b) {
b->height = h;
}
static void swap_children(swayc_t *container, int a, int b) {
if (a >= 0 && b >= 0 && a < container->children->length
&& b < container->children->length
&& a != b) {
swayc_t *pa = (swayc_t *)container->children->items[a];
swayc_t *pb = (swayc_t *)container->children->items[b];
container->children->items[a] = container->children->items[b];
container->children->items[b] = pa;
static void swap_children(swayc_t *container, size_t a, size_t b) {
if (a < container->children->length && b < container->children->length && a != b) {
swayc_t *pa = list_getp(container->children, a);
swayc_t *pb = list_getp(container->children, b);
*(swayc_t **)list_get(container->children, a) = list_getp(container->children, b);
*(swayc_t **)list_get(container->children, b) = pa;
if (is_auto_layout(container->layout)) {
size_t ga = auto_group_index(container, a);
size_t gb = auto_group_index(container, b);
@ -385,7 +384,7 @@ void move_container(swayc_t *container, enum movement_direction dir, int move_am
// swap first child in auto layout with currently focused child
if (is_auto_layout(parent->layout)) {
int focused_idx = index_child(container);
swayc_t *first = parent->children->items[0];
swayc_t *first = list_getp(parent->children, 0);
if (focused_idx > 0) {
list_swap(parent->children, 0, focused_idx);
swap_geometry(first, container);
@ -432,20 +431,20 @@ void move_container(swayc_t *container, enum movement_direction dir, int move_am
diff = dir == MOVE_LEFT || dir == MOVE_UP || dir == MOVE_PREV ? -1 : 1;
}
int idx = index_child(child);
int desired = idx + diff;
ssize_t desired = idx + diff;
if (dir == MOVE_NEXT || dir == MOVE_PREV) {
// Next/Prev always wrap.
if (desired < 0) {
desired += parent->children->length;
} else if (desired >= parent->children->length) {
} else if (desired >= (ssize_t)parent->children->length) {
desired = 0;
}
}
// when it has ascended, legal insertion position is 0:len
// when it has not, legal insertion position is 0:len-1
if (desired >= 0 && desired - ascended < parent->children->length) {
if (desired >= 0 && desired - ascended < (ssize_t)parent->children->length) {
if (!ascended) {
child = parent->children->items[desired];
child = list_getp(parent->children, desired);
// Move container into sibling container
if (child->type == C_CONTAINER) {
parent = child;
@ -469,7 +468,7 @@ void move_container(swayc_t *container, enum movement_direction dir, int move_am
swayc_t *old_parent = remove_child(container);
insert_child(parent, container, desired);
destroy_container(old_parent);
sway_log(L_DEBUG,"Moving to %p %d", parent, desired);
sway_log(L_DEBUG,"Moving to %p %zd", parent, desired);
}
break;
}
@ -676,9 +675,8 @@ void update_layout_geometry(swayc_t *parent, enum swayc_layouts prev_layout) {
case L_STACKED:
if (prev_layout != L_TABBED && prev_layout != L_STACKED) {
// cache current geometry for all non-float children
int i;
for (i = 0; i < parent->children->length; ++i) {
swayc_t *child = parent->children->items[i];
for (size_t i = 0; i < parent->children->length; ++i) {
swayc_t *child = list_getp(parent->children, i);
child->cached_geometry.origin.x = child->x;
child->cached_geometry.origin.y = child->y;
child->cached_geometry.size.w = child->width;
@ -689,9 +687,8 @@ void update_layout_geometry(swayc_t *parent, enum swayc_layouts prev_layout) {
default:
if (prev_layout == L_TABBED || prev_layout == L_STACKED) {
// recover cached geometry for all non-float children
int i;
for (i = 0; i < parent->children->length; ++i) {
swayc_t *child = parent->children->items[i];
for (size_t i = 0; i < parent->children->length; ++i) {
swayc_t *child = list_getp(parent->children, i);
// only recoverer cached geometry if non-zero
if (!wlc_geometry_equals(&child->cached_geometry, &wlc_geometry_zero)) {
child->x = child->cached_geometry.origin.x;
@ -831,15 +828,15 @@ void update_geometry(swayc_t *container) {
int title_bar_height = config->font_height + 4; //borders + padding
if (parent->layout == L_TABBED && parent->children->length > 1) {
int i, x = 0, w, l, r;
int x = 0, w, l, r;
l = parent->children->length;
w = geometry.size.w / l;
r = geometry.size.w % l;
for (i = 0; i < parent->children->length; ++i) {
swayc_t *view = parent->children->items[i];
for (size_t i = 0; i < parent->children->length; ++i) {
swayc_t *view = list_getp(parent->children, i);
if (view == container) {
x = w * i;
if (i == l - 1) {
if ((ssize_t)i == l - 1) {
w += r;
}
break;
@ -862,9 +859,9 @@ void update_geometry(swayc_t *container) {
geometry.size.h -= (border_bottom + title_bar.size.h);
container->title_bar_geometry = title_bar;
} else if (parent->layout == L_STACKED && parent->children->length > 1) {
int i, y = 0;
for (i = 0; i < parent->children->length; ++i) {
swayc_t *view = parent->children->items[i];
int y = 0;
for (size_t i = 0; i < parent->children->length; ++i) {
swayc_t *view = list_getp(parent->children, i);
if (view == container) {
y = title_bar_height * i;
}
@ -951,7 +948,7 @@ static void apply_auto_layout(swayc_t *container, const double x, const double y
bool master_first);
static void arrange_windows_r(swayc_t *container, double width, double height) {
int i;
size_t i;
if (width == -1 || height == -1) {
swayc_log(L_DEBUG, container, "Arranging layout for %p", container);
width = container->width;
@ -971,7 +968,7 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
switch (container->type) {
case C_ROOT:
for (i = 0; i < container->children->length; ++i) {
swayc_t *output = container->children->items[i];
swayc_t *output = list_getp(container->children, i);
sway_log(L_DEBUG, "Arranging output '%s' at %f,%f", output->name, output->x, output->y);
arrange_windows_r(output, -1, -1);
}
@ -988,12 +985,12 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
}
// arrange all workspaces:
for (i = 0; i < container->children->length; ++i) {
swayc_t *child = container->children->items[i];
swayc_t *child = list_getp(container->children, i);
arrange_windows_r(child, -1, -1);
}
// Bring all unmanaged views to the front
for (i = 0; i < container->unmanaged->length; ++i) {
wlc_handle *handle = container->unmanaged->items[i];
wlc_handle *handle = list_getp(container->unmanaged, i);
wlc_view_bring_to_front(*handle);
}
return;
@ -1002,7 +999,7 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
swayc_t *output = swayc_parent_by_type(container, C_OUTPUT);
width = output->width, height = output->height;
for (i = 0; i < desktop_shell.panels->length; ++i) {
struct panel_config *config = desktop_shell.panels->items[i];
struct panel_config *config = list_getp(desktop_shell.panels, i);
if (config->output == output->handle) {
struct wlc_size size = *wlc_surface_get_size(config->surface);
sway_log(L_DEBUG, "-> Found panel for this workspace: %ux%u, position: %u", size.w, size.h, config->panel_position);
@ -1107,8 +1104,8 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
// Arrage floating layouts for workspaces last
if (container->type == C_WORKSPACE) {
for (int i = 0; i < container->floating->length; ++i) {
swayc_t *view = container->floating->items[i];
for (size_t i = 0; i < container->floating->length; ++i) {
swayc_t *view = list_getp(container->floating, i);
if (view->type == C_VIEW) {
update_geometry(view);
sway_log(L_DEBUG, "Set floating view to %.f x %.f @ %.f, %.f",
@ -1130,7 +1127,7 @@ void apply_horiz_layout(swayc_t *container, const double x, const double y,
double scale = 0;
// Calculate total width
for (int i = start; i < end; ++i) {
double *old_width = &((swayc_t *)container->children->items[i])->width;
double *old_width = &((swayc_t *)list_getp(container->children, i))->width;
if (*old_width <= 0) {
if (end - start > 1) {
*old_width = width / (end - start - 1);
@ -1148,7 +1145,7 @@ void apply_horiz_layout(swayc_t *container, const double x, const double y,
sway_log(L_DEBUG, "Arranging %p horizontally", container);
swayc_t *focused = NULL;
for (int i = start; i < end; ++i) {
swayc_t *child = container->children->items[i];
swayc_t *child = list_getp(container->children, i);
sway_log(L_DEBUG,
"Calculating arrangement for %p:%d (will scale %f by %f)", child,
child->type, width, scale);
@ -1183,7 +1180,7 @@ void apply_vert_layout(swayc_t *container, const double x, const double y,
double scale = 0;
// Calculate total height
for (i = start; i < end; ++i) {
double *old_height = &((swayc_t *)container->children->items[i])->height;
double *old_height = &((swayc_t *)list_getp(container->children, i))->height;
if (*old_height <= 0) {
if (end - start > 1) {
*old_height = height / (end - start - 1);
@ -1201,7 +1198,7 @@ void apply_vert_layout(swayc_t *container, const double x, const double y,
sway_log(L_DEBUG, "Arranging %p vertically", container);
swayc_t *focused = NULL;
for (i = start; i < end; ++i) {
swayc_t *child = container->children->items[i];
swayc_t *child = list_getp(container->children, i);
sway_log(L_DEBUG,
"Calculating arrangement for %p:%d (will scale %f by %f)", child,
child->type, height, scale);
@ -1231,10 +1228,9 @@ void apply_vert_layout(swayc_t *container, const double x, const double y,
void apply_tabbed_or_stacked_layout(swayc_t *container, double x, double y,
double width, double height) {
int i;
swayc_t *focused = NULL;
for (i = 0; i < container->children->length; ++i) {
swayc_t *child = container->children->items[i];
for (size_t i = 0; i < container->children->length; ++i) {
swayc_t *child = list_getp(container->children, i);
child->x = x;
child->y = y;
if (child == container->focused) {
@ -1326,7 +1322,7 @@ void apply_auto_layout(swayc_t *container, const double x, const double y,
for (size_t group = 0; group < nb_groups; ++group) {
int idx;
if (auto_group_bounds(container, group, &idx, NULL)) {
swayc_t *child = container->children->items[idx];
swayc_t *child = list_getp(container->children, idx);
double *dim = group_layout == L_HORIZ ? &child->height : &child->width;
if (*dim <= 0) {
// New child with uninitialized dimension
@ -1380,9 +1376,8 @@ void arrange_windows(swayc_t *container, double width, double height) {
}
void arrange_backgrounds(void) {
struct background_config *bg;
for (int i = 0; i < desktop_shell.backgrounds->length; ++i) {
bg = desktop_shell.backgrounds->items[i];
for (size_t i = 0; i < desktop_shell.backgrounds->length; ++i) {
struct background_config *bg = list_getp(desktop_shell.backgrounds, i);
wlc_view_send_to_back(bg->handle);
}
}
@ -1400,10 +1395,10 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output, enum movement_dir
switch (dir) {
case MOVE_LEFT:
// get most right child of new output
return ws->children->items[ws->children->length-1];
return list_getp(ws->children, ws->children->length-1);
case MOVE_RIGHT:
// get most left child of new output
return ws->children->items[0];
return list_getp(ws->children, 0);
case MOVE_UP:
case MOVE_DOWN:
{
@ -1413,10 +1408,10 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output, enum movement_dir
if (parent->layout == L_VERT) {
if (dir == MOVE_UP) {
// get child furthest down on new output
return parent->children->items[parent->children->length-1];
return list_getp(parent->children, parent->children->length-1);
} else if (dir == MOVE_DOWN) {
// get child furthest up on new output
return parent->children->items[0];
return list_getp(parent->children, 0);
}
}
return focused_view;
@ -1455,7 +1450,7 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio
if (desired < 0) {
desired += parent->children->length;
}
return parent->children->items[desired];
return list_getp(parent->children, desired);
}
}
@ -1523,33 +1518,34 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio
if (can_move) {
if (container->is_floating) {
if (desired < 0) {
wrap_candidate = parent->floating->items[parent->floating->length-1];
} else if (desired >= parent->floating->length){
wrap_candidate = parent->floating->items[0];
wrap_candidate = list_getp(parent->floating, parent->floating->length-1);
} else if (desired >= (ssize_t)parent->floating->length){
wrap_candidate = list_getp(parent->floating, 0);
} else {
wrap_candidate = parent->floating->items[desired];
wrap_candidate = list_getp(parent->floating, desired);
}
if (wrap_candidate) {
wlc_view_bring_to_front(wrap_candidate->handle);
}
return wrap_candidate;
} else if (desired < 0 || desired >= parent->children->length) {
} else if (desired < 0 || desired >= (ssize_t)parent->children->length) {
can_move = false;
int len = parent->children->length;
if (!wrap_candidate && len > 1) {
if (desired < 0) {
wrap_candidate = parent->children->items[len-1];
wrap_candidate = list_getp(parent->children, len-1);
} else {
wrap_candidate = parent->children->items[0];
wrap_candidate = list_getp(parent->children, 0);
}
if (config->force_focus_wrapping) {
return wrap_candidate;
}
}
} else {
swayc_t *item = list_getp(parent->children, desired);
sway_log(L_DEBUG, "%s cont %d-%p dir %i sibling %d: %p", __func__,
idx, container, dir, desired, parent->children->items[desired]);
return parent->children->items[desired];
idx, container, dir, desired, item);
return item;
}
}
if (!can_move) {
@ -1568,7 +1564,6 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir)
}
void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge) {
int i;
bool layout_match = true;
sway_log(L_DEBUG, "Resizing %p with amount: %f", container, amount);
if (edge == WLC_RESIZE_EDGE_LEFT || edge == WLC_RESIZE_EDGE_RIGHT) {
@ -1583,12 +1578,14 @@ void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge ed
return;
}
if (layout_match) {
for (i = 0; i < container->children->length; i++) {
recursive_resize(container->children->items[i], amount/container->children->length, edge);
for (size_t i = 0; i < container->children->length; i++) {
swayc_t *item = list_getp(container->children, i);
recursive_resize(item, amount/container->children->length, edge);
}
} else {
for (i = 0; i < container->children->length; i++) {
recursive_resize(container->children->items[i], amount, edge);
for (size_t i = 0; i < container->children->length; i++) {
swayc_t *item = list_getp(container->children, i);
recursive_resize(item, amount, edge);
}
}
}
@ -1613,8 +1610,6 @@ bool is_auto_layout(enum swayc_layouts layout) {
* Return the number of master elements in a container
*/
static inline size_t auto_master_count(const swayc_t *container) {
sway_assert(container->children->length >= 0, "Container %p has (negative) children %d",
container, container->children->length);
return MIN(container->nb_master, (size_t)container->children->length);
}
@ -1661,7 +1656,7 @@ int auto_group_start_index(const swayc_t *container, int index) {
} else {
start_idx = idx2 + ((index - idx2) / (grp_sz + 1)) * (grp_sz + 1);
}
return MIN(start_idx, container->children->length);
return MIN(start_idx, (ssize_t)container->children->length);
}
}
@ -1689,7 +1684,7 @@ int auto_group_end_index(const swayc_t *container, int index) {
nxt_idx = idx2 + ((index - idx2) / (grp_sz + 1) + 1) * (grp_sz + 1);
}
}
return MIN(nxt_idx, container->children->length);
return MIN(nxt_idx, (ssize_t)container->children->length);
}
}

View file

@ -367,7 +367,7 @@ int main(int argc, char **argv) {
log_env();
detect_proprietary();
input_devices = create_list();
input_devices = list_new(sizeof(struct libudev_device *), 0);
/* Changing code earlier than this point requires detailed review */
/* (That code runs as root on systems without logind, and wlc_init drops to

View file

@ -37,8 +37,8 @@ swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos) {
output = swayc_opposite_output(MOVE_UP, abs_pos);
}
} else {
for(int i = 0; i < root_container.children->length; ++i) {
swayc_t *c = root_container.children->items[i];
for (size_t i = 0; i < root_container.children->length; ++i) {
swayc_t *c = list_getp(root_container.children, i);
if (c->type == C_OUTPUT && strcasecmp(c->name, name) == 0) {
return c;
}
@ -58,8 +58,8 @@ swayc_t *swayc_opposite_output(enum movement_direction dir,
switch(dir) {
case MOVE_LEFT:
case MOVE_RIGHT: ;
for (int i = 0; i < root_container.children->length; ++i) {
swayc_t *c = root_container.children->items[i];
for (size_t i = 0; i < root_container.children->length; ++i) {
swayc_t *c = list_getp(root_container.children, i);
if (abs_pos->y >= c->y && abs_pos->y <= c->y + c->height) {
if (!opposite) {
opposite = c;
@ -73,8 +73,8 @@ swayc_t *swayc_opposite_output(enum movement_direction dir,
break;
case MOVE_UP:
case MOVE_DOWN: ;
for (int i = 0; i < root_container.children->length; ++i) {
swayc_t *c = root_container.children->items[i];
for (size_t i = 0; i < root_container.children->length; ++i) {
swayc_t *c = list_getp(root_container.children, i);
if (abs_pos->x >= c->x && abs_pos->x <= c->x + c->width) {
if (!opposite) {
opposite = c;
@ -116,8 +116,8 @@ swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir,
case MOVE_LEFT:
case MOVE_RIGHT: ;
double delta_y = 0;
for(int i = 0; i < root_container.children->length; ++i) {
swayc_t *c = root_container.children->items[i];
for (size_t i = 0; i < root_container.children->length; ++i) {
swayc_t *c = list_getp(root_container.children, i);
if (c == output || c->type != C_OUTPUT) {
continue;
}
@ -169,8 +169,8 @@ swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir,
case MOVE_UP:
case MOVE_DOWN: ;
double delta_x = 0;
for(int i = 0; i < root_container.children->length; ++i) {
swayc_t *c = root_container.children->items[i];
for (size_t i = 0; i < root_container.children->length; ++i) {
swayc_t *c = list_getp(root_container.children, i);
if (c == output || c->type != C_OUTPUT) {
continue;
}
@ -273,5 +273,5 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
}
void sort_workspaces(swayc_t *output) {
list_stable_sort(output->children, sort_workspace_cmp_qsort);
list_isort(output->children, sort_workspace_cmp_qsort);
}

View file

@ -48,8 +48,8 @@ struct feature_policy *alloc_feature_policy(const char *program) {
if (!validate_ipc_target(program)) {
return NULL;
}
for (int i = 0; i < config->feature_policies->length; ++i) {
struct feature_policy *policy = config->feature_policies->items[i];
for (size_t i = 0; i < config->feature_policies->length; ++i) {
struct feature_policy *policy = list_getp(config->feature_policies, i);
if (strcmp(policy->program, "*") == 0) {
default_policy = policy->features;
break;
@ -76,8 +76,8 @@ struct ipc_policy *alloc_ipc_policy(const char *program) {
if (!validate_ipc_target(program)) {
return NULL;
}
for (int i = 0; i < config->ipc_policies->length; ++i) {
struct ipc_policy *policy = config->ipc_policies->items[i];
for (size_t i = 0; i < config->ipc_policies->length; ++i) {
struct ipc_policy *policy = list_getp(config->ipc_policies, i);
if (strcmp(policy->program, "*") == 0) {
default_policy = policy->features;
break;
@ -143,8 +143,8 @@ static const char *get_pid_exe(pid_t pid) {
struct feature_policy *get_feature_policy(const char *name) {
struct feature_policy *policy = NULL;
for (int i = 0; i < config->feature_policies->length; ++i) {
struct feature_policy *p = config->feature_policies->items[i];
for (size_t i = 0; i < config->feature_policies->length; ++i) {
struct feature_policy *p = list_getp(config->feature_policies, i);
if (strcmp(p->program, name) == 0) {
policy = p;
break;
@ -155,7 +155,7 @@ struct feature_policy *get_feature_policy(const char *name) {
if (!policy) {
sway_abort("Unable to allocate security policy");
}
list_add(config->feature_policies, policy);
list_add(config->feature_policies, &policy);
}
return policy;
}
@ -164,8 +164,8 @@ uint32_t get_feature_policy_mask(pid_t pid) {
uint32_t default_policy = 0;
const char *link = get_pid_exe(pid);
for (int i = 0; i < config->feature_policies->length; ++i) {
struct feature_policy *policy = config->feature_policies->items[i];
for (size_t i = 0; i < config->feature_policies->length; ++i) {
struct feature_policy *policy = list_getp(config->feature_policies, i);
if (strcmp(policy->program, "*") == 0) {
default_policy = policy->features;
}
@ -181,8 +181,8 @@ uint32_t get_ipc_policy_mask(pid_t pid) {
uint32_t default_policy = 0;
const char *link = get_pid_exe(pid);
for (int i = 0; i < config->ipc_policies->length; ++i) {
struct ipc_policy *policy = config->ipc_policies->items[i];
for (size_t i = 0; i < config->ipc_policies->length; ++i) {
struct ipc_policy *policy = list_getp(config->ipc_policies, i);
if (strcmp(policy->program, "*") == 0) {
default_policy = policy->features;
}
@ -197,8 +197,8 @@ uint32_t get_ipc_policy_mask(pid_t pid) {
uint32_t get_command_policy_mask(const char *cmd) {
uint32_t default_policy = 0;
for (int i = 0; i < config->command_policies->length; ++i) {
struct command_policy *policy = config->command_policies->items[i];
for (size_t i = 0; i < config->command_policies->length; ++i) {
struct command_policy *policy = list_getp(config->command_policies, i);
if (strcmp(policy->command, "*") == 0) {
default_policy = policy->context;
}

View file

@ -29,9 +29,8 @@ struct workspace_by_number_data {
};
static bool workspace_valid_on_output(const char *output_name, const char *ws_name) {
int i;
for (i = 0; i < config->workspace_outputs->length; ++i) {
struct workspace_output *wso = config->workspace_outputs->items[i];
for (size_t i = 0; i < config->workspace_outputs->length; ++i) {
struct workspace_output *wso = list_getp(config->workspace_outputs, i);
if (strcasecmp(wso->workspace, ws_name) == 0) {
if (strcasecmp(wso->output, output_name) != 0) {
return false;
@ -44,7 +43,6 @@ static bool workspace_valid_on_output(const char *output_name, const char *ws_na
char *workspace_next_name(const char *output_name) {
sway_log(L_DEBUG, "Workspace: Generating new workspace name for output %s", output_name);
int i;
int l = 1;
// Scan all workspace bindings to find the next available workspace name,
// if none are found/available then default to a number
@ -52,8 +50,8 @@ char *workspace_next_name(const char *output_name) {
int order = INT_MAX;
char *target = NULL;
for (i = 0; i < mode->bindings->length; ++i) {
struct sway_binding *binding = mode->bindings->items[i];
for (size_t i = 0; i < mode->bindings->length; ++i) {
struct sway_binding *binding = list_getp(mode->bindings, i);
char *cmdlist = strdup(binding->command);
char *dup = cmdlist;
char *name = NULL;
@ -133,15 +131,14 @@ char *workspace_next_name(const char *output_name) {
swayc_t *workspace_create(const char* name) {
swayc_t *parent;
// Search for workspace<->output pair
int i, e = config->workspace_outputs->length;
size_t i, e = config->workspace_outputs->length;
for (i = 0; i < e; ++i) {
struct workspace_output *wso = config->workspace_outputs->items[i];
if (strcasecmp(wso->workspace, name) == 0)
{
struct workspace_output *wso = list_getp(config->workspace_outputs, i);
if (strcasecmp(wso->workspace, name) == 0) {
// Find output to use if it exists
e = root_container.children->length;
for (i = 0; i < e; ++i) {
parent = root_container.children->items[i];
parent = list_getp(root_container.children, i);
if (strcmp(parent->name, wso->output) == 0) {
return new_workspace(parent, name);
}
@ -208,10 +205,10 @@ swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) {
return NULL;
}
int i;
for (i = 0; i < output->children->length; i++) {
if (output->children->items[i] == output->focused) {
return output->children->items[wrap(i + (next ? 1 : -1), output->children->length)];
for (size_t i = 0; i < output->children->length; i++) {
swayc_t *item = list_getp(output->children, i);
if (item == output->focused) {
return list_getp(output->children, (wrap(i + (next ? 1 : -1), output->children->length)));
}
}
@ -231,20 +228,21 @@ swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) {
swayc_t *current_output = workspace->parent;
int offset = next ? 1 : -1;
int start = next ? 0 : 1;
int end = next ? (current_output->children->length) - 1 : current_output->children->length;
int i;
for (i = start; i < end; i++) {
if (current_output->children->items[i] == workspace) {
return current_output->children->items[i + offset];
size_t start = next ? 0 : 1;
size_t end = next ? (current_output->children->length) - 1 : current_output->children->length;
for (size_t i = start; i < end; i++) {
swayc_t *item = list_getp(current_output->children, i);
if (item == workspace) {
return list_getp(current_output->children, i + offset);
}
}
// Given workspace is the first/last on the output, jump to the previous/next output
int num_outputs = root_container.children->length;
for (i = 0; i < num_outputs; i++) {
if (root_container.children->items[i] == current_output) {
swayc_t *next_output = root_container.children->items[wrap(i + offset, num_outputs)];
size_t num_outputs = root_container.children->length;
for (size_t i = 0; i < num_outputs; i++) {
swayc_t *item = list_getp(root_container.children, i);
if (item == current_output) {
swayc_t *next_output = list_getp(root_container.children, wrap(i + offset, num_outputs));
return workspace_output_prev_next_impl(next_output, next);
}
}
@ -294,15 +292,15 @@ bool workspace_switch(swayc_t *workspace) {
// move sticky containers
if (swayc_parent_by_type(active_ws, C_OUTPUT) == swayc_parent_by_type(workspace, C_OUTPUT)) {
// don't change list while traversing it, use intermediate list instead
list_t *stickies = create_list();
for (int i = 0; i < active_ws->floating->length; i++) {
swayc_t *cont = active_ws->floating->items[i];
list_t *stickies = list_new(sizeof(swayc_t *), 0);
for (size_t i = 0; i < active_ws->floating->length; i++) {
swayc_t *cont = list_getp(active_ws->floating, i);
if (cont->sticky) {
list_add(stickies, cont);
list_add(stickies, &cont);
}
}
for (int i = 0; i < stickies->length; i++) {
swayc_t *cont = stickies->items[i];
for (size_t i = 0; i < stickies->length; i++) {
swayc_t *cont = list_getp(stickies, i);
sway_log(L_DEBUG, "Moving sticky container %p to %p:%s",
cont, workspace, workspace->name);
swayc_t *parent = remove_child(cont);
@ -323,9 +321,9 @@ bool workspace_switch(swayc_t *workspace) {
}
swayc_t *workspace_for_pid(pid_t pid) {
int i;
swayc_t *ws = NULL;
struct pid_workspace *pw = NULL;
size_t i;
sway_log(L_DEBUG, "looking for workspace for pid %d", pid);
@ -338,7 +336,7 @@ swayc_t *workspace_for_pid(pid_t pid) {
do {
for (i = 0; i < config->pid_workspaces->length; i++) {
pw = config->pid_workspaces->items[i];
pw = list_getp(config->pid_workspaces, i);
pid_t *pw_pid = pw->pid;
if (pid == *pw_pid) {
@ -367,7 +365,7 @@ swayc_t *workspace_for_pid(pid_t pid) {
ws = workspace_create(pw->workspace);
}
list_del(config->pid_workspaces, i);
list_delete(config->pid_workspaces, i);
}
return ws;

View file

@ -19,7 +19,7 @@
static void bar_init(struct bar *bar) {
bar->config = init_config();
bar->status = init_status_line();
bar->outputs = create_list();
bar->outputs = list_new(sizeof(struct output *), 0);
}
static void spawn_status_cmd_proc(struct bar *bar) {
@ -55,7 +55,7 @@ struct output *new_output(const char *name) {
output->name = strdup(name);
output->window = NULL;
output->registry = NULL;
output->workspaces = create_list();
output->workspaces = list_new(sizeof(struct workspace *), 0);
return output;
}
@ -67,8 +67,8 @@ static void mouse_button_notify(struct window *window, int x, int y,
}
struct output *clicked_output = NULL;
for (int i = 0; i < swaybar.outputs->length; i++) {
struct output *output = swaybar.outputs->items[i];
for (size_t i = 0; i < swaybar.outputs->length; i++) {
struct output *output = list_getp(swaybar.outputs, i);
if (window == output->window) {
clicked_output = output;
break;
@ -80,8 +80,8 @@ static void mouse_button_notify(struct window *window, int x, int y,
}
double button_x = 0.5;
for (int i = 0; i < clicked_output->workspaces->length; i++) {
struct workspace *workspace = clicked_output->workspaces->items[i];
for (size_t i = 0; i < clicked_output->workspaces->length; i++) {
struct workspace *workspace = list_getp(clicked_output->workspaces, i);
int button_width, button_height;
workspace_button_size(window, workspace->name, &button_width, &button_height);
@ -95,14 +95,14 @@ static void mouse_button_notify(struct window *window, int x, int y,
}
static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) {
size_t i;
sway_log(L_DEBUG, "Mouse wheel scrolled %s", direction == SCROLL_UP ? "up" : "down");
if (!swaybar.config->wrap_scroll) {
// Find output this window lives on
int i;
struct output *output = NULL;
for (i = 0; i < swaybar.outputs->length; ++i) {
output = swaybar.outputs->items[i];
output = list_getp(swaybar.outputs, i);
if (output->window == window) {
break;
}
@ -112,7 +112,7 @@ static void mouse_scroll_notify(struct window *window, enum scroll_direction dir
}
int focused = -1;
for (i = 0; i < output->workspaces->length; ++i) {
struct workspace *ws = output->workspaces->items[i];
struct workspace *ws = list_getp(output->workspaces, i);
if (ws->focused) {
focused = i;
break;
@ -122,7 +122,7 @@ static void mouse_scroll_notify(struct window *window, enum scroll_direction dir
return;
}
if ((focused == 0 && direction == SCROLL_UP) ||
(focused == output->workspaces->length - 1 && direction == SCROLL_DOWN)) {
(focused == (ssize_t)output->workspaces->length - 1 && direction == SCROLL_DOWN)) {
// Do not wrap
return;
}
@ -142,9 +142,8 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
ipc_bar_init(bar, bar_id);
int i;
for (i = 0; i < bar->outputs->length; ++i) {
struct output *bar_output = bar->outputs->items[i];
for (size_t i = 0; i < bar->outputs->length; ++i) {
struct output *bar_output = list_getp(bar->outputs, i);
bar_output->registry = registry_poll();
@ -152,7 +151,7 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
sway_abort("swaybar requires the compositor to support the desktop-shell extension.");
}
struct output_state *output = bar_output->registry->outputs->items[bar_output->idx];
struct output_state *output = list_getp(bar_output->registry->outputs, bar_output->idx);
bar_output->window = window_setup(bar_output->registry,
output->width / output->scale, 30, output->scale, false);
@ -190,18 +189,16 @@ void bar_run(struct bar *bar) {
pfd[1].fd = bar->status_read_fd;
pfd[1].events = POLLIN;
int i;
for (i = 0; i < bar->outputs->length; ++i) {
struct output *output = bar->outputs->items[i];
for (size_t i = 0; i < bar->outputs->length; ++i) {
struct output *output = list_getp(bar->outputs, i);
pfd[i+2].fd = wl_display_get_fd(output->registry->display);
pfd[i+2].events = POLLIN;
}
while (1) {
if (dirty) {
int i;
for (i = 0; i < bar->outputs->length; ++i) {
struct output *output = bar->outputs->items[i];
for (size_t i = 0; i < bar->outputs->length; ++i) {
struct output *output = list_getp(bar->outputs, i);
if (window_prerender(output->window) && output->window->cairo) {
render(output, bar->config, bar->status);
window_render(output->window);
@ -225,8 +222,8 @@ void bar_run(struct bar *bar) {
}
// dispatch wl_display events
for (i = 0; i < bar->outputs->length; ++i) {
struct output *output = bar->outputs->items[i];
for (size_t i = 0; i < bar->outputs->length; ++i) {
struct output *output = list_getp(bar->outputs, i);
if (pfd[i+2].revents & POLLIN) {
if (wl_display_dispatch(output->registry->display) == -1) {
sway_log(L_ERROR, "failed to dispatch wl: %d", errno);
@ -239,9 +236,8 @@ void bar_run(struct bar *bar) {
}
void free_workspaces(list_t *workspaces) {
int i;
for (i = 0; i < workspaces->length; ++i) {
struct workspace *ws = workspaces->items[i];
for (size_t i = 0; i < workspaces->length; ++i) {
struct workspace *ws = list_getp(workspaces, i);
free(ws->name);
free(ws);
}
@ -264,9 +260,9 @@ static void free_output(struct output *output) {
}
static void free_outputs(list_t *outputs) {
int i;
for (i = 0; i < outputs->length; ++i) {
free_output(outputs->items[i]);
for (size_t i = 0; i < outputs->length; ++i) {
struct output *item = list_getp(outputs, i);
free_output(item);
}
list_free(outputs);
}

View file

@ -43,7 +43,7 @@ struct config *init_config() {
config->wrap_scroll = false;
config->workspace_buttons = true;
config->all_outputs = false;
config->outputs = create_list();
config->outputs = list_new(sizeof(char *), 0);
/* height */
config->height = 0;

View file

@ -84,25 +84,25 @@ static void ipc_parse_config(struct config *config, const char *payload) {
}
// free previous outputs list
int i;
for (i = 0; i < config->outputs->length; ++i) {
free(config->outputs->items[i]);
for (size_t i = 0; i < config->outputs->length; ++i) {
free(list_getp(config->outputs, i));
}
list_free(config->outputs);
config->outputs = create_list();
config->outputs = list_new(sizeof(char *), 0);
if (outputs) {
int length = json_object_array_length(outputs);
json_object *output;
const char *output_str;
for (i = 0; i < length; ++i) {
for (int i = 0; i < length; ++i) {
output = json_object_array_get_idx(outputs, i);
output_str = json_object_get_string(output);
if (strcmp("*", output_str) == 0) {
config->all_outputs = true;
break;
}
list_add(config->outputs, strdup(output_str));
char *ptr = strdup(output_str);
list_add(config->outputs, &ptr);
}
} else {
config->all_outputs = true;
@ -214,13 +214,12 @@ static void ipc_parse_config(struct config *config, const char *payload) {
}
static void ipc_update_workspaces(struct bar *bar) {
int i;
for (i = 0; i < bar->outputs->length; ++i) {
struct output *output = bar->outputs->items[i];
for (size_t i = 0; i < bar->outputs->length; ++i) {
struct output *output = list_getp(bar->outputs, i);
if (output->workspaces) {
free_workspaces(output->workspaces);
}
output->workspaces = create_list();
output->workspaces = list_new(sizeof(struct workspace *), 0);
}
uint32_t len = 0;
@ -234,7 +233,7 @@ static void ipc_update_workspaces(struct bar *bar) {
int length = json_object_array_length(results);
json_object *ws_json;
json_object *num, *name, *visible, *focused, *out, *urgent;
for (i = 0; i < length; ++i) {
for (int i = 0; i < length; ++i) {
ws_json = json_object_array_get_idx(results, i);
json_object_object_get_ex(ws_json, "num", &num);
@ -244,9 +243,8 @@ static void ipc_update_workspaces(struct bar *bar) {
json_object_object_get_ex(ws_json, "output", &out);
json_object_object_get_ex(ws_json, "urgent", &urgent);
int j;
for (j = 0; j < bar->outputs->length; ++j) {
struct output *output = bar->outputs->items[j];
for (size_t j = 0; j < bar->outputs->length; ++j) {
struct output *output = list_getp(bar->outputs, j);
if (strcmp(json_object_get_string(out), output->name) == 0) {
struct workspace *ws = malloc(sizeof(struct workspace));
ws->num = json_object_get_int(num);
@ -261,7 +259,7 @@ static void ipc_update_workspaces(struct bar *bar) {
output->focused = true;
}
ws->urgent = json_object_get_boolean(urgent);
list_add(output->workspaces, ws);
list_add(output->workspaces, &ws);
}
}
}
@ -301,9 +299,8 @@ void ipc_bar_init(struct bar *bar, const char *bar_id) {
if (bar->config->all_outputs) {
use_output = true;
} else {
int j = 0;
for (j = 0; j < bar->config->outputs->length; ++j) {
const char *conf_name = bar->config->outputs->items[j];
for (size_t j = 0; j < bar->config->outputs->length; ++j) {
const char *conf_name = list_getp(bar->config->outputs, j);
if (strcasecmp(name, conf_name) == 0) {
use_output = true;
break;
@ -318,7 +315,7 @@ void ipc_bar_init(struct bar *bar, const char *bar_id) {
// add bar to the output
struct output *bar_output = new_output(name);
bar_output->idx = i;
list_add(bar->outputs, bar_output);
list_add(bar->outputs, &bar_output);
}
free(res);
json_object_put(outputs);

View file

@ -275,8 +275,6 @@ static void render_binding_mode_indicator(struct window *window, struct config *
}
void render(struct output *output, struct config *config, struct status_line *line) {
int i;
struct window *window = output->window;
cairo_t *cairo = window->cairo;
bool is_focused = output->focused;
@ -316,8 +314,8 @@ void render(struct output *output, struct config *config, struct status_line *li
} else if (line->protocol == I3BAR && line->block_line) {
double pos = (window->width * window->scale) - 0.5;
bool edge = true;
for (i = line->block_line->length - 1; i >= 0; --i) {
struct status_block *block = line->block_line->items[i];
for (ssize_t i = line->block_line->length - 1; i >= 0; --i) {
struct status_block *block = list_getp(line->block_line, i);
if (block->full_text && block->full_text[0]) {
render_block(window, config, block, &pos, edge, is_focused);
edge = false;
@ -330,8 +328,8 @@ void render(struct output *output, struct config *config, struct status_line *li
// Workspaces
if (config->workspace_buttons) {
for (i = 0; i < output->workspaces->length; ++i) {
struct workspace *ws = output->workspaces->items[i];
for (size_t i = 0; i < output->workspaces->length; ++i) {
struct workspace *ws = list_getp(output->workspaces, i);
render_workspace_button(window, config, ws, &x);
}
}

View file

@ -62,11 +62,15 @@ static void parse_json(struct bar *bar, const char *text) {
}
if (bar->status->block_line) {
list_foreach(bar->status->block_line, free_status_block);
//list_foreach(bar->status->block_line, free_status_block);
for (size_t i = 0; i < bar->status->block_line->length; ++i) {
struct status_block *item = list_getp(bar->status->block_line, i);
free_status_block(item);
}
list_free(bar->status->block_line);
}
bar->status->block_line = create_list();
bar->status->block_line = list_new(sizeof(struct status_block *), 0);
int i;
for (i = 0; i < json_object_array_length(results); ++i) {
@ -199,7 +203,7 @@ static void parse_json(struct bar *bar, const char *text) {
new->border_right = 1;
}
list_add(bar->status->block_line, new);
list_add(bar->status->block_line, &new);
}
json_object_put(results);
@ -438,7 +442,7 @@ bool handle_status_line(struct bar *bar) {
struct status_line *init_status_line() {
struct status_line *line = malloc(sizeof(struct status_line));
line->block_line = create_list();
line->block_line = list_new(sizeof(struct status_block *), 0);
line->text_line = NULL;
line->protocol = UNDEF;
@ -447,7 +451,11 @@ struct status_line *init_status_line() {
void free_status_line(struct status_line *line) {
if (line->block_line) {
list_foreach(line->block_line, free_status_block);
//list_foreach(line->block_line, free_status_block);
for (size_t i = 0; i < line->block_line->length; ++i) {
struct status_block *item = list_getp(line->block_line, i);
free_status_block(item);
}
list_free(line->block_line);
}
}

View file

@ -25,9 +25,8 @@ enum scaling_mode {
};
void sway_terminate(int exit_code) {
int i;
for (i = 0; i < surfaces->length; ++i) {
struct window *window = surfaces->items[i];
for (size_t i = 0; i < surfaces->length; ++i) {
struct window *window = list_getp(surfaces, i);
window_teardown(window);
}
list_free(surfaces);
@ -54,7 +53,7 @@ bool is_valid_color(const char *color) {
int main(int argc, const char **argv) {
init_log(L_INFO);
surfaces = create_list();
surfaces = list_new(sizeof(struct window *), 0);
registry = registry_poll();
if (argc != 4) {
@ -66,9 +65,8 @@ int main(int argc, const char **argv) {
}
int desired_output = atoi(argv[1]);
sway_log(L_INFO, "Using output %d of %d", desired_output, registry->outputs->length);
int i;
struct output_state *output = registry->outputs->items[desired_output];
sway_log(L_INFO, "Using output %d of %zu", desired_output, registry->outputs->length);
struct output_state *output = list_getp(registry->outputs, desired_output);
struct window *window = window_setup(registry,
output->width, output->height, output->scale, false);
if (!window) {
@ -76,7 +74,7 @@ int main(int argc, const char **argv) {
}
desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
window_make_shell(window);
list_add(surfaces, window);
list_add(surfaces, &window);
if (strcmp(argv[3], "solid_color") == 0 && is_valid_color(argv[2])) {
cairo_set_source_u32(window->cairo, parse_color(argv[2]));
@ -119,8 +117,8 @@ int main(int argc, const char **argv) {
int wwidth = window->width * window->scale;
int wheight = window->height * window->scale;
for (i = 0; i < surfaces->length; ++i) {
struct window *window = surfaces->items[i];
for (size_t i = 0; i < surfaces->length; ++i) {
struct window *window = list_getp(surfaces, i);
if (window_prerender(window) && window->cairo) {
switch (scaling_mode) {
case SCALING_MODE_STRETCH:
@ -196,8 +194,8 @@ int main(int argc, const char **argv) {
while (wl_display_dispatch(registry->display) != -1);
for (i = 0; i < surfaces->length; ++i) {
struct window *window = surfaces->items[i];
for (size_t i = 0; i < surfaces->length; ++i) {
struct window *window = list_getp(surfaces, i);
window_teardown(window);
}
list_free(surfaces);

View file

@ -44,9 +44,8 @@ void sigalarm_handler(int sig) {
}
void sway_terminate(int exit_code) {
int i;
for (i = 0; i < render_data.surfaces->length; ++i) {
struct window *window = render_data.surfaces->items[i];
for (size_t i = 0; i < render_data.surfaces->length; ++i) {
struct window *window = list_getp(render_data.surfaces, i);
window_teardown(window);
}
list_free(render_data.surfaces);
@ -346,7 +345,6 @@ cairo_surface_t *load_image(char *image_path) {
int main(int argc, char **argv) {
const char *scaling_mode_str = "fit", *socket_path = NULL;
int i;
void *images = NULL;
config = init_config();
@ -535,7 +533,7 @@ int main(int argc, char **argv) {
password_size = 1024;
password = malloc(password_size);
password[0] = '\0';
render_data.surfaces = create_list();
render_data.surfaces = list_new(sizeof(struct window *), 0);
if (!socket_path) {
socket_path = get_socketpath();
if (!socket_path) {
@ -557,14 +555,14 @@ int main(int argc, char **argv) {
registry->pointer = NULL;
}
for (i = 0; i < registry->outputs->length; ++i) {
struct output_state *output = registry->outputs->items[i];
for (size_t i = 0; i < registry->outputs->length; ++i) {
struct output_state *output = list_getp(registry->outputs, i);
struct window *window = window_setup(registry,
output->width, output->height, output->scale, true);
if (!window) {
sway_abort("Failed to create surfaces.");
}
list_add(render_data.surfaces, window);
list_add(render_data.surfaces, &window);
}
registry->input->notify = notify_key;
@ -579,7 +577,7 @@ int main(int argc, char **argv) {
char *outputs = ipc_single_command(socketfd, IPC_GET_OUTPUTS, "", &len);
struct json_object *json_outputs = json_tokener_parse(outputs);
for (i = 0; i < registry->outputs->length; ++i) {
for (size_t i = 0; i < registry->outputs->length; ++i) {
if (displays_paths[i * 2] != NULL) {
for (int j = 0;; ++j) {
if (j >= json_object_array_length(json_outputs)) {
@ -608,9 +606,9 @@ int main(int argc, char **argv) {
bool locked = false;
while (wl_display_dispatch(registry->display) != -1) {
if (!locked) {
for (i = 0; i < registry->outputs->length; ++i) {
struct output_state *output = registry->outputs->items[i];
struct window *window = render_data.surfaces->items[i];
for (size_t i = 0; i < registry->outputs->length; ++i) {
struct output_state *output = list_getp(registry->outputs, i);
struct window *window = list_getp(render_data.surfaces, i);
lock_set_lock_surface(registry->swaylock, output->output, window->surface);
}
locked = true;
@ -621,7 +619,7 @@ int main(int argc, char **argv) {
if (render_data.num_images == -1) {
cairo_surface_destroy(render_data.image);
} else if (render_data.num_images >= 1) {
for (i = 0; i < registry->outputs->length; ++i) {
for (size_t i = 0; i < registry->outputs->length; ++i) {
if (render_data.images[i] != NULL) {
cairo_surface_destroy(render_data.images[i]);
}
@ -629,8 +627,8 @@ int main(int argc, char **argv) {
free(render_data.images);
}
for (i = 0; i < render_data.surfaces->length; ++i) {
struct window *window = render_data.surfaces->items[i];
for (size_t i = 0; i < render_data.surfaces->length; ++i) {
struct window *window = list_getp(render_data.surfaces, i);
window_teardown(window);
}
list_free(render_data.surfaces);
@ -642,10 +640,9 @@ int main(int argc, char **argv) {
}
void render(struct render_data *render_data, struct lock_config *config) {
int i;
for (i = 0; i < render_data->surfaces->length; ++i) {
sway_log(L_DEBUG, "Render surface %d of %d", i, render_data->surfaces->length);
struct window *window = render_data->surfaces->items[i];
for (size_t i = 0; i < render_data->surfaces->length; ++i) {
sway_log(L_DEBUG, "Render surface %zu of %zu", i, render_data->surfaces->length);
struct window *window = list_getp(render_data->surfaces, i);
if (!window_prerender(window) || !window->cairo) {
continue;
}

View file

@ -227,7 +227,7 @@ static void registry_global(void *data, struct wl_registry *registry,
ostate->output = output;
ostate->scale = 1;
wl_output_add_listener(output, &output_listener, ostate);
list_add(reg->outputs, ostate);
list_add(reg->outputs, &ostate);
} else if (strcmp(interface, desktop_shell_interface.name) == 0) {
reg->desktop_shell = wl_registry_bind(registry, name, &desktop_shell_interface, version);
} else if (strcmp(interface, lock_interface.name) == 0) {
@ -247,7 +247,7 @@ static const struct wl_registry_listener registry_listener = {
struct registry *registry_poll(void) {
struct registry *registry = malloc(sizeof(struct registry));
memset(registry, 0, sizeof(struct registry));
registry->outputs = create_list();
registry->outputs = list_new(sizeof(struct output_state *), 0);
registry->input = calloc(sizeof(struct input), 1);
registry->input->xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
@ -287,7 +287,7 @@ void registry_teardown(struct registry *registry) {
wl_display_disconnect(registry->display);
}
if (registry->outputs) {
free_flat_list(registry->outputs);
list_free_withp(registry->outputs, free);
}
free(registry);
}