aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorRyan Dwyer <RyanDwyer@users.noreply.github.com>2018-12-09 21:50:19 +1000
committerGitHub <noreply@github.com>2018-12-09 21:50:19 +1000
commitb61a936c8060bc4ac4320a5f76fd98b5042e5e41 (patch)
tree279a5554686d6e862282c943bda50787b69711e1 /sway
parente7efa0e27b7bf44217d7f147281d463708d2dfc9 (diff)
parent98c1e19466c0d83c8e1ca86eda5b273eda7eff3c (diff)
downloadsway-b61a936c8060bc4ac4320a5f76fd98b5042e5e41.tar.xz
Merge pull request #3271 from ianyfan/list-cleanup
list.c: Remove list_foreach
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c3
-rw-r--r--sway/commands/bar/modifier.c5
-rw-r--r--sway/commands/bind.c16
-rw-r--r--sway/commands/reload.c7
-rw-r--r--sway/commands/workspace.c2
-rw-r--r--sway/config.c19
-rw-r--r--sway/config/bar.c7
-rw-r--r--sway/config/seat.c5
-rw-r--r--sway/ipc-server.c7
-rw-r--r--sway/main.c5
-rw-r--r--sway/tree/container.c8
-rw-r--r--sway/tree/workspace.c2
12 files changed, 31 insertions, 55 deletions
diff --git a/sway/commands.c b/sway/commands.c
index d5cab655..f6d1cc3e 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -43,8 +43,7 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type
}
void apply_seat_config(struct seat_config *seat_config) {
- int i;
- i = list_seq_find(config->seat_configs, seat_name_cmp, seat_config->name);
+ int i = list_seq_find(config->seat_configs, seat_name_cmp, seat_config->name);
if (i >= 0) {
// merge existing config
struct seat_config *sc = config->seat_configs->items[i];
diff --git a/sway/commands/bar/modifier.c b/sway/commands/bar/modifier.c
index 09025fff..b5a16f45 100644
--- a/sway/commands/bar/modifier.c
+++ b/sway/commands/bar/modifier.c
@@ -20,15 +20,14 @@ struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
uint32_t tmp_mod;
if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) {
mod |= tmp_mod;
- continue;
} else {
error = cmd_results_new(CMD_INVALID, "modifier",
"Unknown modifier '%s'", split->items[i]);
- free_flat_list(split);
+ list_free_items_and_destroy(split);
return error;
}
}
- free_flat_list(split);
+ list_free_items_and_destroy(split);
config->current_bar->modifier = mod;
wlr_log(WLR_DEBUG,
"Show/Hide the bar when pressing '%s' in hide mode.", argv[0]);
diff --git a/sway/commands/bind.c b/sway/commands/bind.c
index c8b634b9..01a35cf2 100644
--- a/sway/commands/bind.c
+++ b/sway/commands/bind.c
@@ -23,9 +23,7 @@ void free_sway_binding(struct sway_binding *binding) {
return;
}
- if (binding->keys) {
- free_flat_list(binding->keys);
- }
+ list_free_items_and_destroy(binding->keys);
free(binding->input);
free(binding->command);
free(binding);
@@ -80,7 +78,6 @@ static int key_qsort_cmp(const void *keyp_a, const void *keyp_b) {
return (key_a < key_b) ? -1 : ((key_a > key_b) ? 1 : 0);
}
-
/**
* From a keycode, bindcode, or bindsym name and the most likely binding type,
* identify the appropriate numeric value corresponding to the key. Return NULL
@@ -223,14 +220,14 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
uint32_t *key = calloc(1, sizeof(uint32_t));
if (!key) {
free_sway_binding(binding);
- free_flat_list(split);
+ list_free_items_and_destroy(split);
return cmd_results_new(CMD_FAILURE, bindtype,
"Unable to allocate binding key");
}
*key = key_val;
list_add(binding->keys, key);
}
- free_flat_list(split);
+ list_free_items_and_destroy(split);
binding->order = binding_order++;
// refine region of interest for mouse binding once we are certain
@@ -280,7 +277,6 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
wlr_log(WLR_DEBUG, "%s - Bound %s to command `%s` for device '%s'",
bindtype, argv[0], binding->command, binding->input);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
-
}
struct cmd_results *cmd_bindsym(int argc, char **argv) {
@@ -291,7 +287,6 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) {
return cmd_bindsym_or_bindcode(argc, argv, true);
}
-
/**
* Execute the command associated to a binding
*/
@@ -301,15 +296,14 @@ void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding)
config->handler_context.seat = seat;
list_t *res_list = execute_command(binding->command, NULL, NULL);
bool success = true;
- while (res_list->length) {
- struct cmd_results *results = res_list->items[0];
+ for (int i = 0; i < res_list->length; ++i) {
+ struct cmd_results *results = res_list->items[i];
if (results->status != CMD_SUCCESS) {
wlr_log(WLR_DEBUG, "could not run command for binding: %s (%s)",
binding->command, results->error);
success = false;
}
free_cmd_results(results);
- list_del(res_list, 0);
}
list_free(res_list);
if (success) {
diff --git a/sway/commands/reload.c b/sway/commands/reload.c
index c64de4bd..3ccbbf34 100644
--- a/sway/commands/reload.c
+++ b/sway/commands/reload.c
@@ -24,8 +24,7 @@ static void do_reload(void *data) {
if (!load_main_config(config->current_config_path, true, false)) {
wlr_log(WLR_ERROR, "Error(s) reloading config");
- list_foreach(bar_ids, free);
- list_free(bar_ids);
+ list_free_items_and_destroy(bar_ids);
return;
}
@@ -42,9 +41,7 @@ static void do_reload(void *data) {
}
}
}
-
- list_foreach(bar_ids, free);
- list_free(bar_ids);
+ list_free_items_and_destroy(bar_ids);
config_update_font_height(true);
root_for_each_container(rebuild_textures_iterator, NULL);
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index 7d32e65b..211b344d 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -33,7 +33,7 @@ static struct workspace_config *workspace_config_find_or_create(char *ws_name) {
void free_workspace_config(struct workspace_config *wsc) {
free(wsc->workspace);
- free_flat_list(wsc->outputs);
+ list_free_items_and_destroy(wsc->outputs);
free(wsc);
}
diff --git a/sway/config.c b/sway/config.c
index ff7de4b9..5b03bc56 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -38,26 +38,24 @@
struct sway_config *config = NULL;
static void free_mode(struct sway_mode *mode) {
- int i;
-
if (!mode) {
return;
}
free(mode->name);
if (mode->keysym_bindings) {
- for (i = 0; i < mode->keysym_bindings->length; i++) {
+ for (int i = 0; i < mode->keysym_bindings->length; i++) {
free_sway_binding(mode->keysym_bindings->items[i]);
}
list_free(mode->keysym_bindings);
}
if (mode->keycode_bindings) {
- for (i = 0; i < mode->keycode_bindings->length; i++) {
+ for (int i = 0; i < mode->keycode_bindings->length; i++) {
free_sway_binding(mode->keycode_bindings->items[i]);
}
list_free(mode->keycode_bindings);
}
if (mode->mouse_bindings) {
- for (i = 0; i < mode->mouse_bindings->length; i++) {
+ for (int i = 0; i < mode->mouse_bindings->length; i++) {
free_sway_binding(mode->mouse_bindings->items[i]);
}
list_free(mode->mouse_bindings);
@@ -446,7 +444,7 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
}
}
- free_flat_list(secconfigs);
+ list_free_items_and_destroy(secconfigs);
}
*/
@@ -654,8 +652,7 @@ bool read_config(FILE *file, struct sway_config *config,
if (read + length > config_size) {
wlr_log(WLR_ERROR, "Config file changed during reading");
- list_foreach(stack, free);
- list_free(stack);
+ list_free_items_and_destroy(stack);
free(line);
return false;
}
@@ -684,8 +681,7 @@ bool read_config(FILE *file, struct sway_config *config,
}
char *expanded = expand_line(block, line, brace_detected > 0);
if (!expanded) {
- list_foreach(stack, free);
- list_free(stack);
+ list_free_items_and_destroy(stack);
free(line);
return false;
}
@@ -750,8 +746,7 @@ bool read_config(FILE *file, struct sway_config *config,
free(line);
free_cmd_results(res);
}
- list_foreach(stack, free);
- list_free(stack);
+ list_free_items_and_destroy(stack);
config->current_config_line_number = 0;
config->current_config_line = NULL;
diff --git a/sway/config/bar.c b/sway/config/bar.c
index 36e10527..45c9e998 100644
--- a/sway/config/bar.c
+++ b/sway/config/bar.c
@@ -49,13 +49,10 @@ void free_bar_config(struct bar_config *bar) {
free(bar->font);
free(bar->separator_symbol);
for (int i = 0; i < bar->bindings->length; i++) {
- struct bar_binding *binding = bar->bindings->items[i];
- free_bar_binding(binding);
+ free_bar_binding(bar->bindings->items[i]);
}
list_free(bar->bindings);
- if (bar->outputs) {
- free_flat_list(bar->outputs);
- }
+ list_free_items_and_destroy(bar->outputs);
if (bar->pid != 0) {
terminate_swaybar(bar->pid);
}
diff --git a/sway/config/seat.c b/sway/config/seat.c
index 56fa6095..1cb4c363 100644
--- a/sway/config/seat.c
+++ b/sway/config/seat.c
@@ -117,11 +117,8 @@ void free_seat_config(struct seat_config *seat) {
free(seat->name);
for (int i = 0; i < seat->attachments->length; ++i) {
- struct seat_attachment_config *attachment =
- seat->attachments->items[i];
- seat_attachment_config_free(attachment);
+ seat_attachment_config_free(seat->attachments->items[i]);
}
-
list_free(seat->attachments);
free(seat);
}
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index b3954259..2c642a37 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -73,14 +73,11 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
unlink(ipc_sockaddr->sun_path);
while (ipc_client_list->length) {
- struct ipc_client *client = ipc_client_list->items[0];
- ipc_client_disconnect(client);
+ ipc_client_disconnect(ipc_client_list->items[ipc_client_list->length-1]);
}
list_free(ipc_client_list);
- if (ipc_sockaddr) {
- free(ipc_sockaddr);
- }
+ free(ipc_sockaddr);
wl_list_remove(&ipc_display_destroy.link);
}
diff --git a/sway/main.c b/sway/main.c
index a74183fe..f70e751d 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -393,13 +393,12 @@ int main(int argc, char **argv) {
while (config->cmd_queue->length) {
char *line = config->cmd_queue->items[0];
list_t *res_list = execute_command(line, NULL, NULL);
- while (res_list->length) {
- struct cmd_results *res = res_list->items[0];
+ for (int i = 0; i < res_list->length; ++i) {
+ struct cmd_results *res = res_list->items[i];
if (res->status != CMD_SUCCESS) {
wlr_log(WLR_ERROR, "Error on line '%s': %s", line, res->error);
}
free_cmd_results(res);
- list_del(res_list, 0);
}
list_free(res_list);
free(line);
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 91e8dd7f..b106e0d9 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -21,6 +21,7 @@
#include "sway/tree/arrange.h"
#include "sway/tree/view.h"
#include "sway/tree/workspace.h"
+#include "list.h"
#include "log.h"
#include "stringop.h"
@@ -67,8 +68,7 @@ void container_destroy(struct sway_container *con) {
list_free(con->current.children);
list_free(con->outputs);
- list_foreach(con->marks, free);
- list_free(con->marks);
+ list_free_items_and_destroy(con->marks);
wlr_texture_destroy(con->marks_focused);
wlr_texture_destroy(con->marks_focused_inactive);
wlr_texture_destroy(con->marks_unfocused);
@@ -1267,7 +1267,9 @@ bool container_find_and_unmark(char *mark) {
}
void container_clear_marks(struct sway_container *con) {
- list_foreach(con->marks, free);
+ for (int i = 0; i < con->marks->length; ++i) {
+ free(con->marks->items[i]);
+ }
con->marks->length = 0;
ipc_event_window(con, "mark");
}
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 4be63311..ed24b4fd 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -142,7 +142,7 @@ void workspace_destroy(struct sway_workspace *workspace) {
free(workspace->name);
free(workspace->representation);
- free_flat_list(workspace->output_priority);
+ list_free_items_and_destroy(workspace->output_priority);
list_free(workspace->floating);
list_free(workspace->tiling);
list_free(workspace->current.floating);