diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-12-08 23:55:14 +0000 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-12-09 01:15:38 +0000 |
commit | c8776fac4232f9faab0a78ef3e18dc4366496421 (patch) | |
tree | 028fbc584d233a7a934feb0b6807c9a988c8e7f1 /sway | |
parent | list.c: Remove list_foreach (diff) | |
download | sway-c8776fac4232f9faab0a78ef3e18dc4366496421.tar.gz sway-c8776fac4232f9faab0a78ef3e18dc4366496421.tar.zst sway-c8776fac4232f9faab0a78ef3e18dc4366496421.zip |
Cleanup list code
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 3 | ||||
-rw-r--r-- | sway/commands/bar/modifier.c | 1 | ||||
-rw-r--r-- | sway/commands/bind.c | 8 | ||||
-rw-r--r-- | sway/config.c | 8 | ||||
-rw-r--r-- | sway/config/bar.c | 3 | ||||
-rw-r--r-- | sway/config/seat.c | 5 | ||||
-rw-r--r-- | sway/ipc-server.c | 7 | ||||
-rw-r--r-- | sway/main.c | 5 |
8 files changed, 12 insertions, 28 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 | ||
45 | void apply_seat_config(struct seat_config *seat_config) { | 45 | void 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..1b3e7492 100644 --- a/sway/commands/bar/modifier.c +++ b/sway/commands/bar/modifier.c | |||
@@ -20,7 +20,6 @@ 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]); |
diff --git a/sway/commands/bind.c b/sway/commands/bind.c index 52a245fa..886a262c 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c | |||
@@ -78,7 +78,6 @@ static int key_qsort_cmp(const void *keyp_a, const void *keyp_b) { | |||
78 | 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); |
79 | } | 79 | } |
80 | 80 | ||
81 | |||
82 | /** | 81 | /** |
83 | * 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, |
84 | * identify the appropriate numeric value corresponding to the key. Return NULL | 83 | * identify the appropriate numeric value corresponding to the key. Return NULL |
@@ -278,7 +277,6 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv, | |||
278 | 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'", |
279 | bindtype, argv[0], binding->command, binding->input); | 278 | bindtype, argv[0], binding->command, binding->input); |
280 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 279 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
281 | |||
282 | } | 280 | } |
283 | 281 | ||
284 | struct cmd_results *cmd_bindsym(int argc, char **argv) { | 282 | struct cmd_results *cmd_bindsym(int argc, char **argv) { |
@@ -289,7 +287,6 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) { | |||
289 | return cmd_bindsym_or_bindcode(argc, argv, true); | 287 | return cmd_bindsym_or_bindcode(argc, argv, true); |
290 | } | 288 | } |
291 | 289 | ||
292 | |||
293 | /** | 290 | /** |
294 | * Execute the command associated to a binding | 291 | * Execute the command associated to a binding |
295 | */ | 292 | */ |
@@ -299,15 +296,14 @@ void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding) | |||
299 | config->handler_context.seat = seat; | 296 | config->handler_context.seat = seat; |
300 | list_t *res_list = execute_command(binding->command, NULL, NULL); | 297 | list_t *res_list = execute_command(binding->command, NULL, NULL); |
301 | bool success = true; | 298 | bool success = true; |
302 | while (res_list->length) { | 299 | for (int i = 0; i < res_list->length; ++i) { |
303 | struct cmd_results *results = res_list->items[0]; | 300 | struct cmd_results *results = res_list->items[i]; |
304 | if (results->status != CMD_SUCCESS) { | 301 | if (results->status != CMD_SUCCESS) { |
305 | 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)", |
306 | binding->command, results->error); | 303 | binding->command, results->error); |
307 | success = false; | 304 | success = false; |
308 | } | 305 | } |
309 | free_cmd_results(results); | 306 | free_cmd_results(results); |
310 | list_del(res_list, 0); | ||
311 | } | 307 | } |
312 | list_free(res_list); | 308 | list_free(res_list); |
313 | if (success) { | 309 | if (success) { |
diff --git a/sway/config.c b/sway/config.c index efb95e31..4621cad9 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -38,26 +38,24 @@ | |||
38 | struct sway_config *config = NULL; | 38 | struct sway_config *config = NULL; |
39 | 39 | ||
40 | static void free_mode(struct sway_mode *mode) { | 40 | static 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); |
diff --git a/sway/config/bar.c b/sway/config/bar.c index 82457ef4..fc773026 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c | |||
@@ -49,8 +49,7 @@ 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 | free_flat_list(bar->outputs); | 55 | free_flat_list(bar->outputs); |
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); |