aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
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/commands
parente7efa0e27b7bf44217d7f147281d463708d2dfc9 (diff)
parent98c1e19466c0d83c8e1ca86eda5b273eda7eff3c (diff)
Merge pull request #3271 from ianyfan/list-cleanup
list.c: Remove list_foreach
Diffstat (limited to 'sway/commands')
-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
4 files changed, 10 insertions, 20 deletions
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);
}