From d6cd79c342495738fc23fbfbf19a01e73cdc42dc Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 17 Aug 2018 19:48:34 +1000 Subject: Implement iterators per container type This introduces the following `for_each` functions: * root_for_each_workspace * root_for_each_container * output_for_each_workspace * output_for_each_container * workspace_for_each_container And introduces the following `find` functions: * root_find_output * root_find_workspace * root_find_container * output_find_workspace * output_find_container * workspace_find_container * container_find_child And removes the following functions: * container_descendants * container_for_each_descendant * container_find This change is preparing the way for demoting sway_container. Eventually these functions will accept and return sway_outputs, sway_workspaces and sway_containers (meaning a C_CONTAINER or C_VIEW). This change also makes it easy to handle abnormalities like the workspace floating list, root's scratchpad list and (once implemented) root's saved workspaces list for when there's no connected outputs. --- include/sway/output.h | 12 ++++++++++++ include/sway/tree/container.h | 11 ++--------- include/sway/tree/root.h | 15 +++++++++++++++ include/sway/tree/workspace.h | 6 ++++++ 4 files changed, 35 insertions(+), 9 deletions(-) (limited to 'include/sway') diff --git a/include/sway/output.h b/include/sway/output.h index 8bdd1919..d0d034b3 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -95,4 +95,16 @@ void output_drag_icons_for_each_surface(struct sway_output *output, struct wl_list *drag_icons, sway_surface_iterator_func_t iterator, void *user_data); +void output_for_each_workspace(struct sway_container *output, + void (*f)(struct sway_container *con, void *data), void *data); + +void output_for_each_container(struct sway_container *output, + void (*f)(struct sway_container *con, void *data), void *data); + +struct sway_container *output_find_workspace(struct sway_container *output, + bool (*test)(struct sway_container *con, void *data), void *data); + +struct sway_container *output_find_container(struct sway_container *output, + bool (*test)(struct sway_container *con, void *data), void *data); + #endif diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index d866ec03..c8410801 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -214,15 +214,11 @@ struct sway_container *container_destroy(struct sway_container *container); struct sway_container *container_close(struct sway_container *container); -void container_descendants(struct sway_container *root, - enum sway_container_type type, - void (*func)(struct sway_container *item, void *data), void *data); - /** * Search a container's descendants a container based on test criteria. Returns * the first container that passes the test. */ -struct sway_container *container_find(struct sway_container *container, +struct sway_container *container_find_child(struct sway_container *container, bool (*test)(struct sway_container *view, void *data), void *data); /** @@ -244,10 +240,7 @@ struct sway_container *tiling_container_at( struct sway_container *con, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy); -/** - * Apply the function for each child of the container depth first. - */ -void container_for_each_descendant(struct sway_container *container, +void container_for_each_child(struct sway_container *container, void (*f)(struct sway_container *container, void *data), void *data); /** diff --git a/include/sway/tree/root.h b/include/sway/tree/root.h index edb7c817..d1f04a96 100644 --- a/include/sway/tree/root.h +++ b/include/sway/tree/root.h @@ -58,4 +58,19 @@ struct sway_container *root_workspace_for_pid(pid_t pid); void root_record_workspace_pid(pid_t pid); +void root_for_each_workspace(void (*f)(struct sway_container *con, void *data), + void *data); + +void root_for_each_container(void (*f)(struct sway_container *con, void *data), + void *data); + +struct sway_container *root_find_output( + bool (*test)(struct sway_container *con, void *data), void *data); + +struct sway_container *root_find_workspace( + bool (*test)(struct sway_container *con, void *data), void *data); + +struct sway_container *root_find_container( + bool (*test)(struct sway_container *con, void *data), void *data); + #endif diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index 5b43ae87..c9dbb538 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -50,6 +50,12 @@ struct sway_container *workspace_output_get_highest_available( void workspace_detect_urgent(struct sway_container *workspace); +void workspace_for_each_container(struct sway_container *ws, + void (*f)(struct sway_container *con, void *data), void *data); + +struct sway_container *workspace_find_container(struct sway_container *ws, + bool (*test)(struct sway_container *con, void *data), void *data); + /** * Wrap the workspace's tiling children in a new container. * The new container will be the only direct tiling child of the workspace. -- cgit v1.2.3