mirror of
https://github.com/gwenhael-le-moine/sway-patched-tray-menu.git
synced 2024-12-26 21:58:08 +01:00
Cleanup list code
This commit is contained in:
parent
19e831ed3d
commit
c8776fac42
11 changed files with 17 additions and 37 deletions
|
@ -48,8 +48,7 @@ void list_del(list_t *list, int index) {
|
|||
}
|
||||
|
||||
void list_cat(list_t *list, list_t *source) {
|
||||
int i;
|
||||
for (i = 0; i < source->length; ++i) {
|
||||
for (int i = 0; i < source->length; ++i) {
|
||||
list_add(list, source->items[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -20,7 +20,6 @@ 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]);
|
||||
|
|
|
@ -78,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
|
||||
|
@ -278,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) {
|
||||
|
@ -289,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
|
||||
*/
|
||||
|
@ -299,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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -49,8 +49,7 @@ 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);
|
||||
free_flat_list(bar->outputs);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -407,9 +407,8 @@ void swaynag_destroy(struct swaynag *swaynag) {
|
|||
swaynag->run_display = false;
|
||||
|
||||
free(swaynag->message);
|
||||
while (swaynag->buttons->length) {
|
||||
struct swaynag_button *button = swaynag->buttons->items[0];
|
||||
list_del(swaynag->buttons, 0);
|
||||
for (int i = 0; i < swaynag->buttons->length; ++i) {
|
||||
struct swaynag_button *button = swaynag->buttons->items[i];
|
||||
free(button->text);
|
||||
free(button->action);
|
||||
free(button);
|
||||
|
|
|
@ -147,10 +147,8 @@ void swaynag_type_free(struct swaynag_type *type) {
|
|||
}
|
||||
|
||||
void swaynag_types_free(list_t *types) {
|
||||
while (types->length) {
|
||||
struct swaynag_type *type = types->items[0];
|
||||
swaynag_type_free(type);
|
||||
list_del(types, 0);
|
||||
for (int i = 0; i < types->length; ++i) {
|
||||
swaynag_type_free(types->items[i]);
|
||||
}
|
||||
list_free(types);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue