aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <RyanDwyer@users.noreply.github.com>2018-12-09 21:50:19 +1000
committerLibravatar GitHub <noreply@github.com>2018-12-09 21:50:19 +1000
commitb61a936c8060bc4ac4320a5f76fd98b5042e5e41 (patch)
tree279a5554686d6e862282c943bda50787b69711e1 /sway
parentMerge pull request #3264 from ianyfan/resize-list (diff)
parentlist.c: rename free_flat_list to list_free_items_and_destroy (diff)
downloadsway-b61a936c8060bc4ac4320a5f76fd98b5042e5e41.tar.gz
sway-b61a936c8060bc4ac4320a5f76fd98b5042e5e41.tar.zst
sway-b61a936c8060bc4ac4320a5f76fd98b5042e5e41.zip
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
43} 43}
44 44
45void apply_seat_config(struct seat_config *seat_config) { 45void apply_seat_config(struct seat_config *seat_config) {
46 int i; 46 int i = list_seq_find(config->seat_configs, seat_name_cmp, seat_config->name);
47 i = list_seq_find(config->seat_configs, seat_name_cmp, seat_config->name);
48 if (i >= 0) { 47 if (i >= 0) {
49 // merge existing config 48 // merge existing config
50 struct seat_config *sc = config->seat_configs->items[i]; 49 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) {
20 uint32_t tmp_mod; 20 uint32_t tmp_mod;
21 if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) { 21 if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) {
22 mod |= tmp_mod; 22 mod |= tmp_mod;
23 continue;
24 } else { 23 } else {
25 error = cmd_results_new(CMD_INVALID, "modifier", 24 error = cmd_results_new(CMD_INVALID, "modifier",
26 "Unknown modifier '%s'", split->items[i]); 25 "Unknown modifier '%s'", split->items[i]);
27 free_flat_list(split); 26 list_free_items_and_destroy(split);
28 return error; 27 return error;
29 } 28 }
30 } 29 }
31 free_flat_list(split); 30 list_free_items_and_destroy(split);
32 config->current_bar->modifier = mod; 31 config->current_bar->modifier = mod;
33 wlr_log(WLR_DEBUG, 32 wlr_log(WLR_DEBUG,
34 "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]); 33 "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) {
23 return; 23 return;
24 } 24 }
25 25
26 if (binding->keys) { 26 list_free_items_and_destroy(binding->keys);
27 free_flat_list(binding->keys);
28 }
29 free(binding->input); 27 free(binding->input);
30 free(binding->command); 28 free(binding->command);
31 free(binding); 29 free(binding);
@@ -80,7 +78,6 @@ static int key_qsort_cmp(const void *keyp_a, const void *keyp_b) {
80 return (key_a < key_b) ? -1 : ((key_a > key_b) ? 1 : 0); 78 return (key_a < key_b) ? -1 : ((key_a > key_b) ? 1 : 0);
81} 79}
82 80
83
84/** 81/**
85 * From a keycode, bindcode, or bindsym name and the most likely binding type, 82 * From a keycode, bindcode, or bindsym name and the most likely binding type,
86 * identify the appropriate numeric value corresponding to the key. Return NULL 83 * 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,
223 uint32_t *key = calloc(1, sizeof(uint32_t)); 220 uint32_t *key = calloc(1, sizeof(uint32_t));
224 if (!key) { 221 if (!key) {
225 free_sway_binding(binding); 222 free_sway_binding(binding);
226 free_flat_list(split); 223 list_free_items_and_destroy(split);
227 return cmd_results_new(CMD_FAILURE, bindtype, 224 return cmd_results_new(CMD_FAILURE, bindtype,
228 "Unable to allocate binding key"); 225 "Unable to allocate binding key");
229 } 226 }
230 *key = key_val; 227 *key = key_val;
231 list_add(binding->keys, key); 228 list_add(binding->keys, key);
232 } 229 }
233 free_flat_list(split); 230 list_free_items_and_destroy(split);
234 binding->order = binding_order++; 231 binding->order = binding_order++;
235 232
236 // refine region of interest for mouse binding once we are certain 233 // 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,
280 wlr_log(WLR_DEBUG, "%s - Bound %s to command `%s` for device '%s'", 277 wlr_log(WLR_DEBUG, "%s - Bound %s to command `%s` for device '%s'",
281 bindtype, argv[0], binding->command, binding->input); 278 bindtype, argv[0], binding->command, binding->input);
282 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 279 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
283
284} 280}
285 281
286struct cmd_results *cmd_bindsym(int argc, char **argv) { 282struct cmd_results *cmd_bindsym(int argc, char **argv) {
@@ -291,7 +287,6 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) {
291 return cmd_bindsym_or_bindcode(argc, argv, true); 287 return cmd_bindsym_or_bindcode(argc, argv, true);
292} 288}
293 289
294
295/** 290/**
296 * Execute the command associated to a binding 291 * Execute the command associated to a binding
297 */ 292 */
@@ -301,15 +296,14 @@ void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding)
301 config->handler_context.seat = seat; 296 config->handler_context.seat = seat;
302 list_t *res_list = execute_command(binding->command, NULL, NULL); 297 list_t *res_list = execute_command(binding->command, NULL, NULL);
303 bool success = true; 298 bool success = true;
304 while (res_list->length) { 299 for (int i = 0; i < res_list->length; ++i) {
305 struct cmd_results *results = res_list->items[0]; 300 struct cmd_results *results = res_list->items[i];
306 if (results->status != CMD_SUCCESS) { 301 if (results->status != CMD_SUCCESS) {
307 wlr_log(WLR_DEBUG, "could not run command for binding: %s (%s)", 302 wlr_log(WLR_DEBUG, "could not run command for binding: %s (%s)",
308 binding->command, results->error); 303 binding->command, results->error);
309 success = false; 304 success = false;
310 } 305 }
311 free_cmd_results(results); 306 free_cmd_results(results);
312 list_del(res_list, 0);
313 } 307 }
314 list_free(res_list); 308 list_free(res_list);
315 if (success) { 309 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) {
24 24
25 if (!load_main_config(config->current_config_path, true, false)) { 25 if (!load_main_config(config->current_config_path, true, false)) {
26 wlr_log(WLR_ERROR, "Error(s) reloading config"); 26 wlr_log(WLR_ERROR, "Error(s) reloading config");
27 list_foreach(bar_ids, free); 27 list_free_items_and_destroy(bar_ids);
28 list_free(bar_ids);
29 return; 28 return;
30 } 29 }
31 30
@@ -42,9 +41,7 @@ static void do_reload(void *data) {
42 } 41 }
43 } 42 }
44 } 43 }
45 44 list_free_items_and_destroy(bar_ids);
46 list_foreach(bar_ids, free);
47 list_free(bar_ids);
48 45
49 config_update_font_height(true); 46 config_update_font_height(true);
50 root_for_each_container(rebuild_textures_iterator, NULL); 47 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) {
33 33
34void free_workspace_config(struct workspace_config *wsc) { 34void free_workspace_config(struct workspace_config *wsc) {
35 free(wsc->workspace); 35 free(wsc->workspace);
36 free_flat_list(wsc->outputs); 36 list_free_items_and_destroy(wsc->outputs);
37 free(wsc); 37 free(wsc);
38} 38}
39 39
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 @@
38struct sway_config *config = NULL; 38struct sway_config *config = NULL;
39 39
40static void free_mode(struct sway_mode *mode) { 40static void free_mode(struct sway_mode *mode) {
41 int i;
42
43 if (!mode) { 41 if (!mode) {
44 return; 42 return;
45 } 43 }
46 free(mode->name); 44 free(mode->name);
47 if (mode->keysym_bindings) { 45 if (mode->keysym_bindings) {
48 for (i = 0; i < mode->keysym_bindings->length; i++) { 46 for (int i = 0; i < mode->keysym_bindings->length; i++) {
49 free_sway_binding(mode->keysym_bindings->items[i]); 47 free_sway_binding(mode->keysym_bindings->items[i]);
50 } 48 }
51 list_free(mode->keysym_bindings); 49 list_free(mode->keysym_bindings);
52 } 50 }
53 if (mode->keycode_bindings) { 51 if (mode->keycode_bindings) {
54 for (i = 0; i < mode->keycode_bindings->length; i++) { 52 for (int i = 0; i < mode->keycode_bindings->length; i++) {
55 free_sway_binding(mode->keycode_bindings->items[i]); 53 free_sway_binding(mode->keycode_bindings->items[i]);
56 } 54 }
57 list_free(mode->keycode_bindings); 55 list_free(mode->keycode_bindings);
58 } 56 }
59 if (mode->mouse_bindings) { 57 if (mode->mouse_bindings) {
60 for (i = 0; i < mode->mouse_bindings->length; i++) { 58 for (int i = 0; i < mode->mouse_bindings->length; i++) {
61 free_sway_binding(mode->mouse_bindings->items[i]); 59 free_sway_binding(mode->mouse_bindings->items[i]);
62 } 60 }
63 list_free(mode->mouse_bindings); 61 list_free(mode->mouse_bindings);
@@ -446,7 +444,7 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
446 } 444 }
447 } 445 }
448 446
449 free_flat_list(secconfigs); 447 list_free_items_and_destroy(secconfigs);
450 } 448 }
451 */ 449 */
452 450
@@ -654,8 +652,7 @@ bool read_config(FILE *file, struct sway_config *config,
654 652
655 if (read + length > config_size) { 653 if (read + length > config_size) {
656 wlr_log(WLR_ERROR, "Config file changed during reading"); 654 wlr_log(WLR_ERROR, "Config file changed during reading");
657 list_foreach(stack, free); 655 list_free_items_and_destroy(stack);
658 list_free(stack);
659 free(line); 656 free(line);
660 return false; 657 return false;
661 } 658 }
@@ -684,8 +681,7 @@ bool read_config(FILE *file, struct sway_config *config,
684 } 681 }
685 char *expanded = expand_line(block, line, brace_detected > 0); 682 char *expanded = expand_line(block, line, brace_detected > 0);
686 if (!expanded) { 683 if (!expanded) {
687 list_foreach(stack, free); 684 list_free_items_and_destroy(stack);
688 list_free(stack);
689 free(line); 685 free(line);
690 return false; 686 return false;
691 } 687 }
@@ -750,8 +746,7 @@ bool read_config(FILE *file, struct sway_config *config,
750 free(line); 746 free(line);
751 free_cmd_results(res); 747 free_cmd_results(res);
752 } 748 }
753 list_foreach(stack, free); 749 list_free_items_and_destroy(stack);
754 list_free(stack);
755 config->current_config_line_number = 0; 750 config->current_config_line_number = 0;
756 config->current_config_line = NULL; 751 config->current_config_line = NULL;
757 752
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) {
49 free(bar->font); 49 free(bar->font);
50 free(bar->separator_symbol); 50 free(bar->separator_symbol);
51 for (int i = 0; i < bar->bindings->length; i++) { 51 for (int i = 0; i < bar->bindings->length; i++) {
52 struct bar_binding *binding = bar->bindings->items[i]; 52 free_bar_binding(bar->bindings->items[i]);
53 free_bar_binding(binding);
54 } 53 }
55 list_free(bar->bindings); 54 list_free(bar->bindings);
56 if (bar->outputs) { 55 list_free_items_and_destroy(bar->outputs);
57 free_flat_list(bar->outputs);
58 }
59 if (bar->pid != 0) { 56 if (bar->pid != 0) {
60 terminate_swaybar(bar->pid); 57 terminate_swaybar(bar->pid);
61 } 58 }
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) {
117 117
118 free(seat->name); 118 free(seat->name);
119 for (int i = 0; i < seat->attachments->length; ++i) { 119 for (int i = 0; i < seat->attachments->length; ++i) {
120 struct seat_attachment_config *attachment = 120 seat_attachment_config_free(seat->attachments->items[i]);
121 seat->attachments->items[i];
122 seat_attachment_config_free(attachment);
123 } 121 }
124
125 list_free(seat->attachments); 122 list_free(seat->attachments);
126 free(seat); 123 free(seat);
127} 124}
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) {
73 unlink(ipc_sockaddr->sun_path); 73 unlink(ipc_sockaddr->sun_path);
74 74
75 while (ipc_client_list->length) { 75 while (ipc_client_list->length) {
76 struct ipc_client *client = ipc_client_list->items[0]; 76 ipc_client_disconnect(ipc_client_list->items[ipc_client_list->length-1]);
77 ipc_client_disconnect(client);
78 } 77 }
79 list_free(ipc_client_list); 78 list_free(ipc_client_list);
80 79
81 if (ipc_sockaddr) { 80 free(ipc_sockaddr);
82 free(ipc_sockaddr);
83 }
84 81
85 wl_list_remove(&ipc_display_destroy.link); 82 wl_list_remove(&ipc_display_destroy.link);
86} 83}
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) {
393 while (config->cmd_queue->length) { 393 while (config->cmd_queue->length) {
394 char *line = config->cmd_queue->items[0]; 394 char *line = config->cmd_queue->items[0];
395 list_t *res_list = execute_command(line, NULL, NULL); 395 list_t *res_list = execute_command(line, NULL, NULL);
396 while (res_list->length) { 396 for (int i = 0; i < res_list->length; ++i) {
397 struct cmd_results *res = res_list->items[0]; 397 struct cmd_results *res = res_list->items[i];
398 if (res->status != CMD_SUCCESS) { 398 if (res->status != CMD_SUCCESS) {
399 wlr_log(WLR_ERROR, "Error on line '%s': %s", line, res->error); 399 wlr_log(WLR_ERROR, "Error on line '%s': %s", line, res->error);
400 } 400 }
401 free_cmd_results(res); 401 free_cmd_results(res);
402 list_del(res_list, 0);
403 } 402 }
404 list_free(res_list); 403 list_free(res_list);
405 free(line); 404 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 @@
21#include "sway/tree/arrange.h" 21#include "sway/tree/arrange.h"
22#include "sway/tree/view.h" 22#include "sway/tree/view.h"
23#include "sway/tree/workspace.h" 23#include "sway/tree/workspace.h"
24#include "list.h"
24#include "log.h" 25#include "log.h"
25#include "stringop.h" 26#include "stringop.h"
26 27
@@ -67,8 +68,7 @@ void container_destroy(struct sway_container *con) {
67 list_free(con->current.children); 68 list_free(con->current.children);
68 list_free(con->outputs); 69 list_free(con->outputs);
69 70
70 list_foreach(con->marks, free); 71 list_free_items_and_destroy(con->marks);
71 list_free(con->marks);
72 wlr_texture_destroy(con->marks_focused); 72 wlr_texture_destroy(con->marks_focused);
73 wlr_texture_destroy(con->marks_focused_inactive); 73 wlr_texture_destroy(con->marks_focused_inactive);
74 wlr_texture_destroy(con->marks_unfocused); 74 wlr_texture_destroy(con->marks_unfocused);
@@ -1267,7 +1267,9 @@ bool container_find_and_unmark(char *mark) {
1267} 1267}
1268 1268
1269void container_clear_marks(struct sway_container *con) { 1269void container_clear_marks(struct sway_container *con) {
1270 list_foreach(con->marks, free); 1270 for (int i = 0; i < con->marks->length; ++i) {
1271 free(con->marks->items[i]);
1272 }
1271 con->marks->length = 0; 1273 con->marks->length = 0;
1272 ipc_event_window(con, "mark"); 1274 ipc_event_window(con, "mark");
1273} 1275}
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) {
142 142
143 free(workspace->name); 143 free(workspace->name);
144 free(workspace->representation); 144 free(workspace->representation);
145 free_flat_list(workspace->output_priority); 145 list_free_items_and_destroy(workspace->output_priority);
146 list_free(workspace->floating); 146 list_free(workspace->floating);
147 list_free(workspace->tiling); 147 list_free(workspace->tiling);
148 list_free(workspace->current.floating); 148 list_free(workspace->current.floating);